require 'spec_helper' describe PlansController, "successful upgrade", :as => :account_admin do let!(:original_plan) { account.plan } let!(:upgraded_plan) { Factory(:paid_plan) } before do Account.stubs(:find_by_keyword! => account) new_account_attributes = Factory.attributes_for(:paid_account).merge({ :plan_id => upgraded_plan.id }) put :update, :account_id => account.to_param, :account => new_account_attributes end it "notifies observers" do should notify_observers("plan_upgraded", :account => account, :request => request, :from_plan => original_plan, :to_plan => upgraded_plan) end end describe PlansController, "successful downgrade", :as => :account_admin do let!(:account) { Factory(:paid_account) } let!(:original_plan) { account.plan } let!(:downgraded_plan) { Factory(:plan) } before do Account.stubs(:find_by_keyword! => account) new_account_attributes = Factory.attributes_for(:paid_account).merge({ :plan_id => downgraded_plan.id }) put :update, :account_id => account.to_param, :account => new_account_attributes end it "notifies observers" do should notify_observers("plan_downgraded", :account => account, :request => request, :from_plan => original_plan, :to_plan => downgraded_plan) end end describe PlansController, "unsuccessful update", :as => :account_admin do let!(:original_plan) { account.plan } let!(:upgraded_plan) { Factory(:paid_plan) } before do Account.stubs(:find_by_keyword! => account) account.stubs(:save_customer_and_subscription! => false) new_account_attributes = Factory.attributes_for(:paid_account).merge({ :plan_id => upgraded_plan.id }) put :update, :account_id => account.to_param, :account => new_account_attributes end it "does not notify observers" do should_not notify_observers("plan_upgraded", :account => account, :request => request, :from_plan => original_plan, :to_plan => upgraded_plan) end end describe PlansController, "successful update that does not change the plan", :as => :account_admin do let!(:original_plan) { account.plan } before do Account.stubs(:find_by_keyword! => account) new_account_attributes = Factory.attributes_for(:paid_account).merge({ :plan_id => original_plan.id }) put :update, :account_id => account.to_param, :account => new_account_attributes end it "does not notify observers about upgrade or downgrade" do should_not notify_observers("plan_upgraded", :account => account, :request => request, :from_plan => original_plan, :to_plan => original_plan) should_not notify_observers("plan_downgraded", :account => account, :request => request, :from_plan => original_plan, :to_plan => original_plan) end end