O
OnRails Ruby
Hi everyon,
Thank you for your help!
I did the controller test, but there is a problem when run the test.
Controller.rb:
def change_password
user = current_user
if User.authenticate(user.login, params[ld_password])
if (params[assword] == params[assword_confirmation])
user.password_confirmation = params[assword_confirmation]
user.password = params[assword]
if user.save
result = _("Password changed!")
reset_current_user(user.id)
else
("Could not save change, please try again.")
end
else
result = _("Your passwords do not match.")
@old_password = params[ld_password]
end
else
result = _("Your old password is incorrect.")
end
end
the controller_test.rb:
def test_should_allow_password_change
post :change_password, { ld_password => '123', assword =>
'newpassword', assword_confirmation => 'newpassword'},
{:user_id=>usersuser1).id}
assert_equal 'newpassword', assignsuser).password
end
when I run this test, There always said,
NoMetodError: You have a ni object when you didn't expect it:
the error occurred while evaluating nil.password.
I have try to use:
assert_equal 'newpassword', assigns('user').password
assert_equal 'newpassword', assigns[:user].password
assert_equal 'newpassword', assigns['user'].password
but there is same problem. I don't know why?
Please help1
Thanks!
Thank you for your help!
I did the controller test, but there is a problem when run the test.
Controller.rb:
def change_password
user = current_user
if User.authenticate(user.login, params[ld_password])
if (params[assword] == params[assword_confirmation])
user.password_confirmation = params[assword_confirmation]
user.password = params[assword]
if user.save
result = _("Password changed!")
reset_current_user(user.id)
else
("Could not save change, please try again.")
end
else
result = _("Your passwords do not match.")
@old_password = params[ld_password]
end
else
result = _("Your old password is incorrect.")
end
end
the controller_test.rb:
def test_should_allow_password_change
post :change_password, { ld_password => '123', assword =>
'newpassword', assword_confirmation => 'newpassword'},
{:user_id=>usersuser1).id}
assert_equal 'newpassword', assignsuser).password
end
when I run this test, There always said,
NoMetodError: You have a ni object when you didn't expect it:
the error occurred while evaluating nil.password.
I have try to use:
assert_equal 'newpassword', assigns('user').password
assert_equal 'newpassword', assigns[:user].password
assert_equal 'newpassword', assigns['user'].password
but there is same problem. I don't know why?
Please help1
Thanks!