Hi,
I'm really struggling getting a controller test to pass while the form that uses the method operates correctly.
I would really welcome a second pair of eyes to help me find out what I'm missing.
The test
def test_set_password @request.session[:user] = users(:admin)
put :set_password, :id => users(:one).id, :user => {:password => "newpass", :password_confirmation => "newpass"}
assert User.authenticate(users(:one).username, "newpass") assert_redirected_to user_path(assigns(:user)) end
The controller method
# POST def set_password @user = User.find(params[:id])
respond_to do |format| if @user.update_attributes(params[:user]) flash[:notice] = 'Password updated.' format.html { redirect_to(@user) } format.xml { head :ok } else format.html { render :action => "edit_password" } format.xml { render :xml => @user.errors, :status => :unprocessable_entity } end end end
The view: edit_password.html.erb
<%= error_messages_for :user %>
<h3><%= @user.username%></h3>
<% form_for @user, :url => {:id => @user.id, :action => "set_password"} do |f| %> <p> <%= f.label :password %><br /> <%= f.password_field :password %> </p>
<p> <%= f.label :password_confirmation, "Confirm Password" %><br /> <%= f.password_field :password_confirmation %> </p>
<p> <%= submit_tag "Change" %> </p> <% end %>
<%= link_to 'Back', @user %>
The view works but the test fails.
Thanks in advance,
Adam