[ANN/RFC] Rathole, a fixtures extension plugin

Like lots of other folks, I've been searching for a way to scratch my
fixture itches. Rathole is my extraction of a few techniques we've
successfully applied at my day job.

We've been using Rathole for a month or so now, but I'd really like
some feedback from a wider audience. Rathole tackles:

* Conflicting PK's (no more id's in fixture files!),
* Bad belongs_to and HABTM FK's (and join table fixtures!),
* Noisy created_at/updated_at (and _on) specifications, and
* Default fixture values

Rathole works for me on MySQL and SQLite on Rails 1.2.5 and trunk, but
YMMV. There's more information in the README, which is available along
with the current version of the plugin at:

  http://svn.geeksomnia.com/rathole/trunk

All comments and suggestions are welcome. Thanks!

~ j.

John, Rathole looks like a great step in the right direction. I had to
write a custom tool that checked all our FK's in each of our fixture
scenarios, and having Rathole in place would've simplified that quite
a bit. Fixtures are one of the weakest parts of Rails and tools like
this are sorely needed. Looking forward to more features and
improvements down the road too.

-Jason

Thanks! I'd be interested to hear about any specific features or
improvements you'd like to see, too.

Rathole's constant label --> PK generation should make it really easy
to hash/watch the entire fixtures directory and only reload changed
fixtures. If we keep an eye on schema_version changes as well, it
should be possible to avoid fixture loading completely except when
fixture files or db structure have changed. If there's any Rathole
uptake, I'll probably start monkeying with this Real Soon Now.

~ j.

So should this work automatically when I run rake?

So should this work automatically when I run rake?

Yup, it should work without any configuration.

~ j.

Could you show some examplel of how to use namespaced models?

Namespaced models should work just like any other models: are you seeing some strange behavior? If so, can you pass along an example of something bad happening? Thanks!

~ j.

My models:

  Content
    has_many :assigned_assets, :class_name =>
'Assets::AssignedAsset', :dependent => :destroy
    has_many :assets, :class_name => 'Assets::Asset', :through
=> :assigned_assets

  Assets::Asset
  Assets::ImageAsset

  Assets::AssignedAsset
    belongs_to :content, :counter_cache => 'assets_count'
    belongs_to :asset

contents.yml:

  message:
    title: Sample
    type: Event
    assigned_assets: one

assets/assigned_assets.yml

  one:
    asset: one
    content: message
    position: 1

assets/assets.yml

  one:
    content_type: image/jpeg
    size: 204047
    file: lgis86g3.jpg
    dimensions: 1280x1024
    type: ImageAsset

Got an error: ActiveRecord::StatementInvalid: PGError: ERROR: column
"assets" of relation "contents" does not exist

Sorry, I am a little wrong. In previous contents.yml "assigned_assets:
one" should be removed.
My problem is that contents(:message).assets always empty. What I
missed?

For those not using edge rails, please note that this plugin has been
merged in edge rails core now. So congrats and thanks to John Barnette
and others should start using this if you're not on edge :slight_smile:

Hi John,

Great plugin (well technically a core Rails feature).

I think I found a small bug. If you have a has_many without an id
column both rathole and foxy fixtures will try to insert an auto-
generated id which fails since there is no id column.

I fixed it locally by modifying your fixtures.rb to check if the
column_names include the primary key name like so:

      if model_class
        # generate a primary key
        row[primary_key_name] = ::Fixtures.identify(label) if
column_names.include? primary_key_name

Also, any plans on adding support for getting rid of has_many :through
fixtures files? As far as I can tell it only works with habtm
correct? I could try to take a stab at it if you aren't planning on
it.

Thanks,
Tom

Polymorphic association support would be fantastic.