Skip to content

LoadError: "Expected admin/known_ip.rb to define Admin::KnownIp", ignores set_fixture_class #2572

@alexeymuranov

Description

@alexeymuranov

I am getting a

LoadError: Expected .../app/models/admin/known_ip.rb to define Admin::KnownIp

when running a Unit Test, because i actually define Admin::KnownIP in models/admin/known_ip.rb.
I specified the class with set_fixture_class, but it didn't help despite that it helps in a situation when KnownIP is not namespaced.

Steps to reproduce

Create a rails 3.1 application with

app/models/admin/known_ip.rb:

class Admin::KnownIP < ActiveRecord::Base
  set_table_name :admin_known_ips
end

test/unit/admin/known_ip_test.rb:

require 'test_helper'

class Admin::KnownIPTest < ActiveSupport::TestCase
  test "the truth" do
    assert true
  end
end

In test/test_helper.rb:

fixtures :all
set_fixture_class 'admin/known_ips' => Admin::KnownIP  

Bug

Then

$ ruby -Itest test/unit/admin/known_ip_test.rb

gives:

Admin::KnownIPTest:
    ERROR the truth (0.02s) 
          LoadError: Expected .../dep_test2/app/models/admin/known_ip.rb to define Admin::KnownIp
          .../activesupport-3.1.0.rc6/lib/active_support/dependencies.rb:486:in `load_missing_constant'

Inconsistency

However(!) this error does not show up if KnownIP is not put inside Admin module: adding set_fixture_class in that case suffices.

The error also does not show up if fixtures :all is commented out.

Another way to make the error go away is to rename the model file known_ip.rb to foo.rb.
Then there is no error regardless whether i use set_fixture_class or not.
I can tell that the Admin::KnownIP class is still loaded from models/admin/foo.rb because if i use set_fixture_class with a wrong class name, it raises an error.

This is with rails 3.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions