Skip to content

Commit

Permalink
store controller specs pass
Browse files Browse the repository at this point in the history
  • Loading branch information
armandofox committed Jun 29, 2017
1 parent 3482c46 commit 73e5735
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 36 deletions.
4 changes: 2 additions & 2 deletions app/controllers/store_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def set_customer
elsif logged_in.is_staff then desired || logged_in
else logged_in
end
p = params.to_h
p = params.to_hash
redirect_to p.merge(:customer_id => desired, :only_path => true)
end
end
Expand Down Expand Up @@ -249,7 +249,7 @@ def finalize_order(order)
end

def showdate_from_params
Showdate.find_by_id(params[:showdate_id]).includes(:show, :valid_vouchers)
Showdate.includes(:show, :valid_vouchers).find_by_id(params[:showdate_id])
end
def showdate_from_show_params
(s = Show.find_by_id(params[:show_id])) &&
Expand Down
24 changes: 12 additions & 12 deletions spec/controllers/store_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@
before :each do ; login_as(nil) ; end
it 'redirects as generic customer' do
get :index
response.should redirect_to_path(store_path(@anon))
response.should redirect_to(store_path(@anon))
end
it 'preserves params' do
get :index, @extra
response.should redirect_to_path(store_path(@anon, @extra))
response.should redirect_to(store_path(@anon, @extra))
end

it 'prevents switching to a different user' do
get :index, {:customer_id => @c.id}
response.should redirect_to_path(store_path(@anon))
response.should redirect_to(store_path(@anon))
end
end
context 'when logged in as regular user' do
before :each do ; login_as(@c) ; end
it 'redirects to your login keeping params' do
get :index, @extra
response.should redirect_to_path(store_path(@c, @extra))
response.should redirect_to(store_path(@c, @extra))
end
it 'prevents you from switching to different user' do
other = create(:customer)
get :index, @extra.merge(:customer_id => other)
response.should redirect_to_path(store_path(@c, @extra))
response.should redirect_to(store_path(@c, @extra))
end
it 'lets you view store as yourself' do
get :index, @extra.merge(:customer_id => @c)
Expand All @@ -48,7 +48,7 @@
before :each do ; login_as(@b = customers(:boxoffice_user)) ; end
it 'redirects to you if no customer specified' do
get :index, @extra
response.should redirect_to_path(store_path(@b,@extra))
response.should redirect_to(store_path(@b,@extra))
end
it 'redirects to another customer' do
get :index, @extra.merge(:customer_id => @c)
Expand All @@ -74,14 +74,14 @@

describe "on InvalidAuthenticityToken exception" do
before(:each) do
@controller.allow_forgery_protection = true
controller.allow_forgery_protection = true
end
it 'should check the authenticity token' do
@controller.should_receive(:verify_authenticity_token)
expect(controller).to receive(:verify_authenticity_token)
post :place_order, {:customer_id => @buyer.id, :authenticity_token => 'wrong'}
end
it "should show the Session Expired page rather than throwing error" do
@controller.should_receive(:verify_authenticity_token).and_raise ActionController::InvalidAuthenticityToken
expect(controller).to receive(:verify_authenticity_token).and_raise ActionController::InvalidAuthenticityToken
post :place_order, {:customer_id => @buyer.id, :authenticity_token => 'wrong'}
response.should render_template 'messages/session_expired'
end
Expand Down Expand Up @@ -119,7 +119,7 @@
context 'when credit card token invalid' do
before :each do
@alert = /Invalid credit card transaction/
Stripe::allow(Charge).to receive(:create).and_raise(Stripe::StripeError)
allow(Stripe::Charge).to receive(:create).and_raise(Stripe::StripeError)
post :donate, {:customer => @new_valid_customer, :donation => 5}
end
it_should_behave_like 'failure'
Expand Down Expand Up @@ -166,8 +166,8 @@
end
it "should add the donation to the cart" do
allow(controller).to receive(:find_cart).and_return(@cart = Order.new)
Donation.should_receive(:from_amount_and_account_code_id).with(13, nil, nil).and_return(d = Donation.new)
@cart.should_receive(:add_donation).with(d)
expect(Donation).to receive(:from_amount_and_account_code_id).with(13, nil, nil).and_return(d = Donation.new)
expect(@cart).to receive(:add_donation).with(d)
post :process_cart, @params
end
end
Expand Down
22 changes: 0 additions & 22 deletions spec/support/redirect_to_path.rb

This file was deleted.

0 comments on commit 73e5735

Please sign in to comment.