Skip to content


Subversion checkout URL

You can clone with
Download ZIP


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

alexeymuranov opened this Issue · 10 comments

5 participants


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


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


require 'test_helper'

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

In test/test_helper.rb:

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



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


    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'


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.


I want to explain that there are actually 2 issues i am pointing out in this report:

  1. set_fixture_class seems to not work the same with a namespaced class as it does otherwise.
  2. LoadError seems inconsistent: why admin/known_ip.rb is expected to define Admin::KnownIp, but admin/foo.rb is not expected to define Admin::Foo in the described above situation? Why to expect a class to be denied somewhere if this class is not mentioned anywhere and does not exist?

Hi, did you run your fix with all the activerecord tests? I got 46 failures.


No, i also do not have PostgreSQL ready for tests. I will try to test with sqlite. Thank you for trying this.


Can you, please, tell if this fix will be only on Rails 3.1 or will be on 3.0 too?


I can rebase it to make a fix for 3.0 too, no problem, but so far my PR #4482 has not been merged.


@tenderlove: can it be fixed in 3.2 please?


@alexeymuranov was this fix put into 3.2? I'm experiencing the LoadError issue.


@vquigley: no, i think @tenderlove is busy :).


@alexeymuranov and such is the way of open source & free software ;) As a workaround I will just require the files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.