fake_braintree 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -3
  3. data/.hound.yml +2 -0
  4. data/.javascript_ignore +2 -0
  5. data/.travis.yml +4 -1
  6. data/CONTRIBUTING.md +6 -2
  7. data/NEWS.md +16 -0
  8. data/README.md +41 -10
  9. data/Rakefile +56 -0
  10. data/asset_versions.yml +3 -0
  11. data/fake_braintree.gemspec +3 -2
  12. data/lib/fake_braintree.rb +17 -22
  13. data/lib/fake_braintree/address.rb +2 -0
  14. data/lib/fake_braintree/braintree_assets/dropin/1.7.0/braintree-dropin-internal.min.js +12 -0
  15. data/lib/fake_braintree/braintree_assets/dropin/1.7.0/braintree-dropin.css +4321 -0
  16. data/lib/fake_braintree/braintree_assets/dropin/1.7.0/images/2x-sf9a66b4f5a.png +0 -0
  17. data/lib/fake_braintree/braintree_assets/dropin/1.7.0/inline-frame.html +48 -0
  18. data/lib/fake_braintree/braintree_assets/dropin/1.7.0/modal-frame.html +25 -0
  19. data/lib/fake_braintree/braintree_assets/dropin/1.7.0/vendor/jquery-2.1.0.js +4 -0
  20. data/lib/fake_braintree/braintree_assets/dropin/1.7.0/vendor/modernizr.js +4 -0
  21. data/lib/fake_braintree/braintree_assets/dropin/1.7.0/vendor/normalize.css +339 -0
  22. data/lib/fake_braintree/client_token.rb +15 -0
  23. data/lib/fake_braintree/credit_card.rb +20 -0
  24. data/lib/fake_braintree/credit_card_serializer.rb +20 -0
  25. data/lib/fake_braintree/customer.rb +11 -3
  26. data/lib/fake_braintree/helpers.rb +3 -0
  27. data/lib/fake_braintree/merchant_account.rb +95 -0
  28. data/lib/fake_braintree/payment_method.rb +11 -0
  29. data/lib/fake_braintree/redirect.rb +6 -0
  30. data/lib/fake_braintree/registry.rb +10 -8
  31. data/lib/fake_braintree/server.rb +12 -4
  32. data/lib/fake_braintree/sinatra_app.rb +148 -14
  33. data/lib/fake_braintree/subscription.rb +48 -13
  34. data/lib/fake_braintree/transaction.rb +42 -0
  35. data/lib/fake_braintree/version.rb +1 -1
  36. data/spec/dummy/checkout_app.rb +44 -0
  37. data/spec/dummy/public/braintree.js +5 -0
  38. data/spec/dummy/public/jquery-2.1.0.js +4 -0
  39. data/spec/dummy/views/advanced_checkout.html.erb +36 -0
  40. data/spec/dummy/views/credit_cards.html.erb +16 -0
  41. data/spec/dummy/views/custom_checkout.html.erb +22 -0
  42. data/spec/dummy/views/dropin_checkout.html.erb +21 -0
  43. data/spec/fake_braintree/checkout_spec.rb +45 -0
  44. data/spec/fake_braintree/client_token_spec.rb +19 -0
  45. data/spec/fake_braintree/credit_card_spec.rb +15 -0
  46. data/spec/fake_braintree/merchant_account_spec.rb +83 -0
  47. data/spec/fake_braintree/payment_method_spec.rb +122 -0
  48. data/spec/fake_braintree/registry_spec.rb +4 -2
  49. data/spec/fake_braintree/subscription_spec.rb +51 -2
  50. data/spec/fake_braintree_spec.rb +34 -1
  51. data/spec/spec_helper.rb +11 -1
  52. data/spec/support/matchers/clear_hash_when_cleared.rb +1 -1
  53. data/spec/support/matchers/have_accessor_for.rb +1 -1
  54. data/spec/support/merchant_account_helpers.rb +24 -0
  55. data/spec/support/subscription_helpers.rb +4 -0
  56. metadata +60 -6
@@ -7,6 +7,7 @@ describe FakeBraintree::Registry do
7
7
  it { should have_hash_accessor_for(:transactions) }
8
8
  it { should have_hash_accessor_for(:redirects) }
9
9
  it { should have_hash_accessor_for(:credit_cards) }
10
+ it { should have_hash_accessor_for(:merchant_accounts) }
10
11
  end
