我想让错误闪现出现在railstutorial.org示例应用程序中。到目前为止,这是我所做的。谁能帮我找到的错误:RailsTutorial登录闪光灯无法正常工作
我RSPEC测试失败:
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
控制器代码:
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
测试代码:
describe "POST 'create'" do
describe "invalid signin" do
before(:each) do
@attr = { :email => "[email protected]", :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
是的,再次,“尝试发布此之前,我的帐户搞砸了”,现在我不能编辑我原来的帖子,包括更多的代码。 – jsttn 2011-05-10 00:22:10
我看到了问题。编辑正在等待批准。我已经在其他问题中批准了您的修改请求。您应该删除其中一个问题。另外,我要求版主解除这个问题并关闭另一个(但你应该自己删除它) – Zabba 2011-05-10 00:35:01
是的,非常感谢。我正在学习我的方式! – jsttn 2011-05-10 00:57:42