views:

37

answers:

1

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' /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:inrequire' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in require' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:265:inrequire_or_load' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:224:in depend_on' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:136:inrequire_dependency' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:853:in try_to_load_dependency' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:868:inrequire_fixture_classes' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:865:in each' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:865:inrequire_fixture_classes' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:848:in fixtures' ./test/functional/../test_helper.rb:35 test/functional/forums_controller_test.rb:1:inrequire' 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' /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:inrequire' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in require' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:265:inrequire_or_load' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:224:in depend_on' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:136:inrequire_dependency' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:853:in try_to_load_dependency' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:868:inrequire_fixture_classes' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:865:in each' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/fixtures.rb:865:inrequire_fixture_classes' /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?!

A: 

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_many join table.

Make sure your users.yml fixture has:

user:
 roles: moderator

and your roles.yml fixture has:

moderator:
 name: 'Moderator'

and that id values are not set in the user.yml or roles.yml files.

inkdeep