fake_braintree 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,38 @@
1
+ We love pull requests. Here's a quick guide:
2
+
3
+ 1. Fork the repo.
4
+
5
+ 2. Run the tests. We only take pull requests with passing tests, and it's great
6
+ to know that you have a clean slate: `bundle && rake`
7
+
8
+ 3. Add a test for your change. Only refactoring and documentation changes
9
+ require no new tests. If you are adding functionality or fixing a bug, we need
10
+ a test!
11
+
12
+ 4. Make the test pass.
13
+
14
+ 5. Push to your fork and submit a pull request.
15
+
16
+
17
+ At this point you're waiting on us. We like to at least comment on, if not
18
+ accept, pull requests within three business days (and, typically, one business
19
+ day). We may suggest some changes or improvements or alternatives.
20
+
21
+ Some things that will increase the chance that your pull request is accepted,
22
+ taken straight from the Ruby on Rails guide:
23
+
24
+ * Use Rails idioms and helpers
25
+ * Include tests that fail without your code, and pass with it
26
+ * Update the documentation, the surrounding one, examples elsewhere, guides,
27
+ whatever is affected by your contribution
28
+
29
+ Syntax:
30
+
31
+ * Two spaces, no tabs.
32
+ * No trailing whitespace. Blank lines should not have any space.
33
+ * Prefer &&/|| over and/or.
34
+ * MyClass.my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
35
+ * a = b and not a=b.
36
+ * Follow the conventions you see used in the source already.
37
+
38
+ And in case we didn't emphasize it enough: we love tests!
data/GOALS ADDED
@@ -0,0 +1,6 @@
1
+ This project hits 1.0.0 when it supports all of the Braintree API.
2
+
3
+ We understand that this is a moving target, so future improvements will
4
+ be the addition of newly addded API endpoints (1.1.0, 1.2.0, etc.), the
5
+ removal of removed or renamed API endpoints (2.0.0, 3.0.0, etc.), and
6
+ bugfixes (1.0.1, 1.0.2, etc.).
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in gimme_brains.gemspec
3
+ # Specify your gem's dependencies in fake_braintree.gemspec
4
4
  gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+
2
+ LICENSE
3
+
4
+ The MIT License
5
+
6
+ Copyright (c) 2011-2012 thoughtbot, inc.
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
25
+
26
+
data/README.md CHANGED
@@ -1,12 +1,16 @@
1
1
  # fake\_braintree, a Braintree fake [![Build Status](https://secure.travis-ci.org/thoughtbot/fake_braintree.png)](http://travis-ci.org/thoughtbot/fake_braintree)
2
2
 
3
3
 
4
- This library is a way to test Braintree code without hitting Braintree's servers.
5
- It uses [Capybara::Server](https://github.com/jnicklas/capybara/blob/master/lib/capybara/server.rb)
6
- to intercept all of the calls from Braintree's Ruby library and returns XML that the Braintree library
7
- can parse. The whole point is not to hit the Braintree API.
4
+ This library is a way to test [Braintree](http://www.braintreepayments.com/)
5
+ code without hitting Braintree's servers. It uses
6
+ [Capybara::Server](https://github.com/jnicklas/capybara/blob/master/lib/capybara/server.rb)
7
+ to intercept all of the calls from Braintree's Ruby library and returns XML that
8
+ the Braintree library can parse. The whole point is not to hit the Braintree
9
+ API.
8
10
 
9
- Currently in alpha (i.e. it does not support every Braintree call).
11
+
12
+ It supports a lot of Braintree methods, but it does not support every single one
13
+ of them (yet).
10
14
 
11
15
  ## Supported API methods
12
16
 
@@ -153,3 +157,19 @@ Full example:
153
157
  # }],
154
158
  # "subscription_id" => "foobar"
155
159
  # }
160
+
161
+ Credits
162
+ -------
163
+
164
+ ![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
165
+
166
+ Fake Braintree is maintained and funded by [thoughtbot, inc](http://thoughtbot.com/community)
167
+
168
+ Thank you to all [the contributors](https://github.com/thoughtbot/fake_braintree/contributors)!
169
+
170
+ The names and logos for thoughtbot are trademarks of thoughtbot, inc.
171
+
172
+ License
173
+ -------
174
+
175
+ Fake Braintree is Copyright © 2011-2012 thoughtbot. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.add_dependency 'i18n'
22
22
  s.add_dependency 'sinatra'
23
23
  s.add_dependency 'braintree', '~> 2.5'
24
- s.add_dependency 'mongrel', '~> 1.2.0.pre'
24
+ s.add_dependency 'thin'
25
25
 
26
26
  s.add_development_dependency 'rspec', '~> 2.6.0'
27
27
  s.add_development_dependency 'bourne', '~> 1.0'
@@ -16,6 +16,10 @@ module FakeBraintree
16
16
  end
17
17
  end
18
18
 
19
+ def to_xml
20
+ @hash.to_xml(:root => 'credit_card')
21
+ end
22
+
19
23
  private
20
24
 
21
25
  def update_existing_credit_card
@@ -1,10 +1,10 @@
1
1
  require 'capybara'
2
2
  require 'capybara/server'
3
- require 'rack/handler/mongrel'
3
+ require 'rack/handler/thin'
4
4
 
5
5
  class FakeBraintree::Server
6
6
  def boot
7
- with_mongrel_runner do
7
+ with_thin_runner do
8
8
  server = Capybara::Server.new(FakeBraintree::SinatraApp)
9
9
  server.boot
10
10
  ENV['GATEWAY_PORT'] = server.port.to_s
@@ -13,10 +13,10 @@ class FakeBraintree::Server
13
13
 
14
14
  private
15
15
 
16
- def with_mongrel_runner
16
+ def with_thin_runner
17
17
  default_server_process = Capybara.server
18
18
  Capybara.server do |app, port|
19
- Rack::Handler::Mongrel.run(app, :Port => port)
19
+ Rack::Handler::Thin.run(app, :Port => port)
20
20
  end
21
21
  yield
22
22
  ensure
@@ -83,6 +83,20 @@ module FakeBraintree
83
83
  gzipped_response(200, credit_card.to_xml(:root => "credit_card"))
84
84
  end
85
85
 
86
+ post "/merchants/:merchant_id/payment_methods" do
87
+ opts = {
88
+ :token => md5("#{Time.now}#{rand}"),
89
+ :merchant_id => params[:merchant_id]
90
+ }
91
+ data = hash_from_request_body_with_key(request, 'credit_card')
92
+ if data[:token]
93
+ opts[:token] = data[:token]
94
+ end
95
+ credit_card = CreditCard.new(data, opts)
96
+ FakeBraintree.registry.credit_cards[opts[:token]] = credit_card
97
+ gzipped_response(200, credit_card.to_xml)
98
+ end
99
+
86
100
  # Braintree::CreditCard.update
87
101
  put "/merchants/:merchant_id/payment_methods/:credit_card_token" do
88
102
  credit_card = FakeBraintree.registry.credit_cards[params[:credit_card_token]]
@@ -115,6 +129,20 @@ module FakeBraintree
115
129
  end
116
130
  end
117
131
 
132
+ # Braintree::Transaction.refund
133
+ # Braintree::CreditCard.refund
134
+ post "/merchants/:merchant_id/transactions/:transaction_id/refund" do
135
+ if FakeBraintree.decline_all_cards?
136
+ gzipped_response(422, FakeBraintree.create_failure.to_xml(:root => 'api_error_response'))
137
+ else
138
+ transaction = hash_from_request_body_with_key(request, "transaction")
139
+ transaction_id = md5("#{params[:merchant_id]}#{Time.now.to_f}")
140
+ transaction_response = {"id" => transaction_id, "amount" => transaction["amount"], "type" => "credit"}
141
+ FakeBraintree.registry.transactions[transaction_id] = transaction_response
142
+ gzipped_response(200, transaction_response.to_xml(:root => "transaction"))
143
+ end
144
+ end
145
+
118
146
  # Braintree::TransparentRedirect.url
119
147
  post "/merchants/:merchant_id/transparent_redirect_requests" do
120
148
  if params[:tr_data]
@@ -1,3 +1,3 @@
1
1
  module FakeBraintree
2
- VERSION = "0.2.0"
2
+ VERSION = '0.2.1'
3
3
  end
@@ -14,6 +14,19 @@ describe "Braintree::CreditCard.find" do
14
14
  let(:token) { braintree_credit_card_token(TEST_CC_NUMBER, [month, year].join('/')) }
15
15
  end
16
16
 
17
+ describe "Braintree::CreditCard.create" do
18
+ let(:month) { '04' }
19
+ let(:year) { '2016' }
20
+ let(:token) { braintree_credit_card_token(TEST_CC_NUMBER, [month, year].join('/')) }
21
+ it "successfully creates card with valid data" do
22
+ result = Braintree::CreditCard.create :token => token,
23
+ :number => TEST_CC_NUMBER
24
+ result.should be_success
25
+
26
+ Braintree::CreditCard.find(token).should be
27
+ end
28
+ end
29
+
17
30
  describe "Braintree::CreditCard.sale" do
18
31
  it "successfully creates a sale" do
19
32
  result = Braintree::CreditCard.sale(cc_token, :amount => 10.00)
@@ -30,7 +30,7 @@ describe "Braintree::Subscription.create" do
30
30
 
31
31
  it "sets the next billing date to a string of 1.month.from_now in UTC" do
32
32
  Timecop.freeze do
33
- create_subscription.subscription.next_billing_date.should == 1.month.from_now.utc.strftime('%Y-%m-%d')
33
+ create_subscription.subscription.next_billing_date.should == 1.month.from_now.strftime('%Y-%m-%d')
34
34
  end
35
35
  end
36
36
  end
@@ -18,6 +18,24 @@ describe FakeBraintree::SinatraApp do
18
18
  end
19
19
  end
20
20
 
21
+ describe FakeBraintree::SinatraApp do
22
+ context "Braintree::Transaction.refund" do
23
+ it "successfully refunds a transaction" do
24
+ result = Braintree::Transaction.refund(create_id('foobar'), '1')
25
+ result.should be_success
26
+ end
27
+
28
+ context "when all cards are declined" do
29
+ before { FakeBraintree.decline_all_cards! }
30
+
31
+ it "fails" do
32
+ result = Braintree::Transaction.refund(create_id('foobar'), '1')
33
+ result.should_not be_success
34
+ end
35
+ end
36
+ end
37
+ end
38
+
21
39
  describe FakeBraintree::SinatraApp do
22
40
  context "Braintree::Transaction.find" do
23
41
  it "can find a created sale" do
@@ -23,6 +23,7 @@ Spork.prefork do
23
23
  config.include BraintreeHelpers
24
24
  config.include CustomerHelpers
25
25
  config.include SubscriptionHelpers
26
+ config.include FakeBraintree::Helpers
26
27
 
27
28
  config.before do
28
29
  FakeBraintree.clear!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake_braintree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-03 00:00:00.000000000 Z
12
+ date: 2012-09-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara
16
- requirement: &70218697304620 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70218697304620
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: activesupport
27
- requirement: &70218697303980 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70218697303980
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: i18n
38
- requirement: &70218697303320 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *70218697303320
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: sinatra
49
- requirement: &70218697315200 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :runtime
56
71
  prerelease: false
57
- version_requirements: *70218697315200
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: braintree
60
- requirement: &70218697312960 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ~>
@@ -65,21 +85,31 @@ dependencies:
65
85
  version: '2.5'
66
86
  type: :runtime
67
87
  prerelease: false
68
- version_requirements: *70218697312960
69
- - !ruby/object:Gem::Dependency
70
- name: mongrel
71
- requirement: &70218697327000 !ruby/object:Gem::Requirement
88
+ version_requirements: !ruby/object:Gem::Requirement
72
89
  none: false
73
90
  requirements:
74
91
  - - ~>
75
92
  - !ruby/object:Gem::Version
76
- version: 1.2.0.pre
93
+ version: '2.5'
94
+ - !ruby/object:Gem::Dependency
95
+ name: thin
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
77
102
  type: :runtime
78
103
  prerelease: false
79
- version_requirements: *70218697327000
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: rspec
82
- requirement: &70218697325220 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ~>
@@ -87,10 +117,15 @@ dependencies:
87
117
  version: 2.6.0
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *70218697325220
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 2.6.0
91
126
  - !ruby/object:Gem::Dependency
92
127
  name: bourne
93
- requirement: &70218697323900 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
94
129
  none: false
95
130
  requirements:
96
131
  - - ~>
@@ -98,10 +133,15 @@ dependencies:
98
133
  version: '1.0'
99
134
  type: :development
100
135
  prerelease: false
101
- version_requirements: *70218697323900
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: '1.0'
102
142
  - !ruby/object:Gem::Dependency
103
143
  name: timecop
104
- requirement: &70218697321420 !ruby/object:Gem::Requirement
144
+ requirement: !ruby/object:Gem::Requirement
105
145
  none: false
106
146
  requirements:
107
147
  - - ~>
@@ -109,10 +149,15 @@ dependencies:
109
149
  version: 0.3.5
110
150
  type: :development
111
151
  prerelease: false
112
- version_requirements: *70218697321420
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 0.3.5
113
158
  - !ruby/object:Gem::Dependency
114
159
  name: spork
115
- requirement: &70218697334620 !ruby/object:Gem::Requirement
160
+ requirement: !ruby/object:Gem::Requirement
116
161
  none: false
117
162
  requirements:
118
163
  - - ~>
@@ -120,10 +165,15 @@ dependencies:
120
165
  version: 0.9.0.rc9
121
166
  type: :development
122
167
  prerelease: false
123
- version_requirements: *70218697334620
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ~>
172
+ - !ruby/object:Gem::Version
173
+ version: 0.9.0.rc9
124
174
  - !ruby/object:Gem::Dependency
125
175
  name: bundler
126
- requirement: &70218697332380 !ruby/object:Gem::Requirement
176
+ requirement: !ruby/object:Gem::Requirement
127
177
  none: false
128
178
  requirements:
129
179
  - - ! '>='
@@ -131,10 +181,15 @@ dependencies:
131
181
  version: 1.0.14
132
182
  type: :development
133
183
  prerelease: false
134
- version_requirements: *70218697332380
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: 1.0.14
135
190
  - !ruby/object:Gem::Dependency
136
191
  name: rake
137
- requirement: &70218697328960 !ruby/object:Gem::Requirement
192
+ requirement: !ruby/object:Gem::Requirement
138
193
  none: false
139
194
  requirements:
140
195
  - - ! '>='
@@ -142,7 +197,12 @@ dependencies:
142
197
  version: '0'
143
198
  type: :development
144
199
  prerelease: false
145
- version_requirements: *70218697328960
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
146
206
  description: A fake Braintree that you can run integration tests against
147
207
  email:
148
208
  - gabe@thoughtbot.com
@@ -153,8 +213,11 @@ extra_rdoc_files: []
153
213
  files:
154
214
  - .gitignore
155
215
  - .travis.yml
216
+ - CONTRIBUTING.md
156
217
  - Changelog.md
218
+ - GOALS
157
219
  - Gemfile
220
+ - LICENSE
158
221
  - README.md
159
222
  - Rakefile
160
223
  - fake_braintree.gemspec
@@ -171,7 +234,6 @@ files:
171
234
  - lib/fake_braintree/version.rb
172
235
  - spec/fake_braintree/credit_card_spec.rb
173
236
  - spec/fake_braintree/customer_spec.rb
174
- - spec/fake_braintree/redirect_spec.rb
175
237
  - spec/fake_braintree/registry_spec.rb
176
238
  - spec/fake_braintree/subscription_spec.rb
177
239
  - spec/fake_braintree/transaction_spec.rb
@@ -197,7 +259,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
259
  version: '0'
198
260
  segments:
199
261
  - 0
200
- hash: 1813003811579628559
262
+ hash: -3718552739890395570
201
263
  required_rubygems_version: !ruby/object:Gem::Requirement
202
264
  none: false
203
265
  requirements:
@@ -206,17 +268,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
268
  version: '0'
207
269
  segments:
208
270
  - 0
209
- hash: 1813003811579628559
271
+ hash: -3718552739890395570
210
272
  requirements: []
211
273
  rubyforge_project:
212
- rubygems_version: 1.8.11
274
+ rubygems_version: 1.8.24
213
275
  signing_key:
214
276
  specification_version: 3
215
277
  summary: A fake Braintree that you can run integration tests against
216
278
  test_files:
217
279
  - spec/fake_braintree/credit_card_spec.rb
218
280
  - spec/fake_braintree/customer_spec.rb
219
- - spec/fake_braintree/redirect_spec.rb
220
281
  - spec/fake_braintree/registry_spec.rb
221
282
  - spec/fake_braintree/subscription_spec.rb
222
283
  - spec/fake_braintree/transaction_spec.rb
File without changes