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

Scoping in Ruby (building profile page)

I've tried running the test a few times after I finished adding the test "only shows the correct user statuses"

1) Failure:

test_only_show_the_correct_user_statuses(ProfilesControllerTest)          [test/functional/profiles_controller_test.rb:24]:
<#<User id: 120214414, first_name: "Dennis", last_name: "Hegstad", profile_name: "dennish", email: "dennis@songsly.com", encrypted_password: "", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2013-09-06 02:21:33", updated_at: "2013-09-06 02:21:33">> expected but was
<nil>.

4 tests, 7 assertions, 1 failures, 0 errors, 0 skips

My code:

require 'test_helper'

class ProfilesControllerTest < ActionController::TestCase
  test "should get show" do
    get :show, id: users(:dennish).profile_name
    assert_response :success
    assert_template 'profiles/show'
  end

  test "should render a 404 on profile not found" do
    get :show, id: "doesn't exist"
    assert_response :not_found
  end

  test "that variables are assigned on successful profile viewing" do
    get :show, id: users(:dennish).profile_name 
    assert assigns(:user)
    assert_not_empty assigns(:statuses)
  end

  test "only show the correct user statuses" do
    get :show, id: users(:dennish).profile_name
    assigns(:statuses).each do |status|
        assert_equal users(:dennish), status.user
    end
  end
end

1 Answer

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey Dennis Hegstad that's a weird error. Can you drop a line to help@teamtreehouse.com with a link to your code on GitHub or a zip archive of your treebook directory?

Jason Seifer
Jason Seifer
Treehouse Guest Teacher

Is this the latest version of your code? There's no profile controller or test in that repository.

There's a profiles_controller. Do i need to generate a new scaffold for 'profile'? Or just rename the profiles_controller to profile_controller ?