spec/integration/smoke_test.rb in mousetrap-0.3.3 vs spec/integration/smoke_test.rb in mousetrap-0.4.0

- old
+ new

@@ -43,10 +43,45 @@ @api_customer.id.should == @customer.id end end end +shared_examples_for "an active Subscription record from CheddarGetter" do + describe "And I get the subscription" do + before :all do + @api_customer = Mousetrap::Customer[@customer.code] + @api_subscription = @api_customer.subscription + end + + it "Then ID is set" do + @api_subscription.id.should be + end + + it "Then canceled_at is not set" do + @api_subscription.canceled_at.should be_nil + end + + it "Then created_at is set" do + @api_subscription.created_at.should be + end + + it "Then I should see the credit card expiration" do + expiration_date_from_api = Date.parse(@api_subscription.credit_card_expiration_date) + expiration_date = Date.parse("#{@customer.subscription.credit_card_expiration_year}-#{@customer.subscription.credit_card_expiration_month}-31") + expiration_date_from_api.should == expiration_date + end + + it "Then I should see the credit card last four digits" do + @api_subscription.credit_card_last_four_digits.should == @customer.subscription.credit_card_number[-4..-1] + end + + it "Then I should see the credit card type" do + @api_subscription.credit_card_type.should == (@credit_card_type || 'visa') + end + end +end + describe "The Wrapper Gem" do describe Mousetrap::Customer do describe ".all" do describe "Given a few customers on CheddarGetter" do before :all do @@ -72,10 +107,11 @@ attributes = Factory.attributes_for :new_customer @customer = Mousetrap::Customer.create attributes end it_should_behave_like "a Customer record from CheddarGetter" + it_should_behave_like "an active Subscription record from CheddarGetter" end end describe ".destroy_all" do describe "Given a few customers on CheddarGetter" do @@ -99,12 +135,19 @@ describe "#cancel" do describe "Given a customer" do before :all do @customer = Factory :new_customer - @customer.save - @api_customer = Mousetrap::Customer[@customer.code] + @api_customer = nil + + if Mousetrap::Customer.all.size == 1 + @api_customer = Mousetrap::Customer.all.first + @customer = @api_customer + else + @customer.save + @api_customer = Mousetrap::Customer[@customer.code] + end end describe "When I cancel" do before :all do @api_customer.cancel @@ -113,13 +156,23 @@ describe "And I get the customer" do before :all do @api_customer = Mousetrap::Customer[@customer.code] end - it "Then I should see a cancelation date on subscription" do + it "Then I should see a cancellation date on subscription" do @api_customer.subscription.canceled_at.should be end + + describe "When I resubscribe them" do + before :all do + @customer = Factory :new_customer, :email => @api_customer.email, :code => @api_customer.email + @customer.save + end + + it_should_behave_like "a Customer record from CheddarGetter" + it_should_behave_like "an active Subscription record from CheddarGetter" + end end end end end @@ -130,19 +183,55 @@ @customer.save end it_should_behave_like "a Customer record from CheddarGetter" - describe "And I save it again, with different attributes" do + describe "When I save it again, with different attributes" do before :all do attributes = Factory.attributes_for :new_customer @customer.first_name = attributes[:first_name] @customer.last_name = attributes[:last_name] @customer.email = attributes[:email] @customer.save end it_should_behave_like "a Customer record from CheddarGetter" + end + + context "When I update subscription information" do + before :all do + @subscription = Mousetrap::Subscription.new(Factory.attributes_for(:alternate_subscription)) + @credit_card_type = 'mc' + @customer.subscription = @subscription + @customer.save + end + + it_should_behave_like "an active Subscription record from CheddarGetter" + end + end + end + + describe '#switch_to_plan' do + describe "Given an existing CheddarGetter customer" do + before :all do + @customer = Factory :new_customer + @customer.save + end + + describe 'When I switch plans' do + before :all do + @customer.switch_to_plan('TEST_2') + end + + describe "And I get the customer" do + before :all do + @api_customer = Mousetrap::Customer[@customer.code] + end + + it 'Then they should be on the new plan' do + @api_customer.subscription.plan.code.should == 'TEST_2' + end + end end end end end end