braintree-rails 1.2.3 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -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::CreditCards do
|
4
4
|
before do
|
@@ -11,12 +11,15 @@ 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
|
+
credit_cards.size.should == 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
|
+
if braintree_credit_card.respond_to?(attribute)
|
21
|
+
credit_card.send(attribute).should == braintree_credit_card.send(attribute)
|
22
|
+
end
|
20
23
|
end
|
21
24
|
end
|
22
25
|
end
|
@@ -30,9 +33,9 @@ describe BraintreeRails::CreditCards do
|
|
30
33
|
credit_cards = BraintreeRails::CreditCards.new(BraintreeRails::Customer.find('customer_id'))
|
31
34
|
credit_card = credit_cards.build(:cardholder_name => 'foo bar')
|
32
35
|
|
33
|
-
credit_card.
|
34
|
-
credit_card.customer_id.
|
35
|
-
credit_card.cardholder_name.
|
36
|
+
credit_card.should_not be_persisted
|
37
|
+
credit_card.customer_id.should == braintree_customer.id
|
38
|
+
credit_card.cardholder_name.should == 'foo bar'
|
36
39
|
end
|
37
40
|
end
|
38
41
|
|
@@ -42,17 +45,19 @@ describe BraintreeRails::CreditCards do
|
|
42
45
|
|
43
46
|
customer = BraintreeRails::Customer.find('customer_id')
|
44
47
|
credit_card = customer.credit_cards.create(credit_card_hash)
|
45
|
-
credit_card.
|
46
|
-
customer.credit_cards.
|
48
|
+
credit_card.should be_persisted
|
49
|
+
customer.credit_cards.should include(credit_card)
|
47
50
|
end
|
48
51
|
|
49
52
|
it 'should not add credit card to collection if creation failed' do
|
50
53
|
stub_braintree_request(:post, '/payment_methods', :body => fixture('credit_card_validation_error.xml'))
|
51
54
|
|
52
55
|
customer = BraintreeRails::Customer.find('customer_id')
|
56
|
+
customer.credit_cards.size.should == 2
|
57
|
+
|
53
58
|
credit_card = customer.credit_cards.create(credit_card_hash)
|
54
|
-
credit_card.
|
55
|
-
customer.credit_cards.
|
59
|
+
credit_card.should_not be_persisted
|
60
|
+
customer.credit_cards.size.should == 2
|
56
61
|
end
|
57
62
|
end
|
58
63
|
end
|
data/{test/unit/braintree_rails/customer_test.rb → spec/unit/braintree_rails/customer_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::Customer do
|
4
4
|
before do
|
@@ -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
|
+
customer.should be_persisted
|
14
14
|
BraintreeRails::Customer.attributes.each do |attribute|
|
15
|
-
customer.send(attribute).
|
15
|
+
customer.send(attribute).should == 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
|
+
customer.should be_persisted
|
24
24
|
BraintreeRails::Customer.attributes.each do |attribute|
|
25
|
-
customer.send(attribute).
|
25
|
+
customer.send(attribute).should == 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
|
+
customer.should_not be_persisted
|
33
|
+
customer.id.should == '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
|
+
customer.should be_persisted
|
40
|
+
customer.id.should == 'foobar'
|
41
|
+
customer.first_name.should == 'Foo'
|
42
|
+
customer.last_name.should == 'Bar'
|
43
43
|
|
44
44
|
customer = BraintreeRails::Customer.new(OpenStruct.new)
|
45
|
-
customer.
|
45
|
+
customer.should_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
|
+
customer.addresses.should respond_to(:each)
|
55
|
+
customer.addresses.size.should == 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
|
+
customer.credit_cards.should respond_to(:each)
|
65
|
+
customer.credit_cards.size.should == 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
|
+
BraintreeRails::Customer.new(:first_name => "Foo", :last_name => 'Bar').full_name.should == "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
|
+
BraintreeRails::Customer.new(:first_name => "Foo").full_name.should == 'Foo'
|
76
|
+
BraintreeRails::Customer.new(:last_name => 'Bar').full_name.should == '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
|
+
customer.errors[:id].should_not be_blank
|
85
85
|
|
86
86
|
customer = BraintreeRails::Customer.new(:id => 'all')
|
87
87
|
customer.valid?
|
88
|
-
customer.errors[:id].
|
88
|
+
customer.errors[:id].should_not be_blank
|
89
89
|
|
90
90
|
customer = BraintreeRails::Customer.new(:id => 'new')
|
91
91
|
customer.valid?
|
92
|
-
customer.errors[:id].
|
92
|
+
customer.errors[:id].should_not be_blank
|
93
93
|
|
94
94
|
customer = BraintreeRails::Customer.new(:id => 'f' * 37)
|
95
95
|
customer.valid?
|
96
|
-
customer.errors[:id].
|
96
|
+
customer.errors[:id].should_not be_blank
|
97
97
|
|
98
98
|
customer = BraintreeRails::Customer.new
|
99
99
|
customer.valid?
|
100
|
-
customer.errors[:id].
|
100
|
+
customer.errors[:id].should be_blank
|
101
101
|
|
102
102
|
customer = BraintreeRails::Customer.new(:id => 'f')
|
103
103
|
customer.valid?
|
104
|
-
customer.errors[:id].
|
104
|
+
customer.errors[:id].should be_blank
|
105
105
|
|
106
106
|
customer = BraintreeRails::Customer.new(:id => 'f' * 36)
|
107
107
|
customer.valid?
|
108
|
-
customer.errors[:id].
|
108
|
+
customer.errors[:id].should 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
|
+
customer.errors[attribute].should be_blank
|
116
116
|
|
117
117
|
customer = BraintreeRails::Customer.new(attribute => 'f' * 255)
|
118
118
|
customer.valid?
|
119
|
-
customer.errors[attribute].
|
119
|
+
customer.errors[attribute].should be_blank
|
120
120
|
|
121
121
|
customer = BraintreeRails::Customer.new(attribute => 'foo' * 256)
|
122
122
|
customer.valid?
|
123
|
-
customer.errors[attribute].
|
123
|
+
customer.errors[attribute].should_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
|
+
customer.should 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
|
+
customer.should_not be_valid
|
136
136
|
end
|
137
137
|
end
|
138
138
|
end
|
@@ -146,65 +146,65 @@ 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
|
+
customer.save.should be_true
|
150
|
+
customer.should 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
|
+
customer.save.should be_false
|
156
|
+
customer.should_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
|
+
customer.save!.should be_true
|
162
|
+
customer.should 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
|
-
|
168
|
-
customer.
|
167
|
+
expect { customer.save! }.to raise_error(BraintreeRails::RecordInvalid)
|
168
|
+
customer.should_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
|
+
customer.update_attributes(:first_name => 'f').should be_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
|
+
customer.update_attributes(:first_name => 'f' * 256).should be_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
|
+
customer.update_attributes!(:first_name => 'f').should be_true
|
186
186
|
end
|
187
187
|
|
188
188
|
it 'should throw error when update_attributes invalid record with bang' do
|
189
189
|
customer = BraintreeRails::Customer.new(Braintree::Customer.find('customer_id'))
|
190
|
-
|
190
|
+
expect { customer.update_attributes!(:first_name => 'f' * 256) }.to raise_error(BraintreeRails::RecordInvalid)
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|
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
|
+
customer.serializable_hash.should 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
|
+
customer.to_xml.should 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
|
+
customer.as_json.should be_kind_of(Hash)
|
208
208
|
end
|
209
209
|
end
|
210
210
|
end
|
data/{test/unit/braintree_rails/discount_test.rb → spec/unit/braintree_rails/discount_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::Discount do
|
4
4
|
before do
|
@@ -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
|
+
discount.should be_persisted
|
14
|
+
discount.never_expires?.should == braintree_discount.never_expires?
|
15
15
|
BraintreeRails::Discount.attributes.each do |attribute|
|
16
|
-
discount.send(attribute).
|
16
|
+
discount.send(attribute).should == 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
|
+
discount.should be_persisted
|
25
25
|
BraintreeRails::Discount.attributes.each do |attribute|
|
26
|
-
discount.send(attribute).
|
26
|
+
discount.send(attribute).should == 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
|
+
discount.should be_persisted
|
35
35
|
BraintreeRails::Discount.attributes.each do |attribute|
|
36
|
-
discount.send(attribute).
|
36
|
+
discount.send(attribute).should == braintree_discount.send(attribute)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -43,8 +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
|
+
discounts.should respond_to(:each)
|
47
|
+
discounts.size.should == braintree_discounts.size
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
data/{test/unit/braintree_rails/discounts_test.rb → spec/unit/braintree_rails/discounts_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::Discounts do
|
4
4
|
before do
|
@@ -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
|
+
discounts.size.should == 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
|
+
discount.send(attribute).should == braintree_discount.send(attribute)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -27,7 +27,7 @@ describe BraintreeRails::Discounts do
|
|
27
27
|
braintree_plan = Braintree::Plan.all.find { |p| p.id == 'plan_id' }
|
28
28
|
braintree_discounts = braintree_plan.discounts
|
29
29
|
discounts = BraintreeRails::Discounts.new(BraintreeRails::Plan.find('plan_id'))
|
30
|
-
|
30
|
+
expect { discounts.create }.to raise_error(BraintreeRails::NotSupportedApiException)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../unit_spec_helper'))
|
2
|
+
|
3
|
+
describe BraintreeRails::FundingDetails do
|
4
|
+
describe 'validations' do
|
5
|
+
it "requries destination" do
|
6
|
+
funding = BraintreeRails::FundingDetails.new(funding_details_hash.merge(:destination => nil))
|
7
|
+
funding.should be_invalid
|
8
|
+
funding.errors[:destination].should == ["can't be blank", "is not included in the list"]
|
9
|
+
end
|
10
|
+
|
11
|
+
it "cannot be trash destination" do
|
12
|
+
funding = BraintreeRails::FundingDetails.new(funding_details_hash.merge(:destination => "foo"))
|
13
|
+
funding.should be_invalid
|
14
|
+
funding.errors[:destination].should == ["is not included in the list"]
|
15
|
+
end
|
16
|
+
|
17
|
+
it "requries email if destination is Email" do
|
18
|
+
funding = BraintreeRails::FundingDetails.new(funding_details_hash.merge(:destination => Braintree::MerchantAccount::FundingDestination::Email, :email => nil))
|
19
|
+
funding.should be_invalid
|
20
|
+
funding.errors[:email].should == ["can't be blank"]
|
21
|
+
end
|
22
|
+
|
23
|
+
it "requries mobile_phone if destination is MobilePhone" do
|
24
|
+
funding = BraintreeRails::FundingDetails.new(funding_details_hash.merge(:destination => Braintree::MerchantAccount::FundingDestination::MobilePhone, :mobile_phone => nil))
|
25
|
+
funding.should be_invalid
|
26
|
+
funding.errors[:mobile_phone].should == ["can't be blank"]
|
27
|
+
end
|
28
|
+
|
29
|
+
it "requries account_number and routing_number if destination is Bank" do
|
30
|
+
funding = BraintreeRails::FundingDetails.new(funding_details_hash.merge(:destination => Braintree::MerchantAccount::FundingDestination::Bank, :account_number => nil, :routing_number => nil))
|
31
|
+
funding.should be_invalid
|
32
|
+
funding.errors[:account_number].should == ["can't be blank"]
|
33
|
+
funding.errors[:routing_number].should == ["can't be blank"]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../unit_spec_helper'))
|
2
|
+
|
3
|
+
describe BraintreeRails::IndividualDetails do
|
4
|
+
describe 'validations' do
|
5
|
+
[:first_name, :last_name, :email, :date_of_birth, :address].each do |attribute|
|
6
|
+
it "requires #{attribute}" do
|
7
|
+
individual = BraintreeRails::IndividualDetails.new(individual_details_hash.merge(attribute => nil))
|
8
|
+
individual.should be_invalid
|
9
|
+
individual.errors[attribute].should == ["can't be blank"]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "validates assocaited address" do
|
14
|
+
individual = BraintreeRails::IndividualDetails.new(individual_details_hash.merge(:address => {}))
|
15
|
+
individual.should be_invalid
|
16
|
+
individual.errors[:address].should_not be_empty
|
17
|
+
end
|
18
|
+
end
|
19
|
+
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::Luhn10Validator do
|
4
4
|
class Validatable < Struct.new(:number)
|
@@ -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
|
+
Validatable.new(4111111111111111).should be_valid
|
12
|
+
Validatable.new('5454545454545454').should 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
|
+
invalid_record.should_not be_valid
|
20
|
+
invalid_record.errors[:number].should include 'failed Luhn 10 validation'
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|