creating fixtures for has_many :through

I'm stymied at how to create a fixture that establishes a has_many :through relationship.

I've watched the railscast at:   http://media.railscasts.com/videos/081_fixtures_in_rails_2.mov ... but that's for HABTM relationships. I've read:   2.0 Fixtures with has_many :through? - Rails - Ruby-Forum but that ultimately doesn't answer any question. So with no further ado:

==== The models: class User < ActiveRecord::Base   has_many :user_roles, :dependent => :destroy   has_many :roles, :through => :user_roles end class Role < ActiveRecord::Base   has_many :user_roles, :dependent => :destroy   has_many :users, :through => :user_roles end class UserRole < ActiveRecord::Base   belongs_to :role   belongs_to :user end ==== The schema:   create_table "users", :force => true do |t|     t.string "name", :default => "", :null => false     t.string "email", :default => "", :null => false   end   create_table "roles", :force => true do |t|     t.string "name"   end   create_table "user_roles", :force => true do |t|     t.integer "role_id"     t.integer "user_id"   end

UPDATE!

In a fit of gentle snarkiness, Fearless Fool wrote:

Before Marnen tells me to put aside my Luddite tendencies and that I should learn factory_girl or Machinist or the next testing framework du jour, is there any sensible way to do this using fixtures?

The more I've looked into it, the more I think Marnen would be justified in telling me to put aside my Luddite tendencies: the fixtures framework creates an arbitrary (and brittle) separation between test data and test functions.

I'm currently grabbing the gems for RSpec and factory_girl.

So there!

- ff (channeling for Marnen :slight_smile:

Fearless Fool wrote:

UPDATE!

In a fit of gentle snarkiness, Fearless Fool wrote:

Before Marnen tells me to put aside my Luddite tendencies and that I should learn factory_girl or Machinist or the next testing framework du jour, is there any sensible way to do this using fixtures?

The more I've looked into it, the more I think Marnen would be justified in telling me to put aside my Luddite tendencies: the fixtures framework creates an arbitrary (and brittle) separation between test data and test functions.

Exactly! That's a big reason that fixtures suck. It's much nicer to use factories to create test data where you need it.

I'm currently grabbing the gems for RSpec and factory_girl.

You may find Machinist easier to work with than FG. Also check out Faker, which is very useful with any fixture gem.

So there!

- ff (channeling for Marnen :slight_smile:

LOL! Well played. This is apparently my week to be snarked on the list. :stuck_out_tongue:

Best,