test/rails_root/test/unit/user_test.rb in muck-commerce-0.1.8 vs test/rails_root/test/unit/user_test.rb in muck-commerce-0.1.9

- old
+ new

@@ -1,23 +1,71 @@ require File.dirname(__FILE__) + '/../test_helper' class UserTest < ActiveSupport::TestCase - context 'A user instance with has_muck_profile' do + context 'A user instance that acts_as_muck_commerce_user' do setup do @user = Factory(:user) end subject { @user } - should_accept_nested_attributes_for :profile - should_have_one :profile + should_have_one :cart + should_have_many :billing_informations + should_have_many :order_transactions + should_have_many :orders + should_have_many :subscriptions - should "have a profile after creation" do - assert @user.profile + should "have a referral_code after creation" do + assert_not_nil @user.referral_code + assert_not_nil @user.referral_code.code + code = @user.referral_code.code + # Make sure that the referral code isn't getting reassigned + assert_equal code, @user.referral_code.code end - should "have a photo method delegated to the profile" do - assert @user.photo + context "subscription" do + setup do + @default = @user.subscriptions.create(Factory.attributes_for(:subscription, :default => true)) + @other = @user.subscriptions.create(Factory.attributes_for(:subscription, :default => false)) + end + should "give the default subscription" do + assert_equal @default, @user.subscription + end end + + context "billing information" do + context "get billing_information" do + setup do + @default = @user.billing_informations.create(Factory.attributes_for(:billing_information, :default => true)) + @other = @user.billing_informations.create(Factory.attributes_for(:billing_information, :default => false)) + end + should "give the default billing information" do + assert_equal @default, @user.billing_information + end + end + context "create_update_billing_information!" do + context "billing information exists" do + should "update existing billing information" do + @default = @user.billing_informations.create(Factory.attributes_for(:billing_information, :default => true)) + @user.create_update_billing_information!(Factory.attributes_for(:billing_information)) + assert_equal @default, @user.billing_information + assert_equal 1, @user.billing_informations.length + end + end + context "no billing information" do + should "create a new billing entry" do + billing_information = @user.create_update_billing_information!(Factory.attributes_for(:billing_information)) + assert_equal billing_information, @user.billing_information + end + end + + end + context "build_billing_information" do + should "build but not save billing information for the user" do + billing_information = @user.build_billing_information(Factory.attributes_for(:billing_information)) + assert_nil @user.billing_information + end + end + end end -end +end \ No newline at end of file