mousetrap 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/VERSION +1 -1
- data/lib/mousetrap/subscription.rb +17 -6
- data/mousetrap.gemspec +8 -4
- data/script/authenticate.rb +3 -0
- data/script/cheddar_getter.example.yml +3 -0
- data/script/console +1 -0
- data/spec/integration/smoke_test.rb +26 -0
- data/spec/integration/spike.rb +22 -8
- data/spec/mousetrap/subscription_spec.rb +84 -13
- metadata +5 -2
data/.gitignore
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.3
|
@@ -59,11 +59,6 @@ module Mousetrap
|
|
59
59
|
self.class.raise_api_unsupported_error
|
60
60
|
end
|
61
61
|
|
62
|
-
def save
|
63
|
-
mutated_attributes = attributes_for_api
|
64
|
-
self.class.put_resource('customers', 'edit-subscription', customer_code, mutated_attributes)
|
65
|
-
end
|
66
|
-
|
67
62
|
def exists?
|
68
63
|
self.class.raise_api_unsupported_error
|
69
64
|
end
|
@@ -74,6 +69,22 @@ module Mousetrap
|
|
74
69
|
subscription
|
75
70
|
end
|
76
71
|
|
72
|
+
def self.update(customer_code, attributes)
|
73
|
+
mutated_attributes = attributes_for_api(attributes)
|
74
|
+
|
75
|
+
mutated_attributes.delete_if { |k, v| v.blank? }
|
76
|
+
|
77
|
+
response = put_resource(
|
78
|
+
'customers',
|
79
|
+
'edit-subscription',
|
80
|
+
customer_code,
|
81
|
+
mutated_attributes
|
82
|
+
)
|
83
|
+
|
84
|
+
raise response['error'] if response['error']
|
85
|
+
end
|
86
|
+
|
87
|
+
|
77
88
|
protected
|
78
89
|
|
79
90
|
attr_writer \
|
@@ -98,7 +109,7 @@ module Mousetrap
|
|
98
109
|
:ccFirstName => attributes[:billing_first_name],
|
99
110
|
:ccLastName => attributes[:billing_last_name],
|
100
111
|
:ccNumber => attributes[:credit_card_number],
|
101
|
-
:ccExpMonth => "%02d" % attributes[:credit_card_expiration_month],
|
112
|
+
:ccExpMonth => ("%02d" % attributes[:credit_card_expiration_month] if attributes[:credit_card_expiration_month]),
|
102
113
|
:ccExpYear => attributes[:credit_card_expiration_year],
|
103
114
|
:ccZip => attributes[:billing_zip_code],
|
104
115
|
}
|
data/mousetrap.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mousetrap}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jon Larkowski", "Sandro Turriate", "Wolfram Arnold", "Corey Grusden"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-22}
|
13
13
|
s.description = %q{CheddarGetter API Client in Ruby}
|
14
14
|
s.email = %q{jonlarkowski@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -28,6 +28,9 @@ Gem::Specification.new do |s|
|
|
28
28
|
"lib/mousetrap/resource.rb",
|
29
29
|
"lib/mousetrap/subscription.rb",
|
30
30
|
"mousetrap.gemspec",
|
31
|
+
"script/authenticate.rb",
|
32
|
+
"script/cheddar_getter.example.yml",
|
33
|
+
"script/console",
|
31
34
|
"spec/factories.rb",
|
32
35
|
"spec/integration/settings.example.yml",
|
33
36
|
"spec/integration/smoke_test.rb",
|
@@ -83,3 +86,4 @@ Gem::Specification.new do |s|
|
|
83
86
|
s.add_dependency(%q<factory_girl>, [">= 1.2.3"])
|
84
87
|
end
|
85
88
|
end
|
89
|
+
|
data/script/console
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
irb -r ubygems -r lib/mousetrap.rb -r factory_girl -r spec/support/random_data.rb -r script/authenticate.rb
|
@@ -240,4 +240,30 @@ describe "The Wrapper Gem" do
|
|
240
240
|
end
|
241
241
|
end
|
242
242
|
end
|
243
|
+
|
244
|
+
describe Mousetrap::Subscription do
|
245
|
+
describe "Given a customer on CheddarGetter" do
|
246
|
+
before :all do
|
247
|
+
@customer = Factory :new_customer
|
248
|
+
violated "Use a visa for setup" unless @customer.subscription.credit_card_number == '4111111111111111'
|
249
|
+
@customer.save
|
250
|
+
end
|
251
|
+
|
252
|
+
describe "When I update a subscription field" do
|
253
|
+
before :all do
|
254
|
+
Mousetrap::Subscription.update @customer.code, :credit_card_number => '5555555555554444'
|
255
|
+
end
|
256
|
+
|
257
|
+
describe "And I get the customer" do
|
258
|
+
before :all do
|
259
|
+
@api_customer = Mousetrap::Customer[@customer.code]
|
260
|
+
end
|
261
|
+
|
262
|
+
it 'Then I should see the updated field' do
|
263
|
+
@api_customer.subscription.credit_card_last_four_digits.should == '4444'
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
243
269
|
end
|
data/spec/integration/spike.rb
CHANGED
@@ -42,21 +42,35 @@ end
|
|
42
42
|
destroy_all_customers
|
43
43
|
customer = Factory :new_customer
|
44
44
|
customer.save
|
45
|
+
|
45
46
|
api_customer = Mousetrap::Customer[customer.code]
|
46
47
|
puts api_customer.to_yaml
|
47
48
|
puts '-' * 80
|
48
49
|
|
49
|
-
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
55
|
-
|
56
|
-
|
50
|
+
Mousetrap::Subscription.update customer.code, {
|
51
|
+
:billing_first_name => 'x',
|
52
|
+
:billing_last_name => 'y',
|
53
|
+
:credit_card_number => '5555555555554444',
|
54
|
+
:credit_card_expiration_month => '05',
|
55
|
+
:credit_card_expiration_year => '2013',
|
56
|
+
:billing_zip_code => '31415'
|
57
|
+
}
|
57
58
|
|
58
59
|
api_customer = Mousetrap::Customer[customer.code]
|
59
60
|
puts api_customer.to_yaml
|
61
|
+
puts '-' * 80
|
62
|
+
|
63
|
+
#customer_only_fields = Mousetrap::Customer.new \
|
64
|
+
#:first_name => 'first',
|
65
|
+
#:last_name => 'last',
|
66
|
+
#:company => 'company',
|
67
|
+
#:email => 'random@example.com',
|
68
|
+
#:code => customer.code
|
69
|
+
|
70
|
+
#customer_only_fields.save
|
71
|
+
|
72
|
+
#api_customer = Mousetrap::Customer[customer.code]
|
73
|
+
#puts api_customer.to_yaml
|
60
74
|
|
61
75
|
|
62
76
|
#code = "rvhljmvenp@example.com"
|
@@ -1,15 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe Mousetrap::Subscription do
|
4
|
-
# subscription:
|
5
|
-
# ccExpirationDate: "2010-01-31T00:00:00+00:00"
|
6
|
-
# gatewayToken:
|
7
|
-
# createdDatetime: "2009-08-27T15:55:51+00:00"
|
8
|
-
# ccType: visa
|
9
|
-
# id: 46ad3f1c-e472-102c-a92d-40402145ee8b
|
10
|
-
# ccLastFour: "1111"
|
11
|
-
# canceledDatetime:
|
12
|
-
|
13
4
|
include Fixtures
|
14
5
|
|
15
6
|
describe '.[]' do
|
@@ -63,10 +54,20 @@ describe Mousetrap::Subscription do
|
|
63
54
|
end
|
64
55
|
|
65
56
|
describe '.attributes_for_api' do
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
57
|
+
context "when month is set" do
|
58
|
+
it 'coerces the month to 2 digits' do
|
59
|
+
Mousetrap::Subscription.attributes_for_api(
|
60
|
+
:credit_card_expiration_month => 2
|
61
|
+
)[:ccExpMonth].should == '02'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when month is not set" do
|
66
|
+
it "is nil" do
|
67
|
+
Mousetrap::Subscription.attributes_for_api(
|
68
|
+
:credit_card_expiration_month => nil
|
69
|
+
)[:ccExpMonth].should == nil
|
70
|
+
end
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
@@ -78,4 +79,74 @@ describe Mousetrap::Subscription do
|
|
78
79
|
end.to raise_error(NotImplementedError, Mousetrap::API_UNSUPPORTED)
|
79
80
|
end
|
80
81
|
end
|
82
|
+
|
83
|
+
describe '.update' do
|
84
|
+
before do
|
85
|
+
Mousetrap::Subscription.stub :put_resource => { 'some' => 'hash' }
|
86
|
+
end
|
87
|
+
|
88
|
+
let (:mutated_attributes) do
|
89
|
+
{
|
90
|
+
:with => 'something',
|
91
|
+
:without => nil,
|
92
|
+
:also_without => ''
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
def do_update
|
97
|
+
Mousetrap::Subscription.update('some customer code', 'some attributes')
|
98
|
+
end
|
99
|
+
|
100
|
+
it "transforms the attribute names for CheddarGetter" do
|
101
|
+
Mousetrap::Subscription.should_receive(:attributes_for_api).with('some attributes').and_return({})
|
102
|
+
do_update
|
103
|
+
end
|
104
|
+
|
105
|
+
it "deletes unfilled attribute entries" do
|
106
|
+
|
107
|
+
Mousetrap::Subscription.stub :attributes_for_api => mutated_attributes
|
108
|
+
|
109
|
+
Mousetrap::Subscription.should_receive(:put_resource).with(
|
110
|
+
'customers',
|
111
|
+
'edit-subscription',
|
112
|
+
'some customer code',
|
113
|
+
{ :with => 'something' }
|
114
|
+
)
|
115
|
+
|
116
|
+
do_update
|
117
|
+
end
|
118
|
+
|
119
|
+
it "calls put_resource" do
|
120
|
+
Mousetrap::Subscription.stub :attributes_for_api => mutated_attributes
|
121
|
+
|
122
|
+
Mousetrap::Subscription.should_receive(:put_resource).with(
|
123
|
+
'customers',
|
124
|
+
'edit-subscription',
|
125
|
+
'some customer code',
|
126
|
+
{ :with => 'something' }
|
127
|
+
)
|
128
|
+
|
129
|
+
do_update
|
130
|
+
end
|
131
|
+
|
132
|
+
it "raises a CheddarGetter error if returned" do
|
133
|
+
Mousetrap::Subscription.stub \
|
134
|
+
:attributes_for_api => mutated_attributes,
|
135
|
+
:put_resource => { 'error' => 'some error message' }
|
136
|
+
|
137
|
+
expect { do_update }.to raise_error('some error message')
|
138
|
+
end
|
139
|
+
end
|
81
140
|
end
|
141
|
+
|
142
|
+
|
143
|
+
__END__
|
144
|
+
|
145
|
+
subscription:
|
146
|
+
ccExpirationDate: "2010-01-31T00:00:00+00:00"
|
147
|
+
gatewayToken:
|
148
|
+
createdDatetime: "2009-08-27T15:55:51+00:00"
|
149
|
+
ccType: visa
|
150
|
+
id: 46ad3f1c-e472-102c-a92d-40402145ee8b
|
151
|
+
ccLastFour: "1111"
|
152
|
+
canceledDatetime:
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mousetrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Larkowski
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2009-10-
|
15
|
+
date: 2009-10-22 00:00:00 -04:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
@@ -76,6 +76,9 @@ files:
|
|
76
76
|
- lib/mousetrap/resource.rb
|
77
77
|
- lib/mousetrap/subscription.rb
|
78
78
|
- mousetrap.gemspec
|
79
|
+
- script/authenticate.rb
|
80
|
+
- script/cheddar_getter.example.yml
|
81
|
+
- script/console
|
79
82
|
- spec/factories.rb
|
80
83
|
- spec/integration/settings.example.yml
|
81
84
|
- spec/integration/smoke_test.rb
|