braintree-rails 0.1.0 → 0.2.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.
@@ -6,18 +6,19 @@ describe 'Address Integration' do
6
6
  end
7
7
 
8
8
  it 'should be able to add address' do
9
- customer = BraintreeRails::Customer.create!(:first_name => 'Brain', :last_name => 'Tree')
10
- customer.addresses.create!(address_hash)
9
+ customer = BraintreeRails::Customer.create!(customer_hash)
10
+ attributes = address_hash()
11
+ customer.addresses.create!(attributes)
11
12
  braintree_customer = Braintree::Customer.find(customer.id)
12
13
  braintree_address = braintree_customer.addresses.first
13
14
 
14
- address_hash.each do |key, value|
15
+ attributes.each do |key, value|
15
16
  braintree_address.send(key).must_equal value
16
17
  end
17
18
  end
18
19
 
19
20
  it 'should be able to update existing address' do
20
- customer = BraintreeRails::Customer.create!(:first_name => 'Brain', :last_name => 'Tree')
21
+ customer = BraintreeRails::Customer.create!(customer_hash)
21
22
  address = customer.addresses.create!(address_hash)
22
23
  address.update_attributes!(:first_name => 'Foo', :last_name => 'Bar')
23
24
  braintree_customer = Braintree::Customer.find(customer.id)
@@ -28,7 +29,7 @@ describe 'Address Integration' do
28
29
  end
29
30
 
30
31
  it 'should be able to destroy existing address' do
31
- customer = BraintreeRails::Customer.create!(:first_name => 'Brain', :last_name => 'Tree')
32
+ customer = BraintreeRails::Customer.create!(customer_hash)
32
33
  address = customer.addresses.create!(address_hash)
33
34
  address.destroy!
34
35
  lambda{ Braintree::Address.find(customer.id, address.id) }.must_raise Braintree::NotFoundError
@@ -6,30 +6,32 @@ describe 'Credit Card Integration' do
6
6
  end
7
7
 
8
8
  it 'should be able to fetch from Braintree for given token' do
9
- braintree_customer = Braintree::Customer.create!(:id => 'customer_id', :first_name => 'Brain', :last_name => 'Tree', :credit_card => credit_card_hash)
9
+ attributes = credit_card_hash()
10
+ braintree_customer = Braintree::Customer.create!(:id => 'customer_id', :first_name => 'Brain', :last_name => 'Tree', :credit_card => attributes)
10
11
 
11
12
  credit_card = BraintreeRails::CreditCard.new(braintree_customer.credit_cards.first.token)
12
13
 
13
- credit_card_hash.except(:number, :cvv, :billing_address).each do |key, value|
14
+ attributes.except(:number, :cvv, :billing_address).each do |key, value|
14
15
  credit_card.send(key).must_equal value
15
16
  end
16
17
 
17
- address_hash.each do |key, value|
18
+ attributes[:billing_address].each do |key, value|
18
19
  credit_card.billing_address.send(key).must_equal value
19
20
  end
20
21
  end
21
22
 
22
23
  it 'should be able to add credit card' do
23
24
  customer = BraintreeRails::Customer.create!(:id => 'customer_id', :first_name => 'Brain', :last_name => 'Tree')
24
- credit_card = customer.credit_cards.create!(credit_card_hash)
25
+ attributes = credit_card_hash()
26
+ credit_card = customer.credit_cards.create!(attributes)
25
27
 
26
28
  braintree_credit_card = Braintree::CreditCard.find(credit_card.id)
27
- credit_card_hash.except(:number, :cvv, :billing_address).each do |key, value|
29
+ attributes.except(:number, :cvv, :billing_address).each do |key, value|
28
30
  braintree_credit_card.send(key).must_equal value
29
31
  end
30
32
 
31
33
  braintree_address = braintree_credit_card.billing_address
32
- address_hash.each do |key, value|
34
+ attributes[:billing_address].each do |key, value|
33
35
  braintree_address.send(key).must_equal value
34
36
  end
35
37
  end
@@ -7,26 +7,39 @@ describe 'Transaction Integration' do
7
7
 
8
8
  it 'should be able to create, submit, void transactions for a customer' do
9
9
 
10
- braintree_customer = Braintree::Customer.create!(:id => 'customer_id', :first_name => 'Brain', :last_name => 'Tree', :credit_card => credit_card_hash)
10
+ braintree_customer = Braintree::Customer.create!(customer_hash.merge(:credit_card => credit_card_hash))
11
+ customer = BraintreeRails::Customer.new(braintree_customer)
12
+
13
+ transaction = BraintreeRails::Transaction.create!(:customer => customer, :amount => rand(1..5))
14
+ transaction.persisted?.must_equal true
15
+ transaction.status.must_equal Braintree::Transaction::Status::Authorized
16
+
17
+ transaction.submit_for_settlement!
18
+ transaction.status.must_equal Braintree::Transaction::Status::SubmittedForSettlement
19
+
20
+ transaction.void!
21
+ transaction.status.must_equal Braintree::Transaction::Status::Voided
22
+ end
23
+
24
+ it 'should be able to create, submit, void transactions for a customer with a credit_card' do
25
+ braintree_customer = Braintree::Customer.create!(customer_hash.merge(:credit_card => credit_card_hash))
11
26
  customer = BraintreeRails::Customer.new(braintree_customer)
