# == Schema Information # # Table name: billing_informations # # id :integer(4) not null, primary key # billable_id :integer(4) # billable_type :string(255) # first_name :string(128) default(""), not null # last_name :string(128) default(""), not null # address1 :string(512) default(""), not null # address2 :string(512) # city :string(128) default(""), not null # state_id :integer(4) # country_id :integer(4) # postal_code :string(255) default(""), not null # telephone :string(255) default(""), not null # payment_method :string(255) default("CC") # credit_card_type :string(255) # credit_card_last_digits :string(4) # credit_card_expiration :datetime # achname :string(1024) # achrouting :string(1024) # achnumber :string(1024) # achholder :string(1024) # achtype :string(64) # vault_id :string(512) # customer_profile_id :string(512) # customer_payment_profile_id :string(512) # default :boolean(1) # created_at :datetime # updated_at :datetime # name :string(256) # company :string(256) # require File.dirname(__FILE__) + '/../test_helper' class BillingInformationTest < ActiveSupport::TestCase context 'A billing_information instance that acts_as_muck_billing_information' do setup do @billing_information = Factory(:billing_information) end subject { @billing_information } should_belong_to :billable should_belong_to :state should_belong_to :country should_validate_presence_of :credit_card_number should_validate_presence_of :credit_card_expiration should_validate_presence_of :achname should_validate_presence_of :achrouting should_validate_presence_of :achnumber should_validate_presence_of :verification_value should "have verification value" do assert_not_nil @billing_information.verification_value end context "named scope" do should_scope_by_newest context "scope by default" do @default = Factory(:billing_information, :default => true) @non_default = Factory(:billing_information, :default => false) end should "find default" do assert BillingInformation.default.include?(@default) end should "not find nondefault" do assert BillingInformation.default.include?(@non_default) end context "expiring credit cards" do setup do @expired_billing_information = Factory(:billing_information, :credit_card_expiration => Time.now - 1.month) @soon_to_expire_billing_information = Factory(:billing_information, :credit_card_expiration => Time.now + 1.month) @non_expired_billing_information = Factory(:billing_information, :credit_card_expiration => Time.now + 1.year) end context "expired_cc" do should "find expired billing information" do assert BillingInformation.expired_cc.include?(@expired_billing_information) end should "not find billing information that is close to expiring" do assert !BillingInformation.expired_cc.include?(@soon_to_expire_billing_information) end should "not find billing information that are not close to expiring" do assert !BillingInformation.expired_cc.include?(@non_expired_billing_information) end end context "will_expired_cc" do should "find billing information that are about to expire" do assert BillingInformation.will_expired_cc.include?(@soon_to_expire_billing_information) end should "not find billing information that have expired" do assert !BillingInformation.will_expired_cc.include?(@expired_billing_information) end should "not find billing information that are not close to expiring" do assert !BillingInformation.will_expired_cc.include?(@non_expired_billing_information) end end context "expired_and_will_expired_cc" do should "find billing information that are about to expire" do assert BillingInformation.expired_and_will_expired_cc.include?(@soon_to_expire_billing_information) end should "find billing information that have expired" do assert BillingInformation.expired_and_will_expired_cc.include?(@expired_billing_information) end should "not find billing information that are not close to expiring" do assert !BillingInformation.expired_and_will_expired_cc.include?(@non_expired_billing_information) end end end end context "credit_card_number" do assert @billing_information.credit_card_number.include?('XXXX-XXXX-XXXX-') end end end