11
12
 
12
13
  describe FakeBraintree::Registry, '#clear!' do
@@ -16,16 +17,17 @@ describe FakeBraintree::Registry, '#clear!' do
16
17
  it { should clear_hash_when_cleared(:transactions) }
17
18
  it { should clear_hash_when_cleared(:redirects) }
18
19
  it { should clear_hash_when_cleared(:credit_cards) }
20
+ it { should clear_hash_when_cleared(:merchant_accounts) }
19
21
  end
20
22
 
21
23
  describe FakeBraintree::Registry, '#failure?' do
22
24
  it 'returns false if the given CC number is not marked as a failure' do
23
- expect(FakeBraintree::Registry.new.failure?('not-a-failure')).to be_false
25
+ expect(FakeBraintree::Registry.new.failure?('not-a-failure')).to be(false)
24
26
  end
25
27
 
26
28
  it 'returns true if the given CC number is marked as a failure' do
27
29
  registry = FakeBraintree::Registry.new
28
30
  registry.failures['abc123'] = 'whatever'
29
- expect(registry.failure?('abc123')).to be_true
31
+ expect(registry.failure?('abc123')).to be(true)
30
32
  end
31
33
  end
@@ -40,6 +40,21 @@ describe 'Braintree::Subscription.create' do
40
40
  expect(FakeBraintree.registry.subscriptions[create_subscription.subscription.id]).not_to be_nil
41
41
  end
42
42
 
43
+ context 'when associated credit card' do
44
+ it 'adds this to its subscriptions' do
45
+ subscription = create_subscription.subscription
46
+ credit_card = Braintree::CreditCard.find(subscription.payment_method_token)
47
+ expect(credit_card.subscriptions.length).to eq 1
48
+
49
+ Braintree::Subscription.create(
50
+ payment_method_token: credit_card.token,
51
+ plan_id: 'my_plan_id'
52
+ )
53
+ credit_card = Braintree::CreditCard.find(subscription.payment_method_token)
54
+ expect(credit_card.subscriptions.length).to eq 2
55
+ end
56
+ end
57
+
43
58
  it 'sets the next billing date to a string of 1.month.from_now in UTC' do
44
59
  Timecop.freeze do
45
60
  expect(create_subscription.subscription.next_billing_date).to eq 1.month.from_now.strftime('%Y-%m-%d')
@@ -96,15 +111,27 @@ describe 'Braintree::Subscription.find' do
96
111
 
97
112
  it 'returns add-ons added with the subscription' do
98
113
  add_on_id = 'def456'
99
- subscription_id = create_subscription(add_ons: { add: [{ inherited_from_id: add_on_id }] }).subscription.id
114
+ subscription_id = create_subscription(add_ons: { add: [{ inherited_from_id: add_on_id, amount: 10.50 }] }).subscription.id
100
115
  subscription = Braintree::Subscription.find(subscription_id)
101
116
  add_ons = subscription.add_ons
102
117
  expect(add_ons.size).to eq 1
103
118
  expect(add_ons.first.id).to eq add_on_id
119
+ expect(add_ons.first.amount).to eq 10.50
120
+ end
121
+
122
+ it 'updates existing add-ons' do
123
+ add_on_id = 'def456'
124
+ subscription_id = create_subscription(add_ons: { add: [{ inherited_from_id: add_on_id, quantity: 2 }] }).subscription.id
125
+ update_subscription(subscription_id, add_ons: { update: [{ existing_id: add_on_id, quantity: 5 }] })
126
+ subscription = Braintree::Subscription.find(subscription_id)
127
+ add_ons = subscription.add_ons
128
+ expect(add_ons.size).to eq 1
129
+ expect(add_ons.first.id).to eq add_on_id
130
+ expect(add_ons.first.quantity).to eq 5
104
131
  end
105
132
 
106
133
  it 'returns discounts added with the subscription' do
107
- discount_id = 'def456'
134
+ discount_id = 'abc123'
108
135
  amount = BigDecimal.new('15.00')
109
136
  subscription_id = create_subscription(discounts: { add: [{ inherited_from_id: discount_id, amount: amount }]}).subscription.id
110
137
  subscription = Braintree::Subscription.find(subscription_id)
@@ -114,6 +141,17 @@ describe 'Braintree::Subscription.find' do
114
141
  expect(discounts.first.amount).to eq amount
