fake_braintree 0.2.1 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,56 +1,103 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe FakeBraintree::SinatraApp do
4
- context "Braintree::TransparentRedirect.url" do
5
- it "returns a URL that will redirect with a token for the specified request" do
6
- redirect_url = "http://example.com/redirect_path"
4
+ context 'Braintree::TransparentRedirect.url' do
5
+ it 'returns a URL that will redirect with a token for the specified request' do
6
+ redirect_url = 'http://example.com/redirect_path'
7
7
 
8
- response = post_transparent_redirect(:redirect_url => redirect_url, :customer => build_customer_hash)
8
+ response = post_transparent_redirect(:create_customer_data, :redirect_url => redirect_url, :customer => build_customer_hash)
9
9
 
10
- response.code.should == "303"
11
- response["Location"].should =~ %r{http://example\.com/redirect_path}
10
+ response.code.should == '303'
11
+ response['Location'].should =~ %r{http://example\.com/redirect_path}
12
12
  params = parse_redirect(response)
13
- params[:http_status].should == "200"
13
+ params[:http_status].should == '200'
14
14
  params[:id].should_not be_nil
15
15
  params[:kind].should_not be_nil
16
16
  end
17
17
 
18
- it "rejects submissions without transparent redirect data" do
18
+ it "preserves redirect_url query parameters" do
19
+ redirect_url = 'http://example.com/redirect_path?preserve=me'
20
+
21
+ response = post_transparent_redirect(
22
+ :create_customer_data,
23
+ :redirect_url => redirect_url,
24
+ :customer => build_customer_hash
25
+ )
26
+
27
+ params = parse_redirect(response)
28
+ params[:preserve].should == 'me'
29
+ end
30
+
31
+ it 'rejects submissions without transparent redirect data' do
19
32
  response = post_transparent_redirect_without_data
20
- response.code.should == "422"
33
+ response.code.should == '422'
21
34
  end
22
35
  end
23
36
 
24
- context "Braintree::TransparentRedirect.confirm" do
25
- it "confirms and runs the specified request" do
26
- number = "4111111111111111"
27
- customer_hash = build_customer_hash(:credit_card => { :number => number })
28
- response = post_transparent_redirect(:customer => customer_hash)
29
- query = parse_query(response)
37
+ context 'Braintree::TransparentRedirect.confirm' do
38
+ describe 'Creating customers' do
39
+ it 'confirms and runs the specified request' do
40
+ number = '4111111111111111'
41
+ customer_hash = build_customer_hash(:credit_card => { :number => number })
42
+ response = post_transparent_redirect(:create_customer_data, :customer => customer_hash)
43
+ query = parse_query(response)
30
44
 
31
- result = Braintree::TransparentRedirect.confirm(query)
45
+ result = Braintree::TransparentRedirect.confirm(query)
32
46
 
33
- result.should be_success
47
+ result.should be_success
34
48
 
35
- customer = Braintree::Customer.find(result.customer.id)
36
- customer.credit_cards.first.last_4.should == "1111"
49
+ customer = Braintree::Customer.find(result.customer.id)
50
+ customer.credit_cards.first.last_4.should == '1111'
51
+ end
52
+ end
53
+
54
+ describe 'Creating credit cards' do
55
+ it 'confirms and runs the specified request' do
56
+ customer = create_customer.customer
57
+ number = '4111111111111337'
58
+ credit_card_hash = build_credit_card_hash({ :number => number, :customer_id => customer.id})
59
+ response = post_transparent_redirect(:create_credit_card_data, :credit_card => credit_card_hash)
60
+ query = parse_query(response)
61
+
62
+ result = Braintree::TransparentRedirect.confirm(query)
63
+
64
+ result.should be_success
65
+
66
+ customer = Braintree::Customer.find(customer.id)
67
+ customer.credit_cards.first.last_4.should == '1111'
68
+ end
37
69
  end
38
70
  end
39
71
 
40
72
  def build_customer_hash(options = {})
41
73
  {
42
74
  :credit_card => {
43
- :number => "4111111111111111",
44
- :expiration_date => "4/2015",
45
- :cardholder_name => "Susie Spender"
75
+ :number => '4111111111111111',
76
+ :expiration_date => '4/2015',
77
+ :cardholder_name => 'Susie Spender'
46
78
  }.update(options[:credit_card] || {})
47
79
  }
48
80
  end
49
81
 
50
- def post_transparent_redirect(data)
82
+ def build_credit_card_hash(options = {})
83
+ {
84
+ :number => '4111111111111111',
85
+ :expiration_date => '4/2015',
86
+ :cardholder_name => 'Susie Spender',
87
+ :cvv => '123',
88
+ :billing_address => {
89
+ :street_address => '123 Sesame Street',
90
+ :locality => 'San Francisco',
91
+ :region => 'CA',
92
+ :postal_code => '94110'
93
+ }
94
+ }.update(options || {})
95
+ end
96
+
97
+ def post_transparent_redirect(type, data)
51
98
  params = data.dup
52
- redirect_url = params.delete(:redirect_url) || "http://example.com/redirect_path"
53
- params[:tr_data] = Braintree::TransparentRedirect.create_customer_data(:redirect_url => redirect_url)
99
+ redirect_url = params.delete(:redirect_url) || 'http://example.com/redirect_path'
100
+ params[:tr_data] = Braintree::TransparentRedirect.send(type, {:redirect_url => redirect_url}.merge(params))
54
101
  post_transparent_redirect_params(params)
55
102
  end
56
103
 
@@ -71,6 +118,6 @@ describe FakeBraintree::SinatraApp do
71
118
  end
72
119
 
73
120
  def parse_query(response)
74
- URI.parse(response["Location"]).query
121
+ URI.parse(response['Location']).query
75
122
  end
76
123
  end
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe FakeBraintree, ".decline_all_cards!" do
3
+ describe FakeBraintree, '.decline_all_cards!' do
4
4
  before { FakeBraintree.decline_all_cards! }
5
5
 
6
- it "declines all cards" do
6
+ it 'declines all cards' do
7
7
  create_sale.should_not be_success
8
8
  end
9
9
 
10
- it "stops declining cards after clear! is called" do
10
+ it 'stops declining cards after clear! is called' do
11
11
  FakeBraintree.clear!
12
12
  create_sale.should be_success
13
13
  end
@@ -17,8 +17,8 @@ describe FakeBraintree, ".decline_all_cards!" do
17
17
  end
18
18
  end
19
19
 
20
- describe FakeBraintree, ".log_file_path" do
21
- it "is tmp/log" do
20
+ describe FakeBraintree, '.log_file_path' do
21
+ it 'is tmp/log' do
22
22
  FakeBraintree.log_file_path.should == 'tmp/log'
23
23
  end
24
24
  end
@@ -26,36 +26,36 @@ end
26
26
  describe Braintree::Configuration do
27
27
  subject { Braintree::Configuration }
28
28
 
29
- it "is running in the development environment" do
29
+ it 'is running in the development environment' do
30
30
  subject.environment.should == :development
31
31
  end
32
32
 
33
- it "has some fake API credentials" do
34
- subject.merchant_id.should == "xxx"
35
- subject.public_key.should == "xxx"
36
- subject.private_key.should == "xxx"
33
+ it 'has some fake API credentials' do
34
+ subject.merchant_id.should == 'xxx'
35
+ subject.public_key.should == 'xxx'
36
+ subject.private_key.should == 'xxx'
37
37
  end
38
38
  end
39
39
 
40
40
  describe FakeBraintree do
41
- it "creates a log file" do
41
+ it 'creates a log file' do
42
42
  File.exist?(FakeBraintree.log_file_path).should == true
43
43
  end
44
44
 
45
- it "logs to the correct path" do
45
+ it 'logs to the correct path' do
46
46
  Braintree::Configuration.logger.info('Logger test')
47
47
  File.readlines(FakeBraintree.log_file_path).last.should == "Logger test\n"
48
48
  end
49
49
  end
50
50
 
51
- describe FakeBraintree, ".clear_log!" do
52
- it "clears the log file" do
51
+ describe FakeBraintree, '.clear_log!' do
52
+ it 'clears the log file' do
53
53
  write_to_log
54
54
  subject.clear_log!
55
- File.read(FakeBraintree.log_file_path).should == ""
55
+ File.read(FakeBraintree.log_file_path).should == ''
56
56
  end
57
57
 
58
- it "is called by clear!" do
58
+ it 'is called by clear!' do
59
59
  FakeBraintree.expects(:clear_log!)
60
60
  FakeBraintree.clear!
61
61
  end
@@ -65,8 +65,8 @@ describe FakeBraintree, ".clear_log!" do
65
65
  end
66
66
  end
67
67
 
68
- describe FakeBraintree, "VALID_CREDIT_CARDS" do
69
- it "includes only credit cards that are valid in the Braintree sandbox" do
68
+ describe FakeBraintree, 'VALID_CREDIT_CARDS' do
69
+ it 'includes only credit cards that are valid in the Braintree sandbox' do
70
70
  FakeBraintree::VALID_CREDIT_CARDS.sort.should == valid_credit_cards.sort
71
71
  end
72
72
 
@@ -82,46 +82,46 @@ describe FakeBraintree, "VALID_CREDIT_CARDS" do
82
82
  end
83
83
  end
84
84
 
85
- describe FakeBraintree, ".failure_response" do
86
- it "can be called with no arguments" do
85
+ describe FakeBraintree, '.failure_response' do
86
+ it 'can be called with no arguments' do
87
87
  expect { FakeBraintree.failure_response }.not_to raise_error
88
88
  end
89
89
  end
90
90
 
91
- describe FakeBraintree, ".generate_transaction" do
92
- it "allows setting the subscription id" do
91
+ describe FakeBraintree, '.generate_transaction' do
92
+ it 'allows setting the subscription id' do
93
93
  transaction = FakeBraintree.generate_transaction(:subscription_id => 'foobar')
94
94
  transaction['subscription_id'].should == 'foobar'
95
95
  end
96
96
 
97
- it "allows setting created_at" do
97
+ it 'allows setting created_at' do
98
98
  time = Time.now
99
99
  transaction = FakeBraintree.generate_transaction(:created_at => time)
100
100
  transaction['created_at'].should == time
101
101
  end
102
102
 
103
- it "sets created_at to Time.now by default" do
103
+ it 'sets created_at to Time.now by default' do
104
104
  Timecop.freeze do
105
105
  transaction = FakeBraintree.generate_transaction
106
106
  transaction['created_at'].should == Time.now
107
107
  end
108
108
  end
109
109
 
110
- it "has the correct amount" do
111
- transaction = FakeBraintree.generate_transaction(:amount => "20.00")
112
- transaction['amount'].should == "20.00"
110
+ it 'has the correct amount' do
111
+ transaction = FakeBraintree.generate_transaction(:amount => '20.00')
112
+ transaction['amount'].should == '20.00'
113
113
  end
114
114
 
115
- it "allows no arguments" do
115
+ it 'allows no arguments' do
116
116
  expect { FakeBraintree.generate_transaction }.not_to raise_error
117
117
  end
118
118
 
119
- context "status_history" do
120
- it "returns a hash with a status_history key" do
119
+ context 'status_history' do
120
+ it 'returns a hash with a status_history key' do
121
121
  FakeBraintree.generate_transaction(:amount => '20').should have_key('status_history')
122
122
  end
123
123
 
124
- it "has a timestamp of Time.now" do
124
+ it 'has a timestamp of Time.now' do
125
125
  Timecop.freeze do
126
126
  transaction = FakeBraintree.generate_transaction(:status => Braintree::Transaction::Status::Failed,
127
127
  :subscription_id => 'my_subscription_id')
@@ -129,12 +129,12 @@ describe FakeBraintree, ".generate_transaction" do
129
129
  end
130
130
  end
131
131
 
132
- it "has the desired amount" do
132
+ it 'has the desired amount' do
133
133
  transaction = FakeBraintree.generate_transaction(:amount => '20.00')
134
134
  transaction['status_history'].first['amount'].should == '20.00'
135
135
  end
136
136
 
137
- it "has the desired status" do
137
+ it 'has the desired status' do
138
138
  status = Braintree::Transaction::Status::Failed
139
139
  transaction = FakeBraintree.generate_transaction(:status => status)
140
140
  transaction['status_history'].first['status'].should == status
data/spec/spec_helper.rb CHANGED
@@ -11,7 +11,7 @@ Spork.prefork do
11
11
  File.new('tmp/braintree_log', 'w').close
12
12
  end
13
13
 
14
- Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f}
14
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each {|f| require f}
15
15
 
16
16
  clear_braintree_log
17
17
 
@@ -1,7 +1,7 @@
1
1
  module BraintreeHelpers
2
2
  def create_braintree_customer(cc_number, expiration_date)
3
3
  Braintree::Customer.create(
4
- :email => "me@example.com",
4
+ :email => 'me@example.com',
5
5
  :credit_card => {
6
6
  :number => cc_number,
7
7
  :expiration_date => expiration_date
@@ -1,11 +1,11 @@
1
1
  RSpec::Matchers.define :clear_hash_when_cleared do |property|
2
2
  match do |object|
3
- object.send(property.to_sym)["key"] = "value"
3
+ object.send(property.to_sym)['key'] = 'value'
4
4
  object.clear!
5
5
  object.send(property.to_sym).should be_empty
6
6
  end
7
7
 
8
- failure_message do
8
+ failure_message_for_should 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
  object.send(property.to_sym)['key'].should == 'value'
5
5
  end
6
6
 
7
- failure_message do
7
+ failure_message_for_should do
8
8
  "Expected #{object} to have accessor for #{property}, but it did not."
9
9
  end
10
10
  end
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.1
4
+ version: '0.3'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-26 00:00:00.000000000 Z
12
+ date: 2013-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara
@@ -114,7 +114,7 @@ dependencies:
114
114
  requirements:
115
115
  - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: 2.6.0
117
+ version: 2.12.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,7 +122,7 @@ dependencies:
122
122
  requirements:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
- version: 2.6.0
125
+ version: 2.12.0
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: bourne
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -214,10 +214,10 @@ files:
214
214
  - .gitignore
215
215
  - .travis.yml
216
216
  - CONTRIBUTING.md
217
- - Changelog.md
218
217
  - GOALS
219
218
  - Gemfile
220
219
  - LICENSE
220
+ - NEWS.md
221
221
  - README.md
222
222
  - Rakefile
223
223
  - fake_braintree.gemspec
@@ -259,7 +259,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
259
259
  version: '0'
260
260
  segments:
261
261
  - 0
262
- hash: -3718552739890395570
262
+ hash: 2263458799663259679
263
263
  required_rubygems_version: !ruby/object:Gem::Requirement
264
264
  none: false
265
265
  requirements:
@@ -268,7 +268,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
268
268
  version: '0'
269
269
  segments:
270
270
  - 0
271
- hash: -3718552739890395570
271
+ hash: 2263458799663259679
272
272
  requirements: []
273
273
  rubyforge_project:
274
274
  rubygems_version: 1.8.24
data/Changelog.md DELETED
@@ -1,41 +0,0 @@
1
- # 0.2.0
2
- * Generated transactions (from FakeBraintree.generate_transaction) now include
3
- the amount.
4
- * Braintree::Customer.update will reject updates that contain credit cards that
5
- have been marked as a failure in the registry.
6
-
7
- # 0.1.1
8
- * Braintree::CreditCard.update now works
9
-
10
- # 0.1.0
11
- * FakeBraintree.{customers, transactions, failures, subscriptions, redirects}
12
- are now accessed via FakeBraintree.registry. For example,
13
- FakeBraintree.customers is now FakeBraintree.registry.customers
14
- * FakeBraintree.credit_card_from_token is now FakeBraintree.registry.credit_card_from_token
15
- * The server code (it intercepts calls to Braintree) now lives in FakeBraintree::Server
16
- * Braintree::Customer.create will use the provided customer ID instead of
17
- overwriting it (#15).
18
- * Braintree::Subscription.cancel now works
19
-
20
- # 0.0.6
21
- * Flesh out the README
22
- * Add support for transparent redirect
23
- * Add basic support for adding add-ons
24
- * Add basic support for adding discounts
25
- * Add support for Braintree::Customer.update
26
- * Add support for Braintree::Customer.delete
27
- * Add support for Braintree::Subscription.delete
28
- * Lots of internal refactorings
29
-
30
- # 0.0.5
31
- * Add support for Braintree::Customer.find
32
-
33
- # 0.0.4
34
- * Allow for very basic card verification
35
-
36
- # 0.0.3
37
- * Ensure FakeBraintree.log_file_path directory exists
38
- * The FakeBraintree.log_file_path attribute can now be read (it could only be set before)
39
- * Clear log when FakeBraintree.clear! is called
40
- * Correctly handle nonexistent subscriptions when using
41
- Braintree::Subscription.find