Skip to content

Instantly share code, notes, and snippets.

@lporras
Forked from enthal/people_controller.rb
Created December 12, 2011 18:01
Show Gist options
  • Save lporras/1468361 to your computer and use it in GitHub Desktop.
Save lporras/1468361 to your computer and use it in GitHub Desktop.
simple rails rsepc testing that devise before_filter :authenticate_user! covers controller actions
class PeopleController < ApplicationController
before_filter :authenticate_user!, :except => [:index, :show]
...
end
describe PeopleController do
include Devise::TestHelpers
...
describe "disallow member-only actions when not logged in (guest/unprivileged)" do
let(:person) { Factory.create(:person) }
after { response.should redirect_to new_user_session_path }
it { get :new }
it { get :edit, :id => person }
it { post :create, :person => FactoryGirl.attributes_for(:person) }
it { put :update, :id => person, :person => {'these' => 'params'} }
it { delete :destroy, :id => person }
it { post :create_thing, :id => person, :what => 'stuff' }
end
end
@panupan
Copy link

panupan commented Nov 15, 2012

Thanks for the example, I saw we can use the its shortcut to make the Test Runner output a bit more meaningful.

For example:

its("#new") { get :new }

will output

#new
      should redirect to "/sign_in"

@szalansky
Copy link

Thank you very much for this gist. Helped me a lot and saved my time :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment