diff options
Diffstat (limited to 'billing/test')
-rw-r--r-- | billing/test/factories.rb | 14 | ||||
-rw-r--r-- | billing/test/unit/customer_test.rb | 6 | ||||
-rw-r--r-- | billing/test/unit/customer_with_payment_info_test.rb | 27 |
3 files changed, 39 insertions, 8 deletions
diff --git a/billing/test/factories.rb b/billing/test/factories.rb index 8648847..8314542 100644 --- a/billing/test/factories.rb +++ b/billing/test/factories.rb @@ -1,11 +1,21 @@ FactoryGirl.define do + TEST_CC_NUMBER = %w(4111 1111 1111 1111).join + factory :customer do user - factory :braintree_customer do - braintree_customer_id { 1 } + factory :customer_with_payment_info do + braintree_customer end end + factory :braintree_customer, class: Braintree::Customer do + first_name 'Big' + last_name 'Spender' + credit_card number: TEST_CC_NUMBER, expiration_date: '04/2016' + initialize_with { Braintree::Customer.create(attributes).customer } + skip_create + end + end diff --git a/billing/test/unit/customer_test.rb b/billing/test/unit/customer_test.rb index abcf96a..0358f38 100644 --- a/billing/test/unit/customer_test.rb +++ b/billing/test/unit/customer_test.rb @@ -34,10 +34,4 @@ class CustomerTest < ActiveSupport::TestCase assert_nil @customer.default_credit_card end - test "user with braintree id" do - @customer = FactoryGirl.build(:braintree_customer) - assert @customer.braintree_customer_id - assert @customer.has_payment_info? - end - end diff --git a/billing/test/unit/customer_with_payment_info_test.rb b/billing/test/unit/customer_with_payment_info_test.rb new file mode 100644 index 0000000..f887674 --- /dev/null +++ b/billing/test/unit/customer_with_payment_info_test.rb @@ -0,0 +1,27 @@ +require 'test_helper' +require 'fake_braintree' + +class CustomerWithPaymentInfoTest < ActiveSupport::TestCase + + setup do + @customer = FactoryGirl.build(:customer_with_payment_info) + end + + test "has payment_info" do + assert @customer.braintree_customer_id + assert @customer.has_payment_info? + end + + test "constructs customer with braintree data" do + @customer.with_braintree_data! + assert_equal 'Big', @customer.first_name + assert_equal 'Spender', @customer.last_name + assert_equal 1, @customer.credit_cards.size + assert_equal Hash.new, @customer.custom_fields + end + + test "sets default_credit_card" do + @customer.with_braintree_data! + assert_equal @customer.credit_cards.first, @customer.default_credit_card + end +end |