RailsTutorial Login Error

I am trying to get flash errors to appear in the railstutorial.org sample application. So far this is what I have done. Can someone help me find the error:

The error of my RSPEC test is:

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 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 
+4
source share
1 answer

It looks like in your app/controllers/sessions_controller.rb you have the second creation method, declared below, which simply says:

 def create render 'new' end 

This second declaration replaces your intended creation method earlier in the file. Just delete these three lines (20-22 in your file) and your specifications will go with flying colors, so I mean only one color, namely green.

+2
source

All Articles