2
votes

When a non-signed-in user tries to access edit or update actions of the users controller, the app should redirect (e.g. to signin page or root_path). App works fine but tests for this are failing with a following error:

Failure/Error: specify { response.should redirect_to(signin_path) }
Expected response to be a redirect to <http://www.example.com/signin> but was a redirect to <https://www.example.com/users/468>
# ./spec/requests/authentication_pages_spec.rb:69:in `block (6 levels) in <top (required)>'

What might be a problem here? How to debug it?

All code is here: https://github.com/tomek-rusilko/miniatury_katalog_2 And failing tests are here: https://github.com/tomek-rusilko/miniatury_katalog_2/blob/master/spec/requests/authentication_pages_spec.rb (lines: 63 and 105)

1

1 Answers

2
votes

Finally had time to re-visit this. I pulled your code from github and had the same problem. I pared the test down to this:

require 'spec_helper'

describe "A non-signed_in user directly issuing PUT to the update action" do
  before { put user_path(7) }
  specify { response.should redirect_to(signin_path) }          
end

As you noted, the binding.pry in the controller code did not stop the execution as I thought it would. After a lot of useless digging/googling around, finally noticed in the log/test.log:

Started PUT "/users/7" for 127.0.0.1 at 2012-05-23 16:17:31 -0400
Processing by UsersController#update as HTML
  Parameters: {"id"=>"7"}
Redirected to https://www.example.com/users/7
Filter chain halted as #<Proc:0x00000102201608@/Users/eric_mccullough/ruby/railstutorial/tomek-rusilko-miniatury_katalog_2-e73d795/vendor/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_controller/metal/force_ssl.rb:28> rendered or redirected
Completed 301 Moved Permanently in 1ms (ActiveRecord: 0.0ms)
   (0.1ms)  rollback transaction
   (0.1ms)  begin transaction

that it was attempting to use SSL. My version of the Rails Tutorial is only using SSL in production. I removed 'force_ssl' from the application_controller.rb and then all tests passed. I'm still new to Rails and didn't even realize there are logs but I know now!