簡體   English   中英

在Rails中,每個表如何使用多套夾具?

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

我想為每個數據庫表定義固定裝置的替代集。

例如,

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

    ...
  end

  describe "some unrelated aspect of businesses" do
    fixtures :fixture_set_2
    ...
  end
end

這或類似的東西可能嗎?

使用factory_girl之類的方法執行此操作要容易得多。 您可以在每個表中定義多個工廠。

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

第二個示例使事情保持干燥。 工廠女孩是固定裝置的簡便替代品。 試試吧,您會喜歡的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM