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
@@ -0,0 +1,37 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../integration_spec_helper'))
2
+
3
+ describe 'MerchantAccount Integration' do
4
+ it 'should fetch merchant account from Braintree for given id' do
5
+ braintree_merchant_account = Braintree::MerchantAccount.find(BraintreeRails::Configuration.default_merchant_account_id)
6
+ merchant_account = BraintreeRails::MerchantAccount.new(BraintreeRails::Configuration.default_merchant_account_id)
7
+ merchant_account.id.should == braintree_merchant_account.id
8
+ merchant_account.status.should == braintree_merchant_account.status
9
+ end
10
+
11
+ it 'can create sub merchant account' do
12
+ merchant_account = BraintreeRails::MerchantAccount.create(merchant_account_hash)
13
+ merchant_account.should be_persisted
14
+ end
15
+
16
+ it 'does not consider merchant account persisted if rejected by Braintree' do
17
+ merchant_account = BraintreeRails::MerchantAccount.create(merchant_account_hash.merge(:tos_accepted => 'false'))
18
+ merchant_account.should_not be_persisted
19
+ end
20
+
21
+ it 'sets validation errors properly to its associations' do
22
+ merchant_account = BraintreeRails::MerchantAccount.create(merchant_account_hash.merge(:individual => {}, :funding => {}, :business => {:legal_name => "foo"}))
23
+ merchant_account.should_not be_persisted
24
+ merchant_account.individual.errors.should_not be_empty
25
+ merchant_account.funding.errors.should_not be_empty
26
+ merchant_account.business.errors.should_not be_empty
27
+ end
28
+
29
+ it 'can update the submerchant account' do
30
+ individual = merchant_account_hash[:individual].merge(:first_name => "foo")
31
+ merchant_account = BraintreeRails::MerchantAccount.create(merchant_account_hash.merge(:individual => individual))
32
+ merchant_account.should be_persisted
33
+ merchant_account.individual.first_name.should == "foo"
34
+ merchant_account.update_attributes(:individual => {:first_name => "bar"})
35
+ merchant_account.individual.first_name.should == "bar"
36
+ end
37
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '../integration_test_helper'))
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../integration_spec_helper'))
2
2
 
3
3
  describe 'Transaction Integration' do
4
4
  before do
@@ -11,14 +11,14 @@ describe 'Transaction Integration' do
11
11
  customer = BraintreeRails::Customer.new(braintree_customer)
12
12
 
13
13
  transaction = BraintreeRails::Transaction.create!(:customer => customer, :amount => (1..5).to_a.sample)
14
- transaction.persisted?.must_equal true
15
- transaction.status.must_equal Braintree::Transaction::Status::Authorized
14
+ transaction.should be_persisted
15
+ transaction.status.should == Braintree::Transaction::Status::Authorized
16
16
 
17
17
  transaction.submit_for_settlement!
18
- transaction.status.must_equal Braintree::Transaction::Status::SubmittedForSettlement
18
+ transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
19
19
 
20
20
  transaction.void!
21
- transaction.status.must_equal Braintree::Transaction::Status::Voided
21
+ transaction.status.should == Braintree::Transaction::Status::Voided
22
22
  end
23
23
 
24
24
  it 'should be able to create, submit, void transactions for a customer with a credit_card' do
@@ -27,14 +27,14 @@ describe 'Transaction Integration' do
27
27
  credit_card = customer.credit_cards.first
28
28
 
29
29
  transaction = BraintreeRails::Transaction.create!(:customer => customer, :amount => (1..5).to_a.sample, :credit_card => credit_card)
30
- transaction.persisted?.must_equal true
31
- transaction.status.must_equal Braintree::Transaction::Status::Authorized
30
+ transaction.should be_persisted
31
+ transaction.status.should == Braintree::Transaction::Status::Authorized
32
32
 
33
33
  transaction.submit_for_settlement!
34
- transaction.status.must_equal Braintree::Transaction::Status::SubmittedForSettlement
34
+ transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
35
35
 
36
36
  transaction.void!
37
- transaction.status.must_equal Braintree::Transaction::Status::Voided
37
+ transaction.status.should == Braintree::Transaction::Status::Voided
38
38
  end
39
39
 
40
40
 
@@ -44,31 +44,31 @@ describe 'Transaction Integration' do
44
44
  credit_card = customer.credit_cards.first
45
45
  transaction = BraintreeRails::Transaction.create!(:amount => (1..10).to_a.sample, :customer => customer)
46
46
 
