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.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/.travis.yml +13 -4
  4. data/CHANGELOG.md +5 -1
  5. data/Gemfile +3 -4
  6. data/Gemfile.lock +33 -14
  7. data/README.md +1 -1
  8. data/Rakefile +1 -1
  9. data/braintree-rails.gemspec +4 -5
  10. data/lib/braintree_rails/address.rb +1 -1
  11. data/lib/braintree_rails/address_details.rb +14 -0
  12. data/lib/braintree_rails/address_details_validator.rb +7 -0
  13. data/lib/braintree_rails/association.rb +2 -2
  14. data/lib/braintree_rails/braintree_ext.rb +27 -1
  15. data/lib/braintree_rails/business_details.rb +29 -0
  16. data/lib/braintree_rails/business_details_validator.rb +12 -0
  17. data/lib/braintree_rails/configuration.rb +1 -1
  18. data/lib/braintree_rails/credit_card.rb +6 -6
  19. data/lib/braintree_rails/credit_card_validator.rb +2 -17
  20. data/lib/braintree_rails/customer.rb +6 -6
  21. data/lib/braintree_rails/customer_validator.rb +1 -12
  22. data/lib/braintree_rails/funding_details.rb +17 -0
  23. data/lib/braintree_rails/funding_details_validator.rb +10 -0
  24. data/lib/braintree_rails/individual_details.rb +32 -0
  25. data/lib/braintree_rails/individual_details_validator.rb +11 -0
  26. data/lib/braintree_rails/merchant_account.rb +45 -0
  27. data/lib/braintree_rails/merchant_account_validator.rb +14 -0
  28. data/lib/braintree_rails/plan.rb +3 -3
  29. data/lib/braintree_rails/subscription.rb +5 -5
  30. data/lib/braintree_rails/transaction.rb +9 -9
  31. data/lib/braintree_rails/transaction_validator.rb +1 -5
  32. data/lib/braintree_rails/validator.rb +13 -0
  33. data/lib/braintree_rails/version.rb +1 -1
  34. data/lib/tasks/ci.rake +7 -0
  35. data/lib/tasks/spec.rake +18 -0
  36. data/lib/test_env.rb +1 -7
  37. data/{test → spec}/config/braintree_auth.yml.example +0 -0
  38. data/{test → spec}/fixtures/add_ons.xml +0 -0
  39. data/{test → spec}/fixtures/address.xml +0 -0
  40. data/{test → spec}/fixtures/credit_card.xml +0 -0
  41. data/{test → spec}/fixtures/credit_card_validation_error.xml +0 -0
  42. data/{test → spec}/fixtures/customer.xml +0 -0
  43. data/{test → spec}/fixtures/discounts.xml +0 -0
  44. data/spec/fixtures/merchant_account.xml +7 -0
  45. data/{test → spec}/fixtures/plans.xml +0 -0
  46. data/{test → spec}/fixtures/subscription.xml +0 -0
  47. data/{test → spec}/fixtures/subscription_ids.xml +0 -0
  48. data/{test → spec}/fixtures/subscriptions.xml +0 -0
  49. data/{test → spec}/fixtures/transaction.xml +0 -0
  50. data/{test → spec}/fixtures/transaction_error.xml +0 -0
  51. data/{test → spec}/fixtures/transaction_ids.xml +0 -0
  52. data/{test → spec}/fixtures/transactions.xml +0 -0
  53. data/{test/integration/braintree_rails/address_integration_test.rb → spec/integration/braintree_rails/address_integration_spec.rb} +8 -8
  54. data/{test/integration/braintree_rails/credit_card_integration_test.rb → spec/integration/braintree_rails/credit_card_integration_spec.rb} +20 -20
  55. data/{test/integration/braintree_rails/customer_integration_test.rb → spec/integration/braintree_rails/customer_integration_spec.rb} +20 -20
  56. data/spec/integration/braintree_rails/merchant_account_integration_spec.rb +37 -0
  57. data/{test/integration/braintree_rails/transaction_integration_test.rb → spec/integration/braintree_rails/transaction_integration_spec.rb} +27 -27
  58. data/spec/integration/integration_spec_helper.rb +23 -0
  59. data/spec/spec_helper.rb +17 -0
  60. data/{test/test_helper.rb → spec/support/helper.rb} +42 -21
  61. data/spec/support/string_ext.rb +5 -0
  62. data/{test/unit/braintree_rails/add_on_test.rb → spec/unit/braintree_rails/add_on_spec.rb} +10 -10
  63. data/{test/unit/braintree_rails/add_ons_test.rb → spec/unit/braintree_rails/add_ons_spec.rb} +4 -4
  64. data/spec/unit/braintree_rails/address_details_spec.rb +13 -0
  65. data/{test/unit/braintree_rails/address_test.rb → spec/unit/braintree_rails/address_spec.rb} +26 -26
  66. data/{test/unit/braintree_rails/addresses_test.rb → spec/unit/braintree_rails/addresses_spec.rb} +7 -7
  67. data/spec/unit/braintree_rails/business_details_spec.rb +28 -0
  68. data/{test/unit/braintree_rails/configuration_test.rb → spec/unit/braintree_rails/configuration_spec.rb} +6 -6
  69. data/{test/unit/braintree_rails/credit_card_test.rb → spec/unit/braintree_rails/credit_card_spec.rb} +78 -72
  70. data/{test/unit/braintree_rails/credit_cards_test.rb → spec/unit/braintree_rails/credit_cards_spec.rb} +15 -10
  71. data/{test/unit/braintree_rails/customer_test.rb → spec/unit/braintree_rails/customer_spec.rb} +46 -46
  72. data/{test/unit/braintree_rails/discount_test.rb → spec/unit/braintree_rails/discount_spec.rb} +10 -10
  73. data/{test/unit/braintree_rails/discounts_test.rb → spec/unit/braintree_rails/discounts_spec.rb} +4 -4
  74. data/spec/unit/braintree_rails/funding_details_spec.rb +36 -0
  75. data/spec/unit/braintree_rails/individual_details_spec.rb +19 -0
  76. data/{test/unit/braintree_rails/luhn_10_validator_test.rb → spec/unit/braintree_rails/luhn_10_validator_spec.rb} +5 -5
  77. data/spec/unit/braintree_rails/merchant_account_spec.rb +50 -0
  78. data/{test/unit/braintree_rails/plan_test.rb → spec/unit/braintree_rails/plan_spec.rb} +12 -12
  79. data/{test/unit/braintree_rails/subscription_test.rb → spec/unit/braintree_rails/subscription_spec.rb} +55 -55
  80. data/{test/unit/braintree_rails/subscriptions_test.rb → spec/unit/braintree_rails/subscriptions_spec.rb} +4 -4
  81. data/{test/unit/braintree_rails/transaction_test.rb → spec/unit/braintree_rails/transaction_spec.rb} +55 -55
  82. data/{test/unit/braintree_rails/transactions_test.rb → spec/unit/braintree_rails/transactions_spec.rb} +9 -9
  83. data/{test/unit/braintree_rails/validation_error_test.rb → spec/unit/braintree_rails/validation_error_spec.rb} +4 -4
  84. data/{test/unit/braintree_rails/validator_test.rb → spec/unit/braintree_rails/validator_spec.rb} +7 -7
  85. data/spec/unit/unit_spec_helper.rb +4 -0
  86. metadata +69 -63
  87. data/lib/tasks/test.rake +0 -18
  88. data/test/integration/integration_test_helper.rb +0 -13
  89. data/test/unit/unit_test_helper.rb +0 -3
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '../unit_test_helper'))
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.must_equal braintree_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
- credit_card.send(attribute).must_equal braintree_credit_card.send(attribute) if braintree_credit_card.respond_to?(attribute)
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.persisted?.must_equal false
34
- credit_card.customer_id.must_equal braintree_customer.id
35
- credit_card.cardholder_name.must_equal 'foo bar'
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.persisted?.must_equal true
46
- customer.credit_cards.must_include credit_card
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.persisted?.must_equal false
55
- customer.credit_cards.wont_include credit_card
59
+ credit_card.should_not be_persisted
60
+ customer.credit_cards.size.should == 2
56
61
  end
