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
@@ -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__), '../
|
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.
|
15
|
-
transaction.status.
|
14
|
+
transaction.should be_persisted
|
15
|
+
transaction.status.should == Braintree::Transaction::Status::Authorized
|
16
16
|
|
17
17
|
transaction.submit_for_settlement!
|
18
|
-
transaction.status.
|
18
|
+
transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
|
19
19
|
|
20
20
|
transaction.void!
|
21
|
-
transaction.status.
|
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.
|
31
|
-
transaction.status.
|
30
|
+
transaction.should be_persisted
|
31
|
+
transaction.status.should == Braintree::Transaction::Status::Authorized
|
32
32
|
|
33
33
|
transaction.submit_for_settlement!
|
34
|
-
transaction.status.
|
34
|
+
transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
|
35
35
|
|
36
36
|
transaction.void!
|
37
|
-
transaction.status.
|
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.
|
47
|
+
customer.transactions.length.should == 1
|
48
48
|
customer.transactions.each do |t|
|
49
|
-
t.
|
49
|
+
t.should == transaction
|
50
50
|
end
|
51
|
-
credit_card.transactions.count.
|
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 =>
|
58
|
-
credit_card2 = customer.credit_cards.create!(credit_card_hash.merge(:token =>
|
59
|
-
customer.credit_cards.size.
|
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.
|
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.
|
69
|
-
transaction.id.
|
70
|
-
transaction.customer.
|
71
|
-
transaction.credit_card.
|
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.
|
82
|
-
transaction.errors[:status].
|
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.
|
94
|
-
transaction.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.
|
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.
|
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.
|
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
|
data/spec/spec_helper.rb
ADDED
@@ -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
|
-
|
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 => '
|
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
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
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
|
@@ -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::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.
|
14
|
-
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).
|
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.
|
24
|
+
add_on.should be_persisted
|
25
25
|
BraintreeRails::AddOn.attributes.each do |attribute|
|
26
|
-
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.
|
34
|
+
add_on.should be_persisted
|
35
35
|
BraintreeRails::AddOn.attributes.each do |attribute|
|
36
|
-
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.
|
47
|
-
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
|
data/{test/unit/braintree_rails/add_ons_test.rb → spec/unit/braintree_rails/add_ons_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::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.
|
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).
|
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
|
-
|
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
|
data/{test/unit/braintree_rails/address_test.rb → spec/unit/braintree_rails/address_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::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.
|
13
|
+
address.should be_persisted
|
14
14
|
BraintreeRails::Address.attributes.each do |attribute|
|
15
|
-
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.
|
25
|
+
address.should be_persisted
|
26
26
|
BraintreeRails::Address.attributes.each do |attribute|
|
27
|
-
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.
|
35
|
-
address.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.
|
42
|
-
address.id.
|
43
|
-
address.first_name.
|
44
|
-
address.last_name.
|
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.
|
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.
|
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.
|
65
|
-
address.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.
|
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.
|
76
|
-
BraintreeRails::Address.new(:last_name => 'Bar').full_name.
|
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].
|
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].
|
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].
|
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].
|
101
|
+
address.errors[attribute].should be_blank
|
102
102
|
|
103
103
|
address = BraintreeRails::Address.new
|
104
104
|
address.valid?
|
105
|
-
address.errors[attribute].
|
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].
|
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].
|
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.
|
123
|
+
subclass.braintree_model_class.should == Braintree::Address
|
124
124
|
end
|
125
125
|
end
|
126
126
|
end
|