Skip to content

Commit

Permalink
Remove ControllerHacks from auth, replace with Spree::Core::TestingSu…
Browse files Browse the repository at this point in the history
…pport::ControllerRequests
  • Loading branch information
radar committed Apr 11, 2012
1 parent 5103b91 commit d5db5fd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 48 deletions.
30 changes: 15 additions & 15 deletions auth/spec/controllers/checkout_controller_spec.rb
Expand Up @@ -25,7 +25,7 @@
before { controller.stub :current_user => user }

it 'should proceed to the first checkout step' do
get :edit, { :state => 'confirm' }
spree_get :edit, { :state => 'confirm' }
response.should render_template :edit
end
end
Expand All @@ -34,7 +34,7 @@
before { controller.stub :auth_user => user }

it 'should redirect to registration step' do
get :edit, { :state => 'confirm' }
spree_get :edit, { :state => 'confirm' }
response.should redirect_to spree.checkout_registration_path
end
end
Expand All @@ -50,7 +50,7 @@
before { controller.stub :current_user => user }

it 'should proceed to the first checkout step' do
get :edit, { :state => 'confirm' }
spree_get :edit, { :state => 'confirm' }
response.should render_template :edit
end
end
Expand All @@ -59,7 +59,7 @@
before { controller.stub :auth_user => user }

it 'should proceed to the first checkout step' do
get :edit, { :state => 'confirm' }
spree_get :edit, { :state => 'confirm' }
response.should render_template :edit
end
end
Expand All @@ -68,14 +68,14 @@

it 'should check if the user is authorized for :edit' do
controller.should_receive(:authorize!).with(:edit, order, token)
get :edit, { :state => 'confirm' }, { :access_token => token }
spree_get :edit, { :state => 'confirm' }, { :access_token => token }
end
end

context '#update' do
it 'should check if the user is authorized for :edit' do
controller.should_receive(:authorize!).with(:edit, order, token)
post :update, { :state => 'confirm' }, { :access_token => token }
spree_post :update, { :state => 'confirm' }, { :access_token => token }
end

context 'when save successful' do
Expand All @@ -100,12 +100,12 @@
end

it 'should redirect to the tokenized order view' do
post :update, { :state => 'confirm' }
spree_post :update, { :state => 'confirm' }
response.should redirect_to spree.token_order_path('R123', 'ABC')
end

it 'should populate the flash message' do
post :update, { :state => 'confirm' }
spree_post :update, { :state => 'confirm' }
flash.notice.should == I18n.t(:order_processed_successfully)
end
end
Expand All @@ -117,7 +117,7 @@
end

it 'should redirect to the standard order view' do
post :update, { :state => 'confirm' }
spree_post :update, { :state => 'confirm' }
response.should redirect_to spree.order_path('R123')
end
end
Expand All @@ -129,12 +129,12 @@
it 'should not check registration' do
controller.stub :check_authorization
controller.should_not_receive :check_registration
get :registration
spree_get :registration
end

it 'should check if the user is authorized for :edit' do
controller.should_receive(:authorize!).with(:edit, order, token)
get :registration, {}, { :access_token => token }
spree_get :registration, {}, { :access_token => token }
end
end

Expand All @@ -145,27 +145,27 @@
controller.stub :check_authorization
order.stub :update_attributes => true
controller.should_not_receive :check_registration
put :update_registration
spree_put :update_registration
end

it 'should render the registration view if unable to save' do
controller.stub :check_authorization
order.should_receive(:update_attributes).with('email' => 'invalid').and_return false
put :update_registration, { :order => { :email => 'invalid' } }
spree_put :update_registration, { :order => { :email => 'invalid' } }
response.should render_template :registration
end

it 'should redirect to the checkout_path after saving' do
order.stub :update_attributes => true
controller.stub :check_authorization
put :update_registration, { :order => { :email => 'jobs@spreecommerce.com' } }
spree_put :update_registration, { :order => { :email => 'jobs@spreecommerce.com' } }
response.should redirect_to spree.checkout_path
end

it 'should check if the user is authorized for :edit' do
order.stub :update_attributes => true
controller.should_receive(:authorize!).with(:edit, order, token)
put :update_registration, { :order => { :email => 'jobs@spreecommerce.com' } }, { :access_token => token }
spree_put :update_registration, { :order => { :email => 'jobs@spreecommerce.com' } }, { :access_token => token }
end
end
end
2 changes: 2 additions & 0 deletions auth/spec/spec_helper.rb
Expand Up @@ -13,6 +13,7 @@
require 'spree/core/testing_support/fixtures'
require 'spree/core/testing_support/factories'
require 'spree/core/testing_support/env'
require 'spree/core/testing_support/controller_requests'

RSpec.configure do |config|
# == Mock Framework
Expand Down Expand Up @@ -48,6 +49,7 @@
end

config.include Spree::Core::UrlHelpers
config.include Spree::Core::TestingSupport::ControllerRequests, :type => :controller
config.include Devise::TestHelpers, :type => :controller
config.include Rack::Test::Methods, :type => :requests
end
Expand Down
33 changes: 0 additions & 33 deletions auth/spec/support/controller_hacks.rb

This file was deleted.

0 comments on commit d5db5fd

Please sign in to comment.