mousetrap 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/mousetrap/customer.rb +33 -8
- data/lib/mousetrap/resource.rb +57 -59
- data/lib/mousetrap/subscription.rb +21 -3
- data/lib/mousetrap.rb +0 -1
- data/mousetrap.gemspec +4 -2
- data/spec/factories.rb +7 -0
- data/spec/integration/smoke_test.rb +93 -4
- data/spec/integration/spike.rb +32 -9
- data/spec/mousetrap/customer_spec.rb +195 -52
- data/spec/mousetrap/resource_spec.rb +80 -24
- data/spec/mousetrap/subscription_spec.rb +46 -7
- data/spec/support/fixtures.rb +189 -0
- metadata +4 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/mousetrap/customer.rb
CHANGED
@@ -23,12 +23,14 @@ module Mousetrap
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def attributes_for_api
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
a[:subscription] = subscription.attributes_for_api
|
30
|
-
end
|
26
|
+
# TODO: superclass?
|
27
|
+
self.class.attributes_for_api(attributes, new_record?)
|
28
|
+
end
|
31
29
|
|
30
|
+
def attributes_for_api_with_subscription
|
31
|
+
raise "Must have subscription" unless subscription
|
32
|
+
a = attributes_for_api
|
33
|
+
a[:subscription] = subscription.attributes_for_api
|
32
34
|
a
|
33
35
|
end
|
34
36
|
|
@@ -36,12 +38,31 @@ module Mousetrap
|
|
36
38
|
member_action 'cancel' unless new_record?
|
37
39
|
end
|
38
40
|
|
41
|
+
def new?
|
42
|
+
if api_customer = self.class[code]
|
43
|
+
self.id = api_customer.id
|
44
|
+
|
45
|
+
return false
|
46
|
+
else
|
47
|
+
return true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
39
51
|
def save
|
40
52
|
new? ? create : update
|
41
53
|
end
|
42
54
|
|
55
|
+
def switch_to_plan(plan_code)
|
56
|
+
raise "Can only call this on an existing CheddarGetter customer." unless exists?
|
57
|
+
|
58
|
+
attributes = { :planCode => plan_code }
|
59
|
+
self.class.put_resource('customers', 'edit-subscription', code, attributes)
|
60
|
+
|
61
|
+
# TODO: Refresh self with reload here?
|
62
|
+
end
|
63
|
+
|
43
64
|
def self.all
|
44
|
-
response = get_resources
|
65
|
+
response = get_resources 'customers'
|
45
66
|
|
46
67
|
if response['error']
|
47
68
|
if response['error'] == 'Resource not found: No customers found.'
|
@@ -102,7 +123,7 @@ module Mousetrap
|
|
102
123
|
end
|
103
124
|
|
104
125
|
def create
|
105
|
-
response = self.class.post_resource 'customers', 'new',
|
126
|
+
response = self.class.post_resource 'customers', 'new', attributes_for_api_with_subscription
|
106
127
|
|
107
128
|
raise response['error'] if response['error']
|
108
129
|
|
@@ -112,7 +133,11 @@ module Mousetrap
|
|
112
133
|
end
|
113
134
|
|
114
135
|
def update
|
115
|
-
|
136
|
+
if subscription
|
137
|
+
self.class.put_resource 'customers', 'edit', code, attributes_for_api_with_subscription
|
138
|
+
else
|
139
|
+
self.class.put_resource 'customers', 'edit-customer', code, attributes_for_api
|
140
|
+
end
|
116
141
|
end
|
117
142
|
end
|
118
143
|
end
|
data/lib/mousetrap/resource.rb
CHANGED
@@ -11,16 +11,22 @@ module Mousetrap
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.[](code)
|
14
|
+
# Example error message:
|
15
|
+
#
|
16
|
+
# { "error" => "Resource not found: Customer not found for
|
17
|
+
# code=cantfindme within productCode=MOUSETRAP_TEST"}
|
18
|
+
|
14
19
|
response = get_resource plural_resource_name, code
|
15
|
-
build_resource_from response
|
16
|
-
end
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
if response['error']
|
22
|
+
if response['error'] =~ /Resource not found/
|
23
|
+
return nil
|
24
|
+
else
|
25
|
+
raise response['error']
|
26
|
+
end
|
27
|
+
end
|
21
28
|
|
22
|
-
|
23
|
-
raise NotImplementedError, NO_BUSINESS_NEED
|
29
|
+
build_resource_from response
|
24
30
|
end
|
25
31
|
|
26
32
|
def self.destroy_all
|
@@ -28,15 +34,19 @@ module Mousetrap
|
|
28
34
|
end
|
29
35
|
|
30
36
|
def self.exists?(code)
|
31
|
-
|
37
|
+
!self[code].nil?
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.new_from_api(attributes)
|
41
|
+
new(attributes_from_api(attributes))
|
32
42
|
end
|
33
43
|
|
34
44
|
def destroy
|
35
45
|
member_action 'delete' unless new_record?
|
36
46
|
end
|
37
47
|
|
38
|
-
def exists?
|
39
|
-
|
48
|
+
def exists?
|
49
|
+
self.class.exists?(code)
|
40
50
|
end
|
41
51
|
|
42
52
|
def new?
|
@@ -45,47 +55,36 @@ module Mousetrap
|
|
45
55
|
|
46
56
|
alias new_record? new?
|
47
57
|
|
48
|
-
def self.new_from_api(attributes)
|
49
|
-
new(attributes_from_api(attributes))
|
50
|
-
end
|
51
|
-
|
52
|
-
def save
|
53
|
-
raise NotImplementedError, NO_BUSINESS_NEED
|
54
|
-
end
|
55
|
-
|
56
58
|
|
57
59
|
protected
|
58
60
|
|
59
|
-
def
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
def self.resource_path(resource, action, code = nil)
|
64
|
-
path = "/xml/#{resource}/#{action}/productCode/#{uri_encode(Mousetrap.product_code)}"
|
65
|
-
path += "/code/#{uri_encode(code)}" if code
|
66
|
-
path
|
61
|
+
def self.build_resource_from(response)
|
62
|
+
resource_attributes = extract_resources(response)
|
63
|
+
new_from_api(resource_attributes)
|
67
64
|
end
|
68
65
|
|
69
|
-
def self.
|
70
|
-
|
71
|
-
end
|
66
|
+
def self.build_resources_from(response)
|
67
|
+
resources = []
|
72
68
|
|
73
|
-
|
74
|
-
path = resource_path(resource, action, code)
|
69
|
+
response_resources = extract_resources(response)
|
75
70
|
|
76
|
-
if
|
77
|
-
|
71
|
+
if response_resources.is_a?(Array)
|
72
|
+
extract_resources(response).each do |resource_attributes|
|
73
|
+
resources << new_from_api(resource_attributes)
|
74
|
+
end
|
78
75
|
else
|
79
|
-
|
76
|
+
resources << new_from_api(response_resources)
|
80
77
|
end
|
78
|
+
|
79
|
+
resources
|
81
80
|
end
|
82
81
|
|
83
82
|
def self.delete_resource(resource, code)
|
84
83
|
member_action(resource, 'delete', code)
|
85
84
|
end
|
86
85
|
|
87
|
-
def self.
|
88
|
-
|
86
|
+
def self.extract_resources(response)
|
87
|
+
response[plural_resource_name][singular_resource_name]
|
89
88
|
end
|
90
89
|
|
91
90
|
def self.get_resource(resource, code)
|
@@ -96,42 +95,41 @@ module Mousetrap
|
|
96
95
|
get resource_path(resource, 'get')
|
97
96
|
end
|
98
97
|
|
98
|
+
def self.member_action(resource, action, code, attributes = nil)
|
99
|
+
path = resource_path(resource, action, code)
|
100
|
+
|
101
|
+
if attributes
|
102
|
+
post path, :body => attributes
|
103
|
+
else
|
104
|
+
post path
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
99
108
|
def self.post_resource(resource, action, attributes)
|
100
109
|
path = resource_path(resource, action)
|
101
110
|
post path, :body => attributes
|
102
111
|
end
|
103
112
|
|
104
|
-
def self.
|
105
|
-
|
113
|
+
def self.put_resource(resource, action, code, attributes)
|
114
|
+
member_action(resource, action, code, attributes)
|
106
115
|
end
|
107
116
|
|
108
|
-
def self.
|
109
|
-
raise
|
117
|
+
def self.raise_api_unsupported_error
|
118
|
+
raise NotImplementedError, API_UNSUPPORTED
|
110
119
|
end
|
111
120
|
|
112
|
-
def self.
|
113
|
-
|
114
|
-
|
121
|
+
def self.resource_path(resource, action, code = nil)
|
122
|
+
path = "/xml/#{resource}/#{action}/productCode/#{uri_encode(Mousetrap.product_code)}"
|
123
|
+
path += "/code/#{uri_encode(code)}" if code
|
124
|
+
path
|
115
125
|
end
|
116
126
|
|
117
|
-
def self.
|
118
|
-
|
119
|
-
|
120
|
-
response_resources = extract_resources(response)
|
121
|
-
|
122
|
-
if response_resources.is_a?(Array)
|
123
|
-
extract_resources(response).each do |resource_attributes|
|
124
|
-
resources << new_from_api(resource_attributes)
|
125
|
-
end
|
126
|
-
else
|
127
|
-
resources << new_from_api(response_resources)
|
128
|
-
end
|
129
|
-
|
130
|
-
resources
|
127
|
+
def self.uri_encode(value)
|
128
|
+
URI.encode(value.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
131
129
|
end
|
132
130
|
|
133
|
-
def
|
134
|
-
|
131
|
+
def member_action(action)
|
132
|
+
self.class.member_action(self.class.plural_resource_name, action, code)
|
135
133
|
end
|
136
134
|
end
|
137
135
|
end
|
@@ -22,8 +22,22 @@ module Mousetrap
|
|
22
22
|
:credit_card_last_four_digits,
|
23
23
|
:credit_card_type
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
def self.[](code)
|
26
|
+
raise_api_unsupported_error
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.all
|
30
|
+
raise_api_unsupported_error
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.destroy_all
|
34
|
+
raise_api_unsupported_error
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.exists?(code)
|
38
|
+
raise_api_unsupported_error
|
39
|
+
end
|
40
|
+
|
27
41
|
def attributes
|
28
42
|
{
|
29
43
|
:id => id,
|
@@ -42,7 +56,7 @@ module Mousetrap
|
|
42
56
|
end
|
43
57
|
|
44
58
|
def destroy
|
45
|
-
|
59
|
+
self.class.raise_api_unsupported_error
|
46
60
|
end
|
47
61
|
|
48
62
|
def save
|
@@ -50,6 +64,10 @@ module Mousetrap
|
|
50
64
|
self.class.put_resource('customers', 'edit-subscription', customer_code, mutated_attributes)
|
51
65
|
end
|
52
66
|
|
67
|
+
def exists?
|
68
|
+
self.class.raise_api_unsupported_error
|
69
|
+
end
|
70
|
+
|
53
71
|
def self.new_from_api(attributes)
|
54
72
|
subscription = new(attributes_from_api(attributes))
|
55
73
|
subscription.plan = Plan.new_from_api(attributes['plans']['plan'])
|
data/lib/mousetrap.rb
CHANGED
data/mousetrap.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mousetrap}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
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-16}
|
13
13
|
s.description = %q{CheddarGetter API Client in Ruby}
|
14
14
|
s.email = %q{jonlarkowski@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -39,6 +39,7 @@ Gem::Specification.new do |s|
|
|
39
39
|
"spec/mousetrap_spec.rb",
|
40
40
|
"spec/spec.opts",
|
41
41
|
"spec/spec_helper.rb",
|
42
|
+
"spec/support/fixtures.rb",
|
42
43
|
"spec/support/random_data.rb"
|
43
44
|
]
|
44
45
|
s.homepage = %q{http://github.com/hashrocket/mousetrap}
|
@@ -56,6 +57,7 @@ Gem::Specification.new do |s|
|
|
56
57
|
"spec/mousetrap/subscription_spec.rb",
|
57
58
|
"spec/mousetrap_spec.rb",
|
58
59
|
"spec/spec_helper.rb",
|
60
|
+
"spec/support/fixtures.rb",
|
59
61
|
"spec/support/random_data.rb"
|
60
62
|
]
|
61
63
|
|
data/spec/factories.rb
CHANGED
@@ -20,3 +20,10 @@ Factory.define :subscription, :class => Mousetrap::Subscription, :default_strate
|
|
20
20
|
f.credit_card_expiration_year '2012'
|
21
21
|
f.billing_zip_code '90210'
|
22
22
|
end
|
23
|
+
|
24
|
+
Factory.define :alternate_subscription, :parent => :subscription, :default_strategy => :stub do |f|
|
25
|
+
f.credit_card_number '5555555555554444'
|
26
|
+
f.credit_card_expiration_month '7'
|
27
|
+
f.credit_card_expiration_year '2013'
|
28
|
+
f.billing_zip_code '12345'
|
29
|
+
end
|
@@ -45,6 +45,41 @@ shared_examples_for "a Customer record from CheddarGetter" do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
shared_examples_for "an active Subscription record from CheddarGetter" do
|
49
|
+
describe "And I get the subscription" do
|
50
|
+
before :all do
|
51
|
+
@api_customer = Mousetrap::Customer[@customer.code]
|
52
|
+
@api_subscription = @api_customer.subscription
|
53
|
+
end
|
54
|
+
|
55
|
+
it "Then ID is set" do
|
56
|
+
@api_subscription.id.should be
|
57
|
+
end
|
58
|
+
|
59
|
+
it "Then canceled_at is not set" do
|
60
|
+
@api_subscription.canceled_at.should be_nil
|
61
|
+
end
|
62
|
+
|
63
|
+
it "Then created_at is set" do
|
64
|
+
@api_subscription.created_at.should be
|
65
|
+
end
|
66
|
+
|
67
|
+
it "Then I should see the credit card expiration" do
|
68
|
+
expiration_date_from_api = Date.parse(@api_subscription.credit_card_expiration_date)
|
69
|
+
expiration_date = Date.parse("#{@customer.subscription.credit_card_expiration_year}-#{@customer.subscription.credit_card_expiration_month}-31")
|
70
|
+
expiration_date_from_api.should == expiration_date
|
71
|
+
end
|
72
|
+
|
73
|
+
it "Then I should see the credit card last four digits" do
|
74
|
+
@api_subscription.credit_card_last_four_digits.should == @customer.subscription.credit_card_number[-4..-1]
|
75
|
+
end
|
76
|
+
|
77
|
+
it "Then I should see the credit card type" do
|
78
|
+
@api_subscription.credit_card_type.should == (@credit_card_type || 'visa')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
48
83
|
describe "The Wrapper Gem" do
|
49
84
|
describe Mousetrap::Customer do
|
50
85
|
describe ".all" do
|
@@ -74,6 +109,7 @@ describe "The Wrapper Gem" do
|
|
74
109
|
end
|
75
110
|
|
76
111
|
it_should_behave_like "a Customer record from CheddarGetter"
|
112
|
+
it_should_behave_like "an active Subscription record from CheddarGetter"
|
77
113
|
end
|
78
114
|
end
|
79
115
|
|
@@ -101,8 +137,15 @@ describe "The Wrapper Gem" do
|
|
101
137
|
describe "Given a customer" do
|
102
138
|
before :all do
|
103
139
|
@customer = Factory :new_customer
|
104
|
-
@
|
105
|
-
|
140
|
+
@api_customer = nil
|
141
|
+
|
142
|
+
if Mousetrap::Customer.all.size == 1
|
143
|
+
@api_customer = Mousetrap::Customer.all.first
|
144
|
+
@customer = @api_customer
|
145
|
+
else
|
146
|
+
@customer.save
|
147
|
+
@api_customer = Mousetrap::Customer[@customer.code]
|
148
|
+
end
|
106
149
|
end
|
107
150
|
|
108
151
|
describe "When I cancel" do
|
@@ -115,9 +158,19 @@ describe "The Wrapper Gem" do
|
|
115
158
|
@api_customer = Mousetrap::Customer[@customer.code]
|
116
159
|
end
|
117
160
|
|
118
|
-
it "Then I should see a
|
161
|
+
it "Then I should see a cancellation date on subscription" do
|
119
162
|
@api_customer.subscription.canceled_at.should be
|
120
163
|
end
|
164
|
+
|
165
|
+
describe "When I resubscribe them" do
|
166
|
+
before :all do
|
167
|
+
@customer = Factory :new_customer, :email => @api_customer.email, :code => @api_customer.email
|
168
|
+
@customer.save
|
169
|
+
end
|
170
|
+
|
171
|
+
it_should_behave_like "a Customer record from CheddarGetter"
|
172
|
+
it_should_behave_like "an active Subscription record from CheddarGetter"
|
173
|
+
end
|
121
174
|
end
|
122
175
|
end
|
123
176
|
end
|
@@ -132,7 +185,7 @@ describe "The Wrapper Gem" do
|
|
132
185
|
|
133
186
|
it_should_behave_like "a Customer record from CheddarGetter"
|
134
187
|
|
135
|
-
describe "
|
188
|
+
describe "When I save it again, with different attributes" do
|
136
189
|
before :all do
|
137
190
|
attributes = Factory.attributes_for :new_customer
|
138
191
|
@customer.first_name = attributes[:first_name]
|
@@ -143,6 +196,42 @@ describe "The Wrapper Gem" do
|
|
143
196
|
|
144
197
|
it_should_behave_like "a Customer record from CheddarGetter"
|
145
198
|
end
|
199
|
+
|
200
|
+
context "When I update subscription information" do
|
201
|
+
before :all do
|
202
|
+
@subscription = Mousetrap::Subscription.new(Factory.attributes_for(:alternate_subscription))
|
203
|
+
@credit_card_type = 'mc'
|
204
|
+
@customer.subscription = @subscription
|
205
|
+
@customer.save
|
206
|
+
end
|
207
|
+
|
208
|
+
it_should_behave_like "an active Subscription record from CheddarGetter"
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe '#switch_to_plan' do
|
214
|
+
describe "Given an existing CheddarGetter customer" do
|
215
|
+
before :all do
|
216
|
+
@customer = Factory :new_customer
|
217
|
+
@customer.save
|
218
|
+
end
|
219
|
+
|
220
|
+
describe 'When I switch plans' do
|
221
|
+
before :all do
|
222
|
+
@customer.switch_to_plan('TEST_2')
|
223
|
+
end
|
224
|
+
|
225
|
+
describe "And I get the customer" do
|
226
|
+
before :all do
|
227
|
+
@api_customer = Mousetrap::Customer[@customer.code]
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'Then they should be on the new plan' do
|
231
|
+
@api_customer.subscription.plan.code.should == 'TEST_2'
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
146
235
|
end
|
147
236
|
end
|
148
237
|
end
|
data/spec/integration/spike.rb
CHANGED
@@ -37,17 +37,40 @@ end
|
|
37
37
|
def destroy_all_customers
|
38
38
|
Mousetrap::Customer.destroy_all
|
39
39
|
end
|
40
|
+
#create_customer
|
41
|
+
|
42
|
+
destroy_all_customers
|
43
|
+
|
44
|
+
#code = "rvhljmvenp@example.com"
|
45
|
+
#api_customer = Mousetrap::Customer[code]
|
46
|
+
##puts api_customer.to_yaml
|
47
|
+
|
48
|
+
#customer = Factory :new_customer
|
49
|
+
#customer.save
|
50
|
+
#api_customer = Mousetrap::Customer[customer.code]
|
51
|
+
|
52
|
+
#puts '-' * 80
|
53
|
+
#p Mousetrap::Customer[customer.code]
|
54
|
+
|
55
|
+
#puts '-' * 80
|
56
|
+
#p Mousetrap::Customer.exists? customer.code
|
57
|
+
|
58
|
+
#puts '-' * 80
|
59
|
+
#p Mousetrap::Customer['cantfindme']
|
60
|
+
|
61
|
+
#puts '-' * 80
|
62
|
+
#p Mousetrap::Customer.exists? 'cantfindme'
|
40
63
|
|
41
64
|
# create_customer
|
42
65
|
|
43
|
-
code = 'igcuvfehrc@example.com'
|
44
|
-
api_customer = Mousetrap::Customer[code]
|
45
|
-
puts api_customer.to_yaml
|
46
|
-
puts '-' * 80
|
47
|
-
puts 'cancel'
|
48
|
-
puts api_customer.cancel
|
49
|
-
puts '-' * 80
|
50
|
-
api_customer = Mousetrap::Customer[code]
|
51
|
-
puts api_customer.to_yaml
|
66
|
+
#code = 'igcuvfehrc@example.com'
|
67
|
+
#api_customer = Mousetrap::Customer[code]
|
68
|
+
#puts api_customer.to_yaml
|
69
|
+
#puts '-' * 80
|
70
|
+
#puts 'cancel'
|
71
|
+
#puts api_customer.cancel
|
72
|
+
#puts '-' * 80
|
73
|
+
#api_customer = Mousetrap::Customer[code]
|
74
|
+
#puts api_customer.to_yaml
|
52
75
|
|
53
76
|
|
@@ -1,50 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe Mousetrap::Customer do
|
4
|
-
|
5
|
-
# customer:
|
6
|
-
# firstName: nvnawrelyv
|
7
|
-
# lastName: vklidifvfd
|
8
|
-
# email: bvvljaeegs@example.com
|
9
|
-
# code: ablntsorai@example.com
|
10
|
-
# company:
|
11
|
-
# gatewayToken:
|
12
|
-
# id: eac1cf0e-fc5b-102c-a92d-40402145ee8b
|
13
|
-
# createdDatetime: "2009-09-27T02:16:15+00:00"
|
14
|
-
# modifiedDatetime: "2009-09-27T02:16:16+00:00"
|
15
|
-
# subscriptions:
|
16
|
-
# subscription:
|
17
|
-
# gatewayToken:
|
18
|
-
# id: eac26b4e-fc5b-102c-a92d-40402145ee8b
|
19
|
-
# createdDatetime: "2009-09-27T02:16:15+00:00"
|
20
|
-
# ccType: visa
|
21
|
-
# ccLastFour: "1111"
|
22
|
-
# ccExpirationDate: "2012-12-31T00:00:00+00:00"
|
23
|
-
# canceledDatetime:
|
24
|
-
# plans:
|
25
|
-
# plan:
|
26
|
-
# name: Test
|
27
|
-
# setupChargeAmount: "0.00"
|
28
|
-
# code: TEST
|
29
|
-
# recurringChargeAmount: "42.00"
|
30
|
-
# billingFrequencyQuantity: "1"
|
31
|
-
# trialDays: "0"
|
32
|
-
# id: 5fbb9a84-e27f-102c-a92d-40402145ee8b
|
33
|
-
# billingFrequency: monthly
|
34
|
-
# createdDatetime: "2009-08-25T04:24:34+00:00"
|
35
|
-
# recurringChargeCode: TEST_RECURRING
|
36
|
-
# isActive: "1"
|
37
|
-
# billingFrequencyUnit: months
|
38
|
-
# description: Test
|
39
|
-
# billingFrequencyPer: month
|
40
|
-
# setupChargeCode: TEST_SETUP
|
41
|
-
# invoices:
|
42
|
-
# invoice:
|
43
|
-
# number: "2"
|
44
|
-
# billingDatetime: "2009-10-27T02:16:15+00:00"
|
45
|
-
# id: eac74d62-fc5b-102c-a92d-40402145ee8b
|
46
|
-
# createdDatetime: "2009-09-27T02:16:15+00:00"
|
47
|
-
# type: subscription
|
4
|
+
include Fixtures
|
48
5
|
|
49
6
|
def customer_attributes_for_api(customer)
|
50
7
|
{
|
@@ -66,7 +23,7 @@ describe Mousetrap::Customer do
|
|
66
23
|
|
67
24
|
describe "when having multiple subscriptions" do
|
68
25
|
it "returns the latest one" do
|
69
|
-
Mousetrap::Customer.new_from_api(
|
26
|
+
Mousetrap::Customer.new_from_api(full_customer).subscription.should_not be_nil
|
70
27
|
end
|
71
28
|
end
|
72
29
|
|
@@ -180,30 +137,216 @@ describe Mousetrap::Customer do
|
|
180
137
|
end
|
181
138
|
end
|
182
139
|
|
140
|
+
describe "#new?" do
|
141
|
+
it "looks up the customer on CheddarGetter" do
|
142
|
+
c = Mousetrap::Customer.new :code => 'some_customer_code'
|
143
|
+
Mousetrap::Customer.should_receive(:[]).with('some_customer_code')
|
144
|
+
c.new?
|
145
|
+
end
|
146
|
+
|
147
|
+
context "with an existing CheddarGetter record" do
|
148
|
+
before do
|
149
|
+
Mousetrap::Customer.stub(:[] => stub(:id => 'some_customer_id'))
|
150
|
+
end
|
151
|
+
|
152
|
+
it "grabs the id from CheddarGetter and assigns it locally" do
|
153
|
+
c = Mousetrap::Customer.new :code => 'some_customer_code'
|
154
|
+
c.should_receive(:id=).with('some_customer_id')
|
155
|
+
c.new?
|
156
|
+
end
|
157
|
+
|
158
|
+
it "is false" do
|
159
|
+
c = Mousetrap::Customer.new
|
160
|
+
c.should_not be_new
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "without a CheddarGetter record" do
|
165
|
+
before do
|
166
|
+
Mousetrap::Customer.stub :[] => nil
|
167
|
+
end
|
168
|
+
|
169
|
+
it "is true" do
|
170
|
+
c = Mousetrap::Customer.new
|
171
|
+
c.should be_new
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
183
176
|
describe '#save' do
|
184
177
|
context "for existing records" do
|
185
178
|
before do
|
186
179
|
@customer = Factory :existing_customer
|
180
|
+
@customer.stub :new? => false
|
187
181
|
end
|
188
182
|
|
189
|
-
|
190
|
-
|
183
|
+
context "with subscription association set up" do
|
184
|
+
it 'posts to edit action' do
|
185
|
+
attributes_for_api = customer_attributes_for_api(@customer)
|
191
186
|
|
192
|
-
|
193
|
-
|
187
|
+
# We don't send code for existing API resources.
|
188
|
+
attributes_for_api.delete(:code)
|
194
189
|
|
195
|
-
|
196
|
-
|
197
|
-
|
190
|
+
@customer.class.should_receive(:put_resource).with(
|
191
|
+
'customers', 'edit', @customer.code, attributes_for_api)
|
192
|
+
@customer.save
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context "with no subscription association" do
|
197
|
+
it 'posts to edit action' do
|
198
|
+
attributes_for_api = customer_attributes_for_api(@customer)
|
199
|
+
|
200
|
+
# We don't send code for existing API resources.
|
201
|
+
attributes_for_api.delete(:code)
|
202
|
+
|
203
|
+
attributes_for_api.delete(:subscription)
|
204
|
+
@customer.subscription = nil
|
205
|
+
|
206
|
+
@customer.class.should_receive(:put_resource).with(
|
207
|
+
'customers', 'edit-customer', @customer.code, attributes_for_api)
|
208
|
+
@customer.save
|
209
|
+
end
|
198
210
|
end
|
199
211
|
end
|
200
212
|
|
201
213
|
context "for new records" do
|
202
214
|
it 'calls create' do
|
203
215
|
customer = Factory :new_customer
|
216
|
+
customer.stub :new? => true
|
217
|
+
Mousetrap::Customer.stub :exists? => false
|
204
218
|
customer.should_receive(:create)
|
205
219
|
customer.save
|
206
220
|
end
|
207
221
|
end
|
208
222
|
end
|
223
|
+
|
224
|
+
describe "#switch_to_plan" do
|
225
|
+
it "raises an error if not existing CheddarGetter customer" do
|
226
|
+
c = Mousetrap::Customer.new :code => 'some_customer_code'
|
227
|
+
c.stub :exists? => false
|
228
|
+
expect { c.switch_to_plan 'some_plan_code' }.to raise_error(/existing/)
|
229
|
+
end
|
230
|
+
|
231
|
+
it "puts a subscription with a plan code" do
|
232
|
+
c = Mousetrap::Customer.new :code => 'some_customer_code'
|
233
|
+
c.stub :exists? => true
|
234
|
+
c.class.should_receive(:put_resource).with(
|
235
|
+
'customers', 'edit-subscription', 'some_customer_code', { :planCode => 'some_plan_code' })
|
236
|
+
c.switch_to_plan 'some_plan_code'
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
describe "protected methods" do
|
241
|
+
describe "#create" do
|
242
|
+
before do
|
243
|
+
@customer = Mousetrap::Customer.new
|
244
|
+
@customer.stub :attributes_for_api_with_subscription => 'some_attributes'
|
245
|
+
end
|
246
|
+
|
247
|
+
it "posts a new customer" do
|
248
|
+
@customer.class.should_receive(:post_resource).with('customers', 'new', 'some_attributes').and_return({:id => 'some_id'})
|
249
|
+
@customer.class.stub :build_resource_from
|
250
|
+
@customer.send :create
|
251
|
+
end
|
252
|
+
|
253
|
+
it "raises error is CheddarGetter reports one" do
|
254
|
+
@customer.class.stub :post_resource => {'error' => 'some error message'}
|
255
|
+
expect { @customer.send(:create) }.to raise_error('some error message')
|
256
|
+
end
|
257
|
+
|
258
|
+
it "builds a customer from the CheddarGetter return values" do
|
259
|
+
@customer.class.stub :post_resource => 'some response'
|
260
|
+
@customer.class.should_receive(:build_resource_from).with('some response').and_return(:id => 'some_id')
|
261
|
+
@customer.send :create
|
262
|
+
end
|
263
|
+
|
264
|
+
it "grabs the id from CheddarGetter and assigns it locally" do
|
265
|
+
@customer.class.stub :post_resource => {}
|
266
|
+
@customer.class.stub :build_resource_from => stub(:id => 'some_id')
|
267
|
+
@customer.should_receive(:id=).with('some_id')
|
268
|
+
@customer.send :create
|
269
|
+
end
|
270
|
+
|
271
|
+
it "returns the response" do
|
272
|
+
@customer.class.stub :post_resource => { :some => :response }
|
273
|
+
@customer.class.stub :build_resource_from => stub(:id => 'some_id')
|
274
|
+
@customer.send(:create).should == { :some => :response }
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
209
278
|
end
|
279
|
+
|
280
|
+
|
281
|
+
__END__
|
282
|
+
|
283
|
+
customers:
|
284
|
+
customer:
|
285
|
+
company:
|
286
|
+
lastName: cgejerpkyw
|
287
|
+
code: krylmrreef@example.com
|
288
|
+
subscriptions:
|
289
|
+
subscription:
|
290
|
+
plans:
|
291
|
+
plan:
|
292
|
+
name: Test
|
293
|
+
setupChargeAmount: "42.00"
|
294
|
+
code: TEST
|
295
|
+
recurringChargeAmount: "13.00"
|
296
|
+
billingFrequencyQuantity: "1"
|
297
|
+
trialDays: "0"
|
298
|
+
id: 8e933180-08b5-102d-a92d-40402145ee8b
|
299
|
+
billingFrequency: monthly
|
300
|
+
createdDatetime: "2009-10-12T19:28:09+00:00"
|
301
|
+
recurringChargeCode: TEST_RECURRING
|
302
|
+
isActive: "1"
|
303
|
+
billingFrequencyUnit: months
|
304
|
+
description: This is my test plan. There are many like it, but this one is mine.
|
305
|
+
billingFrequencyPer: month
|
306
|
+
setupChargeCode: TEST_SETUP
|
307
|
+
gatewayToken:
|
308
|
+
id: 7ccea6de-0a4d-102d-a92d-40402145ee8b
|
309
|
+
createdDatetime: "2009-10-14T20:08:14+00:00"
|
310
|
+
ccType: visa
|
311
|
+
ccLastFour: "1111"
|
312
|
+
ccExpirationDate: "2012-12-31T00:00:00+00:00"
|
313
|
+
canceledDatetime:
|
314
|
+
invoices:
|
315
|
+
invoice:
|
316
|
+
- number: "5"
|
317
|
+
transactions:
|
318
|
+
transaction:
|
319
|
+
response: approved
|
320
|
+
code: ""
|
321
|
+
amount: "42.00"
|
322
|
+
memo: This is a simulated transaction
|
323
|
+
id: 7ce53c78-0a4d-102d-a92d-40402145ee8b
|
324
|
+
createdDatetime: "2009-10-14T20:08:14+00:00"
|
325
|
+
transactedDatetime: "2009-10-14T20:08:14+00:00"
|
326
|
+
parentId:
|
327
|
+
charges:
|
328
|
+
charge:
|
329
|
+
code: TEST_SETUP
|
330
|
+
quantity: "1"
|
331
|
+
id: 7ce2cb6e-0a4d-102d-a92d-40402145ee8b
|
332
|
+
createdDatetime: "2009-10-14T20:08:14+00:00"
|
333
|
+
type: setup
|
334
|
+
eachAmount: "42.00"
|
335
|
+
description:
|
336
|
+
gatewayAccount:
|
337
|
+
id: ""
|
338
|
+
billingDatetime: "2009-10-14T20:08:14+00:00"
|
339
|
+
id: 7cd25072-0a4d-102d-a92d-40402145ee8b
|
340
|
+
createdDatetime: "2009-10-14T20:08:14+00:00"
|
341
|
+
type: setup
|
342
|
+
- number: "6"
|
343
|
+
billingDatetime: "2009-11-14T20:08:14+00:00"
|
344
|
+
id: 7cd4253c-0a4d-102d-a92d-40402145ee8b
|
345
|
+
createdDatetime: "2009-10-14T20:08:14+00:00"
|
346
|
+
type: subscription
|
347
|
+
gatewayToken:
|
348
|
+
id: 7ccd6e5e-0a4d-102d-a92d-40402145ee8b
|
349
|
+
createdDatetime: "2009-10-14T20:08:14+00:00"
|
350
|
+
modifiedDatetime: "2009-10-14T20:08:14+00:00"
|
351
|
+
firstName: wqaqyhjdfg
|
352
|
+
email: krylmrreef@example.com
|
@@ -62,6 +62,22 @@ describe Mousetrap::Resource do
|
|
62
62
|
it { should_not be_new_record }
|
63
63
|
it { subject.code.should == @code }
|
64
64
|
end
|
65
|
+
|
66
|
+
context "when there's errors" do
|
67
|
+
it "handles kludgy 'Resource not found' response" do
|
68
|
+
Mousetrap::Widget.stub :get_resource => {
|
69
|
+
'error' => 'Resource not found: Customer not found for code=cantfindme within productCode=MOUSETRAP_TEST'
|
70
|
+
}
|
71
|
+
Mousetrap::Widget['cantfindme'].should be_nil
|
72
|
+
end
|
73
|
+
|
74
|
+
it "raises error if response has one" do
|
75
|
+
expect do
|
76
|
+
Mousetrap::Widget.stub :get_resource => { 'error' => 'some other error' }
|
77
|
+
Mousetrap::Widget['some_resource_code'].should be_nil
|
78
|
+
end.to raise_error(RuntimeError, 'some other error')
|
79
|
+
end
|
80
|
+
end
|
65
81
|
end
|
66
82
|
|
67
83
|
describe ".destroy_all" do
|
@@ -73,6 +89,23 @@ describe Mousetrap::Resource do
|
|
73
89
|
end
|
74
90
|
end
|
75
91
|
|
92
|
+
describe ".exists?" do
|
93
|
+
it "gets by code" do
|
94
|
+
Mousetrap::Widget.should_receive(:[]).with('some_resource_code')
|
95
|
+
Mousetrap::Widget.exists? 'some_resource_code'
|
96
|
+
end
|
97
|
+
|
98
|
+
it "returns true when resource exists" do
|
99
|
+
Mousetrap::Widget.stub :[] => stub('some_widget')
|
100
|
+
Mousetrap::Widget.exists?('some_resource_code').should be_true
|
101
|
+
end
|
102
|
+
|
103
|
+
it "returns false when resource doesn't exist" do
|
104
|
+
Mousetrap::Widget.stub :[] => nil
|
105
|
+
Mousetrap::Widget.exists?('some_resource_code').should be_false
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
76
109
|
describe '#destroy' do
|
77
110
|
context "for existing records" do
|
78
111
|
it 'destroys' do
|
@@ -93,40 +126,63 @@ describe Mousetrap::Resource do
|
|
93
126
|
end
|
94
127
|
end
|
95
128
|
|
96
|
-
describe "
|
97
|
-
it "
|
98
|
-
|
99
|
-
|
129
|
+
describe "#exists?" do
|
130
|
+
it "calls .exists? with code" do
|
131
|
+
Mousetrap::Widget.should_receive(:exists?).with('some_resource_code')
|
132
|
+
r = Mousetrap::Widget.new :code => 'some_resource_code'
|
133
|
+
r.exists?
|
100
134
|
end
|
101
135
|
end
|
102
136
|
|
103
|
-
describe
|
104
|
-
it
|
105
|
-
|
106
|
-
|
137
|
+
describe '#new?' do
|
138
|
+
it 'is true if id is nil' do
|
139
|
+
s = Mousetrap::Widget.new
|
140
|
+
s.should be_new
|
107
141
|
end
|
108
|
-
end
|
109
142
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
143
|
+
it 'is false if id exists' do
|
144
|
+
s = Mousetrap::Widget.new
|
145
|
+
s.stub :id => 'some_id'
|
146
|
+
s.should_not be_new
|
114
147
|
end
|
115
148
|
end
|
116
149
|
|
117
|
-
describe "
|
118
|
-
|
119
|
-
|
120
|
-
|
150
|
+
describe "protected methods" do
|
151
|
+
describe ".delete_resource" do
|
152
|
+
it "gets /xml/<resource>/delete/productCode/<my_product_code>/code/<resource_code>" do
|
153
|
+
subject.should_receive(:post).with('/xml/widgets/delete/productCode/my_product_code/code/some_resource_code')
|
154
|
+
subject.delete_resource 'widgets', 'some_resource_code'
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe ".get_resource" do
|
159
|
+
it "gets /xml/<resource>/get/productCode/<my_product_code>/code/<resource_code>" do
|
160
|
+
subject.should_receive(:get).with('/xml/widgets/get/productCode/my_product_code/code/some%2Bresource%2Bcode')
|
161
|
+
subject.get_resource 'widgets', 'some+resource+code'
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe ".get_resources" do
|
166
|
+
it "gets /xml/<resource>/get/productCode/<my_product_code>" do
|
167
|
+
subject.should_receive(:get).with('/xml/widgets/get/productCode/my_product_code')
|
168
|
+
subject.get_resources 'widgets'
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe ".post_resource" do
|
173
|
+
it "posts to /xml/<resource>/<action>/productCode/<product_code>" do
|
174
|
+
subject.should_receive(:post).with('/xml/widgets/some_action/productCode/my_product_code', :body => 'some_hash')
|
175
|
+
subject.post_resource 'widgets', 'some_action', 'some_hash'
|
176
|
+
end
|
121
177
|
end
|
122
|
-
end
|
123
178
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
179
|
+
describe ".put_resource" do
|
180
|
+
it "puts to /xml/<resource>/<action>/productCode/<product_code>/code/<resource_code>" do
|
181
|
+
subject.should_receive(:post).with(
|
182
|
+
'/xml/widgets/some_action/productCode/my_product_code/code/some_widget_code',
|
183
|
+
:body => 'some_hash')
|
184
|
+
subject.put_resource 'widgets', 'some_action', 'some_widget_code', 'some_hash'
|
185
|
+
end
|
130
186
|
end
|
131
187
|
end
|
132
188
|
end
|
@@ -1,9 +1,5 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
|
-
FULL_CUSTOMER ={"company"=>nil, "lastName"=>"LasterName1255024322", "code"=>"1255024322", "gatewayToken"=>nil, "createdDatetime"=>"2009-10-08T17:55:30+00:00", "modifiedDatetime"=>"2009-10-08T17:55:30+00:00", "subscriptions"=>{"subscription"=>[{"ccExpirationDate"=>"2010-01-31T00:00:00+00:00", "plans"=>{"plan"=>{"name"=>"Plus", "billingFrequencyQuantity"=>"1", "code"=>"PLUS", "recurringChargeAmount"=>"49.00", "createdDatetime"=>"2009-10-06T14:54:24+00:00", "id"=>"51a912d0-03d8-102d-a92d-40402145ee8b", "isActive"=>"1", "billingFrequency"=>"monthly", "description"=>nil, "trialDays"=>"0", "setupChargeCode"=>"PLUS_SETUP", "recurringChargeCode"=>"PLUS_RECURRING", "billingFrequencyUnit"=>"months", "setupChargeAmount"=>"49.00", "billingFrequencyPer"=>"month"}}, "gatewayToken"=>nil, "createdDatetime"=>"2009-10-08T17:55:31+00:00", "ccType"=>"visa", "id"=>"f426d5ae-0583-102d-a92d-40402145ee8b", "ccLastFour"=>"2222", "canceledDatetime"=>nil, "invoices"=>{"invoice"=>{"number"=>"12", "createdDatetime"=>"2009-10-08T17:55:30+00:00", "type"=>"subscription", "billingDatetime"=>"2009-11-08T17:55:30+00:00", "id"=>"f3142928-0583-102d-a92d-40402145ee8b"}}}, {"ccExpirationDate"=>"2010-01-31T00:00:00+00:00", "plans"=>{"plan"=>{"name"=>"Basic", "billingFrequencyQuantity"=>"1", "code"=>"BASIC", "recurringChargeAmount"=>"24.00", "createdDatetime"=>"2009-10-06T14:53:49+00:00", "id"=>"3cd2e840-03d8-102d-a92d-40402145ee8b", "isActive"=>"1", "billingFrequency"=>"monthly", "description"=>nil, "trialDays"=>"0", "setupChargeCode"=>"BASIC_SETUP", "recurringChargeCode"=>"BASIC_RECURRING", "billingFrequencyUnit"=>"months", "setupChargeAmount"=>"24.00", "billingFrequencyPer"=>"month"}}, "gatewayToken"=>nil, "createdDatetime"=>"2009-10-08T17:55:30+00:00", "ccType"=>"visa", "id"=>"f30e0e94-0583-102d-a92d-40402145ee8b", "ccLastFour"=>"2222", "canceledDatetime"=>nil, "invoices"=>{"invoice"=>{"number"=>"11", "createdDatetime"=>"2009-10-08T17:55:30+00:00", "transactions"=>{"transaction"=>{"response"=>"approved", "code"=>"", "createdDatetime"=>"2009-10-08T17:55:30+00:00", "memo"=>"This is a simulated transaction", "id"=>"f327b178-0583-102d-a92d-40402145ee8b", "parentId"=>nil, "amount"=>"24.00", "transactedDatetime"=>"2009-10-08T17:55:30+00:00", "gatewayAccount"=>{"id"=>""}, "charges"=>{"charge"=>{"code"=>"BASIC_SETUP", "createdDatetime"=>"2009-10-08T17:55:30+00:00", "type"=>"setup", "quantity"=>"1", "id"=>"f325406e-0583-102d-a92d-40402145ee8b", "description"=>nil, "eachAmount"=>"24.00"}}}}, "type"=>"setup", "billingDatetime"=>"2009-10-08T17:55:30+00:00", "id"=>"f3125468-0583-102d-a92d-40402145ee8b"}}}]}, "id"=>"f30cd614-0583-102d-a92d-40402145ee8b", "firstName"=>"FirsterName1", "email"=>"example1@example.com"}
|
4
|
-
MULTIPLE_SUBSCRIPTIONS =[{"ccExpirationDate"=>"2010-01-31T00:00:00+00:00", "plans"=>{"plan"=>{"name"=>"Plus", "billingFrequencyQuantity"=>"1", "code"=>"PLUS", "recurringChargeAmount"=>"49.00", "createdDatetime"=>"2009-10-06T14:54:24+00:00", "id"=>"51a912d0-03d8-102d-a92d-40402145ee8b", "isActive"=>"1", "billingFrequency"=>"monthly", "description"=>nil, "trialDays"=>"0", "setupChargeCode"=>"PLUS_SETUP", "recurringChargeCode"=>"PLUS_RECURRING", "billingFrequencyUnit"=>"months", "setupChargeAmount"=>"49.00", "billingFrequencyPer"=>"month"}}, "gatewayToken"=>nil, "createdDatetime"=>"2009-10-08T17:55:31+00:00", "ccType"=>"visa", "id"=>"f426d5ae-0583-102d-a92d-40402145ee8b", "ccLastFour"=>"2222", "canceledDatetime"=>nil, "invoices"=>{"invoice"=>{"number"=>"12", "createdDatetime"=>"2009-10-08T17:55:30+00:00", "type"=>"subscription", "billingDatetime"=>"2009-11-08T17:55:30+00:00", "id"=>"f3142928-0583-102d-a92d-40402145ee8b"}}}, {"ccExpirationDate"=>"2010-01-31T00:00:00+00:00", "plans"=>{"plan"=>{"name"=>"Basic", "billingFrequencyQuantity"=>"1", "code"=>"BASIC", "recurringChargeAmount"=>"24.00", "createdDatetime"=>"2009-10-06T14:53:49+00:00", "id"=>"3cd2e840-03d8-102d-a92d-40402145ee8b", "isActive"=>"1", "billingFrequency"=>"monthly", "description"=>nil, "trialDays"=>"0", "setupChargeCode"=>"BASIC_SETUP", "recurringChargeCode"=>"BASIC_RECURRING", "billingFrequencyUnit"=>"months", "setupChargeAmount"=>"24.00", "billingFrequencyPer"=>"month"}}, "gatewayToken"=>nil, "createdDatetime"=>"2009-10-08T17:55:30+00:00", "ccType"=>"visa", "id"=>"f30e0e94-0583-102d-a92d-40402145ee8b", "ccLastFour"=>"2222", "canceledDatetime"=>nil, "invoices"=>{"invoice"=>{"number"=>"11", "createdDatetime"=>"2009-10-08T17:55:30+00:00", "transactions"=>{"transaction"=>{"response"=>"approved", "code"=>"", "createdDatetime"=>"2009-10-08T17:55:30+00:00", "memo"=>"This is a simulated transaction", "id"=>"f327b178-0583-102d-a92d-40402145ee8b", "parentId"=>nil, "amount"=>"24.00", "transactedDatetime"=>"2009-10-08T17:55:30+00:00", "gatewayAccount"=>{"id"=>""}, "charges"=>{"charge"=>{"code"=>"BASIC_SETUP", "createdDatetime"=>"2009-10-08T17:55:30+00:00", "type"=>"setup", "quantity"=>"1", "id"=>"f325406e-0583-102d-a92d-40402145ee8b", "description"=>nil, "eachAmount"=>"24.00"}}}}, "type"=>"setup", "billingDatetime"=>"2009-10-08T17:55:30+00:00", "id"=>"f3125468-0583-102d-a92d-40402145ee8b"}}}]
|
5
|
-
|
6
|
-
|
7
3
|
describe Mousetrap::Subscription do
|
8
4
|
# subscription:
|
9
5
|
# ccExpirationDate: "2010-01-31T00:00:00+00:00"
|
@@ -14,16 +10,50 @@ describe Mousetrap::Subscription do
|
|
14
10
|
# ccLastFour: "1111"
|
15
11
|
# canceledDatetime:
|
16
12
|
|
13
|
+
include Fixtures
|
14
|
+
|
15
|
+
describe '.[]' do
|
16
|
+
it 'raises NotImplementedError' do
|
17
|
+
expect do
|
18
|
+
Mousetrap::Subscription['some_code']
|
19
|
+
end.to raise_error(NotImplementedError, Mousetrap::API_UNSUPPORTED)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.all' do
|
24
|
+
it 'raises NotImplementedError' do
|
25
|
+
expect do
|
26
|
+
Mousetrap::Subscription.all
|
27
|
+
end.to raise_error(NotImplementedError, Mousetrap::API_UNSUPPORTED)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '.destroy_all' do
|
32
|
+
it 'raises NotImplementedError' do
|
33
|
+
expect do
|
34
|
+
Mousetrap::Subscription.destroy_all
|
35
|
+
end.to raise_error(NotImplementedError, Mousetrap::API_UNSUPPORTED)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '.exists?' do
|
40
|
+
it 'raises NotImplementedError' do
|
41
|
+
expect do
|
42
|
+
Mousetrap::Subscription.exists?('some_code')
|
43
|
+
end.to raise_error(NotImplementedError, Mousetrap::API_UNSUPPORTED)
|
44
|
+
end
|
45
|
+
end
|
17
46
|
|
18
47
|
describe "plan" do
|
19
48
|
it 'has the correct planCode populated' do
|
20
|
-
Mousetrap::Subscription.new_from_api(
|
49
|
+
Mousetrap::Subscription.new_from_api(multiple_subscriptions.first).plan.code.should == "PLUS"
|
21
50
|
end
|
22
51
|
|
23
52
|
it 'exists' do
|
24
|
-
Mousetrap::Subscription.new_from_api(
|
53
|
+
Mousetrap::Subscription.new_from_api(multiple_subscriptions.first).plan.should_not be_nil
|
25
54
|
end
|
26
55
|
end
|
56
|
+
|
27
57
|
describe '#destroy' do
|
28
58
|
it "raises a NotImplementedError" do
|
29
59
|
expect do
|
@@ -32,11 +62,20 @@ describe Mousetrap::Subscription do
|
|
32
62
|
end
|
33
63
|
end
|
34
64
|
|
35
|
-
describe '
|
65
|
+
describe '.attributes_for_api' do
|
36
66
|
it 'coerces the month to 2 digits' do
|
37
67
|
Mousetrap::Subscription.attributes_for_api(
|
38
68
|
:credit_card_expiration_month => 2
|
39
69
|
)[:ccExpMonth].should == '02'
|
40
70
|
end
|
41
71
|
end
|
72
|
+
|
73
|
+
describe '#exists?' do
|
74
|
+
it 'raises NotImplementedError' do
|
75
|
+
expect do
|
76
|
+
s = Mousetrap::Subscription.new
|
77
|
+
s.exists?
|
78
|
+
end.to raise_error(NotImplementedError, Mousetrap::API_UNSUPPORTED)
|
79
|
+
end
|
80
|
+
end
|
42
81
|
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
module Fixtures
|
2
|
+
def full_customer
|
3
|
+
{
|
4
|
+
"company"=>nil,
|
5
|
+
"lastName"=>"LasterName1255024322",
|
6
|
+
"code"=>"1255024322",
|
7
|
+
"gatewayToken"=>nil,
|
8
|
+
"createdDatetime"=>"2009-10-08T17:55:30+00:00",
|
9
|
+
"modifiedDatetime"=>"2009-10-08T17:55:30+00:00",
|
10
|
+
"subscriptions"=> {
|
11
|
+
"subscription" => [
|
12
|
+
{
|
13
|
+
"ccExpirationDate"=>"2010-01-31T00:00:00+00:00",
|
14
|
+
"plans"=> {
|
15
|
+
"plan"=> {
|
16
|
+
"name"=>"Plus",
|
17
|
+
"billingFrequencyQuantity"=>"1",
|
18
|
+
"code"=>"PLUS",
|
19
|
+
"recurringChargeAmount"=>"49.00",
|
20
|
+
"createdDatetime"=>"2009-10-06T14:54:24+00:00",
|
21
|
+
"id"=>"51a912d0-03d8-102d-a92d-40402145ee8b",
|
22
|
+
"isActive"=>"1",
|
23
|
+
"billingFrequency"=>"monthly",
|
24
|
+
"description"=>nil,
|
25
|
+
"trialDays"=>"0",
|
26
|
+
"setupChargeCode"=>"PLUS_SETUP",
|
27
|
+
"recurringChargeCode"=>"PLUS_RECURRING",
|
28
|
+
"billingFrequencyUnit"=>"months",
|
29
|
+
"setupChargeAmount"=>"49.00",
|
30
|
+
"billingFrequencyPer"=>"month"}},
|
31
|
+
"gatewayToken"=>nil,
|
32
|
+
"createdDatetime"=>"2009-10-08T17:55:31+00:00",
|
33
|
+
"ccType"=>"visa",
|
34
|
+
"id"=>"f426d5ae-0583-102d-a92d-40402145ee8b",
|
35
|
+
"ccLastFour"=>"2222",
|
36
|
+
"canceledDatetime"=>nil,
|
37
|
+
"invoices"=>
|
38
|
+
{"invoice"=>
|
39
|
+
{"number"=>"12",
|
40
|
+
"createdDatetime"=>"2009-10-08T17:55:30+00:00",
|
41
|
+
"type"=>"subscription",
|
42
|
+
"billingDatetime"=>"2009-11-08T17:55:30+00:00",
|
43
|
+
"id"=>"f3142928-0583-102d-a92d-40402145ee8b"}}},
|
44
|
+
|
45
|
+
{"ccExpirationDate"=>"2010-01-31T00:00:00+00:00",
|
46
|
+
"plans"=>
|
47
|
+
{"plan"=>
|
48
|
+
{"name"=>"Basic",
|
49
|
+
"billingFrequencyQuantity"=>"1",
|
50
|
+
"code"=>"BASIC",
|
51
|
+
"recurringChargeAmount"=>"24.00",
|
52
|
+
"createdDatetime"=>"2009-10-06T14:53:49+00:00",
|
53
|
+
"id"=>"3cd2e840-03d8-102d-a92d-40402145ee8b",
|
54
|
+
"isActive"=>"1",
|
55
|
+
"billingFrequency"=>"monthly",
|
56
|
+
"description"=>nil,
|
57
|
+
"trialDays"=>"0",
|
58
|
+
"setupChargeCode"=>"BASIC_SETUP",
|
59
|
+
"recurringChargeCode"=>"BASIC_RECURRING",
|
60
|
+
"billingFrequencyUnit"=>"months",
|
61
|
+
"setupChargeAmount"=>"24.00",
|
62
|
+
"billingFrequencyPer"=>"month"}},
|
63
|
+
"gatewayToken"=>nil,
|
64
|
+
"createdDatetime"=>"2009-10-08T17:55:30+00:00",
|
65
|
+
"ccType"=>"visa",
|
66
|
+
"id"=>"f30e0e94-0583-102d-a92d-40402145ee8b",
|
67
|
+
"ccLastFour"=>"2222",
|
68
|
+
"canceledDatetime"=>nil,
|
69
|
+
"invoices"=>
|
70
|
+
{"invoice"=>
|
71
|
+
{"number"=>"11",
|
72
|
+
"createdDatetime"=>"2009-10-08T17:55:30+00:00",
|
73
|
+
"transactions"=>
|
74
|
+
{"transaction"=>
|
75
|
+
{"response"=>"approved",
|
76
|
+
"code"=>"",
|
77
|
+
"createdDatetime"=>"2009-10-08T17:55:30+00:00",
|
78
|
+
"memo"=>"This is a simulated transaction",
|
79
|
+
"id"=>"f327b178-0583-102d-a92d-40402145ee8b",
|
80
|
+
"parentId"=>nil,
|
81
|
+
"amount"=>"24.00",
|
82
|
+
"transactedDatetime"=>"2009-10-08T17:55:30+00:00",
|
83
|
+
"gatewayAccount"=>
|
84
|
+
{"id"=>""},
|
85
|
+
"charges"=>
|
86
|
+
{"charge"=>
|
87
|
+
{"code"=>"BASIC_SETUP",
|
88
|
+
"createdDatetime"=>"2009-10-08T17:55:30+00:00",
|
89
|
+
"type"=>"setup",
|
90
|
+
"quantity"=>"1",
|
91
|
+
"id"=>"f325406e-0583-102d-a92d-40402145ee8b",
|
92
|
+
"description"=>nil,
|
93
|
+
"eachAmount"=>"24.00"}}}},
|
94
|
+
"type"=>"setup",
|
95
|
+
"billingDatetime"=>"2009-10-08T17:55:30+00:00",
|
96
|
+
"id"=>"f3125468-0583-102d-a92d-40402145ee8b"}}}]},
|
97
|
+
"id"=>"f30cd614-0583-102d-a92d-40402145ee8b",
|
98
|
+
"firstName"=>"FirsterName1",
|
99
|
+
"email"=>"example1@example.com"}
|
100
|
+
end
|
101
|
+
|
102
|
+
def multiple_subscriptions
|
103
|
+
[
|
104
|
+
{"ccExpirationDate"=>"2010-01-31T00:00:00+00:00",
|
105
|
+
"plans"=>
|
106
|
+
{"plan"=>
|
107
|
+
{"name"=>"Plus",
|
108
|
+
"billingFrequencyQuantity"=>"1",
|
109
|
+
"code"=>"PLUS",
|
110
|
+
"recurringChargeAmount"=>"49.00",
|
111
|
+
"createdDatetime"=>"2009-10-06T14:54:24+00:00",
|
112
|
+
"id"=>"51a912d0-03d8-102d-a92d-40402145ee8b",
|
113
|
+
"isActive"=>"1",
|
114
|
+
"billingFrequency"=>"monthly",
|
115
|
+
"description"=>nil,
|
116
|
+
"trialDays"=>"0",
|
117
|
+
"setupChargeCode"=>"PLUS_SETUP",
|
118
|
+
"recurringChargeCode"=>"PLUS_RECURRING",
|
119
|
+
"billingFrequencyUnit"=>"months",
|
120
|
+
"setupChargeAmount"=>"49.00",
|
121
|
+
"billingFrequencyPer"=>"month"}},
|
122
|
+
"gatewayToken"=>nil,
|
123
|
+
"createdDatetime"=>"2009-10-08T17:55:31+00:00",
|
124
|
+
"ccType"=>"visa",
|
125
|
+
"id"=>"f426d5ae-0583-102d-a92d-40402145ee8b",
|
126
|
+
"ccLastFour"=>"2222",
|
127
|
+
"canceledDatetime"=>nil,
|
128
|
+
"invoices"=>
|
129
|
+
{"invoice"=>
|
130
|
+
{"number"=>"12",
|
131
|
+
"createdDatetime"=>"2009-10-08T17:55:30+00:00",
|
132
|
+
"type"=>"subscription",
|
133
|
+
"billingDatetime"=>"2009-11-08T17:55:30+00:00",
|
134
|
+
"id"=>"f3142928-0583-102d-a92d-40402145ee8b"}}},
|
135
|
+
|
136
|
+
{"ccExpirationDate"=>"2010-01-31T00:00:00+00:00",
|
137
|
+
"plans"=>
|
138
|
+
{"plan"=>
|
139
|
+
{"name"=>"Basic",
|
140
|
+
"billingFrequencyQuantity"=>"1",
|
141
|
+
"code"=>"BASIC",
|
142
|
+
"recurringChargeAmount"=>"24.00",
|
143
|
+
"createdDatetime"=>"2009-10-06T14:53:49+00:00",
|
144
|
+
"id"=>"3cd2e840-03d8-102d-a92d-40402145ee8b",
|
145
|
+
"isActive"=>"1",
|
146
|
+
"billingFrequency"=>"monthly",
|
147
|
+
"description"=>nil,
|
148
|
+
"trialDays"=>"0",
|
149
|
+
"setupChargeCode"=>"BASIC_SETUP",
|
150
|
+
"recurringChargeCode"=>"BASIC_RECURRING",
|
151
|
+
"billingFrequencyUnit"=>"months",
|
152
|
+
"setupChargeAmount"=>"24.00",
|
153
|
+
"billingFrequencyPer"=>"month"}},
|
154
|
+
"gatewayToken"=>nil,
|
155
|
+
"createdDatetime"=>"2009-10-08T17:55:30+00:00",
|
156
|
+
"ccType"=>"visa",
|
157
|
+
"id"=>"f30e0e94-0583-102d-a92d-40402145ee8b",
|
158
|
+
"ccLastFour"=>"2222",
|
159
|
+
"canceledDatetime"=>nil,
|
160
|
+
"invoices"=>
|
161
|
+
{"invoice"=>
|
162
|
+
{"number"=>"11",
|
163
|
+
"createdDatetime"=>"2009-10-08T17:55:30+00:00",
|
164
|
+
"transactions"=>
|
165
|
+
{"transaction"=>
|
166
|
+
{"response"=>"approved",
|
167
|
+
"code"=>"",
|
168
|
+
"createdDatetime"=>"2009-10-08T17:55:30+00:00",
|
169
|
+
"memo"=>"This is a simulated transaction",
|
170
|
+
"id"=>"f327b178-0583-102d-a92d-40402145ee8b",
|
171
|
+
"parentId"=>nil,
|
172
|
+
"amount"=>"24.00",
|
173
|
+
"transactedDatetime"=>"2009-10-08T17:55:30+00:00",
|
174
|
+
"gatewayAccount"=>
|
175
|
+
{"id"=>""},
|
176
|
+
"charges"=>
|
177
|
+
{"charge"=>
|
178
|
+
{"code"=>"BASIC_SETUP",
|
179
|
+
"createdDatetime"=>"2009-10-08T17:55:30+00:00",
|
180
|
+
"type"=>"setup",
|
181
|
+
"quantity"=>"1",
|
182
|
+
"id"=>"f325406e-0583-102d-a92d-40402145ee8b",
|
183
|
+
"description"=>nil,
|
184
|
+
"eachAmount"=>"24.00"}}}},
|
185
|
+
"type"=>"setup",
|
186
|
+
"billingDatetime"=>"2009-10-08T17:55:30+00:00",
|
187
|
+
"id"=>"f3125468-0583-102d-a92d-40402145ee8b"}}}]
|
188
|
+
end
|
189
|
+
end
|
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
|
+
version: 0.4.0
|
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-16 00:00:00 -04:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- spec/mousetrap_spec.rb
|
88
88
|
- spec/spec.opts
|
89
89
|
- spec/spec_helper.rb
|
90
|
+
- spec/support/fixtures.rb
|
90
91
|
- spec/support/random_data.rb
|
91
92
|
has_rdoc: true
|
92
93
|
homepage: http://github.com/hashrocket/mousetrap
|
@@ -126,4 +127,5 @@ test_files:
|
|
126
127
|
- spec/mousetrap/subscription_spec.rb
|
127
128
|
- spec/mousetrap_spec.rb
|
128
129
|
- spec/spec_helper.rb
|
130
|
+
- spec/support/fixtures.rb
|
129
131
|
- spec/support/random_data.rb
|