I'm reading Ruby on Rails tutorial. On chapter 9 after wrote all the code, for sign in and remember me code. My rspec test still fail. this are the exactly error:
Failures:
1) SessionsController POST 'create' with valid email and password should sign the user in
Failure/Error: post :create, :session => @attr
undefined local variable or method `summitted_password' for #<Class:0x007fc05395e280>
# ./app/models/user.rb:38:in `authenticate'
# ./app/controllers/sessions_controller.rb:7:in `create'
# ./spec/controllers/sessions_controller_spec.rb:47:in `block (4 levels) in <top (required)>'
2) SessionsController POST 'create' with valid email and password should redirect to the user show page
Failure/Error: post :create, :session => @attr
undefined local variable or method `summitted_password' for #<Class:0x007fc05395e280>
# ./app/models/user.rb:38:in `authenticate'
# ./app/controllers/sessions_controller.rb:7:in `create'
# ./spec/controllers/sessions_controller_spec.rb:53:in `block (4 levels) in <top (required)>'
Finished in 0.90025 seconds
7 examples, 2 failures
Does anybody have the same problem, because I didn't find any typo.
This is my session_controller
class SessionsController < ApplicationController
def new
@title = "Sign in"
end
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_in user
redirect_to user
end
end
def destroy
end
end
After fixed the type on the user model, I get this error on the test:
Failures:
1) SessionsController POST 'create' with valid email and password should sign the user in
Failure/Error: post :create, :session => @attr
undefined method `user_url' for #<SessionsController:0x007fc347354e38>
# ./app/controllers/sessions_controller.rb:15:in `create'
# ./spec/controllers/sessions_controller_spec.rb:47:in `block (4 levels) in <top (required)>'
2) SessionsController POST 'create' with valid email and password should redirect to the user show page
Failure/Error: post :create, :session => @attr
undefined method `user_url' for #<SessionsController:0x007fc34679aa20>
# ./app/controllers/sessions_controller.rb:15:in `create'
# ./spec/controllers/sessions_controller_spec.rb:53:in `block (4 levels) in <top (required)>'
Finished in 0.58335 seconds
This is my bundle exec rake routes
WARNING: 'require 'rake/rdoctask'' is deprecated. Please use 'require 'rdoc/task' (in RDoc 2.4.2+)' instead.
at /Users/jeanosorio/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rake-0.9.2.2/lib/rake/rdoctask.rb
WARNING: Global access to Rake DSL methods is deprecated. Please include
... Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method SampleApp::Application#task called at /Users/jeanosorio/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/railties-3.0.0/lib/rails/application.rb:214:in `initialize_tasks'
users POST /users(.:format) {:action=>"create", :controller=>"users"}
new_users GET /users/new(.:format) {:action=>"new", :controller=>"users"}
edit_users GET /users/edit(.:format) {:action=>"edit", :controller=>"users"}
users GET /users(.:format) {:action=>"show", :controller=>"users"}
users PUT /users(.:format) {:action=>"update", :controller=>"users"}
users DELETE /users(.:format) {:action=>"destroy", :controller=>"users"}
sessions POST /sessions(.:format) {:action=>"create", :controller=>"sessions"}
new_sessions GET /sessions/new(.:format) {:action=>"new", :controller=>"sessions"}
sessions DELETE /sessions(.:format) {:action=>"destroy", :controller=>"sessions"}
signup /signup(.:format) {:controller=>"users", :action=>"new"}
signin /signin(.:format) {:controller=>"sessions", :action=>"new"}
signout /signout(.:format) {:controller=>"sessions", :action=>"destroy"}
contact /contact(.:format) {:controller=>"pages", :action=>"contact"}
about /about(.:format) {:controller=>"pages", :action=>"about"}
help /help(.:format) {:controller=>"pages", :action=>"help"}
root /(.:format) {:controller=>"pages", :action=>"home"}
routes.rb file
SampleApp::Application.routes.draw do
resource :users
resource :sessions, :only => [:new, :create, :destroy]
match '/signup', :to => 'users#new'
match '/signin', :to => 'sessions#new'
match '/signout', :to => 'sessions#destroy'
match '/contact', :to => 'pages#contact'
match '/about', :to => 'pages#about'
match '/help', :to => 'pages#help'
root :to => 'pages#home'
end
Thanks
submitted_password
? I think you may have made a typo inuser.rb
– Bradley Priest