fake_braintree 0.0.6 → 0.1.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.
- data/Changelog.md +13 -0
- data/README.md +25 -0
- data/fake_braintree.gemspec +1 -1
- data/lib/fake_braintree.rb +12 -49
- data/lib/fake_braintree/customer.rb +7 -5
- data/lib/fake_braintree/registry.rb +28 -0
- data/lib/fake_braintree/server.rb +25 -0
- data/lib/fake_braintree/sinatra_app.rb +15 -7
- data/lib/fake_braintree/subscription.rb +6 -4
- data/lib/fake_braintree/version.rb +1 -1
- data/spec/fake_braintree/credit_card_spec.rb +16 -18
- data/spec/fake_braintree/customer_spec.rb +6 -0
- data/spec/fake_braintree/registry_spec.rb +94 -0
- data/spec/fake_braintree/subscription_spec.rb +16 -2
- data/spec/fake_braintree_spec.rb +5 -23
- data/spec/spec_helper.rb +1 -0
- metadata +176 -109
data/Changelog.md
CHANGED
@@ -1,8 +1,21 @@
|
|
1
|
+
# 0.1.0 (not yet released)
|
2
|
+
* FakeBraintree.{customers, transactions, failures, subscriptions, redirects}
|
3
|
+
are now accessed via FakeBraintree.registry. For example,
|
4
|
+
FakeBraintree.customers is now FakeBraintree.registry.customers
|
5
|
+
* FakeBraintree.credit_card_from_token is now FakeBraintree.registry.credit_card_from_token
|
6
|
+
* The server code (it intercepts calls to Braintree) now lives in FakeBraintree::Server
|
7
|
+
* Braintree::Customer.create will use the provided customer ID instead of
|
8
|
+
overwriting it (#15).
|
9
|
+
* Braintree::Subscription.cancel now works
|
10
|
+
|
1
11
|
# 0.0.6
|
2
12
|
* Flesh out the README
|
3
13
|
* Add support for transparent redirect
|
4
14
|
* Add basic support for adding add-ons
|
5
15
|
* Add basic support for adding discounts
|
16
|
+
* Add support for Braintree::Customer.update
|
17
|
+
* Add support for Braintree::Customer.delete
|
18
|
+
* Add support for Braintree::Subscription.delete
|
6
19
|
* Lots of internal refactorings
|
7
20
|
|
8
21
|
# 0.0.5
|
data/README.md
CHANGED
@@ -20,6 +20,7 @@ Currently in alpha (i.e. it does not support every Braintree call).
|
|
20
20
|
* `Braintree::Subscription.find`
|
21
21
|
* `Braintree::Subscription.create`
|
22
22
|
* `Braintree::Subscription.update`
|
23
|
+
* `Braintree::Subscription.cancel`
|
23
24
|
|
24
25
|
### CreditCard
|
25
26
|
* `Braintree::CreditCard.find`
|
@@ -60,6 +61,30 @@ If you're using Cucumber, add this too:
|
|
60
61
|
FakeBraintree.clear!
|
61
62
|
end
|
62
63
|
|
64
|
+
## Spork
|
65
|
+
|
66
|
+
To use fake\_braintree with Spork, do this:
|
67
|
+
|
68
|
+
# Gemfile
|
69
|
+
group :test do
|
70
|
+
gem 'fake_braintree', :require => false
|
71
|
+
end
|
72
|
+
|
73
|
+
# spec/spec_helper.rb
|
74
|
+
Spork.each_run do
|
75
|
+
require 'fake_braintree'
|
76
|
+
# ...other FakeBraintree configuration, for example:
|
77
|
+
# FakeBraintree.verify_all_cards!
|
78
|
+
end
|
79
|
+
|
80
|
+
# features/support/env.rb
|
81
|
+
Spork.each_run do
|
82
|
+
require 'fake_braintree'
|
83
|
+
# ...other FakeBraintree configuration, for example:
|
84
|
+
# FakeBraintree.verify_all_cards!
|
85
|
+
end
|
86
|
+
|
87
|
+
|
63
88
|
## Verifying credit cards
|
64
89
|
|
65
90
|
To verify every credit card you try to use, call:
|
data/fake_braintree.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_dependency 'mongrel', '~> 1.2.0.pre'
|
25
25
|
|
26
26
|
s.add_development_dependency 'rspec', '~> 2.6.0'
|
27
|
-
s.add_development_dependency '
|
27
|
+
s.add_development_dependency 'bourne', '~> 1.0'
|
28
28
|
s.add_development_dependency 'timecop', '~> 0.3.5'
|
29
29
|
s.add_development_dependency 'spork', '~> 0.9.0.rc9'
|
30
30
|
s.add_development_dependency 'bundler', '>= 1.0.14'
|
data/lib/fake_braintree.rb
CHANGED
@@ -1,35 +1,28 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'braintree'
|
3
|
-
require '
|
4
|
-
require 'capybara/server'
|
5
|
-
require 'rack/handler/mongrel'
|
3
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
6
4
|
|
7
5
|
require 'fake_braintree/helpers'
|
8
6
|
require 'fake_braintree/customer'
|
9
7
|
require 'fake_braintree/subscription'
|
10
8
|
require 'fake_braintree/redirect'
|
11
9
|
|
10
|
+
require 'fake_braintree/registry'
|
11
|
+
require 'fake_braintree/server'
|
12
12
|
require 'fake_braintree/sinatra_app'
|
13
13
|
require 'fake_braintree/valid_credit_cards'
|
14
14
|
require 'fake_braintree/version'
|
15
15
|
|
16
16
|
module FakeBraintree
|
17
|
-
|
18
|
-
@customers = {}
|
19
|
-
@subscriptions = {}
|
20
|
-
@failures = {}
|
21
|
-
@transactions = {}
|
22
|
-
@redirects = {}
|
23
|
-
|
24
|
-
@decline_all_cards = false
|
25
|
-
@verify_all_cards = false
|
26
|
-
attr_accessor :customers, :subscriptions, :failures, :transactions, :decline_all_cards, :verify_all_cards, :redirects
|
27
|
-
end
|
17
|
+
mattr_accessor :registry, :verify_all_cards, :decline_all_cards
|
28
18
|
|
29
19
|
def self.activate!
|
20
|
+
self.registry = Registry.new
|
21
|
+
self.verify_all_cards = false
|
22
|
+
|
30
23
|
set_configuration
|
31
24
|
clear!
|
32
|
-
|
25
|
+
Server.new.boot
|
33
26
|
end
|
34
27
|
|
35
28
|
def self.log_file_path
|
@@ -37,11 +30,7 @@ module FakeBraintree
|
|
37
30
|
end
|
38
31
|
|
39
32
|
def self.clear!
|
40
|
-
self.
|
41
|
-
self.subscriptions = {}
|
42
|
-
self.failures = {}
|
43
|
-
self.transactions = {}
|
44
|
-
self.redirects = {}
|
33
|
+
self.registry.clear!
|
45
34
|
self.decline_all_cards = false
|
46
35
|
clear_log!
|
47
36
|
end
|
@@ -52,11 +41,11 @@ module FakeBraintree
|
|
52
41
|
end
|
53
42
|
|
54
43
|
def self.failure?(card_number)
|
55
|
-
|
44
|
+
registry.failure?(card_number)
|
56
45
|
end
|
57
46
|
|
58
47
|
def self.failure_response(card_number = nil)
|
59
|
-
failure =
|
48
|
+
failure = registry.failures[card_number] || {}
|
60
49
|
failure["errors"] ||= { "errors" => [] }
|
61
50
|
|
62
51
|
{ "message" => failure["message"],
|
@@ -83,22 +72,13 @@ module FakeBraintree
|
|
83
72
|
end
|
84
73
|
|
85
74
|
def self.decline_all_cards?
|
86
|
-
|
75
|
+
decline_all_cards
|
87
76
|
end
|
88
77
|
|
89
78
|
def self.verify_all_cards!
|
90
79
|
self.verify_all_cards = true
|
91
80
|
end
|
92
81
|
|
93
|
-
def self.credit_card_from_token(token)
|
94
|
-
self.customers.values.detect do |customer|
|
95
|
-
next unless customer.key?("credit_cards")
|
96
|
-
|
97
|
-
card = customer["credit_cards"].detect {|card| card["token"] == token }
|
98
|
-
return card if card
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
82
|
def self.generate_transaction(options = {})
|
103
83
|
history_item = { 'timestamp' => Time.now,
|
104
84
|
'amount' => options[:amount],
|
@@ -118,23 +98,6 @@ module FakeBraintree
|
|
118
98
|
Braintree::Configuration.private_key = "xxx"
|
119
99
|
end
|
120
100
|
|
121
|
-
def self.boot_server
|
122
|
-
with_mongrel_runner do
|
123
|
-
server = Capybara::Server.new(FakeBraintree::SinatraApp)
|
124
|
-
server.boot
|
125
|
-
ENV['GATEWAY_PORT'] = server.port.to_s
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
def self.with_mongrel_runner
|
130
|
-
default_server_process = Capybara.server
|
131
|
-
Capybara.server do |app, port|
|
132
|
-
Rack::Handler::Mongrel.run(app, :Port => port)
|
133
|
-
end
|
134
|
-
yield
|
135
|
-
ensure
|
136
|
-
Capybara.server(&default_server_process)
|
137
|
-
end
|
138
101
|
end
|
139
102
|
|
140
103
|
FakeBraintree.activate!
|
@@ -3,8 +3,10 @@ module FakeBraintree
|
|
3
3
|
include Helpers
|
4
4
|
|
5
5
|
def initialize(customer_hash, options)
|
6
|
-
@customer_hash =
|
7
|
-
|
6
|
+
@customer_hash = {
|
7
|
+
"id" => options[:id],
|
8
|
+
"merchant_id" => options[:merchant_id]
|
9
|
+
}.merge(customer_hash)
|
8
10
|
end
|
9
11
|
|
10
12
|
def create
|
@@ -12,7 +14,7 @@ module FakeBraintree
|
|
12
14
|
failure_response
|
13
15
|
else
|
14
16
|
hash = customer_hash
|
15
|
-
FakeBraintree.customers[hash["id"]] = hash
|
17
|
+
FakeBraintree.registry.customers[hash["id"]] = hash
|
16
18
|
gzipped_response(201, hash.to_xml(:root => 'customer'))
|
17
19
|
end
|
18
20
|
end
|
@@ -27,7 +29,7 @@ module FakeBraintree
|
|
27
29
|
end
|
28
30
|
|
29
31
|
def delete
|
30
|
-
FakeBraintree.customers[existing_customer_id] = nil
|
32
|
+
FakeBraintree.registry.customers[existing_customer_id] = nil
|
31
33
|
gzipped_response(200, '')
|
32
34
|
end
|
33
35
|
|
@@ -63,7 +65,7 @@ module FakeBraintree
|
|
63
65
|
end
|
64
66
|
|
65
67
|
def existing_customer_hash
|
66
|
-
existing_customer_id && FakeBraintree.customers[existing_customer_id]
|
68
|
+
existing_customer_id && FakeBraintree.registry.customers[existing_customer_id]
|
67
69
|
end
|
68
70
|
|
69
71
|
def update_existing_customer!
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class FakeBraintree::Registry
|
2
|
+
def initialize
|
3
|
+
clear!
|
4
|
+
end
|
5
|
+
|
6
|
+
attr_accessor :customers, :subscriptions, :failures, :transactions, :redirects
|
7
|
+
|
8
|
+
def clear!
|
9
|
+
@customers = {}
|
10
|
+
@subscriptions = {}
|
11
|
+
@failures = {}
|
12
|
+
@transactions = {}
|
13
|
+
@redirects = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def failure?(card_number)
|
17
|
+
@failures.keys.include?(card_number)
|
18
|
+
end
|
19
|
+
|
20
|
+
def credit_card_from_token(token)
|
21
|
+
@customers.values.detect do |customer|
|
22
|
+
next unless customer.key?("credit_cards")
|
23
|
+
|
24
|
+
card = customer["credit_cards"].detect {|card| card["token"] == token }
|
25
|
+
return card if card
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'capybara'
|
2
|
+
require 'capybara/server'
|
3
|
+
require 'rack/handler/mongrel'
|
4
|
+
|
5
|
+
class FakeBraintree::Server
|
6
|
+
def boot
|
7
|
+
with_mongrel_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_mongrel_runner
|
17
|
+
default_server_process = Capybara.server
|
18
|
+
Capybara.server do |app, port|
|
19
|
+
Rack::Handler::Mongrel.run(app, :Port => port)
|
20
|
+
end
|
21
|
+
yield
|
22
|
+
ensure
|
23
|
+
Capybara.server(&default_server_process)
|
24
|
+
end
|
25
|
+
end
|
@@ -18,7 +18,7 @@ module FakeBraintree
|
|
18
18
|
|
19
19
|
# Braintree::Customer.find
|
20
20
|
get "/merchants/:merchant_id/customers/:id" do
|
21
|
-
customer = FakeBraintree.customers[params[:id]]
|
21
|
+
customer = FakeBraintree.registry.customers[params[:id]]
|
22
22
|
if customer
|
23
23
|
gzipped_response(200, customer.to_xml(:root => 'customer'))
|
24
24
|
else
|
@@ -49,7 +49,7 @@ module FakeBraintree
|
|
49
49
|
|
50
50
|
# Braintree::Subscription.find
|
51
51
|
get "/merchants/:merchant_id/subscriptions/:id" do
|
52
|
-
subscription = FakeBraintree.subscriptions[params[:id]]
|
52
|
+
subscription = FakeBraintree.registry.subscriptions[params[:id]]
|
53
53
|
if subscription
|
54
54
|
gzipped_response(200, subscription.to_xml(:root => 'subscription'))
|
55
55
|
else
|
@@ -64,9 +64,17 @@ module FakeBraintree
|
|
64
64
|
Subscription.new(subscription_hash, options).update
|
65
65
|
end
|
66
66
|
|
67
|
+
# Braintree::Subscription.cancel
|
68
|
+
put "/merchants/:merchant_id/subscriptions/:id/cancel" do
|
69
|
+
subscription = FakeBraintree.registry.subscriptions[params[:id]]
|
70
|
+
updates = {"status" => Braintree::Subscription::Status::Canceled}
|
71
|
+
options = {:id => params[:id], :merchant_id => params[:merchant_id]}
|
72
|
+
Subscription.new(updates, options).update
|
73
|
+
end
|
74
|
+
|
67
75
|
# Braintree::CreditCard.find
|
68
76
|
get "/merchants/:merchant_id/payment_methods/:credit_card_token" do
|
69
|
-
credit_card = FakeBraintree.credit_card_from_token(params[:credit_card_token])
|
77
|
+
credit_card = FakeBraintree.registry.credit_card_from_token(params[:credit_card_token])
|
70
78
|
gzipped_response(200, credit_card.to_xml(:root => "credit_card"))
|
71
79
|
end
|
72
80
|
|
@@ -79,14 +87,14 @@ module FakeBraintree
|
|
79
87
|
transaction = Hash.from_xml(request.body)["transaction"]
|
80
88
|
transaction_id = md5("#{params[:merchant_id]}#{Time.now.to_f}")
|
81
89
|
transaction_response = {"id" => transaction_id, "amount" => transaction["amount"]}
|
82
|
-
FakeBraintree.transactions[transaction_id] = transaction_response
|
90
|
+
FakeBraintree.registry.transactions[transaction_id] = transaction_response
|
83
91
|
gzipped_response(200, transaction_response.to_xml(:root => "transaction"))
|
84
92
|
end
|
85
93
|
end
|
86
94
|
|
87
95
|
# Braintree::Transaction.find
|
88
96
|
get "/merchants/:merchant_id/transactions/:transaction_id" do
|
89
|
-
transaction = FakeBraintree.transactions[params[:transaction_id]]
|
97
|
+
transaction = FakeBraintree.registry.transactions[params[:transaction_id]]
|
90
98
|
if transaction
|
91
99
|
gzipped_response(200, transaction.to_xml(:root => "transaction"))
|
92
100
|
else
|
@@ -98,7 +106,7 @@ module FakeBraintree
|
|
98
106
|
post "/merchants/:merchant_id/transparent_redirect_requests" do
|
99
107
|
if params[:tr_data]
|
100
108
|
redirect = Redirect.new(params, params[:merchant_id])
|
101
|
-
FakeBraintree.redirects[redirect.id] = redirect
|
109
|
+
FakeBraintree.registry.redirects[redirect.id] = redirect
|
102
110
|
redirect to(redirect.url), 303
|
103
111
|
else
|
104
112
|
[422, { "Content-Type" => "text/html" }, ["Invalid submission"]]
|
@@ -107,7 +115,7 @@ module FakeBraintree
|
|
107
115
|
|
108
116
|
# Braintree::TransparentRedirect.confirm
|
109
117
|
post "/merchants/:merchant_id/transparent_redirect_requests/:id/confirm" do
|
110
|
-
redirect = FakeBraintree.redirects[params[:id]]
|
118
|
+
redirect = FakeBraintree.registry.redirects[params[:id]]
|
111
119
|
redirect.confirm
|
112
120
|
end
|
113
121
|
end
|
@@ -9,7 +9,7 @@ module FakeBraintree
|
|
9
9
|
|
10
10
|
def create
|
11
11
|
hash = subscription_hash
|
12
|
-
FakeBraintree.subscriptions[hash["id"]] = hash
|
12
|
+
FakeBraintree.registry.subscriptions[hash["id"]] = hash
|
13
13
|
gzipped_response(201, hash.to_xml(:root => 'subscription'))
|
14
14
|
end
|
15
15
|
|
@@ -17,6 +17,8 @@ module FakeBraintree
|
|
17
17
|
if existing_subscription_hash
|
18
18
|
hash = update_existing_subscription!
|
19
19
|
gzipped_response(200, hash.to_xml(:root => 'subscription'))
|
20
|
+
else
|
21
|
+
gzipped_response(404, {})
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
@@ -29,7 +31,7 @@ module FakeBraintree
|
|
29
31
|
subscription_hash["plan_id"] = @subscription_hash["plan_id"]
|
30
32
|
subscription_hash["next_billing_date"] = braintree_formatted_date(1.month.from_now)
|
31
33
|
subscription_hash["payment_method_token"] = @subscription_hash["payment_method_token"]
|
32
|
-
subscription_hash["status"]
|
34
|
+
subscription_hash["status"] ||= Braintree::Subscription::Status::Active
|
33
35
|
|
34
36
|
subscription_hash
|
35
37
|
end
|
@@ -37,12 +39,12 @@ module FakeBraintree
|
|
37
39
|
private
|
38
40
|
|
39
41
|
def existing_subscription_hash
|
40
|
-
@subscription_hash['id'] && FakeBraintree.subscriptions[@subscription_hash["id"]]
|
42
|
+
@subscription_hash['id'] && FakeBraintree.registry.subscriptions[@subscription_hash["id"]]
|
41
43
|
end
|
42
44
|
|
43
45
|
def update_existing_subscription!
|
44
46
|
new_hash = existing_subscription_hash.merge(subscription_hash)
|
45
|
-
FakeBraintree.subscriptions[@subscription_hash['id']] = new_hash
|
47
|
+
FakeBraintree.registry.subscriptions[@subscription_hash['id']] = new_hash
|
46
48
|
end
|
47
49
|
|
48
50
|
def braintree_formatted_date(date)
|
@@ -1,25 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
5
|
-
|
6
|
-
credit_card = Braintree::CreditCard.find(token)
|
3
|
+
describe "Braintree::CreditCard.find" do
|
4
|
+
it "gets the correct credit card" do
|
5
|
+
credit_card = Braintree::CreditCard.find(token)
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:month) { '04' }
|
14
|
-
let(:year) { '2016' }
|
15
|
-
let(:token) { braintree_credit_card_token(TEST_CC_NUMBER, [month, year].join('/')) }
|
7
|
+
credit_card.last_4.should == TEST_CC_NUMBER[-4,4]
|
8
|
+
credit_card.expiration_month.should == month
|
9
|
+
credit_card.expiration_year.should == year
|
16
10
|
end
|
17
11
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
12
|
+
let(:month) { '04' }
|
13
|
+
let(:year) { '2016' }
|
14
|
+
let(:token) { braintree_credit_card_token(TEST_CC_NUMBER, [month, year].join('/')) }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "Braintree::CreditCard.sale" do
|
18
|
+
it "successfully creates a sale" do
|
19
|
+
result = Braintree::CreditCard.sale(cc_token, :amount => 10.00)
|
20
|
+
result.should be_success
|
21
|
+
Braintree::Transaction.find(result.transaction.id).should be
|
24
22
|
end
|
25
23
|
end
|
@@ -14,6 +14,12 @@ describe "Braintree::Customer.create" do
|
|
14
14
|
result.should be_success
|
15
15
|
end
|
16
16
|
|
17
|
+
it "does not overwrite a passed customer id" do
|
18
|
+
result = Braintree::Customer.create({ "id" => '123' })
|
19
|
+
|
20
|
+
result.customer.id.should eq('123')
|
21
|
+
end
|
22
|
+
|
17
23
|
it "creates a customer using an expiration month and year" do
|
18
24
|
result = Braintree::Customer.create(:credit_card => { :number => TEST_CC_NUMBER,
|
19
25
|
:expiration_month => '04',
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FakeBraintree::Registry do
|
4
|
+
it "exposes a customers accessor" do
|
5
|
+
registry.customers['abc123'] = "Bob"
|
6
|
+
registry.customers['abc123'].should == "Bob"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "exposes a subscriptions accessor" do
|
10
|
+
registry.subscriptions['abc123'] = "Bob"
|
11
|
+
registry.subscriptions['abc123'].should == "Bob"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "exposes a failures accessor" do
|
15
|
+
registry.failures['abc123'] = "Bob"
|
16
|
+
registry.failures['abc123'].should == "Bob"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "exposes a transactions accessor" do
|
20
|
+
registry.transactions['abc123'] = "Bob"
|
21
|
+
registry.transactions['abc123'].should == "Bob"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "exposes a redirects accessor" do
|
25
|
+
registry.redirects['abc123'] = "Bob"
|
26
|
+
registry.redirects['abc123'].should == "Bob"
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:registry) { subject }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe FakeBraintree::Registry, "#clear!" do
|
33
|
+
it "clears stored customers" do
|
34
|
+
registry.customers['abc123'] = "Bob"
|
35
|
+
registry.clear!
|
36
|
+
registry.customers.should be_empty
|
37
|
+
end
|
38
|
+
|
39
|
+
it "clears stored subscriptions" do
|
40
|
+
registry.subscriptions['abc123'] = "Bob"
|
41
|
+
registry.clear!
|
42
|
+
registry.subscriptions.should be_empty
|
43
|
+
end
|
44
|
+
|
45
|
+
it "clears stored failures" do
|
46
|
+
registry.failures['abc123'] = "Bob"
|
47
|
+
registry.clear!
|
48
|
+
registry.failures.should be_empty
|
49
|
+
end
|
50
|
+
|
51
|
+
it "clears stored transactions" do
|
52
|
+
registry.transactions['abc123'] = "Bob"
|
53
|
+
registry.clear!
|
54
|
+
registry.transactions.should be_empty
|
55
|
+
end
|
56
|
+
|
57
|
+
it "clears stored redirects" do
|
58
|
+
registry.redirects['abc123'] = "Bob"
|
59
|
+
registry.clear!
|
60
|
+
registry.redirects.should be_empty
|
61
|
+
end
|
62
|
+
|
63
|
+
let(:registry) { subject }
|
64
|
+
end
|
65
|
+
|
66
|
+
describe FakeBraintree::Registry, "#failure?" do
|
67
|
+
it "returns false if the given CC number is not marked as a failure" do
|
68
|
+
registry.failure?('not-a-failure').should be_false
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns true if the given CC number is marked as a failure" do
|
72
|
+
registry.failures['abc123'] = 'whatever'
|
73
|
+
registry.failure?('abc123').should be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
let(:registry) { subject }
|
78
|
+
end
|
79
|
+
|
80
|
+
describe FakeBraintree::Registry, ".credit_card_from_token" do
|
81
|
+
it "looks up the credit card based on a CC token" do
|
82
|
+
number = %w(4111 1111 1111 2222).join
|
83
|
+
expiration_date = "04/2016"
|
84
|
+
customer = create_braintree_customer(number, expiration_date)
|
85
|
+
credit_card = customer.credit_cards.first
|
86
|
+
|
87
|
+
# registry.customers[customer.id] = customer
|
88
|
+
|
89
|
+
registry.credit_card_from_token(credit_card.token)["last_4"].should == "2222"
|
90
|
+
end
|
91
|
+
|
92
|
+
# let(:registry) { FakeBraintree::Registry.new }
|
93
|
+
let(:registry) { FakeBraintree.registry }
|
94
|
+
end
|
@@ -24,8 +24,8 @@ describe "Braintree::Subscription.create" do
|
|
24
24
|
first_result.subscription.id.should_not == second_result.subscription.id
|
25
25
|
end
|
26
26
|
|
27
|
-
it "stores created subscriptions in FakeBraintree.subscriptions" do
|
28
|
-
FakeBraintree.subscriptions[create_subscription.subscription.id].should_not be_nil
|
27
|
+
it "stores created subscriptions in FakeBraintree.registry.subscriptions" do
|
28
|
+
FakeBraintree.registry.subscriptions[create_subscription.subscription.id].should_not be_nil
|
29
29
|
end
|
30
30
|
|
31
31
|
it "sets the next billing date to a string of 1.month.from_now in UTC" do
|
@@ -80,3 +80,17 @@ describe "Braintree::Subscription.update" do
|
|
80
80
|
let(:subscription_id) { subscription.subscription.id }
|
81
81
|
let(:subscription) { create_subscription }
|
82
82
|
end
|
83
|
+
|
84
|
+
describe "Braintree::Subscription.cancel" do
|
85
|
+
it "can cancel a subscription" do
|
86
|
+
Braintree::Subscription.cancel(subscription_id).should be_success
|
87
|
+
Braintree::Subscription.find(subscription_id).status.should == Braintree::Subscription::Status::Canceled
|
88
|
+
end
|
89
|
+
|
90
|
+
it "can't cancel an unknown subscription" do
|
91
|
+
expect { Braintree::Subscription.cancel("totally-bogus-id") }.to raise_error(Braintree::NotFoundError)
|
92
|
+
end
|
93
|
+
|
94
|
+
let(:subscription_id) { subscription.subscription.id }
|
95
|
+
let(:subscription) { create_subscription }
|
96
|
+
end
|
data/spec/fake_braintree_spec.rb
CHANGED
@@ -1,25 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe FakeBraintree, ".credit_card_from_token" do
|
4
|
-
it "looks up the credit card based on a CC token" do
|
5
|
-
credit_card = FakeBraintree.credit_card_from_token(token)
|
6
|
-
credit_card["last_4"].should == TEST_CC_NUMBER[-4,4]
|
7
|
-
credit_card["expiration_year"].should == "2016"
|
8
|
-
credit_card["expiration_month"].should == "04"
|
9
|
-
|
10
|
-
credit_card = FakeBraintree.credit_card_from_token(token_2)
|
11
|
-
credit_card["last_4"].should == "2222"
|
12
|
-
credit_card["expiration_year"].should == "2019"
|
13
|
-
credit_card["expiration_month"].should == "05"
|
14
|
-
end
|
15
|
-
|
16
|
-
let(:cc_number_2) { %w(4111 1111 1111 2222).join }
|
17
|
-
let(:expiration_date) { "04/2016" }
|
18
|
-
let(:expiration_date_2) { "05/2019" }
|
19
|
-
let(:token) { braintree_credit_card_token(TEST_CC_NUMBER, expiration_date) }
|
20
|
-
let(:token_2) { braintree_credit_card_token(cc_number_2, expiration_date_2) }
|
21
|
-
end
|
22
|
-
|
23
3
|
describe FakeBraintree, ".decline_all_cards!" do
|
24
4
|
before { FakeBraintree.decline_all_cards! }
|
25
5
|
|
@@ -46,22 +26,24 @@ end
|
|
46
26
|
describe Braintree::Configuration do
|
47
27
|
subject { Braintree::Configuration }
|
48
28
|
|
49
|
-
it "
|
29
|
+
it "is running in the development environment" do
|
50
30
|
subject.environment.should == :development
|
51
31
|
end
|
52
32
|
|
53
|
-
it "
|
33
|
+
it "has some fake API credentials" do
|
54
34
|
subject.merchant_id.should == "xxx"
|
55
35
|
subject.public_key.should == "xxx"
|
56
36
|
subject.private_key.should == "xxx"
|
57
37
|
end
|
38
|
+
end
|
58
39
|
|
40
|
+
describe FakeBraintree do
|
59
41
|
it "creates a log file" do
|
60
42
|
File.exist?(FakeBraintree.log_file_path).should == true
|
61
43
|
end
|
62
44
|
|
63
45
|
it "logs to the correct path" do
|
64
|
-
|
46
|
+
Braintree::Configuration.logger.info('Logger test')
|
65
47
|
File.readlines(FakeBraintree.log_file_path).last.should == "Logger test\n"
|
66
48
|
end
|
67
49
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,156 +1,216 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: fake_braintree
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- thoughtbot, inc.
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2012-01-11 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 3
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
requirement: *id001
|
31
|
+
type: :runtime
|
32
|
+
prerelease: false
|
15
33
|
name: capybara
|
16
|
-
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
17
36
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
hash: 3
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
requirement: *id002
|
22
45
|
type: :runtime
|
23
46
|
prerelease: false
|
24
|
-
version_requirements: *70247558335960
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
47
|
name: activesupport
|
27
|
-
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
28
50
|
none: false
|
29
|
-
requirements:
|
30
|
-
- -
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
requirement: *id003
|
33
59
|
type: :runtime
|
34
60
|
prerelease: false
|
35
|
-
version_requirements: *70247558333760
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
61
|
name: i18n
|
38
|
-
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
39
64
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
requirement: *id004
|
44
73
|
type: :runtime
|
45
74
|
prerelease: false
|
46
|
-
version_requirements: *70247558345380
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
75
|
name: sinatra
|
49
|
-
|
50
|
-
|
51
|
-
requirements:
|
52
|
-
- - ! '>='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
type: :runtime
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: *70247558343320
|
58
|
-
- !ruby/object:Gem::Dependency
|
59
|
-
name: braintree
|
60
|
-
requirement: &70247558341980 !ruby/object:Gem::Requirement
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
61
78
|
none: false
|
62
|
-
requirements:
|
79
|
+
requirements:
|
63
80
|
- - ~>
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 9
|
83
|
+
segments:
|
84
|
+
- 2
|
85
|
+
- 5
|
86
|
+
version: "2.5"
|
87
|
+
requirement: *id005
|
66
88
|
type: :runtime
|
67
89
|
prerelease: false
|
68
|
-
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
|
71
|
-
requirement: &70247562466060 !ruby/object:Gem::Requirement
|
90
|
+
name: braintree
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
72
93
|
none: false
|
73
|
-
requirements:
|
94
|
+
requirements:
|
74
95
|
- - ~>
|
75
|
-
- !ruby/object:Gem::Version
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 961915972
|
98
|
+
segments:
|
99
|
+
- 1
|
100
|
+
- 2
|
101
|
+
- 0
|
102
|
+
- pre
|
76
103
|
version: 1.2.0.pre
|
104
|
+
requirement: *id006
|
77
105
|
type: :runtime
|
78
106
|
prerelease: false
|
79
|
-
|
80
|
-
- !ruby/object:Gem::Dependency
|
81
|
-
|
82
|
-
requirement: &70247562473440 !ruby/object:Gem::Requirement
|
107
|
+
name: mongrel
|
108
|
+
- !ruby/object:Gem::Dependency
|
109
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
83
110
|
none: false
|
84
|
-
requirements:
|
111
|
+
requirements:
|
85
112
|
- - ~>
|
86
|
-
- !ruby/object:Gem::Version
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
hash: 23
|
115
|
+
segments:
|
116
|
+
- 2
|
117
|
+
- 6
|
118
|
+
- 0
|
87
119
|
version: 2.6.0
|
120
|
+
requirement: *id007
|
88
121
|
type: :development
|
89
122
|
prerelease: false
|
90
|
-
|
91
|
-
- !ruby/object:Gem::Dependency
|
92
|
-
|
93
|
-
requirement: &70247562468440 !ruby/object:Gem::Requirement
|
123
|
+
name: rspec
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
94
126
|
none: false
|
95
|
-
requirements:
|
127
|
+
requirements:
|
96
128
|
- - ~>
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
hash: 15
|
131
|
+
segments:
|
132
|
+
- 1
|
133
|
+
- 0
|
134
|
+
version: "1.0"
|
135
|
+
requirement: *id008
|
99
136
|
type: :development
|
100
137
|
prerelease: false
|
101
|
-
|
102
|
-
- !ruby/object:Gem::Dependency
|
103
|
-
|
104
|
-
requirement: &70247562490280 !ruby/object:Gem::Requirement
|
138
|
+
name: bourne
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
105
141
|
none: false
|
106
|
-
requirements:
|
142
|
+
requirements:
|
107
143
|
- - ~>
|
108
|
-
- !ruby/object:Gem::Version
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
hash: 25
|
146
|
+
segments:
|
147
|
+
- 0
|
148
|
+
- 3
|
149
|
+
- 5
|
109
150
|
version: 0.3.5
|
151
|
+
requirement: *id009
|
110
152
|
type: :development
|
111
153
|
prerelease: false
|
112
|
-
|
113
|
-
- !ruby/object:Gem::Dependency
|
114
|
-
|
115
|
-
requirement: &70247558422540 !ruby/object:Gem::Requirement
|
154
|
+
name: timecop
|
155
|
+
- !ruby/object:Gem::Dependency
|
156
|
+
version_requirements: &id010 !ruby/object:Gem::Requirement
|
116
157
|
none: false
|
117
|
-
requirements:
|
158
|
+
requirements:
|
118
159
|
- - ~>
|
119
|
-
- !ruby/object:Gem::Version
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
hash: 15424151
|
162
|
+
segments:
|
163
|
+
- 0
|
164
|
+
- 9
|
165
|
+
- 0
|
166
|
+
- rc
|
167
|
+
- 9
|
120
168
|
version: 0.9.0.rc9
|
169
|
+
requirement: *id010
|
121
170
|
type: :development
|
122
171
|
prerelease: false
|
123
|
-
|
124
|
-
- !ruby/object:Gem::Dependency
|
125
|
-
|
126
|
-
requirement: &70247558426500 !ruby/object:Gem::Requirement
|
172
|
+
name: spork
|
173
|
+
- !ruby/object:Gem::Dependency
|
174
|
+
version_requirements: &id011 !ruby/object:Gem::Requirement
|
127
175
|
none: false
|
128
|
-
requirements:
|
129
|
-
- -
|
130
|
-
- !ruby/object:Gem::Version
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
hash: 11
|
180
|
+
segments:
|
181
|
+
- 1
|
182
|
+
- 0
|
183
|
+
- 14
|
131
184
|
version: 1.0.14
|
185
|
+
requirement: *id011
|
132
186
|
type: :development
|
133
187
|
prerelease: false
|
134
|
-
|
135
|
-
- !ruby/object:Gem::Dependency
|
136
|
-
|
137
|
-
requirement: &70247558440000 !ruby/object:Gem::Requirement
|
188
|
+
name: bundler
|
189
|
+
- !ruby/object:Gem::Dependency
|
190
|
+
version_requirements: &id012 !ruby/object:Gem::Requirement
|
138
191
|
none: false
|
139
|
-
requirements:
|
140
|
-
- -
|
141
|
-
- !ruby/object:Gem::Version
|
142
|
-
|
192
|
+
requirements:
|
193
|
+
- - ">="
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
hash: 3
|
196
|
+
segments:
|
197
|
+
- 0
|
198
|
+
version: "0"
|
199
|
+
requirement: *id012
|
143
200
|
type: :development
|
144
201
|
prerelease: false
|
145
|
-
|
202
|
+
name: rake
|
146
203
|
description: A fake Braintree that you can run integration tests against
|
147
|
-
email:
|
204
|
+
email:
|
148
205
|
- gabe@thoughtbot.com
|
149
206
|
- ben@thoughtbot.com
|
150
207
|
executables: []
|
208
|
+
|
151
209
|
extensions: []
|
210
|
+
|
152
211
|
extra_rdoc_files: []
|
153
|
-
|
212
|
+
|
213
|
+
files:
|
154
214
|
- .gitignore
|
155
215
|
- .travis.yml
|
156
216
|
- Changelog.md
|
@@ -162,12 +222,15 @@ files:
|
|
162
222
|
- lib/fake_braintree/customer.rb
|
163
223
|
- lib/fake_braintree/helpers.rb
|
164
224
|
- lib/fake_braintree/redirect.rb
|
225
|
+
- lib/fake_braintree/registry.rb
|
226
|
+
- lib/fake_braintree/server.rb
|
165
227
|
- lib/fake_braintree/sinatra_app.rb
|
166
228
|
- lib/fake_braintree/subscription.rb
|
167
229
|
- lib/fake_braintree/valid_credit_cards.rb
|
168
230
|
- lib/fake_braintree/version.rb
|
169
231
|
- spec/fake_braintree/credit_card_spec.rb
|
170
232
|
- spec/fake_braintree/customer_spec.rb
|
233
|
+
- spec/fake_braintree/registry_spec.rb
|
171
234
|
- spec/fake_braintree/subscription_spec.rb
|
172
235
|
- spec/fake_braintree/transaction_spec.rb
|
173
236
|
- spec/fake_braintree/transparent_redirect_spec.rb
|
@@ -176,39 +239,43 @@ files:
|
|
176
239
|
- spec/support/braintree_helpers.rb
|
177
240
|
- spec/support/customer_helpers.rb
|
178
241
|
- spec/support/subscription_helpers.rb
|
179
|
-
homepage:
|
242
|
+
homepage: ""
|
180
243
|
licenses: []
|
244
|
+
|
181
245
|
post_install_message:
|
182
246
|
rdoc_options: []
|
183
|
-
|
247
|
+
|
248
|
+
require_paths:
|
184
249
|
- lib
|
185
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
250
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
186
251
|
none: false
|
187
|
-
requirements:
|
188
|
-
- -
|
189
|
-
- !ruby/object:Gem::Version
|
190
|
-
|
191
|
-
segments:
|
252
|
+
requirements:
|
253
|
+
- - ">="
|
254
|
+
- !ruby/object:Gem::Version
|
255
|
+
hash: 3
|
256
|
+
segments:
|
192
257
|
- 0
|
193
|
-
|
194
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
258
|
+
version: "0"
|
259
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
260
|
none: false
|
196
|
-
requirements:
|
197
|
-
- -
|
198
|
-
- !ruby/object:Gem::Version
|
199
|
-
|
200
|
-
segments:
|
261
|
+
requirements:
|
262
|
+
- - ">="
|
263
|
+
- !ruby/object:Gem::Version
|
264
|
+
hash: 3
|
265
|
+
segments:
|
201
266
|
- 0
|
202
|
-
|
267
|
+
version: "0"
|
203
268
|
requirements: []
|
269
|
+
|
204
270
|
rubyforge_project:
|
205
271
|
rubygems_version: 1.8.11
|
206
272
|
signing_key:
|
207
273
|
specification_version: 3
|
208
274
|
summary: A fake Braintree that you can run integration tests against
|
209
|
-
test_files:
|
275
|
+
test_files:
|
210
276
|
- spec/fake_braintree/credit_card_spec.rb
|
211
277
|
- spec/fake_braintree/customer_spec.rb
|
278
|
+
- spec/fake_braintree/registry_spec.rb
|
212
279
|
- spec/fake_braintree/subscription_spec.rb
|
213
280
|
- spec/fake_braintree/transaction_spec.rb
|
214
281
|
- spec/fake_braintree/transparent_redirect_spec.rb
|