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 trialDan H
372 PointsNameError Uninitialized Constant in UserFriendship Model Test
Hi, I am running Rails 4 and getting a frustrating NameError when I run the test on the UserFriendship model. In my app, this is called the ActivityParticipant model, but it works the same way.
Here is the model:
class ActivityParticipant < ActiveRecord::Base
belongs_to :activity
belongs_to :participant, class_name: 'User', foreign_key: 'participant_id'
attr_accessible :activity, :participant
state_machine :state, initial: :pending do
end
end
This is the test:
require 'test_helper'
class ActivityParticipantTest < ActiveSupport::TestCase
should belong_to(:activity)
should belong_to(:participant)
test "that creating a participant works" do
ActivityPartcipant.new participant: users(:jim), activity: activities(:one)
assert activities(:one).participants.include?(users(:jim))
end
end
And here is the output from running the test:
1) Error: ActivityParticipantTest#test_that_creating_a_participant_works: NameError: uninitialized constant ActivityParticipantTest::ActivityPartcipant test/models/activity_participant_test.rb:8:in `block in <class:ActivityParticipantTest>'
Any ideas?? Thank you
2 Answers
Kevin McGladdery
Courses Plus Student 1,894 PointsYou made a typo in the class name in line 8 of your test.
Whenever I get an uninitialized constant that I think should exist, 9 times out of 10 I typed it wrong.
Michelle Cannito
8,992 PointsIt's kind of funny that the missing letter was an "i". You can come up with some lame pun humor:
"I" have been looking and looking, but my "eye" did not see the missing "i", but Kevin's eagle "eye" found that "i" was gone.
Oh my, is part of becoming a coder thinking like this and thinking it's funny when it really isn't? Is this a Sheldon (nerd) symptom?
Dan H
372 PointsDan H
372 PointsThank you so much Kevin! I must have looked for a typo ten times without seeing it.