require 'spec_helper' describe "chargify_api_ares gem" do before(:each) do FakeChargify.activate! end describe "Chargify::Subscription.create" do it "returns the correct values" do subscription = Chargify::Subscription.create( :customer_reference => 'jblow', :product_handle => 'Starter', :credit_card_attributes => { :first_name => "Lester", :last_name => "Tester", :expiration_month => 1, :expiration_year => 2020, :full_number => "1" } ) subscription.customer_reference.should == 'jblow' subscription.product_handle.should == 'Starter' end end describe "Chargify::Subscription.find" do it "returns the correct values" do subscription = Chargify::Subscription.create( :customer_reference => 'jblow', :product_handle => 'Starter', :credit_card_attributes => { :first_name => "Lester", :last_name => "Tester", :expiration_month => 1, :expiration_year => 2020, :full_number => "1" } ) subscriptions = Chargify::Subscription.find(:all) subscriptions.count.should == 1 end end describe "Chargify::Subscription.show" do it "returns the correct values" do Chargify::Subscription.create( :id => 1, :customer_reference => 'jblow', :product_handle => 'Starter', :credit_card_attributes => { :first_name => "Lester", :last_name => "Tester", :expiration_month => 1, :expiration_year => 2020, :full_number => "1" } ) subscription = Chargify::Subscription.find 1 subscription.credit_card.expiration_month.should == '1' subscription.credit_card.expiration_year.should == '2020' subscription.credit_card.masked_card_number.should == 'XXXX-XXXX-XXXX-1' end end describe "Chargify::Subscription.update" do it "returns the correct values" do subscription = Chargify::Subscription.create( :id => 2, :product_handle => 'Starter', :credit_card_attributes => { :first_name => "Lester", :last_name => "Tester", :expiration_month => 1, :expiration_year => 2020, :full_number => "1" } ) subscription.balance_in_cents = 1000 subscription.save subscription = Chargify::Subscription.find 2 subscription.balance_in_cents.should == '1000' end end describe "Chargify::Subscription.cancel" do it "returns the correct values" do subscription = Chargify::Subscription.create( :id => 3, :product_handle => 'Starter', :credit_card_attributes => { :first_name => "Lester", :last_name => "Tester", :expiration_month => 1, :expiration_year => 2020, :full_number => "1" } ) subscription.cancel lambda { Chargify::Subscription.find(3) }.should raise_error end end end describe "FakeChargify::Subscription" do describe ".to_xml" do it "returns xml from object properties" do subscription = FakeChargify::Subscription.new subscription.id = 5 subscription.state = 'active' subscription.balance_in_cents = 39 subscription.customer = FakeChargify::Customer.new subscription.customer.id = 6 subscription.customer.first_name = 'Joe' subscription.customer.last_name = 'Blow' subscription.customer.email = 'joe@example.com' subscription.product = FakeChargify::Product.new subscription.product.accounting_code = '1234' subscription.product.handle = 'Starter' subscription.product.interval = 4 subscription.product.name = 'Subscription' subscription.product.price_in_cents = 897 subscription.product.family = FakeChargify::ProductFamily.new subscription.product.family.accounting_code = '1234' subscription.product.family.handle = 'Starter' subscription.product.family.name = 'Subscription' subscription.to_xml.gsub(/\s/,'').should == """ 5 active 39 6 Joe Blow joe@example.com 1234 Starter 4 Subscription 897 1234 Starter Subscription """.gsub(/\s/,'') end end describe ".from_xml" do it "parses valid xml and sets properties" do subscription = FakeChargify::Subscription.from_xml """ Starter Joe Blow joe@example.com 1 10 2020 """ subscription.product.handle.should == 'Starter' subscription.customer.first_name.should == 'Joe' subscription.customer.last_name.should == 'Blow' subscription.customer.email.should == 'joe@example.com' subscription.credit_card.masked_card_number.should == 'XXXX-XXXX-XXXX-1' subscription.credit_card.expiration_month.should == 10 subscription.credit_card.expiration_year.should == 2020 end end end