Hello, i have a problem with autoloading model classes.
I have had similar problems before when a file’s name in Rails’ opinion
did not match with the name of the class defined inside, but eventually
everything worked, so i didn’t look into details.
This time the problem comes from running Unit Tests and does not want to
go away.
I have a model class KnownIP defined in a file named “known_ip.rb”
(rather than “known_i_p.rb”).
This file name was generated by the model generator, in i prefer it this
way.
In any case, the application works.
The database table is called “known_ips”.
To my test_helper.rb, i added
set_fixture_class :known_ips => KnownIP,
(otherwise it would guess “KnownIp”).
Now, when i try to run Unit Tests, i get an error:
LoadError: Expected …/known_ip.rb to define KnownIp.
gems/activesupport-3.1.0.rc6/lib/active_support/dependencies.rb:486:in
`load_missing_constant’
I looked into the source and experimented a bit.
I would be ready to say that autoloading loads everything in the models
directory, and KnownIP class gets defined just fine, but then Rails gets
surprised that it has loaded a file named “known_ip.rb” but has no class
named “KnownIp” (even though such class was never mentioned anywhere).
However, if i rename known_ip.rb to foo.rb, Rails does not complain that
“Expected …/foo.rb to define Foo”, and everything works.
But i am picky and do not want a class named “KnownIP” to be defined in
a filed named “foo.rb”.
Can anybody please explain this or tell how to just load a file,
without complains from Rails about what has not been defined inside?
Thanks.
Alexey.