fake_braintree 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 90895aa7f5953a1df73fedda78c56cf804b119f5
4
+ data.tar.gz: 2f12cc8250442c5f6a6de12a6e40cf22f3f44905
5
+ SHA512:
6
+ metadata.gz: 86fd2e92a281e532424652cb7d80f2bacaf82fc7d2f75ae120d7cbe3bc1398b63fa18a05987c659e9694cbdde726d893d70c54b0c8f369e457baa09ca37d707f
7
+ data.tar.gz: 64eb83bd4581fc26e508aad73dca9b60d9a90a1df6465c62ede7495b1ed4d14fc8c9a7262a40e8267f44e60e6a46603ec80fa6fd3182d094c33d139f620f62f9
data/.travis.yml CHANGED
@@ -1,8 +1,8 @@
1
1
  rvm:
2
- - ree
3
- - 1.8.7
4
2
  - 1.9.2
5
3
  - 1.9.3
4
+ before_install:
5
+ - gem update --system
6
6
  branches:
7
7
  only:
8
8
  - master
data/NEWS.md CHANGED
@@ -1,3 +1,10 @@
1
+ # HEAD (unreleased)
2
+
3
+ * Add support for `Braintree::Address.create`
4
+ * Add support for creating a card with an existing billing address (#45)
5
+ * Transactions have a type of "sale" (#46)
6
+ * Require at least Ruby 1.9.2
7
+
1
8
  # 0.3
2
9
 
3
10
  * Braintree::Transaction.void updates the existing sale transaction instead of
data/README.md CHANGED
@@ -40,6 +40,9 @@ of them (yet).
40
40
  * `Braintree::TransparentRedirect.url`
41
41
  * `Braintree::TransparentRedirect.confirm` (only for creating customers)
42
42
 
43
+ ### Address
44
+ * `Braintree::Address.create`
45
+
43
46
  ## Quick start
44
47
  Just require the library and you're good to go:
45
48
 
@@ -102,7 +105,7 @@ This will stay "on" until you set
102
105
 
103
106
  FakeBraintree.verify_all_cards = false
104
107
 
105
- Calling FakeBraintree.clear! _will not_ change this setting. It does very basic
108
+ Calling `FakeBraintree.clear!` _will not_ change this setting. It does very basic
106
109
  verification: it only matches the credit card number against these:
107
110
  http://www.braintreepayments.com/docs/ruby/reference/sandbox and rejects them if
108
111
  they aren't one of the listed numbers.
@@ -15,6 +15,7 @@ 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
19
 
19
20
  s.add_dependency 'capybara'
20
21
  s.add_dependency 'activesupport'
@@ -24,9 +25,11 @@ Gem::Specification.new do |s|
24
25
  s.add_dependency 'thin'
25
26
 
26
27
  s.add_development_dependency 'rspec', '~> 2.12.0'
27
- s.add_development_dependency 'bourne', '~> 1.0'
28
- s.add_development_dependency 'timecop', '~> 0.3.5'
29
- s.add_development_dependency 'spork', '~> 0.9.0.rc9'
30
- s.add_development_dependency 'bundler', '>= 1.0.14'
28
+ # Capybara 2.1.0 requires 1.9.3+ so we install a version that works with
29
+ # every Ruby version we test against. This can be removed if we stop testing
30
+ # against 1.9.2.
31
+ s.add_development_dependency 'capybara', '~> 2.0.3'
32
+ s.add_development_dependency 'bourne', '~> 1.3'
33
+ s.add_development_dependency 'timecop', '~> 0.6'
31
34
  s.add_development_dependency 'rake'
32
35
  end
@@ -7,6 +7,7 @@ require 'fake_braintree/customer'
7
7
  require 'fake_braintree/subscription'
8
8
  require 'fake_braintree/redirect'
9
9
  require 'fake_braintree/credit_card'
10
+ require 'fake_braintree/address'
10
11
 
11
12
  require 'fake_braintree/registry'
12
13
  require 'fake_braintree/server'
@@ -89,7 +90,7 @@ module FakeBraintree
89
90
 
90
91
  def self.generate_transaction(options = {})
91
92
  history_item = {
92
- 'timestamp' => Time.now,
93
+ 'timestamp' => Time.now,
93
94
  'amount' => options[:amount],
94
95
  'status' => options[:status]
95
96
  }
@@ -0,0 +1,39 @@
1
+ module FakeBraintree
2
+ class Address
3
+ include Helpers
4
+
5
+ def initialize(address_hash_from_params, options)
6
+ set_up_address(address_hash_from_params, options)
7
+ end
8
+
9
+ def create
10
+ @hash['id'] = generate_id
11
+ FakeBraintree.registry.addresses[id] = @hash
12
+ customer['addresses'] << @hash
13
+ response_for_updated_address
14
+ end
15
+
16
+ def customer
17
+ FakeBraintree.registry.customers[@hash['customer_id']]
18
+ end
19
+
20
+ def response_for_updated_address
21
+ gzipped_response(200, @hash.to_xml(:root => 'address'))
22
+ end
23
+
24
+ def set_up_address(address_hash_from_params, options)
25
+ @hash = {
26
+ "merchant_id" => options[:merchant_id],
27
+ "customer_id" => options[:customer_id],
28
+ }.merge(address_hash_from_params)
29
+ end
30
+
31
+ def generate_id
32
+ "#{@hash['customer_id']}_#{customer['addresses'].size}"
33
+ end
34
+
35
+ def id
36
+ @hash['id']
37
+ end
38
+ end
39
+ end
@@ -4,6 +4,7 @@ module FakeBraintree
4
4
 
5
5
  def initialize(credit_card_hash_from_params, options)
6
6
  set_up_credit_card(credit_card_hash_from_params, options)
7
+ set_billing_address
7
8
  set_expiration_month_and_year
8
9
  end
9
10
 
@@ -104,6 +105,12 @@ module FakeBraintree
104
105
  }.merge(credit_card_hash_from_params)
105
106
  end
106
107
 
108
+ def set_billing_address
109
+ if @hash["billing_address_id"]
110
+ @hash["billing_address"] = FakeBraintree.registry.addresses[@hash['billing_address_id']]
111
+ end
112
+ end
113
+
107
114
  def set_expiration_month_and_year
108
115
  if expiration_month
109
116
  @hash['expiration_month'] = expiration_month
@@ -5,7 +5,8 @@ module FakeBraintree
5
5
  def initialize(customer_hash_from_params, options)
6
6
  @customer_hash = {
7
7
  'id' => options[:id],
8
- 'merchant_id' => options[:merchant_id]
8
+ 'merchant_id' => options[:merchant_id],
9
+ 'addresses' => []
9
10
  }
10
11
  @customer_hash.merge!(customer_hash_from_params)
11
12
  set_customer_id
@@ -4,9 +4,10 @@ class FakeBraintree::Registry
4
4
  end
5
5
 
6
6
  attr_accessor :customers,:subscriptions, :failures, :transactions, :redirects,
7
- :credit_cards
7
+ :credit_cards, :addresses
8
8
 
9
9
  def clear!
10
+ @addresses = {}
10
11
  @customers = {}
11
12
  @subscriptions = {}
12
13
  @failures = {}
@@ -51,6 +51,13 @@ module FakeBraintree
51
51
  Customer.new(customer_hash, options).delete
52
52
  end
53
53
 
54
+ # Braintree::Address.create
55
+ post "/merchants/:merchant_id/customers/:customer_id/addresses" do
56
+ address_hash = hash_from_request_body_with_key('address')
57
+ options = {:customer_id => params[:customer_id], :merchant_id => params[:merchant_id]}
58
+ Address.new(address_hash, options).create
59
+ end
60
+
54
61
  # Braintree::Subscription.create
55
62
  post '/merchants/:merchant_id/subscriptions' do
56
63
  subscription_hash = hash_from_request_body_with_key('subscription')
@@ -125,7 +132,7 @@ module FakeBraintree
125
132
  if options.fetch("submit_for_settlement", false) == true
126
133
  status = "submitted_for_settlement"
127
134
  end
128
- transaction_response = {'id' => transaction_id, 'amount' => transaction['amount'], 'status' => status}
135
+ transaction_response = {'id' => transaction_id, 'amount' => transaction['amount'], 'status' => status, 'type' => 'sale'}
129
136
  FakeBraintree.registry.transactions[transaction_id] = transaction_response
130
137
  gzipped_response(200, transaction_response.to_xml(:root => 'transaction'))
131
138
  end
@@ -1,3 +1,3 @@
1
1
  module FakeBraintree
2
- VERSION = '0.3'
2
+ VERSION = '0.4'
3
3
  end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Braintree::Address.create" do
4
+ it "successfully creates address with valid data" do
5
+ result = create_customer
6
+ result = Braintree::Address.create(:customer_id => result.customer.id, :postal_code => 30339)
7
+ result.should be_success
8
+ end
9
+ end
@@ -72,6 +72,7 @@ describe 'Braintree::CreditCard.create' do
72
72
  result.should be_success
73
73
  Braintree::Customer.find(@customer.id).credit_cards.last.token.should == 'token'
74
74
  Braintree::Customer.find(@customer.id).credit_cards.last.default?.should be_true
75
+ Braintree::Customer.find(@customer.id).credit_cards.last.billing_address.postal_code.should == "94110"
75
76
  end
76
77
 
77
78
  it 'only allows one credit card to be default' do
@@ -8,6 +8,7 @@ describe FakeBraintree::SinatraApp do
8
8
  :amount => 10.00
9
9
  )