12
27
  credit_card = customer.credit_cards.first
13
28
 
14
- [{:amount => rand(1..10), :customer => customer}, {:amount => rand(1..10), :customer => customer, :credit_card => credit_card}].each do |params|
15
- transaction = BraintreeRails::Transaction.create!(params)
16
- transaction.persisted?.must_equal true
17
- transaction.amount.must_equal params[:amount]
18
- transaction.status.must_equal Braintree::Transaction::Status::Authorized
29
+ transaction = BraintreeRails::Transaction.create!(:customer => customer, :amount => rand(1..5), :credit_card => credit_card)
30
+ transaction.persisted?.must_equal true
31
+ transaction.status.must_equal Braintree::Transaction::Status::Authorized
19
32
 
20
- transaction.submit_for_settlement!
21
- transaction.status.must_equal Braintree::Transaction::Status::SubmittedForSettlement
33
+ transaction.submit_for_settlement!
34
+ transaction.status.must_equal Braintree::Transaction::Status::SubmittedForSettlement
22
35
 
23
- transaction.void!
24
- transaction.status.must_equal Braintree::Transaction::Status::Voided
25
- end
36
+ transaction.void!
37
+ transaction.status.must_equal Braintree::Transaction::Status::Voided
26
38
  end
27
39
 
40
+
28
41
  it "should be able to load transactions for given customer and credit_card" do
29
- braintree_customer = Braintree::Customer.create!(:id => 'customer_id', :first_name => 'Brain', :last_name => 'Tree', :credit_card => credit_card_hash)
42
+ braintree_customer = Braintree::Customer.create!(customer_hash.merge(:credit_card => credit_card_hash))
30
43
  customer = BraintreeRails::Customer.new(braintree_customer)
31
44
  credit_card = customer.credit_cards.first
32
45
  transaction = BraintreeRails::Transaction.create!(:amount => rand(1..10), :customer => customer)
@@ -35,8 +48,14 @@ describe 'Transaction Integration' do
35
48
  credit_card.transactions.count.must_equal 1
36
49
  end
37
50
 
51
+ it 'should be able to create a one time transaction' do
52
+ transaction = BraintreeRails::Transaction.create!(:amount => rand(1..10), :customer => customer_hash, :credit_card => credit_card_hash)
53
+ transaction.persisted?.must_equal true
54
+ transaction.id.wont_be :blank?
55
+ end
56
+
38
57
  it 'should be able to capture braintree api errors' do
39
- braintree_customer = Braintree::Customer.create!(:id => 'customer_id', :first_name => 'Brain', :last_name => 'Tree', :credit_card => credit_card_hash)
58
+ braintree_customer = Braintree::Customer.create!(customer_hash.merge(:credit_card => credit_card_hash))
40
59
  customer = BraintreeRails::Customer.new(braintree_customer)
41
60
  credit_card = customer.credit_cards.first
42
61
  transaction = BraintreeRails::Transaction.create!(:amount => rand(1..10), :customer => customer)
data/test/test_helper.rb CHANGED
@@ -25,11 +25,11 @@ MiniTest::Unit::TestCase.class_eval do
25
25
  :first_name => 'Brain',
26
26
  :last_name => 'Tree',
27
27
  :company => 'Braintree',
28
- :street_address => '1134 Crane Avenue',
29
- :extended_address => 'Suite 200',
28
+ :street_address => "#{rand(1000..9999)} Crane Avenue",
29
+ :extended_address => "Suite #{rand(100..999)}",
30
30
  :locality => 'Menlo Park',
31
31
  :region => 'California',
32
- :postal_code => '94025',
32
+ :postal_code => ("00001".."99999").to_a.shuffle.first,
33
33
  :country_name => 'United States of America'
34
34
  }
35
35
  end
@@ -37,14 +37,21 @@ MiniTest::Unit::TestCase.class_eval do
37
37
  def credit_card_hash
38
38
  {
39
39
  :token => 'credit_card_id',
40
- :number => '4111111111111111',
41
- :cvv => '123',
40
+ :number => (Braintree::Test::CreditCardNumbers::All - Braintree::Test::CreditCardNumbers::AmExes).shuffle.first,
41
+ :cvv => ("100".."999").to_a.shuffle.first,
42
42
  :cardholder_name => 'Brain Tree',
43
- :expiration_month => '05',
44
- :expiration_year => '2037',
43
+ :expiration_month => ("01".."12").to_a.shuffle.first,
44
+ :expiration_year => ("2012".."2035").to_a.shuffle.first,
45
45
  :billing_address => address_hash,
46
46
  }
47
47
  end
48
+
49
+ def customer_hash
50
+ {
51
+ :first_name => "Brain#{rand(1..100)}",
52
+ :last_name => "Tree#{rand(1..100)}"
53
+ }
54
+ end
48
55
  end
49
56
 
50
57
  String.class_eval do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: braintree-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-16 00:00:00.000000000 Z
12
+ date: 2012-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: braintree
@@ -113,6 +113,7 @@ executables: []
113
113
  extensions: []
114
114
  extra_rdoc_files: []
115
115
  files:
116
+ - braintree-rails-0.1.0.gem
116
117
  - braintree-rails.gemspec
117
118
  - Gemfile
118
119
  - Gemfile.lock