Skip to content

Instantly share code, notes, and snippets.

@enthal
Created October 24, 2011 21:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save enthal/1310280 to your computer and use it in GitHub Desktop.
Save enthal/1310280 to your computer and use it in GitHub Desktop.
simple rails rspec 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
@lporras
Copy link

lporras commented Dec 12, 2011

Hey man I tried to do this with Devise 1.5.2 and I got this: ArgumentError:uncaught throw :warden

@alexandru-calinoiu
Copy link

Iporras You need something like:

before :each do
@request.env["devise.mapping"] = Devise.mappings[:user]
end

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