From a49c63eb117abf47ca1804493c25ae34804f8ee1 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 1 Jul 2013 09:55:54 +0200 Subject: test non braintree parts of customer, validate user --- billing/test/factories.rb | 11 +++++++++ billing/test/unit/customer_test.rb | 47 +++++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 billing/test/factories.rb (limited to 'billing/test') diff --git a/billing/test/factories.rb b/billing/test/factories.rb new file mode 100644 index 0000000..8648847 --- /dev/null +++ b/billing/test/factories.rb @@ -0,0 +1,11 @@ +FactoryGirl.define do + + factory :customer do + user + + factory :braintree_customer do + braintree_customer_id { 1 } + end + end + +end diff --git a/billing/test/unit/customer_test.rb b/billing/test/unit/customer_test.rb index 4ed6392..abcf96a 100644 --- a/billing/test/unit/customer_test.rb +++ b/billing/test/unit/customer_test.rb @@ -1,38 +1,43 @@ require 'test_helper' class CustomerTest < ActiveSupport::TestCase - setup do - #cannot get this working with FakeBraintree becuase the methods in customer.rb try to find the customer in braintree itself. - - @user = FactoryGirl.build(:user) - @user.save - @customer = Customer.new(:user_id => @user.id) - result = Braintree::Customer.create() - @customer.braintree_customer_id = result.customer.id - @customer.save - @braintree_customer_data = Braintree::Customer.find(@customer.braintree_customer_id) + setup do + @customer = FactoryGirl.build(:customer) + end - result = Braintree::Customer.create(:credit_card => { :number => "5105105105105100", :expiration_date => "05/2012"}) + test "test set of attributes should be valid" do + @customer.valid? + assert_equal Hash.new, @customer.errors.messages end - teardown do - @user.destroy - @customer.destroy - Braintree::Customer.delete(@customer.braintree_customer_id) + test "customer belongs to user" do + assert_equal User, @customer.user.class end - test "default credit card" do - assert_nil @customer.default_credit_card(@braintree_customer_data) - Braintree::Customer.update(@customer.braintree_customer_id, :credit_card => { :number => "5105105105105100", :expiration_date => "05/2012" } ) - assert_not_nil @customer.default_credit_card - assert_equal @customer.default_credit_card.expiration_date, "05/2012" + 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 "single subscription" do + test "with no braintree data" do + skip "this is currently commented out in the model" + assert_equal @customer, @customer.with_braintree_data! + end + test "without default credit card" do + 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 -- cgit v1.2.3