Has_many_polymorphs is breaking my spec file

Hey folks

I have a bunch of classes that are polymorphs, with has_many_polymorphs
(they are all ‘labellable’, which is similar to being ‘taggable’ in the
acts_as_taggable scheme). I have a couple of modules,
LabellableInstanceMethods and LabellableClassMethods in a file called
labellable_methods.rb.

The classes all get labelled with ‘properties’, and i set out to write
the
Property class first, using bdd of course. This all went fine.
However,
when i came to start testing that the labelling was working properly, i
added the following code:

POLYMORPHIC_TABLENAMES = [:instructional_objects, :resources,
:lessons,
:courses]
#this is breaking tests currently
has_many_polymorphs :labellables,
:from => POLYMORPHIC_TABLENAMES,
:through => :labellings,
:dependent => :destroy

Now, whenever i run the spec file, it bombs out as soon as it hits a
reference to the Property class (at the start of my main describe
block),
saying
“/home/jars/rails/lesson_planner/branches/max/vendor/rails/activerecord/lib/…/…/activesupport/lib/active_support/dependencies.rb:249:in
`load_missing_constant’: Expected
/home/jars/rails/lesson_planner/branches/max/app/models/property.rb to
define Property (LoadError)”

If i play around with the labelling system in the console, it seems to
work
fine: ie, the above code works ‘normally’, but is totally breaking the
spec
file.

Does anyone have any ideas about this? It’s driving me crazy and
stopping
me speccing other aspects of my labelling system.

thanks
max

On Wed, Mar 5, 2008 at 4:40 AM, Max W.
[email protected] wrote:

when i came to start testing that the labelling was working properly, i
Now, whenever i run the spec file, it bombs out as soon as it hits a
reference to the Property class (at the start of my main describe block),
saying
“/home/jars/rails/lesson_planner/branches/max/vendor/rails/activerecord/lib/…/…/activesupport/lib/active_support/dependencies.rb:249:in
`load_missing_constant’: Expected
/home/jars/rails/lesson_planner/branches/max/app/models/property.rb to
define Property (LoadError)”

This error is coming from Rails. Keep in mind that RSpec wrap Rails’
built-in test infrastructure. Can you try writing the same examples in
test/unit and see if they work?

Hmm, the results are exactly the same, down to the error message. And,
as
before, if i remove the has_many_polymorphs declaration there’s no
problem.

So its not rspec’s fault. But i’m still no closer to finding out what
it is
about my has_many_polymorphs declaration that the tests don’t like. :frowning:

no, just the ruby forum. I’ll try the rails list next. thanks

On Wed, Mar 5, 2008 at 7:53 AM, Max W.
[email protected] wrote:

Hmm, the results are exactly the same, down to the error message. And, as
before, if i remove the has_many_polymorphs declaration there’s no problem.

So its not rspec’s fault. But i’m still no closer to finding out what it is
about my has_many_polymorphs declaration that the tests don’t like. :frowning:

Have you posted to the rails list?