Ruby on Rails Tutorial Test Not Passing -
i'm working through railstutorial.org book, chapter 9. when running test suite, can't rid of following failure. code has been attempted first typing in , copying , pasting book.
...............f............................................ failures: 1) sessionscontroller delete 'destroy' should sign user out failure/error: controller.should_not be_signed_in expected signed_in? return false, got true # ./spec/controllers/sessions_controller_spec.rb:69:in `block (3 levels) in <top (required)>' finished in 8.28 seconds 60 examples, 1 failure
here's code test in sessions_controller_spec.rb:
describe "delete 'destroy'" "should sign user out" test_sign_in(factory(:user)) delete :destroy controller.should_not be_signed_in response.should redirect_to(root_path) end end
the (i think) relevant portions of sessions_controller.rb:
def destroy sign_out redirect_to root_path end
the sign_out method found in sessions_helper.rb
def current_user=(user) @current_user ||= user_from_remember_token end def current_user @current_user end def signed_in? !current_user.nil? end def sign_out cookies.delete(:remember_token) self.current_user = nil end
so, if understand correctly, test, after signing in factory user, calling sessionscontroller's destroy method, calls sign_out (from sessionshelper), explicitly setting self.current_user nil. test checks signed_in? line be_signed_in. since code sets self.current_user nil, current_user.nil? should return true, !current_user.nil? should return false, test wants (controller.should_not be_signed_in).
any appreciated. i'm learning ruby, rails , tdd @ same time, i'm not sure problem lies.
the problem how setting current user - ever setting login remember token, aren't ever allowing set nil. might want try following:
def current_user=(user) @current_user = user end def current_user @current_user ||= user_from_remember_token end
Comments
Post a Comment