10
10
  result.should be_success
11
+ result.transaction.type.should == 'sale'
11
12
  end
12
13
 
13
14
  context 'when all cards are declined' do
data/spec/spec_helper.rb CHANGED
@@ -1,36 +1,29 @@
1
- require 'spork'
2
-
3
- Spork.prefork do
4
- require 'rspec'
5
- require 'fake_braintree'
6
- require 'timecop'
7
- require 'bourne'
8
-
9
- def clear_braintree_log
10
- Dir.mkdir('tmp') unless File.directory?('tmp')
11
- File.new('tmp/braintree_log', 'w').close
12
- end
1
+ require 'rspec'
2
+ require 'fake_braintree'
3
+ require 'timecop'
4
+ require 'bourne'
5
+
6
+ def clear_braintree_log
7
+ Dir.mkdir('tmp') unless File.directory?('tmp')
8
+ File.new('tmp/braintree_log', 'w').close
9
+ end
13
10
 
14
- Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each {|f| require f}
11
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each {|f| require f}
15
12
 
16
- clear_braintree_log
13
+ clear_braintree_log
17
14
 
18
- TEST_CC_NUMBER = %w(4111 1111 1111 1111).join
15
+ TEST_CC_NUMBER = %w(4111 1111 1111 1111).join
19
16
 
