开发者

How can I use more than one set of fixtures per table in Rails?

开发者 https://www.devze.com 2022-12-10 19:39 出处:网络
I want to define alternative sets of fixtures per database table. For example, class BusinessSpec describe \"some aspect of businesses\" do

I want to define alternative sets of fixtures per database table.

For example,

class BusinessSpec
  describe "some aspect of businesses" do
    fixtures :fixture_set_1

    ...
  end

  describe "so开发者_开发百科me unrelated aspect of businesses" do
    fixtures :fixture_set_2
    ...
  end
end

Is this, or something similar, possible?


It's much easier to do this using something like factory_girl. You can define multiple factories per table.

Factory.define :my_post, :class => Post do |f|
  f.name "Mine"
  f.created_at 2.weeks.ago
end

Factory.define :another_post, :class => Post, :parent => :my_post do |f|
  f.name "Another"
end

The 2nd example keeps things dry. Factory girl is an easy replacement for fixtures. Try it, you'll love it.

0

精彩评论

暂无评论...
验证码 换一张
取 消