ryanwood-mousetrap 0.5.6

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,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ryanwood-mousetrap
3
+ version: !ruby/object:Gem::Version
4
+ hash: 7
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 5
9
+ - 6
10
+ version: 0.5.6
11
+ platform: ruby
12
+ authors:
13
+ - Jon Larkowski
14
+ - Sandro Turriate
15
+ - Wolfram Arnold
16
+ - Corey Grusden
17
+ - Cameron Cox
18
+ - Ryan Wood
19
+ autorequire:
20
+ bindir: bin
21
+ cert_chain: []
22
+
23
+ date: 2010-05-20 00:00:00 -04:00
24
+ default_executable:
25
+ dependencies:
26
+ - !ruby/object:Gem::Dependency
27
+ name: httparty
28
+ prerelease: false
29
+ requirement: &id001 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ hash: 11
35
+ segments:
36
+ - 0
37
+ - 4
38
+ - 2
39
+ version: 0.4.2
40
+ type: :runtime
41
+ version_requirements: *id001
42
+ - !ruby/object:Gem::Dependency
43
+ name: activesupport
44
+ prerelease: false
45
+ requirement: &id002 !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ hash: 5
51
+ segments:
52
+ - 2
53
+ - 3
54
+ - 3
55
+ version: 2.3.3
56
+ type: :development
57
+ version_requirements: *id002
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ prerelease: false
61
+ requirement: &id003 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 13
67
+ segments:
68
+ - 1
69
+ - 2
70
+ - 9
71
+ version: 1.2.9
72
+ type: :development
73
+ version_requirements: *id003
74
+ - !ruby/object:Gem::Dependency
75
+ name: factory_girl
76
+ prerelease: false
77
+ requirement: &id004 !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 25
83
+ segments:
84
+ - 1
85
+ - 2
86
+ - 3
87
+ version: 1.2.3
88
+ type: :development
89
+ version_requirements: *id004
90
+ description: CheddarGetter API Client in Ruby
91
+ email: ryan.wood@gmail.com
92
+ executables: []
93
+
94
+ extensions: []
95
+
96
+ extra_rdoc_files:
97
+ - README.textile
98
+ files:
99
+ - .document
100
+ - .gitignore
101
+ - MIT-LICENSE
102
+ - README.textile
103
+ - Rakefile
104
+ - VERSION
105
+ - lib/mousetrap.rb
106
+ - lib/mousetrap/customer.rb
107
+ - lib/mousetrap/invoice.rb
108
+ - lib/mousetrap/plan.rb
109
+ - lib/mousetrap/resource.rb
110
+ - lib/mousetrap/subscription.rb
111
+ - mousetrap.gemspec
112
+ - script/authenticate.rb
113
+ - script/cheddar_getter.example.yml
114
+ - script/console
115
+ - spec/factories.rb
116
+ - spec/integration/settings.example.yml
117
+ - spec/integration/smoke_test.rb
118
+ - spec/integration/spike.rb
119
+ - spec/mousetrap/customer_spec.rb
120
+ - spec/mousetrap/plan_spec.rb
121
+ - spec/mousetrap/resource_spec.rb
122
+ - spec/mousetrap/subscription_spec.rb
123
+ - spec/mousetrap_spec.rb
124
+ - spec/spec.opts
125
+ - spec/spec_helper.rb
126
+ - spec/support/fixtures.rb
127
+ - spec/support/random_data.rb
128
+ has_rdoc: true
129
+ homepage: http://github.com/ryanwood/mousetrap
130
+ licenses: []
131
+
132
+ post_install_message:
133
+ rdoc_options:
134
+ - --charset=UTF-8
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ hash: 3
143
+ segments:
144
+ - 0
145
+ version: "0"
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ hash: 3
152
+ segments:
153
+ - 0
154
+ version: "0"
155
+ requirements: []
156
+
157
+ rubyforge_project:
158
+ rubygems_version: 1.3.7
159
+ signing_key:
160
+ specification_version: 3
161
+ summary: CheddarGetter API Client in Ruby
162
+ test_files:
163
+ - spec/factories.rb
164
+ - spec/integration/smoke_test.rb
165
+ - spec/integration/spike.rb
166
+ - spec/mousetrap/customer_spec.rb
167
+ - spec/mousetrap/plan_spec.rb
168
+ - spec/mousetrap/resource_spec.rb
169
+ - spec/mousetrap/subscription_spec.rb
170
+ - spec/mousetrap_spec.rb
171
+ - spec/spec_helper.rb
172
+ - spec/support/fixtures.rb
173
+ - spec/support/random_data.rb