115
142
  end
116
143
 
144
+ it 'updates existing discounts' do
145
+ discount_id = 'abc123'
146
+ subscription_id = create_subscription(discounts: { add: [{ inherited_from_id: discount_id, quantity: 2 }] }).subscription.id
147
+ update_subscription(subscription_id, discounts: { update: [{ existing_id: discount_id, quantity: 5 }] })
148
+ subscription = Braintree::Subscription.find(subscription_id)
149
+ discounts = subscription.discounts
150
+ expect(discounts.size).to eq 1
151
+ expect(discounts.first.id).to eq discount_id
152
+ expect(discounts.first.quantity).to eq 5
153
+ end
154
+
117
155
  it 'finds subscriptions created with custom id' do
118
156
  create_subscription(id: 'bob-smiths-subscription')
119
157
  expect(Braintree::Subscription.find('bob-smiths-subscription')).to be_a Braintree::Subscription
@@ -154,6 +192,17 @@ describe 'Braintree::Subscription.cancel' do
154
192
  expect(Braintree::Subscription.find(subscription_id).status).to eq Braintree::Subscription::Status::Canceled
155
193
  end
156
194
 
195
+ it 'leaves discounts and add_ons alone' do
196
+ discounts = { add: [{ inherited_from_id: 'abc123', quantity: 2 }] }
197
+ add_ons = { add: [{ inherited_from_id: 'def456', quantity: 4 }] }
198
+ subscription_id = create_subscription(discounts: discounts, add_ons: add_ons).subscription.id
199
+
200
+ expect(Braintree::Subscription.cancel(subscription_id)).to be_success
201
+ subscription = Braintree::Subscription.find(subscription_id)
202
+ expect(subscription.discounts).not_to be_empty
203
+ expect(subscription.add_ons).not_to be_empty
204
+ end
205
+
157
206
  it 'cannot cancel an unknown subscription' do
158
207
  expect { Braintree::Subscription.cancel('totally-bogus-id') }.to raise_error(Braintree::NotFoundError)
159
208
  end
@@ -1,5 +1,38 @@
1
1
  require 'spec_helper'
2
2
 
3
+ describe FakeBraintree, '.activate!' do
4
+ around do |example|
5
+ old_gateway_port = ENV['GATEWAY_PORT']
6
+ begin
7
+ example.call
8
+ ensure
9
+ ENV['GATEWAY_PORT'] = old_gateway_port
10
+ end
11
+ end
12
+
13
+ before do
14
+ # Ensure no examples will manage to actually boot another server, but
15
+ # provide them with access to the server instance.
16
+ allow_any_instance_of(Capybara::Server).to receive(:boot) do |server|
17
+ @capybara_server = server
18
+ end
19
+ end
20
+
21
+ it 'starts the server at ephemeral port assigned by Capybara::Server' do
22
+ ENV.delete 'GATEWAY_PORT'
23
+ FakeBraintree.activate!
24
+
25
+ expect(ENV['GATEWAY_PORT']).to eq(@capybara_server.port.to_s)
26
+ end
27
+
28
+ it 'starts the server at specified port' do
29
+ FakeBraintree.activate! :gateway_port => 1337
30
+
31
+ expect(@capybara_server.port).to be(1337)
32
+ expect(ENV['GATEWAY_PORT']).to eq('1337')
33
+ end
34
+ end
35
+
3
36
  describe FakeBraintree, '.decline_all_cards!' do
4
37
  before { FakeBraintree.decline_all_cards! }
5
38
 
@@ -51,7 +84,7 @@ describe FakeBraintree, '.clear_log!' do
51
84
  end
52
85
 
53
86
  it 'is called by clear!' do
54
- FakeBraintree.stub(:clear_log!)
87
+ allow(FakeBraintree).to receive(:clear_log!)
55
88
 
56
89
  FakeBraintree.clear!
57
90
 
@@ -3,13 +3,22 @@ Bundler.require
3
3
 
4
4
  require 'fake_braintree'
5
5
  require 'timecop'
6
+ require 'dummy/checkout_app'
7
+ require 'capybara-webkit'
8
+
9
+ FakeBraintree.activate!
6
10
 
7
11
  Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each {|f| require f}
8
12
 
9
13
  TEST_CC_NUMBER = %w(4111 1111 1111 1111).join
10
14
 
