fixtures in edge and polymorphic associations


I've been using the fixture enhancements in edge rails to manage associations between objects. It has been working great except for polymorphic associations. I saw that they weren't supported in Rathole.

I read some post that the id's generated by the fixtures are constant so I just pulled the generated id's and manually set the polymorphic id and the polymorphic type in the fixture as well.

This worked great locally on my machine, but when I moved the application to a staging are the generated id's were different, breaking all of the associations.

Anyone have any better luck with another approach?

Hi Dan,

You can insert the generated ID for any fixture using ERB:

   foo:      bar_id: <%= Fixtures.identify(:the_target_fixture_label) %>

As far as polymorphic assoiations go, take a look at this patch:

~ j.

You actually don't need the patch to support polymorphic relationships.

The patch suggests this:

# instead of saying foo:   pet_id: 1 # a pet fixture labelled "horace"   pet_type: Ferret

# you can say foo:   pet: horace (Ferret)

But in fact you can do this:

foo:   pet: horace   pet_type: Ferret

This is good enough for me.

Tiago Macedo

John Barnette wrote:

Thanks for the replies.

I've been trying this syntax

foo:   pet: horace   pet_type: Ferret

and the relationship isn't resolving. This is in edge and I don't need a patch?

It's working for me in edge, as long as I don't specify ids for fixtures (currently this will disable foxy fixtures).

There is a patch in the Rails Trac that allows you to specify ids and still use foxy fixtures:

As I need this patch and don't want to use a monkey patched version of Rails, I turned this into a plugin:

Tiago Macedo

Dan wrote: