I'm new to RSpec, and trying to write a simple test that shows Devise is working. I've picked a random page and want to write a test that shows that a non logged-in user is re-redirected to /users/sign_in.
describe OrgsController do
describe "GET index when not logged in" do
it "redirects to new_user_session_path" do
user = FactoryGirl.create(:user)
user.confirm!
sign_in user
sign_out user
get :index
response.should redirect_to new_user_session_path
end
end
before(:each) do
user = FactoryGirl.create(:user)
user.confirm!
sign_in user
end
# remaining specs
end
I get "Expected response to be a redirect to <http://test.host/users/sign_in?locale=en> but was a redirect to <http://test.host/users/sign_in>."
I have implemented i18n, and have in my Application Controller:
before_filter :set_i18n_locale_from_params
What is the best way to get this working in terms of:
- Getting the routes to match?
- The hackishness of signing a user in and out again to get round the effects of the before(:each) block?
- The overall approach?