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"
Member Avatar for LastMitch

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])
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.