madebyrocket-mousetrap 0.5.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,152 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Mousetrap::Subscription do
4
+ include Fixtures
5
+
6
+ describe '.[]' do
7
+ it 'raises NotImplementedError' do
8
+ expect do
9
+ Mousetrap::Subscription['some_code']
10
+ end.to raise_error(NotImplementedError, Mousetrap::API_UNSUPPORTED)
11
+ end
12
+ end
13
+
14
+ describe '.all' do
15
+ it 'raises NotImplementedError' do
16
+ expect do
17
+ Mousetrap::Subscription.all
18
+ end.to raise_error(NotImplementedError, Mousetrap::API_UNSUPPORTED)
19
+ end
20
+ end
21
+
22
+ describe '.destroy_all' do
23
+ it 'raises NotImplementedError' do
24
+ expect do
25
+ Mousetrap::Subscription.destroy_all
26
+ end.to raise_error(NotImplementedError, Mousetrap::API_UNSUPPORTED)
27
+ end
28
+ end
29
+
30
+ describe '.exists?' do
31
+ it 'raises NotImplementedError' do
32
+ expect do
33
+ Mousetrap::Subscription.exists?('some_code')
34
+ end.to raise_error(NotImplementedError, Mousetrap::API_UNSUPPORTED)
35
+ end
36
+ end
37
+
38
+ describe "plan" do
39
+ it 'has the correct planCode populated' do
40
+ Mousetrap::Subscription.new_from_api(multiple_subscriptions.first).plan.code.should == "PLUS"
41
+ end
42
+
43
+ it 'exists' do
44
+ Mousetrap::Subscription.new_from_api(multiple_subscriptions.first).plan.should_not be_nil
45
+ end
46
+ end
47
+
48
+ describe '#destroy' do
49
+ it "raises a NotImplementedError" do
50
+ expect do
51
+ Mousetrap::Subscription.new.destroy
52
+ end.to raise_error(NotImplementedError)
53
+ end
54
+ end
55
+
56
+ describe '.attributes_for_api' do
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
71
+ end
72
+ end
73
+
74
+ describe '#exists?' do
75
+ it 'raises NotImplementedError' do
76
+ expect do
77
+ s = Mousetrap::Subscription.new
78
+ s.exists?
79
+ end.to raise_error(NotImplementedError, Mousetrap::API_UNSUPPORTED)
80
+ end
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
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:
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Mousetrap do
4
+ subject { Mousetrap }
5
+
6
+ it "stores product code" do
7
+ subject.product_code = 'my_product_code'
8
+ subject.product_code.should == 'my_product_code'
9
+ end
10
+
11
+ describe "#authenticate" do
12
+ it "sets basic auth based on the supplied user and password" do
13
+ Mousetrap::Resource.should_receive(:basic_auth).with('lark@example.com', 'abc123')
14
+ subject.authenticate 'lark@example.com', 'abc123'
15
+ end
16
+ end
17
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format nested
@@ -0,0 +1,23 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'mousetrap'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+ require 'factory_girl'
7
+ require 'active_support'
8
+
9
+ # Requires supporting files with custom matchers and macros, etc,
10
+ # in ./support/ and its subdirectories.
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12
+
13
+ module Mousetrap
14
+ class Resource
15
+ def self.get(*args)
16
+ raise 'You must stub this, or should_receive at a higher level.'
17
+ end
18
+
19
+ def self.post(*args)
20
+ raise 'You must stub this, or should_receive at a higher level.'
21
+ end
22
+ end
23
+ 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
@@ -0,0 +1,21 @@
1
+ def random_email_address
2
+ "#{random_string}@example.com"
3
+ end
4
+
5
+ def random_string
6
+ random_alpha_string_of_length(10)
7
+ end
8
+
9
+ def random_alpha_string_of_length(length)
10
+ letters = *'a'..'z'
11
+ random_string_for_uniqueness = ''
12
+ length.times { random_string_for_uniqueness += letters[rand(letters.size - 1)]}
13
+ random_string_for_uniqueness
14
+ end
15
+
16
+ def random_number_string_of_length(length)
17
+ numbers = *'0'..'9'
18
+ random_string_for_uniqueness = ''
19
+ length.times { random_string_for_uniqueness += numbers[rand(numbers.size - 1)]}
20
+ random_string_for_uniqueness
21
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: madebyrocket-mousetrap
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 5
8
+ - 3
9
+ - 7
10
+ version: 0.5.3.7
11
+ platform: ruby
12
+ authors:
13
+ - Jon Larkowski
14
+ - Sandro Turriate
15
+ - Wolfram Arnold
16
+ - Corey Grusden
17
+ autorequire:
18
+ bindir: bin
19
+ cert_chain: []
20
+
21
+ date: 2009-10-25 00:00:00 -06:00
22
+ default_executable:
23
+ dependencies:
24
+ - !ruby/object:Gem::Dependency
25
+ name: httparty
26
+ prerelease: false
27
+ requirement: &id001 !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ segments:
32
+ - 0
33
+ - 4
34
+ - 2
35
+ version: 0.4.2
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: activesupport
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 2
47
+ - 3
48
+ - 3
49
+ version: 2.3.3
50
+ type: :development
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rspec
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ segments:
60
+ - 1
61
+ - 2
62
+ - 9
63
+ version: 1.2.9
64
+ type: :development
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: factory_girl
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 1
75
+ - 2
76
+ - 3
77
+ version: 1.2.3
78
+ type: :development
79
+ version_requirements: *id004
80
+ description: CheddarGetter API Client in Ruby
81
+ email: jonlarkowski@gmail.com
82
+ executables: []
83
+
84
+ extensions: []
85
+
86
+ extra_rdoc_files:
87
+ - README.textile
88
+ files:
89
+ - .document
90
+ - .gitignore
91
+ - MIT-LICENSE
92
+ - README.textile
93
+ - Rakefile
94
+ - VERSION
95
+ - lib/mousetrap.rb
96
+ - lib/mousetrap/customer.rb
97
+ - lib/mousetrap/invoice.rb
98
+ - lib/mousetrap/plan.rb
99
+ - lib/mousetrap/resource.rb
100
+ - lib/mousetrap/subscription.rb
101
+ - mousetrap.gemspec
102
+ - script/authenticate.rb
103
+ - script/cheddar_getter.example.yml
104
+ - script/console
105
+ - spec/factories.rb
106
+ - spec/integration/settings.example.yml
107
+ - spec/integration/smoke_test.rb
108
+ - spec/integration/spike.rb
109
+ - spec/mousetrap/customer_spec.rb
110
+ - spec/mousetrap/plan_spec.rb
111
+ - spec/mousetrap/resource_spec.rb
112
+ - spec/mousetrap/subscription_spec.rb
113
+ - spec/mousetrap_spec.rb
114
+ - spec/spec.opts
115
+ - spec/spec_helper.rb
116
+ - spec/support/fixtures.rb
117
+ - spec/support/random_data.rb
118
+ has_rdoc: true
119
+ homepage: http://github.com/hashrocket/mousetrap
120
+ licenses: []
121
+
122
+ post_install_message:
123
+ rdoc_options:
124
+ - --charset=UTF-8
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ segments:
139
+ - 0
140
+ version: "0"
141
+ requirements: []
142
+
143
+ rubyforge_project:
144
+ rubygems_version: 1.3.6
145
+ signing_key:
146
+ specification_version: 3
147
+ summary: CheddarGetter API Client in Ruby
148
+ test_files:
149
+ - spec/factories.rb
150
+ - spec/integration/smoke_test.rb
151
+ - spec/integration/spike.rb
152
+ - spec/mousetrap/customer_spec.rb
153
+ - spec/mousetrap/plan_spec.rb
154
+ - spec/mousetrap/resource_spec.rb
155
+ - spec/mousetrap/subscription_spec.rb
156
+ - spec/mousetrap_spec.rb
157
+ - spec/spec_helper.rb
158
+ - spec/support/fixtures.rb
159
+ - spec/support/random_data.rb