47
- customer.transactions.length.must_equal 1
47
+ customer.transactions.length.should == 1
48
48
  customer.transactions.each do |t|
49
- t.must_equal transaction
49
+ t.should == transaction
50
50
  end
51
- credit_card.transactions.count.must_equal 1
51
+ credit_card.transactions.count.should == 1
52
52
  end
53
53
 
54
54
  it "should be able to load all transactions for a given customer" do
55
55
  braintree_customer = Braintree::Customer.create!(customer_hash)
56
56
  customer = BraintreeRails::Customer.new(braintree_customer)
57
- credit_card1 = customer.credit_cards.create!(credit_card_hash.merge(:token => 'card_1'))
58
- credit_card2 = customer.credit_cards.create!(credit_card_hash.merge(:token => 'card_2'))
59
- customer.credit_cards.size.must_equal 2
57
+ credit_card1 = customer.credit_cards.create!(credit_card_hash.merge(:token => nil))
58
+ credit_card2 = customer.credit_cards.create!(credit_card_hash.merge(:token => nil))
59
+ customer.credit_cards.size.should == 2
60
60
 
61
61
  transaction1 = BraintreeRails::Transaction.create!(:amount => (1..10).to_a.sample, :customer => customer, :credit_card => credit_card1)
62
62
  transaction2 = BraintreeRails::Transaction.create!(:amount => (1..10).to_a.sample, :customer => customer, :credit_card => credit_card2)
63
- customer.transactions.size.must_equal 2
63
+ customer.transactions.size.should == 2
64
64
  end
65
65
 
66
66
  it 'should be able to create a one time transaction' do
67
67
  transaction = BraintreeRails::Transaction.create!(:amount => (1..10).to_a.sample, :billing => address_hash, :customer => customer_hash, :credit_card => credit_card_hash)
68
- transaction.persisted?.must_equal true
69
- transaction.id.wont_be :blank?
70
- transaction.customer.wont_be :blank?
71
- transaction.credit_card.wont_be :blank?
68
+ transaction.should be_persisted
69
+ transaction.id.should_not be_blank
70
+ transaction.customer.should_not be_blank
71
+ transaction.credit_card.should_not be_blank
72
72
  end
73
73
 
74
74
  it 'should be able to capture braintree api errors' do
@@ -78,8 +78,8 @@ describe 'Transaction Integration' do
78
78
  transaction = BraintreeRails::Transaction.create!(:amount => (1..10).to_a.sample, :customer => customer)
79
79
 
80
80
  transaction.void!
81
- transaction.submit_for_settlement.must_equal false
82
- transaction.errors[:status].wont_be :blank?
81
+ transaction.submit_for_settlement.should be_false
82
+ transaction.errors[:status].should_not be_blank
83
83
  end
84
84
 
85
85
  describe BraintreeRails::Transactions do
@@ -90,8 +90,8 @@ describe 'Transaction Integration' do
90
90
  credit_card = customer.default_credit_card
91
91
 
92
92
  transaction = BraintreeRails::Transactions.new(customer).create!(:amount => (1..10).to_a.sample)
93
- transaction.customer.must_equal customer
94
- transaction.credit_card.must_equal credit_card
93
+ transaction.customer.should == customer
94
+ transaction.credit_card.should == credit_card
95
95
  end
96
96
 
97
97
  it 'can use default credit_card to build new record' do
@@ -100,7 +100,7 @@ describe 'Transaction Integration' do
100
100
  credit_card = customer.default_credit_card
101
101
 
102
102
  transaction = BraintreeRails::Transactions.new(credit_card).create!(:amount => (1..10).to_a.sample)
103
- transaction.credit_card.must_equal credit_card
103
+ transaction.credit_card.should == credit_card
104
104
  end
105
105
  end
106
106
 
@@ -109,10 +109,10 @@ describe 'Transaction Integration' do
109
109
  customer = BraintreeRails::Customer.create!(customer_hash.merge(:credit_card => credit_card_hash))
110
110
  credit_card = customer.credit_cards.create!(credit_card_hash.merge(:token => 'card_1'))
111
111
  transactions = customer.transactions
112
- transactions.must_be :empty?
112
+ transactions.should be_empty
113
113
 
114
114
  transaction = BraintreeRails::Transaction.create!(:amount => (1..10).to_a.sample, :customer => customer, :credit_card => credit_card)
115
- transactions.reload.size.must_equal 1
115
+ transactions.reload.size.should == 1
116
116
  end
117
117
  end
118
118
  end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
