1) Failure: test_login_failure_with_nonexistent_screen_name(UserControllerTest) [./ test/functional/user_controller_test.rb:140]: <"Invalid screen name/password combination"> expected but was <nil>. 2) Failure: test_login_failure_with_wrong_password(UserControllerTest) [./test/ functional/user_controller_test.rb:155]: <"Invalid screen name/password combination"> expected but was <nil>. ---------------UserControllerTest----------------------- # Test a login with invalid screen name. # Giving a Failure def test_login_failure_with_nonexistent_screen_name invalid_user = @valid_user invalid_user.screen_name = "no such user" try_to_login invalid_user assert_template "login" assert_equal "Invalid screen name/password combination", flash[ :notice] # Make sure screen_name will be redisplayed, but not the password. user = assigns(:user) assert_equal invalid_user.screen_name, user.screen_name assert_nil user.password end # Test a login with invalid password. # Giving a Failure def test_login_failure_with_wrong_password invalid_user = @valid_user # Construct an invalid password. invalid_user.password += "baz" try_to_login invalid_user assert_template "login" assert_equal "Invalid screen name/password combination", flash[ :notice] # Make sure screen_name will be redisplayed, but not the password. user = assigns(:user) assert_equal invalid_user.screen_name, user.screen_name assert_nil user.password end -----------------------UserController--------------------------- def login @title = "Log in to RailsSpace" if param_posted?(:user) @user = User.new(params[:user]) user User.find_by_screen_name_and_password(@user.screen_name, @user.password) if user user.login!(session) flash[:notice] = "User #{user.screen_name} logged in!" redirect_to_forwarding_url else # Don''t show the password again in the view. @user.clear_password! flash[:notice] = "Invalid screen name/password combination" end end end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Christopher Redinger
2007-Nov-24 20:12 UTC
Re: can someone please tell me why these test are failing?
On Nov 24, 10:39 am, specpro <specpr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> try_to_login invalid_userIs it possible your try_to_login method isn''t doing a post? Because the test and code you''ve provided look fine. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nicholas Henry
2007-Nov-24 22:50 UTC
Re: can someone please tell me why these test are failing?
There is a couple of things here that would help to know to solve your issue: invalid_user = @valid_user invalid_user.screen_name = "no such user" try_to_login invalid_user * try_to_login: is this a helper method that actually does a post? * if so, it looks like you are passing a model rather than a hash of parameters In other words, I would expect to be seeing something like this: post :login, ''user'' => {''screen_name'' => ''no such user'', ''password'' => ''testing''} maybe show us the try_to_login method may enable us to help you. On Nov 24, 3:12 pm, Christopher Redinger <redin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Nov 24, 10:39 am, specpro <specpr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > try_to_login invalid_user > > Is it possible your try_to_login method isn''t doing a post? Because > the test and code you''ve provided look fine.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for your help Christopher and Nicholas. Here is the try_to_login code in the user_controller_test.rb file: private # Authorize a user. def authorize(user) @request.session[:user_id] = user.id end # Try to log a user in using the login action. def try_to_login(user) post :login, :user => { :screen_name => user.screen_name, :password => user.password } end On Nov 25, 6:50 am, Nicholas Henry <nicholas.he...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> There is a couple of things here that would help to know to solve your > issue: > > invalid_user = @valid_user > invalid_user.screen_name = "no such user" > try_to_login invalid_user > > * try_to_login: is this a helper method that actually does a post? > * if so, it looks like you are passing a model rather than a hash of > parameters > > In other words, I would expect to be seeing something like this: > > post :login, ''user'' => {''screen_name'' => ''no such user'', ''password'' => > ''testing''} > > maybe show us the try_to_login method may enable us to help you. > > On Nov 24, 3:12 pm, Christopher Redinger <redin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Nov 24, 10:39 am, specpro <specpr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > try_to_login invalid_user > > > Is it possible your try_to_login method isn''t doing a post? Because > > the test and code you''ve provided look fine.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nicholas Henry
2007-Nov-25 16:21 UTC
Re: can someone please tell me why these test are failing?
I''m wondering if the block if param_posted?(:user) is getting executed at all. How about moving the following assertions before the flash message assertion. What do you get when you run the test? # Make sure screen_name will be redisplayed, but not the password. user = assigns(:user) assert_equal invalid_user.screen_name, user.screen_name assert_nil user.password On Nov 24, 10:00 pm, specpro <specpr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for your help Christopher and Nicholas. Here is the > try_to_login code in the user_controller_test.rb file: > > private > > # Authorize a user. > def authorize(user) > @request.session[:user_id] = user.id > end > > # Try to log a user in using the login action. > def try_to_login(user) > post :login, :user => { :screen_name => user.screen_name, > :password => user.password } > end > > On Nov 25, 6:50 am, Nicholas Henry <nicholas.he...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > There is a couple of things here that would help to know to solve your > > issue: > > > invalid_user = @valid_user > > invalid_user.screen_name = "no such user" > > try_to_login invalid_user > > > * try_to_login: is this a helper method that actually does a post? > > * if so, it looks like you are passing a model rather than a hash of > > parameters > > > In other words, I would expect to be seeing something like this: > > > post :login, ''user'' => {''screen_name'' => ''no such user'', ''password'' => > > ''testing''} > > > maybe show us the try_to_login method may enable us to help you. > > > On Nov 24, 3:12 pm, Christopher Redinger <redin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On Nov 24, 10:39 am, specpro <specpr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > try_to_login invalid_user > > > > Is it possible your try_to_login method isn''t doing a post? Because > > > the test and code you''ve provided look fine.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nicholas Henry
2007-Nov-25 16:23 UTC
Re: can someone please tell me why these test are failing?
Acuta On Nov 24, 10:00 pm, specpro <specpr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for your help Christopher and Nicholas. Here is the > try_to_login code in the user_controller_test.rb file: > > private > > # Authorize a user. > def authorize(user) > @request.session[:user_id] = user.id > end > > # Try to log a user in using the login action. > def try_to_login(user) > post :login, :user => { :screen_name => user.screen_name, > :password => user.password } > end > > On Nov 25, 6:50 am, Nicholas Henry <nicholas.he...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > There is a couple of things here that would help to know to solve your > > issue: > > > invalid_user = @valid_user > > invalid_user.screen_name = "no such user" > > try_to_login invalid_user > > > * try_to_login: is this a helper method that actually does a post? > > * if so, it looks like you are passing a model rather than a hash of > > parameters > > > In other words, I would expect to be seeing something like this: > > > post :login, ''user'' => {''screen_name'' => ''no such user'', ''password'' => > > ''testing''} > > > maybe show us the try_to_login method may enable us to help you. > > > On Nov 24, 3:12 pm, Christopher Redinger <redin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On Nov 24, 10:39 am, specpro <specpr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > try_to_login invalid_user > > > > Is it possible your try_to_login method isn''t doing a post? Because > > > the test and code you''ve provided look fine.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Nicholas, I''ve moved the block you suggested to before the flash assertion but still getting the same result: ruby test/functional/user_controller_test.rb -n /test_login_failure/ Loaded suite test/functional/user_controller_test Started FF Finished in 0.638922 seconds. 1) Failure: test_login_failure_with_nonexistent_screen_name(UserControllerTest) [test/functional/user_controller_test.rb:180]: <"Invalid screen name/password combination"> expected but was <nil>. 2) Failure: test_login_failure_with_wrong_password(UserControllerTest) [test/ functional/user_controller_test.rb:196]: <"Invalid screen name/password combination"> expected but was <nil>. 2 tests, 8 assertions, 2 failures, 0 errors On Nov 26, 12:23 am, Nicholas Henry <nicholas.he...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Acuta > > On Nov 24, 10:00 pm, specpro <specpr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Thanks for your help Christopher and Nicholas. Here is the > > try_to_login code in the user_controller_test.rb file: > > > private > > > # Authorize a user. > > def authorize(user) > > @request.session[:user_id] = user.id > > end > > > # Try to log a user in using the login action. > > def try_to_login(user) > > post :login, :user => { :screen_name => user.screen_name, > > :password => user.password } > > end > > > On Nov 25, 6:50 am, Nicholas Henry <nicholas.he...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > There is a couple of things here that would help to know to solve your > > > issue: > > > > invalid_user = @valid_user > > > invalid_user.screen_name = "no such user" > > > try_to_login invalid_user > > > > * try_to_login: is this a helper method that actually does a post? > > > * if so, it looks like you are passing a model rather than a hash of > > > parameters > > > > In other words, I would expect to be seeing something like this: > > > > post :login, ''user'' => {''screen_name'' => ''no such user'', ''password'' => > > > ''testing''} > > > > maybe show us the try_to_login method may enable us to help you. > > > > On Nov 24, 3:12 pm, Christopher Redinger <redin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Nov 24, 10:39 am, specpro <specpr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > try_to_login invalid_user > > > > > Is it possible your try_to_login method isn''t doing a post? Because > > > > the test and code you''ve provided look fine.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nicholas Henry
2007-Nov-26 15:41 UTC
Re: can someone please tell me why these test are failing?
Well, I''m stumped - I took your code and quickly setup a test app and your assertions passed. Are you having problems with other flash messages? How about changing the flash messages to see if that helps, perhaps you have a funny character in there. Sorry I couldn''t be of further help. On Nov 26, 9:46 am, specpro <specpr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Nicholas, > > I''ve moved the block you suggested to before the flash assertion but > still getting the same result: > > ruby test/functional/user_controller_test.rb -n /test_login_failure/ > Loaded suite test/functional/user_controller_test > Started > FF > Finished in 0.638922 seconds. > > 1) Failure: > test_login_failure_with_nonexistent_screen_name(UserControllerTest) > [test/functional/user_controller_test.rb:180]: > <"Invalid screen name/password combination"> expected but was > <nil>. > > 2) Failure: > test_login_failure_with_wrong_password(UserControllerTest) [test/ > functional/user_controller_test.rb:196]: > <"Invalid screen name/password combination"> expected but was > <nil>. > > 2 tests, 8 assertions, 2 failures, 0 errors > > On Nov 26, 12:23 am, Nicholas Henry <nicholas.he...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Acuta > > > On Nov 24, 10:00 pm, specpro <specpr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Thanks for your help Christopher and Nicholas. Here is the > > > try_to_login code in the user_controller_test.rb file: > > > > private > > > > # Authorize a user. > > > def authorize(user) > > > @request.session[:user_id] = user.id > > > end > > > > # Try to log a user in using the login action. > > > def try_to_login(user) > > > post :login, :user => { :screen_name => user.screen_name, > > > :password => user.password } > > > end > > > > On Nov 25, 6:50 am, Nicholas Henry <nicholas.he...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > There is a couple of things here that would help to know to solve your > > > > issue: > > > > > invalid_user = @valid_user > > > > invalid_user.screen_name = "no such user" > > > > try_to_login invalid_user > > > > > * try_to_login: is this a helper method that actually does a post? > > > > * if so, it looks like you are passing a model rather than a hash of > > > > parameters > > > > > In other words, I would expect to be seeing something like this: > > > > > post :login, ''user'' => {''screen_name'' => ''no such user'', ''password'' => > > > > ''testing''} > > > > > maybe show us the try_to_login method may enable us to help you. > > > > > On Nov 24, 3:12 pm, Christopher Redinger <redin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > On Nov 24, 10:39 am, specpro <specpr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > try_to_login invalid_user > > > > > > Is it possible your try_to_login method isn''t doing a post? Because > > > > > the test and code you''ve provided look fine.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---