diff options
author | azul <azul@riseup.net> | 2014-04-17 10:12:05 +0200 |
---|---|---|
committer | azul <azul@riseup.net> | 2014-04-17 10:12:05 +0200 |
commit | 3513ad74f950b113af1ba1e3d06bc6a55c48fde5 (patch) | |
tree | db49ebd4428053d5c8d720275b77594a531a1ad1 /engines/billing/test/unit | |
parent | cb6442c344d6bdaf52c3878b2de2fcf4d85f2648 (diff) | |
parent | 3d3688647fab7049e5b531c45b85c1e46a1d528f (diff) |
Merge pull request #146 from azul/refactor/engines
Refactor/engines
Diffstat (limited to 'engines/billing/test/unit')
-rw-r--r-- | engines/billing/test/unit/customer_test.rb | 38 | ||||
-rw-r--r-- | engines/billing/test/unit/customer_with_payment_info_test.rb | 40 |
2 files changed, 78 insertions, 0 deletions
diff --git a/engines/billing/test/unit/customer_test.rb b/engines/billing/test/unit/customer_test.rb new file mode 100644 index 0000000..6156f87 --- /dev/null +++ b/engines/billing/test/unit/customer_test.rb @@ -0,0 +1,38 @@ +require 'test_helper' + +class CustomerTest < ActiveSupport::TestCase + include StubRecordHelper + + setup do + @user = find_record :user + @customer = FactoryGirl.build(:customer, user: @user) + end + + test "test set of attributes should be valid" do + @customer.valid? + assert_equal Hash.new, @customer.errors.messages + end + + test "customer belongs to user" do + assert_equal User, @customer.user.class + end + + test "user validation" do + @customer.user = nil + assert !@customer.valid? + end + + test "has no payment info" do + assert !@customer.braintree_customer_id + assert !@customer.has_payment_info? + end + + test "with no braintree data" do + assert_equal @customer, @customer.with_braintree_data! + end + + test "without default credit card" do + assert_nil @customer.default_credit_card + end + +end diff --git a/engines/billing/test/unit/customer_with_payment_info_test.rb b/engines/billing/test/unit/customer_with_payment_info_test.rb new file mode 100644 index 0000000..0589a59 --- /dev/null +++ b/engines/billing/test/unit/customer_with_payment_info_test.rb @@ -0,0 +1,40 @@ +require 'test_helper' +require 'fake_braintree' + +class CustomerWithPaymentInfoTest < ActiveSupport::TestCase + include StubRecordHelper + + setup do + @user = find_record :user + @customer = FactoryGirl.build(:customer_with_payment_info, user: @user) + 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 "can access braintree_customer after reload" do + @customer.save + @customer = Customer.find_by_user_id(@customer.user_id) + @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 + @customer.destroy + end + + test "sets default_credit_card" do + @customer.with_braintree_data! + assert_equal @customer.credit_cards.first, @customer.default_credit_card + end +end |