public
Created

Items, Widget, and Gears controller spec examples

  • Download Gist
controller_specs.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
# Client required that *all* routes for controllers are covered and
# do not allow guest access.
#
# There are several other controllers that, for guest test coverage,
# are identical to the Items Controller spec below
# Note: there are several non-CRUD methods; destroy makes a record
# inactive; there is no record removal revealed via the API (client's request)
 
# spec/controllers/items_controller_spec.rb
require 'spec_helper'
 
describe ItemsController do
context 'guest' do
describe 'GET to index' do
before { get :index }
specify { response.should redirect_to(login_path) }
specify { flash.alert.should =~ /You must be logged in to access this page/ }
end
 
describe 'GET to show' do
before { get :show, :id => 1 }
specify { response.should redirect_to(login_path) }
specify { flash.alert.should =~ /You must be logged in to access this page/ }
end
 
describe 'GET to export' do
before { get :export }
specify { response.should redirect_to(login_path) }
specify { flash.alert.should =~ /You must be logged in to access this page/ }
end
 
describe 'GET to new' do
before { get :new }
specify { response.should redirect_to(login_path) }
specify { flash.alert.should =~ /You must be logged in to access this page/ }
end
 
describe 'POST to create' do
before { post :create }
specify { response.should redirect_to(login_path) }
specify { flash.alert.should =~ /You must be logged in to access this page/ }
end
 
describe 'GET to edit' do
before { get :edit, :id => 1 }
specify { response.should redirect_to(login_path) }
specify { flash.alert.should =~ /You must be logged in to access this page/ }
end
 
describe 'PUT to update' do
before { put :update, :id => 1 }
specify { response.should redirect_to(login_path) }
specify { flash.alert.should =~ /You must be logged in to access this page/ }
end
 
describe 'DELETE to destroy' do
before { delete :destroy, :id => 1 }
specify { response.should redirect_to(login_path) }
specify { flash.alert.should =~ /You must be logged in to access this page/ }
end
 
describe 'PUT to activate' do
before { put :activate, :id => 1 }
specify { response.should redirect_to(login_path) }
specify { flash.alert.should =~ /You must be logged in to access this page/ }
end
end
end
 
# spec/controllers/widgets_controller_spec.rb
require 'spec_helper'
 
describe WidgetsController do
context 'guest' do
# same code as ItemsControllerSpec above
end
end
 
# spec/controllers/gears_controller_spec.rb
require 'spec_helper'
 
describe GearsController do
context 'guest' do
# same code as ItemsControllerSpec above
end
end
 
# etc.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.