我正在阅读Ruby on Rails教程。在写完所有代码后的第9章,用于登录并记住我的代码。我的rspec测试仍然失败。这是完全错误的:
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
有没有人有同样的问题,因为我没有发现任何拼写错误。
这是我的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
在用户模型上修改了类型后,我在测试中得到了这个错误:
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
这是我的捆绑exec rake路线
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文件
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
由于