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


Steve Monsen
Steve Monsen
5,207 Points

statuses_controller_test.rb will not sign_in

I've tried messing around with it and reading the Rails and Devise documentation to no avail. Here is the response of the test:

ruby -Itest test/functional/statuses_controller_test.rb Run options:

# Running tests:

[3/9] StatusesControllerTest#test_should_create_status_when_logged_in = 0.07 s            
  1) Failure:
"Status.count" didn't change by 1.
<3> expected but was

Finished tests in 0.216054s, 41.6563 tests/s, 60.1701 assertions/s.                         
9 tests, 13 assertions, 1 failures, 0 errors, 0 skips

ruby -v: ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0]

File: app/test/functional/statuses_controller_test.rb

test "should create status when logged in" do
  sign_in users(:steve)

  assert_difference('Status.count') do          ***[ Error on line 35 ]***
    post :create, status: { content: 'This is a test status.'}

  assert_redirected_to status_path(assigns(:status))

File: app/test/fixtures/users.yml

    first_name: Steve
    last_name: Monsen
    email: stevem@treehouse.com
    profile_name: stevem

File: app/controllers/statuses_controller.rb

# POST /statuses
# POST /statuses.json
def create
  @status = Status.new(params[:status])

  respond_to do |format|
    if @status.save
      format.html { redirect_to @status, notice: 'Status was successfully created.' }
      format.json { render json: @status, status: :created, location: @status }
      format.html { render action: "new" }
      format.json { render json: @status.errors, status: :unprocessable_entity }

2 Answers

Jason Seifer
Jason Seifer
Treehouse Guest Teacher

Try making it:

@status = current_user.statuses.new(params[:status])

That may be causing the problem.

Steve Monsen
Steve Monsen
5,207 Points

That worked! Thanks. It also solved a problem I ran into after the project was over. When logged in, I could still post statuses as other users by selecting them in the statuses#new view. That's fixed now because the statuses are correctly assigned to the currently signed in user.

Maybe I missed something or skipped that part in the project?

Jason Seifer
Jason Seifer
Treehouse Guest Teacher

We delete all the statuses in one of the videos. We also fix this way later on in the project.

Jason, how do you delete all the statuses using the console? I've tried searching the Googles and going through previous videos, I know it's there, but I can't seem to find it.

Jason Seifer
Jason Seifer
Treehouse Guest Teacher

Michael Ballentine Launch the console by running:

bundle exec rails console

Then type:


That should do it!