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