RailsTutorial Sign In flash not working
-
31-10-2019 - |
Question
I am trying to get the error flash to appear in the railstutorial.org sample app. So far this is what I have done. Can anyone help me find the error:
My RSPEC test fail:
1) SessionsController POST 'create' invalid signin should have a flash.now message
Failure/Error: flash.now[:error].should =~ /invalid/i
expected: /invalid/i
got: nil (using =~)
./spec/controllers/sessions_controller_spec.rb:27
Controller code:
def create
user = User.authenticate(params[:session][:email],
params[:session][:password])
if user.nil?
flash.now[:error] = "Invalid email/password combination."
@title = "Sign in"
render 'new'
else
# Sign the user in and redirect to the user's show page.
end
end
Test code:
describe "POST 'create'" do
describe "invalid signin" do
before(:each) do
@attr = { :email => "example@gmail.com", :password => "invalid"}
end
it "should re-render the new page" do
post :create, :session => @attr
response.should render_template('new')
end
it "should have a flash.now message" do
post :create, :session => @attr
flash.now[:error].should =~ /invalid/i
end
end
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow