1.11M Members

RSpec test PUT update action

 
0
 

Hey!

Here is my update action in users_controller.rb and I want to test it with RSpec but it doesnt seem to work for me. Can somebody notice a mistake?

  def update
    @user = User.find(params[:id])
    respond_to do |format|
      if @user.update_attributes(params[:user])
        format.html { redirect_to edit_user_path(@user), :notice => "Your settings were successfully updated."}
        format.json { head :no_content }
      else
        flash[:notice] = "Something went wrong."
        format.html { render action: "edit" }
        format.json { render json: @user.errors, status: :unprocessable_entity }
      end
    end
  end



it "changes user settings" do
    @user = create_and_login_user
    @attr = {:email=>"abc@ad.oo"}
    put :update, :id => @user.id, :user => @attr
    @user.reload
    @user.email.should eq("abc@ad.oo")
end

The error is:

Failure/Error: @user.email.should eq("abc@ad.oo")

expected: "abc@ad.ee"
    got: "user3@example.com"
LastMitch
Deleted Member
 
0
 

Here is my update action in users_controller.rb and I want to test it with RSpec but it doesnt seem to work for me. Can somebody notice a mistake?

Your id is not fetching the email.

@user = User.find(params[:id])
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: