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,14 +11,14 @@ describe BraintreeRails::CreditCards do
|
|
11
11
|
braintree_credit_cards = braintree_customer.credit_cards
|
12
12
|
credit_cards = BraintreeRails::CreditCards.new(BraintreeRails::Customer.find('customer_id'))
|
13
13
|
|
14
|
-
credit_cards.size.
|
14
|
+
expect(credit_cards.size).to eq(braintree_credit_cards.size)
|
15
15
|
|
16
16
|
braintree_credit_cards.each do |braintree_credit_card|
|
17
17
|
credit_card = credit_cards.find(braintree_credit_card.token)
|
18
18
|
BraintreeRails::CreditCard.attributes.each do |attribute|
|
19
19
|
next if BraintreeRails::CreditCard.associations.include?(attribute)
|
20
20
|
if braintree_credit_card.respond_to?(attribute)
|
21
|
-
credit_card.send(attribute).
|
21
|
+
expect(credit_card.send(attribute)).to eq(braintree_credit_card.send(attribute))
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -33,9 +33,9 @@ describe BraintreeRails::CreditCards do
|
|
33
33
|
credit_cards = BraintreeRails::CreditCards.new(BraintreeRails::Customer.find('customer_id'))
|
34
34
|
credit_card = credit_cards.build(:cardholder_name => 'foo bar')
|
35
35
|
|
36
|
-
credit_card.
|
37
|
-
credit_card.customer_id.
|
38
|
-
credit_card.cardholder_name.
|
36
|
+
expect(credit_card).to_not be_persisted
|
37
|
+
expect(credit_card.customer_id).to eq(braintree_customer.id)
|
38
|
+
expect(credit_card.cardholder_name).to eq('foo bar')
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -45,19 +45,19 @@ describe BraintreeRails::CreditCards do
|
|
45
45
|
|
46
46
|
customer = BraintreeRails::Customer.find('customer_id')
|
47
47
|
credit_card = customer.credit_cards.create(credit_card_hash)
|
48
|
-
credit_card.
|
49
|
-
customer.credit_cards.
|
48
|
+
expect(credit_card).to be_persisted
|
49
|
+
expect(customer.credit_cards).to include(credit_card)
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'should not add credit card to collection if creation failed' do
|
53
53
|
stub_braintree_request(:post, '/payment_methods', :body => fixture('credit_card_validation_error.xml'))
|
54
54
|
|
55
55
|
customer = BraintreeRails::Customer.find('customer_id')
|
56
|
-
customer.credit_cards.size.
|
56
|
+
expect(customer.credit_cards.size).to eq(2)
|
57
57
|
|
58
58
|
credit_card = customer.credit_cards.create(credit_card_hash)
|
59
|
-
credit_card.
|
60
|
-
customer.credit_cards.size.
|
59
|
+
expect(credit_card).to_not be_persisted
|
60
|
+
expect(customer.credit_cards.size).to eq(2)
|
61
61
|
end
|
62
62
|
end
|
63
|
-
end
|
63
|
+
end
|
@@ -10,9 +10,9 @@ describe BraintreeRails::Customer do
|
|
10
10
|
customer = BraintreeRails::Customer.new('customer_id')
|
11
11
|
braintree_customer = Braintree::Customer.find('customer_id')
|
12
12
|
|
13
|
-
customer.
|
13
|
+
expect(customer).to be_persisted
|
14
14
|
BraintreeRails::Customer.attributes.each do |attribute|
|
15
|
-
customer.send(attribute).
|
15
|
+
expect(customer.send(attribute)).to eq(braintree_customer.send(attribute)) if braintree_customer.respond_to?(attribute)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -20,29 +20,29 @@ describe BraintreeRails::Customer do
|
|
20
20
|
braintree_customer = Braintree::Customer.find('customer_id')
|
21
21
|
customer = BraintreeRails::Customer.new(braintree_customer)
|
22
22
|
|
23
|
-
customer.
|
23
|
+
expect(customer).to be_persisted
|
24
24
|
BraintreeRails::Customer.attributes.each do |attribute|
|
25
|
-
customer.send(attribute).
|
25
|
+
expect(customer.send(attribute)).to eq(braintree_customer.send(attribute)) if braintree_customer.respond_to?(attribute)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'should extract values from hash' do
|
30
30
|
customer = BraintreeRails::Customer.new(:id => 'new_id')
|
31
31
|
|
32
|
-
customer.
|
33
|
-
customer.id.
|
32
|
+
expect(customer).to_not be_persisted
|
33
|
+
expect(customer.id).to eq('new_id')
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'should try to extract value from other types' do
|
37
37
|
customer = BraintreeRails::Customer.new(OpenStruct.new(:id => 'foobar', :first_name => 'Foo', :last_name => 'Bar', :persisted? => true))
|
38
38
|
|
39
|
-
customer.
|
40
|
-
customer.id.
|
41
|
-
customer.first_name.
|
42
|
-
customer.last_name.
|
39
|
+
expect(customer).to be_persisted
|
40
|
+
expect(customer.id).to eq('foobar')
|
41
|
+
expect(customer.first_name).to eq('Foo')
|
42
|
+
expect(customer.last_name).to eq('Bar')
|
43
43
|
|
44
44
|
customer = BraintreeRails::Customer.new(OpenStruct.new)
|
45
|
-
customer.
|
45
|
+
expect(customer).to_not be_persisted
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -51,8 +51,8 @@ describe BraintreeRails::Customer do
|
|
51
51
|
braintree_customer = Braintree::Customer.find('customer_id')
|
52
52
|
customer = BraintreeRails::Customer.new(braintree_customer)
|
53
53
|
|
54
|
-
customer.addresses.
|
55
|
-
customer.addresses.size.
|
54
|
+
expect(customer.addresses).to respond_to(:each)
|
55
|
+
expect(customer.addresses.size).to eq(braintree_customer.addresses.size)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -61,19 +61,19 @@ describe BraintreeRails::Customer do
|
|
61
61
|
braintree_customer = Braintree::Customer.find('customer_id')
|
62
62
|
customer = BraintreeRails::Customer.new(braintree_customer)
|
63
63
|
|
64
|
-
customer.credit_cards.
|
65
|
-
customer.credit_cards.size.
|
64
|
+
expect(customer.credit_cards).to respond_to(:each)
|
65
|
+
expect(customer.credit_cards.size).to eq(braintree_customer.credit_cards.size)
|
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::Customer.new(:first_name => "Foo", :last_name => 'Bar').full_name.
|
71
|
+
expect(BraintreeRails::Customer.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::Customer.new(:first_name => "Foo").full_name.
|
76
|
-
BraintreeRails::Customer.new(:last_name => 'Bar').full_name.
|
75
|
+
expect(BraintreeRails::Customer.new(:first_name => "Foo").full_name).to eq('Foo')
|
76
|
+
expect(BraintreeRails::Customer.new(:last_name => 'Bar').full_name).to eq('Bar')
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -81,58 +81,58 @@ describe BraintreeRails::Customer do
|
|
81
81
|
it 'should validate id' do
|
82
82
|
customer = BraintreeRails::Customer.new(:id => '%')
|
83
83
|
customer.valid?
|
84
|
-
customer.errors[:id].
|
84
|
+
expect(customer.errors[:id]).to_not be_blank
|
85
85
|
|
86
86
|
customer = BraintreeRails::Customer.new(:id => 'all')
|
87
87
|
customer.valid?
|
88
|
-
customer.errors[:id].
|
88
|
+
expect(customer.errors[:id]).to_not be_blank
|
89
89
|
|
90
90
|
customer = BraintreeRails::Customer.new(:id => 'new')
|
91
91
|
customer.valid?
|
92
|
-
customer.errors[:id].
|
92
|
+
expect(customer.errors[:id]).to_not be_blank
|
93
93
|
|
94
94
|
customer = BraintreeRails::Customer.new(:id => 'f' * 37)
|
95
95
|
customer.valid?
|
96
|
-
customer.errors[:id].
|
96
|
+
expect(customer.errors[:id]).to_not be_blank
|
97
97
|
|
98
98
|
customer = BraintreeRails::Customer.new
|
99
99
|
customer.valid?
|
100
|
-
customer.errors[:id].
|
100
|
+
expect(customer.errors[:id]).to be_blank
|
101
101
|
|
102
102
|
customer = BraintreeRails::Customer.new(:id => 'f')
|
103
103
|
customer.valid?
|
104
|
-
customer.errors[:id].
|
104
|
+
expect(customer.errors[:id]).to be_blank
|
105
105
|
|
106
106
|
customer = BraintreeRails::Customer.new(:id => 'f' * 36)
|
107
107
|
customer.valid?
|
108
|
-
customer.errors[:id].
|
108
|
+
expect(customer.errors[:id]).to be_blank
|
109
109
|
end
|
110
110
|
|
111
111
|
[:first_name, :last_name, :company, :website, :phone, :fax].each do |attribute|
|
112
112
|
it "should validate length of #{attribute}" do
|
113
113
|
customer = BraintreeRails::Customer.new(attribute => 'f')
|
114
114
|
customer.valid?
|
115
|
-
customer.errors[attribute].
|
115
|
+
expect(customer.errors[attribute]).to be_blank
|
116
116
|
|
117
117
|
customer = BraintreeRails::Customer.new(attribute => 'f' * 255)
|
118
118
|
customer.valid?
|
119
|
-
customer.errors[attribute].
|
119
|
+
expect(customer.errors[attribute]).to be_blank
|
120
120
|
|
121
121
|
customer = BraintreeRails::Customer.new(attribute => 'foo' * 256)
|
122
122
|
customer.valid?
|
123
|
-
customer.errors[attribute].
|
123
|
+
expect(customer.errors[attribute]).to_not be_blank
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
127
|
describe 'credit_card' do
|
128
128
|
it 'is valid if new credit card is valid' do
|
129
129
|
customer = BraintreeRails::Customer.new(:credit_card => credit_card_hash)
|
130
|
-
customer.
|
130
|
+
expect(customer).to be_valid
|
131
131
|
end
|
132
132
|
|
133
133
|
it 'is not valid if new credit card is invalid' do
|
134
134
|
customer = BraintreeRails::Customer.new(:credit_card => credit_card_hash.except(:number))
|
135
|
-
customer.
|
135
|
+
expect(customer).to_not be_valid
|
136
136
|
end
|
137
137
|
end
|
138
138
|
end
|
@@ -146,43 +146,43 @@ describe BraintreeRails::Customer do
|
|
146
146
|
describe 'save, save!' do
|
147
147
|
it 'should return true when saved' do
|
148
148
|
customer = BraintreeRails::Customer.new
|
149
|
-
customer.save.
|
150
|
-
customer.
|
149
|
+
expect(customer.save).to eq(true)
|
150
|
+
expect(customer).to be_persisted
|
151
151
|
end
|
152
152
|
|
153
153
|
it 'should not throw error when not valid' do
|
154
154
|
customer = BraintreeRails::Customer.new(:first_name => 'f' * 256)
|
155
|
-
customer.save.
|
156
|
-
customer.
|
155
|
+
expect(customer.save).to eq(false)
|
156
|
+
expect(customer).to_not be_persisted
|
157
157
|
end
|
158
158
|
|
159
159
|
it 'should return true when saved with bang' do
|
160
160
|
customer = BraintreeRails::Customer.new
|
161
|
-
customer.save
|
162
|
-
customer.
|
161
|
+
expect(customer.save!).to eq(true)
|
162
|
+
expect(customer).to be_persisted
|
163
163
|
end
|
164
164
|
|
165
165
|
it 'should throw error when save invalid record with bang' do
|
166
166
|
customer = BraintreeRails::Customer.new(:first_name => 'f' * 256)
|
167
167
|
expect { customer.save! }.to raise_error(BraintreeRails::RecordInvalid)
|
168
|
-
customer.
|
168
|
+
expect(customer).to_not be_persisted
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
172
172
|
describe 'update_attributes, update_attributes!' do
|
173
173
|
it 'should return true when update_attributes' do
|
174
174
|
customer = BraintreeRails::Customer.new(Braintree::Customer.find('customer_id'))
|
175
|
-
customer.update_attributes(:first_name => 'f').
|
175
|
+
expect(customer.update_attributes(:first_name => 'f')).to eq(true)
|
176
176
|
end
|
177
177
|
|
178
178
|
it 'should not throw error when not valid' do
|
179
179
|
customer = BraintreeRails::Customer.new(Braintree::Customer.find('customer_id'))
|
180
|
-
customer.update_attributes(:first_name => 'f' * 256).
|
180
|
+
expect(customer.update_attributes(:first_name => 'f' * 256)).to eq(false)
|
181
181
|
end
|
182
182
|
|
183
183
|
it 'should return true when update_attributesd with bang' do
|
184
184
|
customer = BraintreeRails::Customer.new(Braintree::Customer.find('customer_id'))
|
185
|
-
customer.update_attributes!(:first_name => 'f').
|
185
|
+
expect(customer.update_attributes!(:first_name => 'f')).to eq(true)
|
186
186
|
end
|
187
187
|
|
188
188
|
it 'should throw error when update_attributes invalid record with bang' do
|
@@ -194,18 +194,18 @@ describe BraintreeRails::Customer do
|
|
194
194
|
describe 'serialization' do
|
195
195
|
it 'can be serializable hash' do
|
196
196
|
customer = BraintreeRails::Customer.new('customer_id')
|
197
|
-
customer.serializable_hash.
|
197
|
+
expect(customer.serializable_hash).to be_kind_of(Hash)
|
198
198
|
end
|
199
199
|
|
200
200
|
it 'can be serialized to xml' do
|
201
201
|
customer = BraintreeRails::Customer.new('customer_id')
|
202
|
-
customer.to_xml.
|
202
|
+
expect(customer.to_xml).to include "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
203
203
|
end
|
204
204
|
|
205
205
|
it 'can be serialized to json' do
|
206
206
|
customer = BraintreeRails::Customer.new('customer_id')
|
207
|
-
customer.as_json.
|
207
|
+
expect(customer.as_json).to be_kind_of(Hash)
|
208
208
|
end
|
209
209
|
end
|
210
210
|
end
|
211
|
-
end
|
211
|
+
end
|
@@ -10,10 +10,10 @@ describe BraintreeRails::Discount do
|
|
10
10
|
braintree_discount = Braintree::Discount.all.find { |d| d.id == 'discount_id' }
|
11
11
|
discount = BraintreeRails::Discount.new(braintree_discount)
|
12
12
|
|
13
|
-
discount.
|
14
|
-
discount.never_expires
|
13
|
+
expect(discount).to be_persisted
|
14
|
+
expect(discount.never_expires?).to eq(braintree_discount.never_expires?)
|
15
15
|
BraintreeRails::Discount.attributes.each do |attribute|
|
16
|
-
discount.send(attribute).
|
16
|
+
expect(discount.send(attribute)).to eq(braintree_discount.send(attribute))
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -21,9 +21,9 @@ describe BraintreeRails::Discount do
|
|
21
21
|
braintree_discount = Braintree::Discount.all.find { |d| d.id == 'discount_id' }
|
22
22
|
discount = BraintreeRails::Discount.new('discount_id')
|
23
23
|
|
24
|
-
discount.
|
24
|
+
expect(discount).to be_persisted
|
25
25
|
BraintreeRails::Discount.attributes.each do |attribute|
|
26
|
-
discount.send(attribute).
|
26
|
+
expect(discount.send(attribute)).to eq(braintree_discount.send(attribute))
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -31,9 +31,9 @@ describe BraintreeRails::Discount do
|
|
31
31
|
braintree_discount = Braintree::Discount.all.find { |d| d.id == 'discount_id' }
|
32
32
|
discount = BraintreeRails::Discount.find('discount_id')
|
33
33
|
|
34
|
-
discount.
|
34
|
+
expect(discount).to be_persisted
|
35
35
|
BraintreeRails::Discount.attributes.each do |attribute|
|
36
|
-
discount.send(attribute).
|
36
|
+
expect(discount.send(attribute)).to eq(braintree_discount.send(attribute))
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -43,9 +43,8 @@ describe BraintreeRails::Discount do
|
|
43
43
|
braintree_discounts = Braintree::Discount.all
|
44
44
|
discounts = BraintreeRails::Discount.all
|
45
45
|
|
46
|
-
discounts.
|
47
|
-
discounts.size.
|
46
|
+
expect(discounts).to respond_to(:each)
|
47
|
+
expect(discounts.size).to eq(braintree_discounts.size)
|
48
48
|
end
|
49
49
|
end
|
50
|
-
end
|
51
|
-
|
50
|
+
end
|
@@ -11,12 +11,12 @@ describe BraintreeRails::Discounts do
|
|
11
11
|
braintree_discounts = braintree_plan.discounts
|
12
12
|
discounts = BraintreeRails::Discounts.new(BraintreeRails::Plan.find('plan_id'))
|
13
13
|
|
14
|
-
discounts.size.
|
14
|
+
expect(discounts.size).to eq(braintree_discounts.size)
|
15
15
|
|
16
16
|
braintree_discounts.each do |braintree_discount|
|
17
17
|
discount = discounts.find(braintree_discount.id)
|
18
18
|
BraintreeRails::Discount.attributes.each do |attribute|
|
19
|
-
discount.send(attribute).
|
19
|
+
expect(discount.send(attribute)).to eq(braintree_discount.send(attribute))
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -30,4 +30,4 @@ describe BraintreeRails::Discounts do
|
|
30
30
|
expect { discounts.create }.to raise_error(BraintreeRails::NotSupportedApiException)
|
31
31
|
end
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
@@ -4,33 +4,33 @@ describe BraintreeRails::FundingDetails do
|
|
4
4
|
describe 'validations' do
|
5
5
|
it "requries destination" do
|
6
6
|
funding = BraintreeRails::FundingDetails.new(funding_details_hash.merge(:destination => nil))
|
7
|
-
funding.
|
8
|
-
funding.errors[:destination].
|
7
|
+
expect(funding).to be_invalid
|
8
|
+
expect(funding.errors[:destination]).to eq(["can't be blank", "is not included in the list"])
|
9
9
|
end
|
10
10
|
|
11
11
|
it "cannot be trash destination" do
|
12
12
|
funding = BraintreeRails::FundingDetails.new(funding_details_hash.merge(:destination => "foo"))
|
13
|
-
funding.
|
14
|
-
funding.errors[:destination].
|
13
|
+
expect(funding).to be_invalid
|
14
|
+
expect(funding.errors[:destination]).to eq(["is not included in the list"])
|
15
15
|
end
|
16
16
|
|
17
17
|
it "requries email if destination is Email" do
|
18
18
|
funding = BraintreeRails::FundingDetails.new(funding_details_hash.merge(:destination => Braintree::MerchantAccount::FundingDestination::Email, :email => nil))
|
19
|
-
funding.
|
20
|
-
funding.errors[:email].
|
19
|
+
expect(funding).to be_invalid
|
20
|
+
expect(funding.errors[:email]).to eq(["can't be blank"])
|
21
21
|
end
|
22
22
|
|
23
23
|
it "requries mobile_phone if destination is MobilePhone" do
|
24
24
|
funding = BraintreeRails::FundingDetails.new(funding_details_hash.merge(:destination => Braintree::MerchantAccount::FundingDestination::MobilePhone, :mobile_phone => nil))
|
25
|
-
funding.
|
26
|
-
funding.errors[:mobile_phone].
|
25
|
+
expect(funding).to be_invalid
|
26
|
+
expect(funding.errors[:mobile_phone]).to eq(["can't be blank"])
|
27
27
|
end
|
28
28
|
|
29
29
|
it "requries account_number and routing_number if destination is Bank" do
|
30
30
|
funding = BraintreeRails::FundingDetails.new(funding_details_hash.merge(:destination => Braintree::MerchantAccount::FundingDestination::Bank, :account_number => nil, :routing_number => nil))
|
31
|
-
funding.
|
32
|
-
funding.errors[:account_number].
|
33
|
-
funding.errors[:routing_number].
|
31
|
+
expect(funding).to be_invalid
|
32
|
+
expect(funding.errors[:account_number]).to eq(["can't be blank"])
|
33
|
+
expect(funding.errors[:routing_number]).to eq(["can't be blank"])
|
34
34
|
end
|
35
35
|
end
|
36
|
-
end
|
36
|
+
end
|
@@ -5,15 +5,15 @@ describe BraintreeRails::IndividualDetails do
|
|
5
5
|
[:first_name, :last_name, :email, :date_of_birth, :address].each do |attribute|
|
6
6
|
it "requires #{attribute}" do
|
7
7
|
individual = BraintreeRails::IndividualDetails.new(individual_details_hash.merge(attribute => nil))
|
8
|
-
individual.
|
9
|
-
individual.errors[attribute].
|
8
|
+
expect(individual).to be_invalid
|
9
|
+
expect(individual.errors[attribute]).to eq(["can't be blank"])
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
it "validates assocaited address" do
|
14
14
|
individual = BraintreeRails::IndividualDetails.new(individual_details_hash.merge(:address => {}))
|
15
|
-
individual.
|
16
|
-
individual.errors[:address].
|
15
|
+
expect(individual).to be_invalid
|
16
|
+
expect(individual.errors[:address]).to_not be_empty
|
17
17
|
end
|
18
18
|
end
|
19
|
-
end
|
19
|
+
end
|
@@ -8,16 +8,16 @@ describe BraintreeRails::Luhn10Validator do
|
|
8
8
|
|
9
9
|
describe 'valid numbers' do
|
10
10
|
it 'should pass for valid numbers' do
|
11
|
-
Validatable.new(4111111111111111).
|
12
|
-
Validatable.new('5454545454545454').
|
11
|
+
expect(Validatable.new(4111111111111111)).to be_valid
|
12
|
+
expect(Validatable.new('5454545454545454')).to be_valid
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
describe 'invalid numbers' do
|
17
17
|
it 'should fail for invalid numbers' do
|
18
18
|
invalid_record = Validatable.new('1234567890123456')
|
19
|
-
invalid_record.
|
20
|
-
invalid_record.errors[:number].
|
19
|
+
expect(invalid_record).to_not be_valid
|
20
|
+
expect(invalid_record.errors[:number]).to include 'failed Luhn 10 validation'
|
21
21
|
end
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|
@@ -5,46 +5,46 @@ describe BraintreeRails::MerchantAccount do
|
|
5
5
|
[:tos_accepted, :master_merchant_account_id, :individual, :funding].each do |attribute|
|
6
6
|
it "requires #{attribute}" do
|
7
7
|
merchant_account = BraintreeRails::MerchantAccount.new(merchant_account_hash.merge(attribute => nil))
|
8
|
-
merchant_account.
|
9
|
-
merchant_account.errors[attribute].
|
8
|
+
expect(merchant_account).to be_invalid
|
9
|
+
expect(merchant_account.errors[attribute]).to eq(["can't be blank"])
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
it "validates id format" do
|
14
14
|
[nil, "", "a", "_", "-", "0", "a"*32].each do |valid_value|
|
15
15
|
merchant_account = BraintreeRails::MerchantAccount.new(merchant_account_hash.merge(:id => valid_value))
|
16
|
-
merchant_account.
|
16
|
+
expect(merchant_account).to be_valid
|
17
17
|
end
|
18
18
|
|
19
19
|
["%", "/"].each do |invalid_value|
|
20
20
|
merchant_account = BraintreeRails::MerchantAccount.new(merchant_account_hash.merge(:id => invalid_value))
|
21
|
-
merchant_account.
|
22
|
-
merchant_account.errors[:id].
|
21
|
+
expect(merchant_account).to be_invalid
|
22
|
+
expect(merchant_account.errors[:id]).to eq(["is invalid"])
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
it "validates id length" do
|
27
27
|
merchant_account = BraintreeRails::MerchantAccount.new(merchant_account_hash.merge(:id => "a"*33))
|
28
|
-
merchant_account.
|
29
|
-
merchant_account.errors[:id].
|
28
|
+
expect(merchant_account).to be_invalid
|
29
|
+
expect(merchant_account.errors[:id]).to eq(["is too long (maximum is 32 characters)"])
|
30
30
|
end
|
31
31
|
|
32
32
|
it "validates individual" do
|
33
33
|
merchant_account = BraintreeRails::MerchantAccount.new(merchant_account_hash.merge(:individual => {}))
|
34
|
-
merchant_account.
|
35
|
-
merchant_account.errors[:individual].
|
34
|
+
expect(merchant_account).to be_invalid
|
35
|
+
expect(merchant_account.errors[:individual]).to_not be_empty
|
36
36
|
end
|
37
37
|
|
38
38
|
it "validates funding" do
|
39
39
|
merchant_account = BraintreeRails::MerchantAccount.new(merchant_account_hash.merge(:funding => {}))
|
40
|
-
merchant_account.
|
41
|
-
merchant_account.errors[:funding].
|
40
|
+
expect(merchant_account).to be_invalid
|
41
|
+
expect(merchant_account.errors[:funding]).to_not be_empty
|
42
42
|
end
|
43
43
|
|
44
44
|
it "validates business if present" do
|
45
45
|
merchant_account = BraintreeRails::MerchantAccount.new(merchant_account_hash.merge(:business => {:legal_name => "foo"}))
|
46
|
-
merchant_account.
|
47
|
-
merchant_account.errors[:business].
|
46
|
+
expect(merchant_account).to be_invalid
|
47
|
+
expect(merchant_account.errors[:business]).to_not be_empty
|
48
48
|
end
|
49
49
|
end
|
50
|
-
end
|
50
|
+
end
|