braintree-rails 1.2.3 → 1.3.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 +4 -4
- data/.gitignore +3 -1
- data/.travis.yml +13 -4
- data/CHANGELOG.md +5 -1
- data/Gemfile +3 -4
- data/Gemfile.lock +33 -14
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/braintree-rails.gemspec +4 -5
- data/lib/braintree_rails/address.rb +1 -1
- data/lib/braintree_rails/address_details.rb +14 -0
- data/lib/braintree_rails/address_details_validator.rb +7 -0
- data/lib/braintree_rails/association.rb +2 -2
- data/lib/braintree_rails/braintree_ext.rb +27 -1
- data/lib/braintree_rails/business_details.rb +29 -0
- data/lib/braintree_rails/business_details_validator.rb +12 -0
- data/lib/braintree_rails/configuration.rb +1 -1
- data/lib/braintree_rails/credit_card.rb +6 -6
- data/lib/braintree_rails/credit_card_validator.rb +2 -17
- data/lib/braintree_rails/customer.rb +6 -6
- data/lib/braintree_rails/customer_validator.rb +1 -12
- data/lib/braintree_rails/funding_details.rb +17 -0
- data/lib/braintree_rails/funding_details_validator.rb +10 -0
- data/lib/braintree_rails/individual_details.rb +32 -0
- data/lib/braintree_rails/individual_details_validator.rb +11 -0
- data/lib/braintree_rails/merchant_account.rb +45 -0
- data/lib/braintree_rails/merchant_account_validator.rb +14 -0
- data/lib/braintree_rails/plan.rb +3 -3
- data/lib/braintree_rails/subscription.rb +5 -5
- data/lib/braintree_rails/transaction.rb +9 -9
- data/lib/braintree_rails/transaction_validator.rb +1 -5
- data/lib/braintree_rails/validator.rb +13 -0
- data/lib/braintree_rails/version.rb +1 -1
- data/lib/tasks/ci.rake +7 -0
- data/lib/tasks/spec.rake +18 -0
- data/lib/test_env.rb +1 -7
- data/{test → spec}/config/braintree_auth.yml.example +0 -0
- data/{test → spec}/fixtures/add_ons.xml +0 -0
- data/{test → spec}/fixtures/address.xml +0 -0
- data/{test → spec}/fixtures/credit_card.xml +0 -0
- data/{test → spec}/fixtures/credit_card_validation_error.xml +0 -0
- data/{test → spec}/fixtures/customer.xml +0 -0
- data/{test → spec}/fixtures/discounts.xml +0 -0
- data/spec/fixtures/merchant_account.xml +7 -0
- data/{test → spec}/fixtures/plans.xml +0 -0
- data/{test → spec}/fixtures/subscription.xml +0 -0
- data/{test → spec}/fixtures/subscription_ids.xml +0 -0
- data/{test → spec}/fixtures/subscriptions.xml +0 -0
- data/{test → spec}/fixtures/transaction.xml +0 -0
- data/{test → spec}/fixtures/transaction_error.xml +0 -0
- data/{test → spec}/fixtures/transaction_ids.xml +0 -0
- data/{test → spec}/fixtures/transactions.xml +0 -0
- data/{test/integration/braintree_rails/address_integration_test.rb → spec/integration/braintree_rails/address_integration_spec.rb} +8 -8
- data/{test/integration/braintree_rails/credit_card_integration_test.rb → spec/integration/braintree_rails/credit_card_integration_spec.rb} +20 -20
- data/{test/integration/braintree_rails/customer_integration_test.rb → spec/integration/braintree_rails/customer_integration_spec.rb} +20 -20
- data/spec/integration/braintree_rails/merchant_account_integration_spec.rb +37 -0
- data/{test/integration/braintree_rails/transaction_integration_test.rb → spec/integration/braintree_rails/transaction_integration_spec.rb} +27 -27
- data/spec/integration/integration_spec_helper.rb +23 -0
- data/spec/spec_helper.rb +17 -0
- data/{test/test_helper.rb → spec/support/helper.rb} +42 -21
- data/spec/support/string_ext.rb +5 -0
- data/{test/unit/braintree_rails/add_on_test.rb → spec/unit/braintree_rails/add_on_spec.rb} +10 -10
- data/{test/unit/braintree_rails/add_ons_test.rb → spec/unit/braintree_rails/add_ons_spec.rb} +4 -4
- data/spec/unit/braintree_rails/address_details_spec.rb +13 -0
- data/{test/unit/braintree_rails/address_test.rb → spec/unit/braintree_rails/address_spec.rb} +26 -26
- data/{test/unit/braintree_rails/addresses_test.rb → spec/unit/braintree_rails/addresses_spec.rb} +7 -7
- data/spec/unit/braintree_rails/business_details_spec.rb +28 -0
- data/{test/unit/braintree_rails/configuration_test.rb → spec/unit/braintree_rails/configuration_spec.rb} +6 -6
- data/{test/unit/braintree_rails/credit_card_test.rb → spec/unit/braintree_rails/credit_card_spec.rb} +78 -72
- data/{test/unit/braintree_rails/credit_cards_test.rb → spec/unit/braintree_rails/credit_cards_spec.rb} +15 -10
- data/{test/unit/braintree_rails/customer_test.rb → spec/unit/braintree_rails/customer_spec.rb} +46 -46
- data/{test/unit/braintree_rails/discount_test.rb → spec/unit/braintree_rails/discount_spec.rb} +10 -10
- data/{test/unit/braintree_rails/discounts_test.rb → spec/unit/braintree_rails/discounts_spec.rb} +4 -4
- data/spec/unit/braintree_rails/funding_details_spec.rb +36 -0
- data/spec/unit/braintree_rails/individual_details_spec.rb +19 -0
- data/{test/unit/braintree_rails/luhn_10_validator_test.rb → spec/unit/braintree_rails/luhn_10_validator_spec.rb} +5 -5
- data/spec/unit/braintree_rails/merchant_account_spec.rb +50 -0
- data/{test/unit/braintree_rails/plan_test.rb → spec/unit/braintree_rails/plan_spec.rb} +12 -12
- data/{test/unit/braintree_rails/subscription_test.rb → spec/unit/braintree_rails/subscription_spec.rb} +55 -55
- data/{test/unit/braintree_rails/subscriptions_test.rb → spec/unit/braintree_rails/subscriptions_spec.rb} +4 -4
- data/{test/unit/braintree_rails/transaction_test.rb → spec/unit/braintree_rails/transaction_spec.rb} +55 -55
- data/{test/unit/braintree_rails/transactions_test.rb → spec/unit/braintree_rails/transactions_spec.rb} +9 -9
- data/{test/unit/braintree_rails/validation_error_test.rb → spec/unit/braintree_rails/validation_error_spec.rb} +4 -4
- data/{test/unit/braintree_rails/validator_test.rb → spec/unit/braintree_rails/validator_spec.rb} +7 -7
- data/spec/unit/unit_spec_helper.rb +4 -0
- metadata +69 -63
- data/lib/tasks/test.rake +0 -18
- data/test/integration/integration_test_helper.rb +0 -13
- data/test/unit/unit_test_helper.rb +0 -3
data/{test/unit/braintree_rails/addresses_test.rb → spec/unit/braintree_rails/addresses_spec.rb}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '../
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../unit_spec_helper'))
|
2
2
|
|
3
3
|
describe BraintreeRails::Addresses do
|
4
4
|
before do
|
@@ -11,12 +11,12 @@ describe BraintreeRails::Addresses do
|
|
11
11
|
braintree_addresses = braintree_customer.addresses
|
12
12
|
addresses = BraintreeRails::Addresses.new(BraintreeRails::Customer.find('customer_id'))
|
13
13
|
|
14
|
-
addresses.size.
|
14
|
+
addresses.size.should == braintree_addresses.size
|
15
15
|
|
16
16
|
braintree_addresses.each do |braintree_address|
|
17
17
|
address = addresses.find(braintree_address.id)
|
18
18
|
BraintreeRails::Address.attributes.each do |attribute|
|
19
|
-
address.send(attribute).
|
19
|
+
address.send(attribute).should == braintree_address.send(attribute)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -29,10 +29,10 @@ describe BraintreeRails::Addresses do
|
|
29
29
|
addresses = BraintreeRails::Addresses.new(BraintreeRails::Customer.find('customer_id'))
|
30
30
|
address = addresses.build({:first_name => 'foo', :last_name => 'bar'})
|
31
31
|
|
32
|
-
address.
|
33
|
-
address.customer_id.
|
34
|
-
address.first_name.
|
35
|
-
address.last_name.
|
32
|
+
address.should_not be_persisted
|
33
|
+
address.customer_id.should == braintree_customer.id
|
34
|
+
address.first_name.should == 'foo'
|
35
|
+
address.last_name.should == 'bar'
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../unit_spec_helper'))
|
2
|
+
|
3
|
+
describe BraintreeRails::BusinessDetails do
|
4
|
+
describe 'validations' do
|
5
|
+
it "requries legal_name if tax_id is present" do
|
6
|
+
business = BraintreeRails::BusinessDetails.new(business_details_hash.merge(:legal_name => nil))
|
7
|
+
business.should be_invalid
|
8
|
+
business.errors[:legal_name].should == ["can't be blank"]
|
9
|
+
end
|
10
|
+
|
11
|
+
it "requries tax_id if legal_name is present" do
|
12
|
+
business = BraintreeRails::BusinessDetails.new(business_details_hash.merge(:tax_id => nil))
|
13
|
+
business.should be_invalid
|
14
|
+
business.errors[:tax_id].should == ["can't be blank"]
|
15
|
+
end
|
16
|
+
|
17
|
+
it "does not requrie either if neither are present" do
|
18
|
+
business = BraintreeRails::BusinessDetails.new({})
|
19
|
+
business.should be_valid
|
20
|
+
end
|
21
|
+
|
22
|
+
it "validates assocaited address" do
|
23
|
+
business = BraintreeRails::BusinessDetails.new(address_details_hash.merge(:address => {}))
|
24
|
+
business.should be_invalid
|
25
|
+
business.errors[:address].should_not be_empty
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '../
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../unit_spec_helper'))
|
2
2
|
|
3
3
|
describe BraintreeRails::Configuration do
|
4
4
|
[:merchant_id, :public_key, :private_key, :logger].each do |config|
|
@@ -6,8 +6,8 @@ describe BraintreeRails::Configuration do
|
|
6
6
|
begin
|
7
7
|
old_value = Braintree::Configuration.send(config)
|
8
8
|
BraintreeRails::Configuration.send("#{config}=", "foo")
|
9
|
-
Braintree::Configuration.send(config).
|
10
|
-
BraintreeRails::Configuration.send(config).
|
9
|
+
Braintree::Configuration.send(config).should == "foo"
|
10
|
+
BraintreeRails::Configuration.send(config).should == "foo"
|
11
11
|
ensure
|
12
12
|
BraintreeRails::Configuration.send("#{config}=", old_value)
|
13
13
|
end
|
@@ -16,11 +16,11 @@ describe BraintreeRails::Configuration do
|
|
16
16
|
|
17
17
|
it "should delegate environment to Braintree::Configuration" do
|
18
18
|
BraintreeRails::Configuration.environment = :sandbox
|
19
|
-
Braintree::Configuration.environment.
|
20
|
-
BraintreeRails::Configuration.environment.
|
19
|
+
Braintree::Configuration.environment.should == :sandbox
|
20
|
+
BraintreeRails::Configuration.environment.should == :sandbox
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should set custom_user_agent to braintree-rails-#{BraintreeRails::Version}" do
|
24
|
-
Braintree::Configuration.instantiate.user_agent.
|
24
|
+
Braintree::Configuration.instantiate.user_agent.should include "braintree-rails-#{BraintreeRails::Version}"
|
25
25
|
end
|
26
26
|
end
|
data/{test/unit/braintree_rails/credit_card_test.rb → spec/unit/braintree_rails/credit_card_spec.rb}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '../
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../unit_spec_helper'))
|
2
2
|
|
3
3
|
describe BraintreeRails::CreditCard do
|
4
4
|
before do
|
@@ -10,12 +10,15 @@ describe BraintreeRails::CreditCard do
|
|
10
10
|
credit_card = BraintreeRails::CreditCard.new('credit_card_id')
|
11
11
|
braintree_credit_card = Braintree::CreditCard.find('credit_card_id')
|
12
12
|
|
13
|
-
credit_card.
|
14
|
-
credit_card.default?.
|
15
|
-
credit_card.expired?.
|
16
|
-
credit_card.masked_number.
|
13
|
+
credit_card.should be_persisted
|
14
|
+
credit_card.default?.should == braintree_credit_card.default?
|
15
|
+
credit_card.expired?.should == braintree_credit_card.expired?
|
16
|
+
credit_card.masked_number.should == braintree_credit_card.masked_number
|
17
17
|
BraintreeRails::CreditCard.attributes.each do |attribute|
|
18
|
-
|
18
|
+
next if BraintreeRails::CreditCard.associations.include?(attribute)
|
19
|
+
if braintree_credit_card.respond_to?(attribute)
|
20
|
+
braintree_credit_card.send(attribute).should eq(credit_card.send(attribute))
|
21
|
+
end
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
@@ -23,28 +26,31 @@ describe BraintreeRails::CreditCard do
|
|
23
26
|
braintree_credit_card = Braintree::CreditCard.find('credit_card_id')
|
24
27
|
credit_card = BraintreeRails::CreditCard.new(braintree_credit_card)
|
25
28
|
|
26
|
-
credit_card.
|
29
|
+
credit_card.should be_persisted
|
27
30
|
BraintreeRails::CreditCard.attributes.each do |attribute|
|
28
|
-
|
31
|
+
next if BraintreeRails::CreditCard.associations.include?(attribute)
|
32
|
+
if braintree_credit_card.respond_to?(attribute)
|
33
|
+
braintree_credit_card.send(attribute).should eq(credit_card.send(attribute))
|
34
|
+
end
|
29
35
|
end
|
30
36
|
end
|
31
37
|
|
32
38
|
it 'should extract values from hash' do
|
33
39
|
credit_card = BraintreeRails::CreditCard.new(:token => 'new_id')
|
34
40
|
|
35
|
-
credit_card.
|
36
|
-
credit_card.token.
|
41
|
+
credit_card.should_not be_persisted
|
42
|
+
credit_card.token.should == 'new_id'
|
37
43
|
end
|
38
44
|
|
39
45
|
it 'should try to extract value from other types' do
|
40
46
|
credit_card = BraintreeRails::CreditCard.new(OpenStruct.new(:token => 'foobar', :cardholder_name => 'Foo Bar', :persisted? => true))
|
41
47
|
|
42
|
-
credit_card.
|
43
|
-
credit_card.token.
|
44
|
-
credit_card.cardholder_name.
|
48
|
+
credit_card.should be_persisted
|
49
|
+
credit_card.token.should == 'foobar'
|
50
|
+
credit_card.cardholder_name.should == 'Foo Bar'
|
45
51
|
|
46
52
|
credit_card = BraintreeRails::CreditCard.new(OpenStruct.new)
|
47
|
-
credit_card.
|
53
|
+
credit_card.should_not be_persisted
|
48
54
|
end
|
49
55
|
end
|
50
56
|
|
@@ -52,8 +58,8 @@ describe BraintreeRails::CreditCard do
|
|
52
58
|
it 'should load customer for persisted credit_card' do
|
53
59
|
credit_card = BraintreeRails::CreditCard.new('credit_card_id')
|
54
60
|
stub_braintree_request(:get, '/customers/customer_id', :body => fixture('customer.xml'))
|
55
|
-
credit_card.customer.
|
56
|
-
credit_card.customer.id.
|
61
|
+
credit_card.customer.should be_persisted
|
62
|
+
credit_card.customer.id.should == 'customer_id'
|
57
63
|
end
|
58
64
|
end
|
59
65
|
|
@@ -62,29 +68,29 @@ describe BraintreeRails::CreditCard do
|
|
62
68
|
credit_card = BraintreeRails::CreditCard.new('credit_card_id')
|
63
69
|
braintree_credit_card = Braintree::CreditCard.find('credit_card_id')
|
64
70
|
|
65
|
-
credit_card.subscriptions.
|
66
|
-
credit_card.subscriptions.size.
|
71
|
+
credit_card.subscriptions.should respond_to(:each)
|
72
|
+
credit_card.subscriptions.size.should == braintree_credit_card.subscriptions.size
|
67
73
|
end
|
68
74
|
|
69
75
|
it 'can build new subscription' do
|
70
76
|
credit_card = BraintreeRails::CreditCard.new('credit_card_id')
|
71
77
|
subscription = credit_card.subscriptions.build
|
72
|
-
subscription.payment_method_token.
|
78
|
+
subscription.payment_method_token.should == credit_card.token
|
73
79
|
end
|
74
80
|
end
|
75
81
|
|
76
82
|
describe '#billing_address' do
|
77
83
|
it 'should wrap billing_address with Address object' do
|
78
84
|
credit_card = BraintreeRails::CreditCard.new(OpenStruct.new(:billing_address => {}))
|
79
|
-
credit_card.billing_address.class.ancestors.
|
85
|
+
credit_card.billing_address.class.ancestors.should include BraintreeRails::Address
|
80
86
|
|
81
87
|
credit_card.billing_address = BraintreeRails::Address.new
|
82
|
-
credit_card.billing_address.class.ancestors.
|
88
|
+
credit_card.billing_address.class.ancestors.should include(BraintreeRails::Address)
|
83
89
|
end
|
84
90
|
|
85
91
|
it 'should keep billing_address nil if assigned nil value' do
|
86
92
|
credit_card = BraintreeRails::CreditCard.new(OpenStruct.new(:billing_address => nil))
|
87
|
-
credit_card.billing_address.
|
93
|
+
credit_card.billing_address.should be_nil
|
88
94
|
end
|
89
95
|
|
90
96
|
end
|
@@ -93,48 +99,48 @@ describe BraintreeRails::CreditCard do
|
|
93
99
|
it 'should validate precence of customer_id on create' do
|
94
100
|
credit_card = BraintreeRails::CreditCard.new
|
95
101
|
credit_card.valid?(:create)
|
96
|
-
credit_card.errors[:customer_id].
|
102
|
+
credit_card.errors[:customer_id].should_not be_blank
|
97
103
|
|
98
104
|
credit_card = BraintreeRails::CreditCard.new(:customer_id => 'foo')
|
99
105
|
credit_card.valid?(:create)
|
100
|
-
credit_card.errors[:customer_id].
|
106
|
+
credit_card.errors[:customer_id].should be_blank
|
101
107
|
end
|
102
108
|
|
103
109
|
it 'should validate length of customer_id' do
|
104
110
|
credit_card = BraintreeRails::CreditCard.new(:customer_id => 'foo' * 13)
|
105
111
|
credit_card.valid?(:create)
|
106
|
-
credit_card.errors[:customer_id].
|
112
|
+
credit_card.errors[:customer_id].should_not be_blank
|
107
113
|
|
108
114
|
credit_card = BraintreeRails::CreditCard.new(:customer_id => 'foo')
|
109
115
|
credit_card.valid?(:create)
|
110
|
-
credit_card.errors[:customer_id].
|
116
|
+
credit_card.errors[:customer_id].should be_blank
|
111
117
|
|
112
118
|
credit_card = BraintreeRails::CreditCard.new(:customer_id => 'foo' * 12)
|
113
119
|
credit_card.valid?(:create)
|
114
|
-
credit_card.errors[:customer_id].
|
120
|
+
credit_card.errors[:customer_id].should be_blank
|
115
121
|
end
|
116
122
|
|
117
123
|
it 'should validate precence of number if new_record?' do
|
118
124
|
credit_card = BraintreeRails::CreditCard.new
|
119
125
|
credit_card.valid?
|
120
|
-
credit_card.errors[:number].
|
126
|
+
credit_card.errors[:number].should_not be_blank
|
121
127
|
|
122
128
|
credit_card = BraintreeRails::CreditCard.new(:number => '4111111111111111')
|
123
129
|
credit_card.valid?
|
124
|
-
credit_card.errors[:number].
|
130
|
+
credit_card.errors[:number].should be_blank
|
125
131
|
|
126
132
|
credit_card = BraintreeRails::CreditCard.new('credit_card_id')
|
127
|
-
credit_card.
|
133
|
+
credit_card.should be_valid
|
128
134
|
end
|
129
135
|
|
130
136
|
it 'should validate precence of cvv' do
|
131
137
|
credit_card = BraintreeRails::CreditCard.new
|
132
138
|
credit_card.valid?
|
133
|
-
credit_card.errors[:cvv].
|
139
|
+
credit_card.errors[:cvv].should_not be_blank
|
134
140
|
|
135
141
|
credit_card = BraintreeRails::CreditCard.new(:cvv => '111')
|
136
142
|
credit_card.valid?
|
137
|
-
credit_card.errors[:cvv].
|
143
|
+
credit_card.errors[:cvv].should be_blank
|
138
144
|
end
|
139
145
|
|
140
146
|
describe 'S2S mode' do
|
@@ -149,101 +155,101 @@ describe BraintreeRails::CreditCard do
|
|
149
155
|
it 'should validate numericality of number' do
|
150
156
|
credit_card = BraintreeRails::CreditCard.new(:number => 'foobar')
|
151
157
|
credit_card.valid?
|
152
|
-
credit_card.errors[:number].
|
158
|
+
credit_card.errors[:number].should_not be_blank
|
153
159
|
|
154
160
|
credit_card = BraintreeRails::CreditCard.new(:number => '4111111111111111')
|
155
161
|
credit_card.valid?
|
156
|
-
credit_card.errors[:number].
|
162
|
+
credit_card.errors[:number].should be_blank
|
157
163
|
end
|
158
164
|
|
159
165
|
it 'should validate length of number' do
|
160
166
|
credit_card = BraintreeRails::CreditCard.new(:number => '1')
|
161
167
|
credit_card.valid?
|
162
|
-
credit_card.errors[:number].
|
168
|
+
credit_card.errors[:number].should_not be_blank
|
163
169
|
|
164
170
|
credit_card = BraintreeRails::CreditCard.new(:number => '1' * 20)
|
165
171
|
credit_card.valid?
|
166
|
-
credit_card.errors[:number].
|
172
|
+
credit_card.errors[:number].should_not be_blank
|
167
173
|
|
168
174
|
credit_card = BraintreeRails::CreditCard.new(:number => '4111111111111111')
|
169
175
|
credit_card.valid?
|
170
|
-
credit_card.errors[:number].
|
176
|
+
credit_card.errors[:number].should be_blank
|
171
177
|
|
172
178
|
credit_card = BraintreeRails::CreditCard.new(:number => '6208645006512478950')
|
173
179
|
credit_card.valid?
|
174
|
-
credit_card.errors[:number].
|
180
|
+
credit_card.errors[:number].should be_blank
|
175
181
|
end
|
176
182
|
|
177
183
|
it 'should validate numericality of cvv' do
|
178
184
|
credit_card = BraintreeRails::CreditCard.new(:cvv => 'foo')
|
179
185
|
credit_card.valid?
|
180
|
-
credit_card.errors[:cvv].
|
186
|
+
credit_card.errors[:cvv].should_not be_blank
|
181
187
|
|
182
188
|
credit_card = BraintreeRails::CreditCard.new(:cvv => '111')
|
183
189
|
credit_card.valid?
|
184
|
-
credit_card.errors[:cvv].
|
190
|
+
credit_card.errors[:cvv].should be_blank
|
185
191
|
end
|
186
192
|
|
187
193
|
it 'should validate length of cvv' do
|
188
194
|
credit_card = BraintreeRails::CreditCard.new(:cvv => '1')
|
189
195
|
credit_card.valid?
|
190
|
-
credit_card.errors[:cvv].
|
196
|
+
credit_card.errors[:cvv].should_not be_blank
|
191
197
|
|
192
198
|
credit_card = BraintreeRails::CreditCard.new(:cvv => '1' * 5)
|
193
199
|
credit_card.valid?
|
194
|
-
credit_card.errors[:cvv].
|
200
|
+
credit_card.errors[:cvv].should_not be_blank
|
195
201
|
|
196
202
|
credit_card = BraintreeRails::CreditCard.new(:cvv => '111')
|
197
203
|
credit_card.valid?
|
198
|
-
credit_card.errors[:cvv].
|
204
|
+
credit_card.errors[:cvv].should be_blank
|
199
205
|
|
200
206
|
credit_card = BraintreeRails::CreditCard.new(:cvv => '1111')
|
201
207
|
credit_card.valid?
|
202
|
-
credit_card.errors[:cvv].
|
208
|
+
credit_card.errors[:cvv].should be_blank
|
203
209
|
end
|
204
210
|
|
205
211
|
it 'should validate expiration month' do
|
206
212
|
credit_card = BraintreeRails::CreditCard.new(:expiration_month => 0)
|
207
213
|
credit_card.valid?
|
208
|
-
credit_card.errors[:expiration_month].
|
214
|
+
credit_card.errors[:expiration_month].should_not be_blank
|
209
215
|
|
210
216
|
credit_card = BraintreeRails::CreditCard.new(:expiration_month => 13)
|
211
217
|
credit_card.valid?
|
212
|
-
credit_card.errors[:expiration_month].
|
218
|
+
credit_card.errors[:expiration_month].should_not be_blank
|
213
219
|
|
214
220
|
credit_card = BraintreeRails::CreditCard.new(:expiration_month => 1.1)
|
215
221
|
credit_card.valid?
|
216
|
-
credit_card.errors[:expiration_month].
|
222
|
+
credit_card.errors[:expiration_month].should_not be_blank
|
217
223
|
|
218
224
|
credit_card = BraintreeRails::CreditCard.new(:expiration_month => 1)
|
219
225
|
credit_card.valid?
|
220
|
-
credit_card.errors[:expiration_month].
|
226
|
+
credit_card.errors[:expiration_month].should be_blank
|
221
227
|
|
222
228
|
credit_card = BraintreeRails::CreditCard.new(:expiration_month => '12')
|
223
229
|
credit_card.valid?
|
224
|
-
credit_card.errors[:expiration_month].
|
230
|
+
credit_card.errors[:expiration_month].should be_blank
|
225
231
|
end
|
226
232
|
|
227
233
|
it 'should validate expiration year' do
|
228
234
|
credit_card = BraintreeRails::CreditCard.new(:expiration_year => 1975)
|
229
235
|
credit_card.valid?
|
230
|
-
credit_card.errors[:expiration_year].
|
236
|
+
credit_card.errors[:expiration_year].should_not be_blank
|
231
237
|
|
232
238
|
credit_card = BraintreeRails::CreditCard.new(:expiration_year => 2201)
|
233
239
|
credit_card.valid?
|
234
|
-
credit_card.errors[:expiration_year].
|
240
|
+
credit_card.errors[:expiration_year].should_not be_blank
|
235
241
|
|
236
242
|
credit_card = BraintreeRails::CreditCard.new(:expiration_year => 1976.1)
|
237
243
|
credit_card.valid?
|
238
|
-
credit_card.errors[:expiration_year].
|
244
|
+
credit_card.errors[:expiration_year].should_not be_blank
|
239
245
|
|
240
246
|
credit_card = BraintreeRails::CreditCard.new(:expiration_year => 1976)
|
241
247
|
credit_card.valid?
|
242
|
-
credit_card.errors[:expiration_year].
|
248
|
+
credit_card.errors[:expiration_year].should be_blank
|
243
249
|
|
244
250
|
credit_card = BraintreeRails::CreditCard.new(:expiration_year => '2200')
|
245
251
|
credit_card.valid?
|
246
|
-
credit_card.errors[:expiration_year].
|
252
|
+
credit_card.errors[:expiration_year].should be_blank
|
247
253
|
end
|
248
254
|
|
249
255
|
end
|
@@ -251,38 +257,38 @@ describe BraintreeRails::CreditCard do
|
|
251
257
|
it 'should validate presence of expiration month' do
|
252
258
|
credit_card = BraintreeRails::CreditCard.new
|
253
259
|
credit_card.valid?
|
254
|
-
credit_card.errors[:expiration_month].
|
260
|
+
credit_card.errors[:expiration_month].should_not be_blank
|
255
261
|
end
|
256
262
|
|
257
263
|
it 'should validate presence of expiration year' do
|
258
264
|
credit_card = BraintreeRails::CreditCard.new
|
259
265
|
credit_card.valid?
|
260
|
-
credit_card.errors[:expiration_year].
|
266
|
+
credit_card.errors[:expiration_year].should_not be_blank
|
261
267
|
end
|
262
268
|
|
263
269
|
it 'should validate length of cardholder_name' do
|
264
270
|
credit_card = BraintreeRails::CreditCard.new(:cardholder_name => 'f' * 256)
|
265
271
|
credit_card.valid?
|
266
|
-
credit_card.errors[:cardholder_name].
|
272
|
+
credit_card.errors[:cardholder_name].should_not be_blank
|
267
273
|
|
268
274
|
credit_card = BraintreeRails::CreditCard.new(:cardholder_name => 'f')
|
269
275
|
credit_card.valid?
|
270
|
-
credit_card.errors[:cardholder_name].
|
276
|
+
credit_card.errors[:cardholder_name].should be_blank
|
271
277
|
|
272
278
|
credit_card = BraintreeRails::CreditCard.new(:cardholder_name => 'f' * 255)
|
273
279
|
credit_card.valid?
|
274
|
-
credit_card.errors[:cardholder_name].
|
280
|
+
credit_card.errors[:cardholder_name].should be_blank
|
275
281
|
end
|
276
282
|
|
277
283
|
it 'should validate billing_address' do
|
278
284
|
credit_card = BraintreeRails::CreditCard.new(:billing_address => OpenStruct.new(:valid? => false))
|
279
285
|
credit_card.valid?
|
280
|
-
credit_card.errors[:billing_address].
|
286
|
+
credit_card.errors[:billing_address].should_not be_blank
|
281
287
|
|
282
288
|
braintree_credit_card = Braintree::CreditCard.find('credit_card_id')
|
283
289
|
credit_card = BraintreeRails::CreditCard.new(:billing_address => braintree_credit_card.billing_address)
|
284
290
|
credit_card.valid?
|
285
|
-
credit_card.errors[:billing_address].
|
291
|
+
credit_card.errors[:billing_address].should be_blank
|
286
292
|
end
|
287
293
|
end
|
288
294
|
|
@@ -291,10 +297,10 @@ describe BraintreeRails::CreditCard do
|
|
291
297
|
stub_braintree_request(:put, '/payment_methods/credit_card_id', :status => 422, :body => fixture('credit_card_validation_error.xml'))
|
292
298
|
credit_card = BraintreeRails::CreditCard.new('credit_card_id')
|
293
299
|
credit_card.update_attributes(:number => '4111111111111111', :cvv => '111')
|
294
|
-
credit_card.errors[:number].
|
300
|
+
credit_card.errors[:number].should_not be_blank
|
295
301
|
|
296
|
-
credit_card.billing_address.errors[:street_address].
|
297
|
-
credit_card.billing_address.errors[:postal_code].
|
302
|
+
credit_card.billing_address.errors[:street_address].should_not be_blank
|
303
|
+
credit_card.billing_address.errors[:postal_code].should_not be_blank
|
298
304
|
end
|
299
305
|
|
300
306
|
it 'should clear encrypted attributes after save' do
|
@@ -302,22 +308,22 @@ describe BraintreeRails::CreditCard do
|
|
302
308
|
credit_card.number = "foo"
|
303
309
|
stub_braintree_request(:put, '/payment_methods/credit_card_id', :body => fixture('credit_card.xml'))
|
304
310
|
credit_card.save
|
305
|
-
credit_card.number.
|
311
|
+
credit_card.number.should be_blank
|
306
312
|
end
|
307
313
|
|
308
314
|
it 'should clear encrypted attributes even when save! fails' do
|
309
315
|
credit_card = BraintreeRails::CreditCard.find('credit_card_id')
|
310
316
|
credit_card.number = "foo"
|
311
317
|
stub_braintree_request(:put, '/payment_methods/credit_card_id', :status => 422, :body => fixture('credit_card_validation_error.xml'))
|
312
|
-
|
313
|
-
credit_card.number.
|
318
|
+
expect {credit_card.save!}.to raise_error(Braintree::ValidationsFailed)
|
319
|
+
credit_card.number.should be_blank
|
314
320
|
end
|
315
321
|
|
316
322
|
it 'should clear encrypted attributes' do
|
317
323
|
credit_card = BraintreeRails::CreditCard.find('credit_card_id')
|
318
324
|
credit_card.number = "foo"
|
319
325
|
credit_card.clear_encryped_attributes
|
320
|
-
credit_card.number.
|
326
|
+
credit_card.number.should be_blank
|
321
327
|
end
|
322
328
|
|
323
329
|
it 'should update expiration_date when required' do
|
@@ -328,20 +334,20 @@ describe BraintreeRails::CreditCard do
|
|
328
334
|
:expiration_date => '02/2020',
|
329
335
|
}
|
330
336
|
credit_card.assign_attributes(attributes)
|
331
|
-
credit_card.attributes_for(:update)[:expiration_date].
|
337
|
+
credit_card.attributes_for(:update)[:expiration_date].should == '02/2020'
|
332
338
|
end
|
333
339
|
end
|
334
340
|
|
335
341
|
describe 'class methods' do
|
336
342
|
it "should wrap Braintree's Model find" do
|
337
343
|
credit_card = BraintreeRails::CreditCard.find('credit_card_id')
|
338
|
-
credit_card.id.
|
339
|
-
credit_card.
|
344
|
+
credit_card.id.should == 'credit_card_id'
|
345
|
+
credit_card.should be_persisted
|
340
346
|
end
|
341
347
|
|
342
348
|
it "should delegate delete to Braintree's Model" do
|
343
349
|
stub_braintree_request(:delete, '/payment_methods/credit_card_id', :body => fixture('credit_card.xml'))
|
344
|
-
BraintreeRails::CreditCard.delete('credit_card_id').
|
350
|
+
BraintreeRails::CreditCard.delete('credit_card_id').should be_true
|
345
351
|
end
|
346
352
|
end
|
347
353
|
end
|