2
+ SimpleCov.command_name "spec:integration"
3
+
4
+ config = File.join(SPEC_PATH, 'config/braintree_auth.yml')
5
+ if File.exist?(config) && auth = YAML.load_file(config)
6
+ BraintreeRails::Configuration.environment = :sandbox
7
+ BraintreeRails::Configuration.merchant_id = auth['merchant_id']
8
+ BraintreeRails::Configuration.public_key = auth['public_key']
9
+ BraintreeRails::Configuration.private_key = auth['private_key']
10
+ BraintreeRails::Configuration.default_merchant_account_id = auth['default_merchant_account_id']
11
+ # BraintreeRails::Configuration.logger = Logger.new('log/braintree.log')
12
+ elsif ENV["TRAVIS_SECURE_ENV_VARS"] == "true" && ENV["TRAVIS_RUBY_VERSION"] == "2.0.0"
13
+ BraintreeRails::Configuration.environment = :sandbox
14
+ BraintreeRails::Configuration.merchant_id = ENV['merchant_id']
15
+ BraintreeRails::Configuration.public_key = ENV['public_key']
16
+ BraintreeRails::Configuration.private_key = ENV['private_key']
17
+ BraintreeRails::Configuration.default_merchant_account_id = ENV['default_merchant_account_id']
18
+ else
19
+ puts '*' * 80
20
+ puts "You need to provide real credentials in #{config} to run integration tests"
21
+ puts '*' * 80
22
+ exit(0)
23
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../lib/test_env'))
2
+
3
+ SPEC_PATH = File.expand_path(File.dirname(__FILE__))
4
+ FIXTURE_PATH = File.join(SPEC_PATH, 'fixtures')
5
+
6
+ BraintreeRails::Configuration.environment = :sandbox
7
+ BraintreeRails::Configuration.merchant_id = 'merchant_id'
8
+ BraintreeRails::Configuration.public_key = 'public_key'
9
+ BraintreeRails::Configuration.private_key = 'private_key'
10
+ BraintreeRails::Configuration.default_merchant_account_id = 'default_merchant_account_id'
11
+ BraintreeRails::Configuration.logger = Logger.new('/dev/null').tap { |logger| logger.level = Logger::INFO }
12
+ BraintreeBaseUri = "https://#{Braintree::Configuration.public_key}:#{Braintree::Configuration.private_key}@api.#{Braintree::Configuration.environment}.braintreegateway.com/merchants/#{Braintree::Configuration.merchant_id}"
13
+
14
+ Dir[File.join(SPEC_PATH, "support/**/*.rb")].each { |f| require f }
15
+ RSpec.configure do |config|
16
+ config.include Helper
17
+ end
@@ -1,16 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '../lib/test_env'))
2
-
3
- TEST_PATH = File.expand_path(File.dirname(__FILE__))
4
- FIXTURE_PATH = File.join(TEST_PATH, 'fixtures')
5
-
6
- Braintree::Configuration.environment = :sandbox
7
- Braintree::Configuration.merchant_id = 'merchant_id'
8
- Braintree::Configuration.public_key = 'public_key'
9
- Braintree::Configuration.private_key = 'private_key'
10
- Braintree::Configuration.logger = Logger.new('/dev/null').tap { |logger| logger.level = Logger::INFO }
11
- BraintreeBaseUri = "https://#{Braintree::Configuration.public_key}:#{Braintree::Configuration.private_key}@#{Braintree::Configuration.environment}.braintreegateway.com/merchants/#{Braintree::Configuration.merchant_id}"
12
-
13
- module TestHelper
1
+ module Helper
14
2
  def fixture(name)
15
3
  File.read(File.join(FIXTURE_PATH, name)).gzip
16
4
  end
@@ -28,7 +16,7 @@ module TestHelper
28
16
  :street_address => "#{(1000..9999).to_a.sample} Crane Avenue",
29
17
  :extended_address => "Suite #{(100..999).to_a.sample}",
30
18
  :locality => 'Menlo Park',
31
- :region => 'California',
19
+ :region => 'CA',
32
20
  :postal_code => ("00001".."99999").to_a.shuffle.first,
33
21
  :country_name => 'United States of America'
34
22
  }
@@ -62,15 +50,48 @@ module TestHelper
62
50
  :price => ''
63
51
  }
64
52
  end
65
- end
66
53
 
