fake_braintree 0.5.0 → 0.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e1f728169a3ebbadce2b17ce18b02573c62bebb
4
- data.tar.gz: ae270d791ae918780fc6d73876d1262b767b2d9c
3
+ metadata.gz: 0385e84347d1d92ab4951d21df8af132e73c6540
4
+ data.tar.gz: 847bcc0ae451a40e220e89a2cb22a410486a3daf
5
5
  SHA512:
6
- metadata.gz: 8760ad110627da619df7e9d01886f106d43c0e79b820185dce901aabf38c1ca563fc81f9449af1dee11bad69fcc125c3f6cc262314aefd0a24140eab68b1876d
7
- data.tar.gz: e436d08996cb0b17ef1ab0cd8668dbeb3cd44ef60717b4f69b68fe2f46dddb3d470722b7698b73f6fd7ed25bddef9c17a00312417195272fdcf8edfdba12f87f
6
+ metadata.gz: 1b4aa0f157daad2ce7d6dd98a1156a7383ccb559289d532069724374448ecf125959eb24218d2b6dfb3135f7789708a0ecd678c3577b13e653af0f0a4530348f
7
+ data.tar.gz: 985280d3c27fd84ce9719721ebe53c3a3133dfc96f213a49fffe2cb9dd9393094913bd9b032fe58dd02cb76fa3443ece70c4639ecb2846822fa15c2686541f12
data/.travis.yml CHANGED
@@ -1,12 +1,11 @@
1
1
  rvm:
2
- - 1.9.2
3
2
  - 1.9.3
4
3
  - 2.0.0
5
- - 2.1.0
6
- - 2.1.1
7
- - 2.1.2
4
+ - 2.1.4
8
5
  before_install:
9
6
  - gem update --system
10
7
  branches:
11
8
  only:
12
9
  - master
10
+ notifications:
11
+ email: false
data/Gemfile CHANGED
@@ -1,21 +1,3 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- # Web servers for different platforms
4
- platform :jruby do
5
- gem 'puma'
6
- end
7
-
8
- platform :mri do
9
- gem 'thin'
10
- end
11
-
12
3
  gemspec
