Concerned_with, and maybe require_dependency issues only when running specs?


#1

Hi all,

So in the interests of keeping a few areas of my code a bit under
control,
I’ve been investigating the concept of “concerned_with” as described
here:

http://paulbarry.com/articles/2008/08/30/concerned-with-skinny-controller-skinny-model

Basically allowing me to have:

/app/models/user.rb
class User < ActiveRecord::Base
concerned_with :something
end

/app/models/user/something.rb
class User < ActiveRecord::Base
def something_method
do_it
end
end

I realize that there might be better ways to deal with this same
issue…some of my code might be better off in separate classes, or
modules,
etc, but for now I’m hoping to try this out. And it’s working working
great
in my code, when I run the server, script/console, etc…

…everywhere except in my specs.

And, its working in my actual model spec just fine
(spec/models/user_spec.rb).

But where it’s not working is in other specs that end up using the user
model, such as some controller specs, and view specs where things aren’t
fully stubbed/mocked out.

It seems like in those other specs, the User class doesn’t have
“something_method” defined. (the failure message is undefined_method
“something_method” for #Class:0x243626c

Anybody have any ideas? I have a feeling it’s related to
require_dependency
or something, but I’m not really sure. I’ve turned on logging in
require_dependency, and it seems like the files are being required. Any
help
would be great, thanks!

Cameron


#2

We are having the same issue. It works fine when config.cache_classes is
on. but when its turned off stuff breaks. The extra files are no longer
parsed.

concerned_with seems to have an issue with eager loading. Right now
we’re looking at alternatives.