15
+ Capybara.app = CheckoutApp
16
+ Capybara.javascript_driver = :webkit
17
+
11
18
  RSpec.configure do |config|
12
- config.mock_with :rspec
19
+ config.mock_with :rspec do |mocks|
20
+ mocks.yield_receiver_to_any_instance_implementation_blocks = true
21
+ end
13
22
 
14
23
  config.expect_with :rspec do |c|
15
24
  c.syntax = :expect
@@ -20,6 +29,7 @@ RSpec.configure do |config|
20
29
  config.include BraintreeHelpers
21
30
  config.include CustomerHelpers
22
31
  config.include SubscriptionHelpers
32
+ config.include MerchantAccountHelpers
23
33
  config.include FakeBraintree::Helpers
24
34
 
25
35
  config.before do
@@ -5,7 +5,7 @@ RSpec::Matchers.define :clear_hash_when_cleared do |property|
5
5
  expect(object.send(property.to_sym)).to be_empty
6
6
  end
7
7
 
8
- failure_message_for_should do
8
+ failure_message do
9
9
  "Expected #{object} to clear #{property} hash after clear!, but it did not."
10
10
  end
11
11
  end
@@ -4,7 +4,7 @@ RSpec::Matchers.define :have_hash_accessor_for do |property|
4
4
  expect(object.send(property.to_sym)['key']).to eq 'value'
5
5
  end
6
6
 
7
- failure_message_for_should do
7
+ failure_message do
8
8
  "Expected #{object} to have accessor for #{property}, but it did not."
9
9
  end
10
10
  end
@@ -0,0 +1,24 @@
1
+ module MerchantAccountHelpers
2
+ def create_merchant_account
3
+ Braintree::MerchantAccount.create(
4
+ tos_accepted: true,
5
+ individual: {
6
+ first_name: 'first',
7
+ last_name: 'last',
8
+ email: 'test@test.com',
9
+ date_of_birth: '1971-01-01',
10
+ address: {
11
+ street_address: '1 E Main St',
12
+ locality: 'Chicago',
13
+ region: 'Illinois',
14
+ postal_code: '60622',
15
+ }
16
+ },
17
+ funding: {
18
+ destination: 'bank',
19
+ account_number: '9900000000',
20
+ routing_number: '021000021'
21
+ }
22
+ )
23
+ end
24
+ end
@@ -7,4 +7,8 @@ module SubscriptionHelpers
7
7
 
8
8
  Braintree::Subscription.create(options)
9
9
  end
10
+
11
+ def update_subscription(subscription_id, user_options = {})
12
+ Braintree::Subscription.update(subscription_id, user_options)
13
+ end
10
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake_braintree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoughtbot, inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-20 00:00:00.000000000 Z
11
+ date: 2015-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 2.0.3
47
+ version: 2.2.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 2.0.3
54
+ version: 2.2.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sinatra
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '2.14'
89
+ version: '3.2'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '2.14'
96
+ version: '3.2'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: timecop
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.6'
111
+ - !ruby/object:Gem::Dependency
112
+ name: capybara-webkit
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: A fake Braintree that you can run integration tests against
112
126
  email:
113
127
  - gabe@thoughtbot.com
@@ -117,6 +131,8 @@ extensions: []
117
131
  extra_rdoc_files: []
118
132
  files:
119
133
  - ".gitignore"
134
+ - ".hound.yml"
135
+ - ".javascript_ignore"
120
136
  - ".travis.yml"
121
137
  - CONTRIBUTING.md
122
138
  - GOALS
@@ -125,22 +141,47 @@ files:
125
141
  - NEWS.md
126
142
  - README.md
127
143
  - Rakefile
144
+ - asset_versions.yml
128
145
  - fake_braintree.gemspec
129
146
  - lib/fake_braintree.rb
130
147
  - lib/fake_braintree/address.rb
148
+ - lib/fake_braintree/braintree_assets/dropin/1.7.0/braintree-dropin-internal.min.js
149
+ - lib/fake_braintree/braintree_assets/dropin/1.7.0/braintree-dropin.css
150
+ - lib/fake_braintree/braintree_assets/dropin/1.7.0/images/2x-sf9a66b4f5a.png
151
+ - lib/fake_braintree/braintree_assets/dropin/1.7.0/inline-frame.html
152
+ - lib/fake_braintree/braintree_assets/dropin/1.7.0/modal-frame.html
153
+ - lib/fake_braintree/braintree_assets/dropin/1.7.0/vendor/jquery-2.1.0.js
154
+ - lib/fake_braintree/braintree_assets/dropin/1.7.0/vendor/modernizr.js
155
+ - lib/fake_braintree/braintree_assets/dropin/1.7.0/vendor/normalize.css
156
+ - lib/fake_braintree/client_token.rb
131
157
  - lib/fake_braintree/credit_card.rb