57
62
  end
58
63
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '../unit_test_helper'))
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.persisted?.must_equal true
13
+ customer.should be_persisted
14
14
  BraintreeRails::Customer.attributes.each do |attribute|
15
- customer.send(attribute).must_equal braintree_customer.send(attribute) if braintree_customer.respond_to?(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.persisted?.must_equal true
23
+ customer.should be_persisted
24
24
  BraintreeRails::Customer.attributes.each do |attribute|
25
- customer.send(attribute).must_equal braintree_customer.send(attribute) if braintree_customer.respond_to?(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.persisted?.must_equal false
33
- customer.id.must_equal 'new_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.persisted?.must_equal true
40
- customer.id.must_equal 'foobar'
41
- customer.first_name.must_equal 'Foo'
42
- customer.last_name.must_equal 'Bar'
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.persisted?.must_equal false
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.must_be_kind_of(Enumerable)
55
- customer.addresses.size.must_equal braintree_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.must_be_kind_of(Enumerable)
65
- customer.credit_cards.size.must_equal braintree_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.must_equal "Foo Bar"
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.must_equal 'Foo'
76
- BraintreeRails::Customer.new(:last_name => 'Bar').full_name.must_equal 'Bar'
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].wont_be :blank?
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].wont_be :blank?
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].wont_be :blank?
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].wont_be :blank?
96
+ customer.errors[:id].should_not be_blank
97
97
 
