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

Creating Friendships - What is a Joint Table - undefined method 'gravatar_url' for nil:NilClass

I'm running

test "should create status for current user when logged in"

I can get the main test to fail and then add the code to make it pass, but I still get one more error which seems to have little to do with my test...not sure.

Here it is:

test_should_get_index(StatusesControllerTest): ActionView::Template::Error: undefined method `gravatar_url' for nil:NilClass

I have run various rake db commands after reading similar posts on the forum but none have worked.

Any ideas out there?

Thanks!

4 Answers

I figured out the answer from this thread: https://teamtreehouse.com/forum/getting-an-error-on-the-gravatarurl-method-when-testing-statuscontroller.

It had to do with statuses.yml and users.yml corresponding to eachother.

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey Elaine Ryan that error means that the user whose gravatar_url you're trying to access is empty. In the statuses controller test you're working on, try making sure that each status has a user attached to it.

Thanks for replying Jason Seifer. I feel slightly embarrassed at this point on the track to say that I don't know what "making sure that each status has a user attached to it" looks like. I'm following along with the videos but having a hard time getting the fundamentals underlying each lesson. There are a bunch of tests and statuses are referred to as the symbol :status, the instance variable @status and status: followed by a hash.

Some, like this one,

test "should show status" do get :show, id: @status assert_response :success end

make no reference to a user.

In which cases do I need to make sure a user is attached and what would that look like?

Thanks!

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Elaine Ryan check your test/fixtures/statuses.yml and look to see if it has a user key. The status fixture will look something like this:

one:
  content: test

Make sure there's a "user" key in there that corresponds to one of the names in test/fixtures/users.yml:

one:
  user: mike
  content: test

test/fixtures/users.yml

mike:
  first_name: Mike
  last_name: TheFrog
  ....

Let us know if you still have problems!