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
Brad Beltowski
2,069 PointsWriting Test > Fixtures > Uniqueness Bug
Hi, I'm having a problem with the "Writing Tests" section of "Build a Simple Ruby on Rails App". Right now I'm stuck on the fixtures. I have tried to narrow it down and fixing it myself before asking for help. I hope the code below and my explanation is enough. Basically I don't know if it's the intention of my YAML or using “validates :profile_name, uniqueness: true” in Ruby 1.9.
=== The Problem ============== If I make a fixture “brad:” it errors out like in the video example. When I append uniqueness to “validates :profile_name” line the errors are still there. I dug around and found validates_unquieness_of and that doesn't fix the problem either. I continued ahead a bit and referred to my fixture object in the user_test.rb file and it doesn't error to the point that it doesn't know what that object is, but the same errors come up when running "ruby -Itest test/unit/user_test.rb" which makes me believe the YAML is formatted correctly. So at this point I have no clue what’s going wrong. I added the versions of my Ruby and Rails below incase it might be helpful.
EDIT: I have the fix
As of right now if you follow the videos you will always get an error after Jason appends the "uniqueness, true" to the "validates :profile_name, presence: true" line. The same 4 errors will pop up using "ruby -Itest test/unit/user_test.rb" but once you remove the password lines from the user fixture it will work out. I believe this is a bug with the newer Devise. Also to check the duplication of a profile name, I don't see the logic behind checking the password to see if the profile names match up.
##################################################
ruby -v "ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin10.8.0]"
rails -v "Rails 3.2.12"
=== # User Model Code # ======================
validates :profile_name, presence: true, uniqueness: true
I dug around the net and found this and it still doesn't work
validates_uniqueness_of :profile_name
=== ### ENDS User Model Code ### ===============
=== # User Fixture Code # ======================
brad: first_name: "Brad" last_name: "Beltowski" email: "brad@test.com" profile_name: "RubyRockstar" password: "password" password_confirmation: "password"
=== ### ENDS User Fixture Code ### =============
=== # unit/user_test.rb Code # ======================
test "a user should have a unquie profile name" do user = User.new user.profile_name = users(:brad).profile_name
assert !user.save
#puts user.errors.inspect
assert !user.errors[:profile_name].empty?
end
=== ### ENDS unit/user_test.rb Code ### ===============
1 Answer
Jason Seifer
Treehouse Guest TeacherHey Brad Beltowski can you zip up your code and email it to help@teamtreehouse.com?