I’m getting the following problem with my functional test.
mrbernz:mylife bernardleung$ ruby test/functional/forums_controller_test.rb
…..
1) Error:
test_should_create_forum(ForumsControllerTest):
ActiveRecord::StatementInvalid: Mysql::BadFieldError: Unknown column ‘id:3 name’ in ‘field list’: INSERT INTO roles (id, id:3 name) VALUES (707834473, ‘Moderator’)
A stack trace of the error points as follows…
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in gem_original_require'require’
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in require'require_or_load’
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:265:in
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:224:in depend_on'require_dependency’
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:136:in
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:853:in try_to_load_dependency'require_fixture_classes’
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:868:in
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:865:in each'require_fixture_classes’
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:865:in
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:848:in fixtures'require’
./test/functional/../test_helper.rb:35
test/functional/forums_controller_test.rb:1:in
test/functional/forums_controller_test.rb:1
Unable to load roles_user, underlying cause no such file to load — roles_user
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in gem_original_require'require’
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in require'require_or_load’
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:265:in
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:224:in depend_on'require_dependency’
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:136:in
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:853:in try_to_load_dependency'require_fixture_classes’
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:868:in
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:865:in each'require_fixture_classes’
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:865:in
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:848:in `fixtures’
test/functional/forums_controller_test.rb:4
My forums_controller_test.rb looks as follows (first few lines anyway)
require File.dirname(__FILE__) + '/../test_helper'
class ForumsControllerTest < ActionController::TestCase
fixtures :forums, :users, :roles, :roles_users
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:forums)
end
I don’t understand why it’s complaining about ‘roles_user’ as I don’t ask for it anywhere, and what I do ask for or declare is ‘roles_users’ which is a table I do have!
mysql> show tables;
+-----------------------+
| Tables_in_mylife_test |
+-----------------------+
| articles |
| categories |
| forums |
| pages |
| posts |
| roles |
| roles_users |
| schema_migrations |
| topics |
| users |
+-----------------------+
10 rows in set (0.15 sec)
help?!
Remove :roles_users from the fixtures declaration in ForumsControllerTest.
By specifying :roles_users as a fixture it is trying to load a model called RolesUser. I’m assuming it is a
has_and_belongs_to_manyjoin table.Make sure your
users.ymlfixture has:and your roles.yml fixture has:
and that
idvalues are not set in theuser.ymlorroles.ymlfiles.