54
+ def merchant_account_hash
55
+ {
56
+ :master_merchant_account_id => BraintreeRails::Configuration.default_merchant_account_id,
57
+ :tos_accepted => true,
58
+ :individual => individual_details_hash,
59
+ :funding => funding_details_hash,
60
+ :business => business_details_hash,
61
+ }
62
+ end
63
+
64
+ def individual_details_hash
65
+ {
66
+ :first_name => "Brain",
67
+ :last_name => "Tree",
68
+ :email => "braintree-rails@exameple.com",
69
+ :date_of_birth => "2014-01-01",
70
+ :address => address_details_hash
71
+ }
72
+ end
67
73
 
68
- MiniTest::Unit::TestCase.class_eval do
69
- include TestHelper
70
- end
74
+ def business_details_hash
75
+ {
76
+ :legal_name => "braintree-rails",
77
+ :dba_name => "braintree-rails",
78
+ :tax_id => "98-7654321"
79
+ }
80
+ end
81
+
82
+ def funding_details_hash
83
+ {
84
+ :destination => Braintree::MerchantAccount::FundingDestination::Email,
85
+ :email => "braintree-rails@exameple.com"
86
+ }
87
+ end
71
88
 
72
- String.class_eval do
73
- def gzip
74
- Zlib::GzipWriter.wrap(StringIO.new(gzipped = '')) { |gz| gz.write(self); gzipped }
89
+ def address_details_hash
90
+ {
91
+ :street_address => "#{(1000..9999).to_a.sample} Crane Avenue",
92
+ :locality => 'Menlo Park',
93
+ :region => 'CA',
94
+ :postal_code => ("00001".."99999").to_a.shuffle.first,
95
+ }
75
96
  end
76
97
  end
@@ -0,0 +1,5 @@
1
+ String.class_eval do
2
+ def gzip
3
+ Zlib::GzipWriter.wrap(StringIO.new(gzipped = '')) { |gz| gz.write(self); gzipped }
4
+ end
5
+ 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::AddOn do
4
4
  before do
@@ -10,10 +10,10 @@ describe BraintreeRails::AddOn do
10
10
  braintree_add_on = Braintree::AddOn.all.find { |a| a.id == 'add_on_id' }
11
11
  add_on = BraintreeRails::AddOn.new(braintree_add_on)
12
12
 
13
- add_on.persisted?.must_equal true
14
- add_on.never_expires?.must_equal braintree_add_on.never_expires?
13
+ add_on.should be_persisted
14
+ add_on.never_expires?.should == braintree_add_on.never_expires?
15
15
  BraintreeRails::AddOn.attributes.each do |attribute|
16
- add_on.send(attribute).must_equal braintree_add_on.send(attribute)
16
+ add_on.send(attribute).should == braintree_add_on.send(attribute)
17
17
  end
18
18
  end
19
19
 
@@ -21,9 +21,9 @@ describe BraintreeRails::AddOn do
21
21
  braintree_add_on = Braintree::AddOn.all.find { |a| a.id == 'add_on_id' }
22
22
  add_on = BraintreeRails::AddOn.new('add_on_id')
23
23
 
24
- add_on.persisted?.must_equal true
24
+ add_on.should be_persisted
25
25
  BraintreeRails::AddOn.attributes.each do |attribute|
26
- add_on.send(attribute).must_equal braintree_add_on.send(attribute)
26
+ add_on.send(attribute).should == braintree_add_on.send(attribute)
27
27
  end
28
28
  end
29
29
 
@@ -31,9 +31,9 @@ describe BraintreeRails::AddOn do
31
31
  braintree_add_on = Braintree::AddOn.all.find { |a| a.id == 'add_on_id' }
32
32
  add_on = BraintreeRails::AddOn.find('add_on_id')
33
33
 
34
- add_on.persisted?.must_equal true
34
+ add_on.should be_persisted
35
35
  BraintreeRails::AddOn.attributes.each do |attribute|
36
- add_on.send(attribute).must_equal braintree_add_on.send(attribute)
36
+ add_on.send(attribute).should == braintree_add_on.send(attribute)
37
37
  end
38
38
  end
39
39
  end
@@ -43,8 +43,8 @@ describe BraintreeRails::AddOn do
43
43
  braintree_add_ons = Braintree::AddOn.all
44
44
  add_ons = BraintreeRails::AddOn.all
45
45
 
46
- add_ons.must_be_kind_of(Enumerable)
47
- add_ons.size.must_equal braintree_add_ons.size
46
+ add_ons.should respond_to(:each)
47
+ add_ons.size.should == braintree_add_ons.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::AddOns do
4
4
  before do
