Charles Choi...
4 posts
|
On page 175 I set up the user.yml as shown. I then copied the tests from the book’s source code. When I try to run the tests I get the following error on all 9 tests.
1) Error:
test_should_assign_new_password(UserTest):
ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'encrypted_password' in 'field list': INSERT INTO `users` (`name`, `encrypted_password`, `salt`, `updated_at`, `admin`, `id`, `created_at`, `email`) VALUES ('Joe Rubenstein', 'c96960b148194296a441c5315e25f1e7a658c391', 'test_salt', '2008-07-16 12:57:33', 1, 666029094, '2008-07-16 12:57:33', '<a href="mailto:joe@example.com">joe@example.com</a>')
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:147:in `log'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/mysql_adapter.rb:299:in `execute'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:145:in `insert_fixture'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/fixtures.rb:639:in `insert_fixtures'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/fixtures.rb:576:in `each'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/fixtures.rb:576:in `insert_fixtures'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/fixtures.rb:520:in `create_fixtures'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/fixtures.rb:520:in `each'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/fixtures.rb:520:in `create_fixtures'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/fixtures.rb:518:in `create_fixtures'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/mysql_adapter.rb:252:in `disable_referential_integrity'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/fixtures.rb:509:in `create_fixtures'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1263:in `silence'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/fixtures.rb:508:in `create_fixtures'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/fixtures.rb:963:in `load_fixtures'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/fixtures.rb:929:in `setup_fixtures'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:173:in `send'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:173:in `evaluate_method'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:161:in `call'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:90:in `run'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:90:in `each'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:90:in `send'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:90:in `run'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:272:in `run_callbacks'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/testing/setup_and_teardown.rb:31:in `run'
If I remove the following lines from users.yml from both admin_user and non_admin_user
encrypted_password: <%= User.encrypt('nam', 'test_salt') %>
The active record error complains about changes to unknown column ‘salt’ instead. When I remove both the encypted password and salt lines from the yaml I get the following error.
test_should_assign_new_password(UserTest):
NameError: undefined local variable or method `encrypted_password' for #<User:0x1230400>
when I try to load the fixtures as shown in the book with
rake db:fixtures:load
I get no errors at all.
I’ve tried everything short of pulling my hair out including copying both the yml, the test, and even the users model from the source and I still get the same errors. Any ideas???
|
Derek DeVries
10 posts
|
Charles,
It looks like your test schema is not up to date with the development schema. Running the 004_add_salt_to_users.rb migration will only apply the migration to the user_group_development database. You’ll want to copy these schema changes to the test database by running the task:
rake db:test:prepare
We briefly discuss this on page 156, but we probably should have mentioned that you need to rerun this task any time you change the development schema to make sure the test database is up to date.
Hope this helps
|
Charles Choi...
4 posts
|
Thanks that took care of it! I knew it was something I had glanced over. Now I have to go track down some missing authentication method errors, I’m pretty sure I haven’t gotten to the authentication section where I’m going to write that method. So it looks like I’m in good shape.
Thanks for responding so quickly. I’m very happy with your book, I’ve tried to learn Rails before and it’s a must to understand basic Ruby before you try to learn, otherwise you end up just doing a bunch of monkey typing and not learning what parts are Ruby and what parts are Rails. Your book explains everything so well. Although I would have liked to go through the user set of tests in the book and have them explained like the meetings round of testing. All in all love the book. Thanks again.
Charles
|