If I have a Devise model User, of which only those users with role :admin are allowed to view a certain url, how can I write an RSpec integration test to check that the stat
I used a slightly different approach, using the Warden::Test::Helpers.
In my spec/support/macros.rb I added:
module RequestMacros
include Warden::Test::Helpers
# for use in request specs
def sign_in_as_a_user
@user ||= FactoryGirl.create :confirmed_user
login_as @user
end
end
And then included that in RSpec's config in spec_helper.rb:
RSpec.configure do |config|
config.include RequestMacros, :type => :request
end
And then in the request specs themselves:
describe "index" do
it "redirects to home page" do
sign_in_as_a_user
visit "/url"
page.should_not have_content 'content'
end
end
In contrast to the post_via_redirect user_session_path
method, this actually works and allows me to use current_user in before_filters, for example.