13
-
14
- # Capybara 2.1.0 requires 1.9.3+ so we install a version that works with every
15
- # Ruby version we test against. This can be removed if we stop testing against
16
- # 1.9.2.
17
- gem 'capybara', '~> 2.0.3'
18
-
19
- if RUBY_VERSION == '1.9.2'
20
- gem 'activesupport', '< 4.0'
21
- end
data/NEWS.md CHANGED
@@ -1,4 +1,21 @@
1
- # HEAD
1
+ # 0.6.0
2
+
3
+ * Remove support for 1.9.2, which is EOL'd. `fake_braintree` now requires
4
+ Ruby 1.9.3+.
5
+ * Use WEBrick as the Capybara server handler in all cases. Previously we used
6
+ Thin and fell back to Puma, which caused problems like issue #54.
7
+ * Customers and Subscriptions that were stored with a custom (non-integer) ID
8
+ can be retrieved (#67)
9
+ * Braintree::Subscription has associated dates thanks to @1st8 (#66):
10
+ - `next_billing_date` is 1 month from billing period start date
11
+ - `billing_day_of_month` is the next billing date's mday, but is true to
12
+ Braintree's [exceptional handling of the 31st day of the
13
+ month](https://www.braintreepayments.com/docs/ruby/subscriptions/details#attributes_that_need_a_bit_more_explaining)
14
+ - `billing_period_start_date` is either the provided start date or today
15
+ - `billing_period_end_date` is the day before the next billing date
16
+ * Save discounts amount when adding them to a Subscription (#72)
17
+
18
+ # 0.5.0
2
19
 
3
20
  * Remove unused `i18n` gem dependency (#56).
4
21
  * Set `credit_card.card_type`, `credit_card.last_4`, and
data/README.md CHANGED
@@ -155,6 +155,31 @@ Full example:
155
155
  # "subscription_id" => "foobar"
156
156
  # }
157
157
 
158
+ Note that the generated transaction is not saved in `fake_braintree` - the
159
+ method just gives you a hash.
160
+
161
+ ## Adding your own transactions
162
+
163
+ If you want `fake_braintree` to be aware of a transaction, you can add it to the
164
+ `FakeBraintree.registry.transactions` hash like this:
165
+
166
+
167
+ ```ruby
168
+ transaction_id = "something"
169
+ example_response = { "id" => transaction_id, "amount" => "10.0", "type" => "credit", "status" => "authorized" }
170
+ FakeBraintree.registry.transactions[transaction_id] = example_response
171
+ ```
172
+
173
+ Now you can do `Braintree::Transaction.find("something")` and it will find that
174
+ transaction.
175
+
176
+ Not all of the keys in `example_response` are necessary, but you'll probably
177
+ want at least `id` and `amount`, depending on the type of response.
178
+
179
+ `FakeBraintree.registry.transactions` will be cleared when you call
180
+ `FakeBraintree.clear!`.
181
+
182
+
158
183
  ## Running the tests
159
184
 
160
185
  During tests, debug-level logs will be sent to `tmp/braintree_log`. This is
@@ -15,11 +15,11 @@ Gem::Specification.new do |s|
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ['lib']
18
- s.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
18
+ s.required_ruby_version = Gem::Requirement.new(">= 1.9.3")
19
19
 
20
20
  s.add_dependency 'activesupport'
21
21
  s.add_dependency 'braintree', '~> 2.32'
22
- s.add_dependency 'capybara'
22
+ s.add_dependency 'capybara', '>= 2.0.3'
23
23
  s.add_dependency 'sinatra'
24
24
 
25
25
  s.add_development_dependency 'rake'
@@ -1,6 +1,9 @@
1
- require 'fileutils'
2
1
  require 'braintree'
3
- require 'active_support/core_ext/module/attribute_accessors'
2
+ require 'capybara'
3
+ require 'digest/md5'
4
+ require 'fileutils'
5
+ require 'active_support/core_ext'
6
+ require 'sinatra/base'
4
7
 
5
8
  require 'fake_braintree/helpers'
6
9
  require 'fake_braintree/customer'
@@ -50,7 +50,7 @@ module FakeBraintree
50
50
  end
51
51
 
52
52
  def create_customer_with(hash)
53
- FakeBraintree.registry.customers[hash['id']] = hash
53
+ FakeBraintree.registry.customers[hash['id'].to_s] = hash
54
54
  end
55
55
 
56
56
  def add_credit_card_to_registry(new_credit_card_hash)
@@ -1,7 +1,3 @@
1
- require 'digest/md5'
2
- require 'active_support'
3
- require 'active_support/core_ext'
4
-
5
1
  module FakeBraintree
6
2
  module Helpers
7
3
  def gzip(content)
@@ -1,37 +1,7 @@
1
- require 'capybara'
2
- require 'capybara/server'
3
-
4
1
  class FakeBraintree::Server
5
-
6
2
  def boot
7
- with_runner do
8
- server = Capybara::Server.new(FakeBraintree::SinatraApp)
9
- server.boot
10
- ENV['GATEWAY_PORT'] = server.port.to_s
11
- end
12
- end
13
-
14
- private
15
-
16
- def with_runner
17
- default_server_process = Capybara.server
18
- Capybara.server do |app, port|
19
- handler.run(app, Port: port)
20
- end
21
- yield
22
- ensure
23
- Capybara.server(&default_server_process)
24
- end
25
-
26
- def handler
27
- if defined?(Thin)
28
- require 'rack/handler/thin'
29
- Rack::Handler::Thin
30
- elsif defined?(Puma)
31
- require 'rack/handler/puma'
32
- Rack::Handler::Puma
33
- else
34
- raise 'No Rack handler was defined! Please include `gem "thin"` or `gem "puma"` in your Gemfile."'
35
- end
3
+ server = Capybara::Server.new(FakeBraintree::SinatraApp)
4
+ server.boot
5
+ ENV['GATEWAY_PORT'] = server.port.to_s
36
6
  end
37
7
  end
@@ -1,5 +1,3 @@
1
- require 'sinatra/base'
2
-
3
1
  module FakeBraintree
4
2
  class SinatraApp < Sinatra::Base
5
3
  set :show_exceptions, false
@@ -33,7 +33,10 @@ module FakeBraintree
33
33
  'transactions' => [],
34
34
  'add_ons' => added_add_ons,
35
35
  'discounts' => added_discounts,
36
- 'next_billing_date' => braintree_formatted_date(1.month.from_now)
36
+ 'next_billing_date' => braintree_formatted_date(next_billing_date),
37
+ 'billing_day_of_month' => billing_day_of_month,
38
+ 'billing_period_start_date' => braintree_formatted_date(billing_period_start_date),
39
+ 'billing_period_end_date' => braintree_formatted_date(billing_period_end_date)
37
40
  )
38
41
  end
39
42
 
@@ -43,7 +46,7 @@ module FakeBraintree
43
46
  end
44
47
 
45
48
  def create_subscription_with(new_subscription_hash)
46
- FakeBraintree.registry.subscriptions[new_subscription_hash['id']] = new_subscription_hash
49
+ FakeBraintree.registry.subscriptions[new_subscription_hash['id'].to_s] = new_subscription_hash
47
50
  end
48
51
 
49
52
  def subscription_from_registry
@@ -68,12 +71,28 @@ module FakeBraintree
68
71
 
69
72
  def added_discounts
70
73
  if @subscription_hash['discounts'].is_a?(Hash) && @subscription_hash['discounts']['add']
71
- @subscription_hash['discounts']['add'].map { |discount| { 'id' => discount['inherited_from_id'] } }
74
+ @subscription_hash['discounts']['add'].map { |discount| { 'id' => discount['inherited_from_id'], 'amount' => discount['amount'] } }
72
75
  else
73
76
  []
74
77
  end
75
78
  end
76
79
 
80
+ def next_billing_date
81
+ billing_period_start_date + 1.month
82
+ end
83
+
84
+ def billing_day_of_month
85
+ next_billing_date.mday > 28 ? 31 : next_billing_date.mday
86
+ end
87
+
88
+ def billing_period_start_date
89
+ @billing_period_start_date ||= Date.today
90
+ end
91
+
92
+ def billing_period_end_date
93
+ next_billing_date - 1.day
94
+ end
95
+
77
96
  def set_subscription_id
78
97
  @subscription_hash['id'] ||= generate_new_subscription_id
79
98
  end
@@ -1,3 +1,3 @@
1
1
  module FakeBraintree
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -125,6 +125,26 @@ describe 'Braintree::Customer.find' do
125
125
  it 'raises an error for a nonexistent customer' do
126
126
  expect(lambda { Braintree::Customer.find('foo') }).to raise_error(Braintree::NotFoundError)
127
127
  end
128
+
129
+ it 'finds customer created with custom id' do
130
+ Braintree::Customer.create(
131
+ id: 'bob-smith',
132
+ first_name: 'Bob',
133
+ last_name: 'Smith'
134
+ )
135
+
136
+ expect(Braintree::Customer.find('bob-smith').first_name).to eq 'Bob'
137
+ end
138
+
139
+ it 'finds customer created with custom integer id' do
140
+ Braintree::Customer.create(
141
+ id: 1,
142
+ first_name: 'Bob',
143
+ last_name: 'Smith'
144
+ )
145
+
146
+ expect(Braintree::Customer.find(1).first_name).to eq 'Bob'
147
+ end
128
148
  end
129
149
 
130
150
  describe 'Braintree::Customer.update' do
@@ -45,6 +45,34 @@ describe 'Braintree::Subscription.create' do
45
45
  expect(create_subscription.subscription.next_billing_date).to eq 1.month.from_now.strftime('%Y-%m-%d')
46
46
  end
47
47
  end
48
+
49
+ # according to https://developers.braintreepayments.com/javascript+ruby/reference/objects/subscription#subscription.billing-day-of-month
50
+ it 'sets billing_day_of_month, keeping values in 1..28' do
51
+ Timecop.freeze(Date.new(2014, 8, 28)) do
52
+ expect(create_subscription.subscription.billing_day_of_month).to eq 28
53
+ end
54
+ end
55
+ it 'sets billing_day_of_month, forcing value to 31 if outside of 1..28' do
56
+ Timecop.freeze(Date.new(2014, 8, 29)) do
57
+ expect(create_subscription.subscription.billing_day_of_month).to eq 31
58
+ end
59
+ end
60
+
61
+ context 'without custom start date' do
62
+ around do |example|
63
+ Timecop.freeze(Date.new(2014, 8, 25), &example)
64
+ end
65
+ it 'sets billing_period_start_date to today' do
66
+ expect(create_subscription.subscription.billing_period_start_date).to eq "2014-08-25"
67
+ end
68
+ it 'sets next_billing_date to one month from now' do
69
+ expect(create_subscription.subscription.next_billing_date).to eq "2014-09-25"
70
+ end
71
+ it 'sets billing_period_end_date to one day before next_billing_date' do
72
+ expect(create_subscription.subscription.billing_period_end_date).to eq "2014-09-24"
73
+ end
74
+ end
75
+
48
76
  end
49
77
 
50
78
  describe 'Braintree::Subscription.find' do
@@ -77,11 +105,23 @@ describe 'Braintree::Subscription.find' do
77
105
 
78
106
  it 'returns discounts added with the subscription' do
79
107
  discount_id = 'def456'
80
- subscription_id = create_subscription(discounts: { add: [{ inherited_from_id: discount_id, amount: BigDecimal.new('15.00') }]}).subscription.id
108
+ amount = BigDecimal.new('15.00')
109
+ subscription_id = create_subscription(discounts: { add: [{ inherited_from_id: discount_id, amount: amount }]}).subscription.id
81
110
  subscription = Braintree::Subscription.find(subscription_id)
82
111
  discounts = subscription.discounts
83
112
  expect(discounts.size).to eq 1
84
113
  expect(discounts.first.id).to eq discount_id
114
+ expect(discounts.first.amount).to eq amount
115
+ end
116
+
117
+ it 'finds subscriptions created with custom id' do
118
+ create_subscription(id: 'bob-smiths-subscription')
119
+ expect(Braintree::Subscription.find('bob-smiths-subscription')).to be_a Braintree::Subscription
120
+ end
121
+
122
+ it 'finds subscriptions created with custom integer id' do
123
+ create_subscription(id: 1)
124
+ expect(Braintree::Subscription.find(1)).to be_a Braintree::Subscription
85
125
  end
86
126
  end
87
127
 
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'bundler'
2
2
  Bundler.require
3
3
 
4
- require 'rspec'
5
4
  require 'fake_braintree'
6
5
  require 'timecop'
7
6
 
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.5.0
4
+ version: 0.6.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-08-08 00:00:00.000000000 Z
11
+ date: 2014-11-20 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: '0'
47
+ version: 2.0.3
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: '0'
54
+ version: 2.0.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sinatra
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -164,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
164
  requirements:
165
165
  - - ">="
166
166
  - !ruby/object:Gem::Version
167
- version: 1.9.2
167
+ version: 1.9.3
168
168
  required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  requirements:
170
170
  - - ">="
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
172
  version: '0'
173
173
  requirements: []
174
174
  rubyforge_project:
175
- rubygems_version: 2.2.0
175
+ rubygems_version: 2.2.2
176
176
  signing_key:
177
177
  specification_version: 4
178
178
  summary: A fake Braintree that you can run integration tests against