James Hunt
9/9/2007 7:25:00 AM
On 9/8/07, OnRails Ruby <zlai@sina.com> claimed:
> Hi everyon,
> Thank you for your help!
> I did the controller test, but there is a problem when run the test.
>
> def test_should_allow_password_change
> post :change_password, { :old_password => '123', :password =>
> 'newpassword', :password_confirmation => 'newpassword'},
> {:user_id=>users(:user1).id}
> assert_equal 'newpassword', assigns(:user).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
>
Are you using fixtures for your tests? (I assume you are, from the
assigns() usage).
Can you post the fixtures?
> Thanks!
You're welcome
--
James