Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Building Social Features in Ruby on Rails Creating Friendships What is a Join Table?

Sean Perryman
Sean Perryman
13,810 Points

Unable to get the update function to pass test

Using the test parameters the Jason Seifer provided in the "What is a Join Table" video, I cannot get the test to pass. Here is the code I am using:

def update
    @status = current_user.statuses.find(params[:id])

    if params[:status] && params[:status].has_key?(:user_id)
    #if status_params && status_params.has_key?(:user_id)
      params[:status].delete(:user_id)
    end

    respond_to do |format|
      if @status.update(status_params)
        format.html { redirect_to @status, notice: 'Status was successfully updated.' }
        format.json { render :show, status: :ok, location: @status } #Original
      else
        format.html { render :edit }
        format.json { render json: @status.errors, status: :unprocessable_entity }
      end
    end
  end

and the error I am getting:

  1) Error:
StatusesControllerTest#test_should_not_update_status_if_nothing_has_changed:
ActionController::ParameterMissing: param is missing or the value is empty: status
    app/controllers/statuses_controller.rb:81:in `status_params'
    app/controllers/statuses_controller.rb:52:in `block in update'
    app/controllers/statuses_controller.rb:51:in `update'
    test/controllers/statuses_controller_test.rb:83:in `block in <class:StatusesControllerTest>'

14 runs, 32 assertions, 0 failures, 1 errors, 0 skips

Any thoughts would be great appreciated!

1 Answer

Sean Perryman
Sean Perryman
13,810 Points

A gracious user on Stack Overflow posted this solution:

The problem is in your test case patch :update, id: @status.

Try this:

patch :update, {id: @status.id, status: {user_id: @status.user_id, content: 'MyText'}}

The problem was I was not passing the status through to the controller. This solution passes the same content as was already there; effectively replicating a condition where no change was made. Success!