Skip to content

Instantly share code, notes, and snippets.

@enthal
Created October 24, 2011 21:00
Show Gist options
  • 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
@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