98
98
  customer = BraintreeRails::Customer.new
99
99
  customer.valid?
100
- customer.errors[:id].must_be :blank?
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].must_be :blank?
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].must_be :blank?
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].must_be :blank?
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].must_be :blank?
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].wont_be :blank?
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.valid?.must_equal true
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.valid?.must_equal false
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.must_equal true
150
- customer.persisted?.must_equal true
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.must_equal false
156
- customer.persisted?.must_equal false
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!.must_equal true
162
- customer.persisted?.must_equal true
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
- lambda{ customer.save! }.must_raise(BraintreeRails::RecordInvalid)
168
- customer.persisted?.must_equal false
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').must_equal true
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).must_equal false
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').must_equal true
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
- lambda{ customer.update_attributes!(:first_name => 'f' * 256) }.must_raise(BraintreeRails::RecordInvalid)
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.must_be_kind_of 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.must_include "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
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.must_be_kind_of Hash
207
+ customer.as_json.should be_kind_of(Hash)
208
208
  end
209
209
  end
210
210
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '../unit_test_helper'))
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.persisted?.must_equal true
14
- discount.never_expires?.must_equal braintree_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).must_equal braintree_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.persisted?.must_equal true
24
+ discount.should be_persisted
25
25
  BraintreeRails::Discount.attributes.each do |attribute|
26
- discount.send(attribute).must_equal braintree_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.persisted?.must_equal true
34
+ discount.should be_persisted
35
35
  BraintreeRails::Discount.attributes.each do |attribute|
36
- discount.send(attribute).must_equal braintree_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.must_be_kind_of(Enumerable)
47
- discounts.size.must_equal braintree_discounts.size
46
+ discounts.should respond_to(:each)
47
+ discounts.size.should == braintree_discounts.size
48
48
  end
49
49
  end
50
50
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '../unit_test_helper'))
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.must_equal braintree_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).must_equal braintree_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
- lambda { discounts.create }.must_raise BraintreeRails::NotSupportedApiException
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__), '../unit_test_helper'))
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).must_be :valid?
12
- Validatable.new('5454545454545454').must_be :valid?
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.wont_be :valid?
20
- invalid_record.errors[:number].must_include 'failed Luhn 10 validation'
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