20
- RSpec.configure do |config|
21
- config.mock_with :mocha
17
+ RSpec.configure do |config|
18
+ config.mock_with :mocha
22
19
 
23
- config.include BraintreeHelpers
24
- config.include CustomerHelpers
25
- config.include SubscriptionHelpers
26
- config.include FakeBraintree::Helpers
20
+ config.include BraintreeHelpers
21
+ config.include CustomerHelpers
22
+ config.include SubscriptionHelpers
23
+ config.include FakeBraintree::Helpers
27
24
 
28
- config.before do
29
- FakeBraintree.clear!
30
- FakeBraintree.verify_all_cards = false
31
- end
25
+ config.before do
26
+ FakeBraintree.clear!
27
+ FakeBraintree.verify_all_cards = false
32
28
  end
33
29
  end
34
-
35
- Spork.each_run do
36
- end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake_braintree
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
5
- prerelease:
4
+ version: '0.4'
6
5
  platform: ruby
7
6
  authors:
8
7
  - thoughtbot, inc.
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-29 00:00:00.000000000 Z
11
+ date: 2013-04-12 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: capybara
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: activesupport
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: i18n
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: sinatra
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ! '>='
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: braintree
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ~>
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :runtime
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ~>
92
81
  - !ruby/object:Gem::Version
@@ -94,7 +83,6 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: thin
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ! '>='
100
88
  - !ruby/object:Gem::Version
@@ -102,7 +90,6 @@ dependencies:
102
90
  type: :runtime
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - ! '>='
108
95
  - !ruby/object:Gem::Version
@@ -110,7 +97,6 @@ dependencies:
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: rspec
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
101
  - - ~>
116
102
  - !ruby/object:Gem::Version
@@ -118,79 +104,55 @@ dependencies:
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
108
  - - ~>
124
109
  - !ruby/object:Gem::Version
125
110
  version: 2.12.0
126
111
  - !ruby/object:Gem::Dependency
127
- name: bourne
112
+ name: capybara
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
115
  - - ~>
132
116
  - !ruby/object:Gem::Version
133
- version: '1.0'
117
+ version: 2.0.3
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
122
  - - ~>
140
123
  - !ruby/object:Gem::Version
141
- version: '1.0'
124
+ version: 2.0.3
142
125
  - !ruby/object:Gem::Dependency
