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
Tessa Davis
4,152 PointsSimple Ruby on Rails Application: Fixtures
I cannot seem to get the final code in this video to pass. I'm still getting 4 errors and cannot work out how to solve them...
4 tests, 0 assertions, 0 failures, 4 errors, 0 skips
They all look like this (same for each test). Can anyone help?
1) Error:
test_a_user_should_enter_a_first_name(UserTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException: table users has no column named password: INSERT INTO "users" ("first_name", "last_name", "profile_name", "email", "password", "password_confirmation", "created_at", "updated_at", "id") VALUES ('John', 'Smith', 'johnsmith', 'johnsmith@gmail.com', 'password', 'password', '2012-12-30 00:44:06', '2012-12-30 00:44:06', 830138774)
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/sqlite3-1.3.6/lib/sqlite3/database.rb:91:in initialize'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/sqlite3-1.3.6/lib/sqlite3/database.rb:91:innew'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/sqlite3-1.3.6/lib/sqlite3/database.rb:91:in prepare'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/sqlite3-1.3.6/lib/sqlite3/database.rb:134:inexecute'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/connection_adapters/sqlite_adapter.rb:278:in block in execute'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract_adapter.rb:280:inblock in log'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.9/lib/active_support/notifications/instrumenter.rb:20:in instrument'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract_adapter.rb:275:inlog'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/connection_adapters/sqlite_adapter.rb:278:in execute'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/database_statements.rb:277:ininsert_fixture'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/fixtures.rb:502:in block (5 levels) in create_fixtures'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/fixtures.rb:501:ineach'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/fixtures.rb:501:in block (4 levels) in create_fixtures'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/fixtures.rb:500:ineach'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/fixtures.rb:500:in block (3 levels) in create_fixtures'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/fixtures.rb:492:ineach'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/fixtures.rb:492:in block (2 levels) in create_fixtures'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/database_statements.rb:192:intransaction'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/fixtures.rb:491:in block in create_fixtures'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract_adapter.rb:168:indisable_referential_integrity'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/fixtures.rb:476:in create_fixtures'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/fixtures.rb:895:inload_fixtures'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/fixtures.rb:849:in setup_fixtures'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:407:inrun4386363440694770963setup2275558649461581134callbacks'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:405:in `_run_callback'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:385:in _run_setup_callbacks'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:81:inrun_callbacks'
/Users/x/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.9/lib/active_support/testing/setup_and_teardown.rb:35:in `run'
6 Answers
Tessa Davis
4,152 PointsFound the solution on another thread thanks to Juan Cano. Does this mean we just have an encrypted_password field and no password confirmation? (I've done it that way and it works, but I think there should probably be a password confirmation too)...
Fixtures: The error at ~1:30 is because the fixture is using the fields "password" and "password_confirmation" when it should be using "encrypted_password" or no field at all for password. You can even see the error message "table users has no column named password" on the video. It doesn't say it's on line 32 and, in fact, there are 4 errors, one for each test. People can get stuck here because this problem is never solved. Adding uniqueness would only make sense if you actually pass the test with the same profile_name as another registered user and the screen with no errors after adding uniqueness is not what you get when you do it on your own.
Juan Cano
2,844 PointsHey! Glad I could help :)
When you create a fixture you are creating an object as it is stored in your database. The attributes "password" and "password_confirmation" are attributes used by Devise to create a user, but are not actually stored in the database. If they did it would not be very safe (if anyone was able to break into the system they could get all the unencrypted passwords) so they create an encrypted password using those fields and store it in the database instead.
This field can be empty, you can create a fixture using only the other fields. If you add a value to this field you may need to know the unencrypted value, for example if you want to test the login process or something like that.
Tessa Davis
4,152 PointsPerfect - great explanation and I actually understand it now. Thanks!
ecp
838 PointsYAAAY TEAMWORK :D
Lucas Lu
1,451 PointsThanks everyone for the answer! I was stuck on this for the longest time :(
Stephen Lee
22,945 PointsThank you for posting this. When he said, "The error is in line 32," I couldn't figure out what was going on because none of my errors said anything about line 32.
I also got this error:
ActiveRecord::Fixture::FormatError: a YAML error occurred parsing /Users/stephenlee/Sites/ruby/treebook/test/fixtures/users.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html
Which was because I used the tab key to make an indentation in my users.yml file instead of actual spaces. After correcting that I was able to get through this.
Thanks again!