@@ -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.must_equal braintree_add_ons.size
14
+ add_ons.size.should == 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).must_equal braintree_add_on.send(attribute)
19
+ add_on.send(attribute).should == braintree_add_on.send(attribute)
20
20
  end
21
21
  end
22
22
  end
@@ -27,7 +27,7 @@ describe BraintreeRails::AddOns do
27
27
  braintree_plan = Braintree::Plan.all.find { |p| p.id == 'plan_id' }
28
28
  braintree_add_ons = braintree_plan.add_ons
29
29
  add_ons = BraintreeRails::AddOns.new(BraintreeRails::Plan.find('plan_id'))
30
- lambda { add_ons.create }.must_raise BraintreeRails::NotSupportedApiException
30
+ expect { add_ons.create }.to raise_error(BraintreeRails::NotSupportedApiException)
31
31
  end
32
32
  end
33
33
  end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../unit_spec_helper'))
2
+
3
+ describe BraintreeRails::AddressDetails do
4
+ describe 'validations' do
5
+ [:street_address, :locality, :region, :postal_code].each do |attribute|
6
+ it "requires #{attribute}" do
7
+ address = BraintreeRails::AddressDetails.new(address_details_hash.merge(attribute => nil))
8
+ address.should be_invalid
9
+ address.errors[attribute].should == ["can't be blank"]
10
+ end
11
+ end
12
+ end
13
+ 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::Address do
4
4
  describe '#initialize' do
@@ -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.persisted?.must_equal true
13
+ address.should be_persisted
14
14
  BraintreeRails::Address.attributes.each do |attribute|
15
- address.send(attribute).must_equal braintree_address.send(attribute)
15
+ address.send(attribute).should == 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.persisted?.must_equal true
25
+ address.should be_persisted
26
26
  BraintreeRails::Address.attributes.each do |attribute|
27
- address.send(attribute).must_equal braintree_address.send(attribute)
27
+ address.send(attribute).should == 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.persisted?.must_equal false
35
- address.id.must_equal 'new_id'
34
+ address.should_not be_persisted
35
+ address.id.should == '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.persisted?.must_equal true
42
- address.id.must_equal 'foobar'
43
- address.first_name.must_equal 'Foo'
44
- address.last_name.must_equal 'Bar'
41
+ address.should be_persisted
42
+ address.id.should == 'foobar'
43
+ address.first_name.should == 'Foo'
44
+ address.last_name.should == 'Bar'
45
45
 
46
46
  address = BraintreeRails::Address.new(Object.new)
47
- address.persisted?.must_equal false
47
+ address.should_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.must_equal 'United States of America'
55
+ address.country_name.should == '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.persisted?.must_equal true
65
- address.customer.id.must_equal 'customer_id'
64
+ address.customer.should be_persisted
65
+ address.customer.id.should == '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.must_equal "Foo Bar"
71
+ BraintreeRails::Address.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::Address.new(:first_name => "Foo").full_name.must_equal 'Foo'
76
- BraintreeRails::Address.new(:last_name => 'Bar').full_name.must_equal 'Bar'
75
+ BraintreeRails::Address.new(:first_name => "Foo").full_name.should == 'Foo'
76
+ BraintreeRails::Address.new(:last_name => 'Bar').full_name.should == '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].must_be :blank?
85
+ address.errors[attribute].should be_blank
86
86
 
87
87
  address = BraintreeRails::Address.new(attribute => 'f' * 255)
88
88
  address.valid?
89
- address.errors[attribute].must_be :blank?
89
+ address.errors[attribute].should be_blank
90
90
 
91
91
  address = BraintreeRails::Address.new(attribute => 'foo' * 256)
92
92
  address.valid?
93
- address.errors[attribute].wont_be :blank?
93
+ address.errors[attribute].should_not be_blank
94
94
  end
95
95
  end
96
96
 
@@ -98,29 +98,29 @@ 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].must_be :blank?
101
+ address.errors[attribute].should be_blank
102
102
 
103
103
  address = BraintreeRails::Address.new
104
104
  address.valid?
105
- address.errors[attribute].wont_be :blank?
105
+ address.errors[attribute].should_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].must_be :blank?
112
+ address.errors[:postal_code].should be_blank
113
113
 
114
114
  address = BraintreeRails::Address.new({:postal_code => '%$'})
115
115
  address.valid?
116
- address.errors[:postal_code].wont_be :blank?
116
+ address.errors[:postal_code].should_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.must_equal Braintree::Address
123
+ subclass.braintree_model_class.should == Braintree::Address
124
124
  end
125
125
  end
126
126
  end