In Michael Hartl's (wonderful) Rails Tutorial, I get an unexpected failure of an Rspec form test:
"The expected answer is to redirect to < http://test.host/signin >, but redirect < http://test.host/signin?notice=Please+sign+in+to+access+this+page. >.
(Find this in Section 10.3.) So, because of the error itself, you can indicate that the server is being redirected to the corresponding page, except that there is an additional notification for "Please Login." The test code is as follows:
describe "GET 'index'" do describe "for non-signed-in users" do it "should deny access" do get :index response.should redirect_to(signin_path) flash[:notice].should =~ /sign in/i end end ...
Am I doing something wrong here? What is the best way to fix this?
Update:
If I changed the code to
response.should redirect_to('http://test.host/signin?notice=Please+sign+in+to+access+this+page.')
then I get the actual ruby ββerror
Error / Error: Flash [: notice] .should = ~ / sign in / i Expected: / sign / i, got: nil (using = ~)
Resolution
The problem was a missing comma in my deny_access function:
redirect_to signin_path :notice => "Please sign in to access this page."
should be
redirect_to signin_path, :notice => "Please sign in to access this page."
This is fixed. Now the side effect of this fix was interesting, right? Does this mean that signin_path is the function itself that can take a hash or arguments that will be added to the end of the path? Strange, wild and wonderful.
source share