143
- name: timecop
126
+ name: bourne
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
129
  - - ~>
148
130
  - !ruby/object:Gem::Version
149
- version: 0.3.5
131
+ version: '1.3'
150
132
  type: :development
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
136
  - - ~>
156
137
  - !ruby/object:Gem::Version
157
- version: 0.3.5
138
+ version: '1.3'
158
139
  - !ruby/object:Gem::Dependency
159
- name: spork
140
+ name: timecop
160
141
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
142
  requirements:
163
143
  - - ~>
164
144
  - !ruby/object:Gem::Version
165
- version: 0.9.0.rc9
145
+ version: '0.6'
166
146
  type: :development
167
147
  prerelease: false
168
148
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
149
  requirements:
171
150
  - - ~>
172
151
  - !ruby/object:Gem::Version
173
- version: 0.9.0.rc9
174
- - !ruby/object:Gem::Dependency
175
- name: bundler
176
- requirement: !ruby/object:Gem::Requirement
177
- none: false
178
- requirements:
179
- - - ! '>='
180
- - !ruby/object:Gem::Version
181
- version: 1.0.14
182
- type: :development
183
- prerelease: false
184
- version_requirements: !ruby/object:Gem::Requirement
185
- none: false
186
- requirements:
187
- - - ! '>='
188
- - !ruby/object:Gem::Version
189
- version: 1.0.14
152
+ version: '0.6'
190
153
  - !ruby/object:Gem::Dependency
191
154
  name: rake
192
155
  requirement: !ruby/object:Gem::Requirement
193
- none: false
194
156
  requirements:
195
157
  - - ! '>='
196
158
  - !ruby/object:Gem::Version
@@ -198,7 +160,6 @@ dependencies:
198
160
  type: :development
199
161
  prerelease: false
200
162
  version_requirements: !ruby/object:Gem::Requirement
201
- none: false
202
163
  requirements:
203
164
  - - ! '>='
204
165
  - !ruby/object:Gem::Version
@@ -222,6 +183,7 @@ files:
222
183
  - Rakefile
223
184
  - fake_braintree.gemspec
224
185
  - lib/fake_braintree.rb
186
+ - lib/fake_braintree/address.rb
225
187
  - lib/fake_braintree/credit_card.rb
226
188
  - lib/fake_braintree/customer.rb
227
189
  - lib/fake_braintree/helpers.rb
@@ -232,6 +194,7 @@ files:
232
194
  - lib/fake_braintree/subscription.rb
233
195
  - lib/fake_braintree/valid_credit_cards.rb
234
196
  - lib/fake_braintree/version.rb
197
+ - spec/fake_braintree/address_spec.rb
235
198
  - spec/fake_braintree/credit_card_spec.rb
236
199
  - spec/fake_braintree/customer_spec.rb
237
200
  - spec/fake_braintree/registry_spec.rb
@@ -247,35 +210,29 @@ files:
247
210
  - spec/support/subscription_helpers.rb
248
211
  homepage: ''
249
212
  licenses: []
213
+ metadata: {}
250
214
  post_install_message:
251
215
  rdoc_options: []
252
216
  require_paths:
253
217
  - lib
254
218
  required_ruby_version: !ruby/object:Gem::Requirement
255
- none: false
256
219
  requirements:
257
220
  - - ! '>='
258
221
  - !ruby/object:Gem::Version
259
- version: '0'
260
- segments:
261
- - 0
262
- hash: 2263458799663259679
222
+ version: 1.9.2
263
223
  required_rubygems_version: !ruby/object:Gem::Requirement
264
- none: false
265
224
  requirements:
266
225
  - - ! '>='
267
226
  - !ruby/object:Gem::Version
268
227
  version: '0'
269
- segments:
270
- - 0
271
- hash: 2263458799663259679
272
228
  requirements: []
273
229
  rubyforge_project:
274
- rubygems_version: 1.8.24
230
+ rubygems_version: 2.0.3
275
231
  signing_key:
276
- specification_version: 3
232
+ specification_version: 4
277
233
  summary: A fake Braintree that you can run integration tests against
278
234
  test_files:
235
+ - spec/fake_braintree/address_spec.rb
279
236
  - spec/fake_braintree/credit_card_spec.rb
280
237
  - spec/fake_braintree/customer_spec.rb
281
238
  - spec/fake_braintree/registry_spec.rb