158
+ - lib/fake_braintree/credit_card_serializer.rb
132
159
  - lib/fake_braintree/customer.rb
133
160
  - lib/fake_braintree/helpers.rb
161
+ - lib/fake_braintree/merchant_account.rb
162
+ - lib/fake_braintree/payment_method.rb
134
163
  - lib/fake_braintree/redirect.rb
135
164
  - lib/fake_braintree/registry.rb
136
165
  - lib/fake_braintree/server.rb
137
166
  - lib/fake_braintree/sinatra_app.rb
138
167
  - lib/fake_braintree/subscription.rb
168
+ - lib/fake_braintree/transaction.rb
139
169
  - lib/fake_braintree/valid_credit_cards.rb
140
170
  - lib/fake_braintree/version.rb
171
+ - spec/dummy/checkout_app.rb
172
+ - spec/dummy/public/braintree.js
173
+ - spec/dummy/public/jquery-2.1.0.js
174
+ - spec/dummy/views/advanced_checkout.html.erb
175
+ - spec/dummy/views/credit_cards.html.erb
176
+ - spec/dummy/views/custom_checkout.html.erb
177
+ - spec/dummy/views/dropin_checkout.html.erb
141
178
  - spec/fake_braintree/address_spec.rb
179
+ - spec/fake_braintree/checkout_spec.rb
180
+ - spec/fake_braintree/client_token_spec.rb
142
181
  - spec/fake_braintree/credit_card_spec.rb
143
182
  - spec/fake_braintree/customer_spec.rb
183
+ - spec/fake_braintree/merchant_account_spec.rb
184
+ - spec/fake_braintree/payment_method_spec.rb
144
185
  - spec/fake_braintree/registry_spec.rb
145
186
  - spec/fake_braintree/subscription_spec.rb
146
187
  - spec/fake_braintree/transaction_spec.rb
@@ -152,6 +193,7 @@ files:
152
193
  - spec/support/customer_helpers.rb
153
194
  - spec/support/matchers/clear_hash_when_cleared.rb
154
195
  - spec/support/matchers/have_accessor_for.rb
196
+ - spec/support/merchant_account_helpers.rb
155
197
  - spec/support/subscription_helpers.rb
156
198
  homepage: ''
157
199
  licenses: []
@@ -177,9 +219,20 @@ signing_key:
177
219
  specification_version: 4
178
220
  summary: A fake Braintree that you can run integration tests against
179
221
  test_files:
222
+ - spec/dummy/checkout_app.rb
223
+ - spec/dummy/public/braintree.js
224
+ - spec/dummy/public/jquery-2.1.0.js
225
+ - spec/dummy/views/advanced_checkout.html.erb
226
+ - spec/dummy/views/credit_cards.html.erb
227
+ - spec/dummy/views/custom_checkout.html.erb
228
+ - spec/dummy/views/dropin_checkout.html.erb
180
229
  - spec/fake_braintree/address_spec.rb
230
+ - spec/fake_braintree/checkout_spec.rb
231
+ - spec/fake_braintree/client_token_spec.rb
181
232
  - spec/fake_braintree/credit_card_spec.rb
182
233
  - spec/fake_braintree/customer_spec.rb
234
+ - spec/fake_braintree/merchant_account_spec.rb
235
+ - spec/fake_braintree/payment_method_spec.rb
183
236
  - spec/fake_braintree/registry_spec.rb
184
237
  - spec/fake_braintree/subscription_spec.rb
185
238
  - spec/fake_braintree/transaction_spec.rb
@@ -191,4 +244,5 @@ test_files:
191
244
  - spec/support/customer_helpers.rb
192
245
  - spec/support/matchers/clear_hash_when_cleared.rb
193
246
  - spec/support/matchers/have_accessor_for.rb
247
+ - spec/support/merchant_account_helpers.rb
194
248
  - spec/support/subscription_helpers.rb