1

在我的Rails 3应用程序中,我有一个包含以下字段的用户模型

   name: string
   email: string
   children: has_many association to another model

我正在使用机械师 2生成模拟数据,它的蓝图看起来像

User.blueprint do
   name { 'user{sn}' }
   email { '{object.name}@domain.com' }
end

和用户的单元测试

require 'test_helper'

class UserTest < ActiveSupport::TestCase
  should have_many( :children )
  should validate_uniqueness_of( :email )
  should_not allow_value("blah").for(:email)
  should_not allow_value("b lah").for(:email)
  should allow_value("a@b.com").for(:email)
  should allow_value("asdf@asdf.com").for(:email)
end

当我生成用户模型时,它创建了一个夹具文件。我的理解是,当我运行时rake,Rails 使用该夹具文件来生成测试中使用的对象。这不是我想要的。我希望 Rails无缝地使用机械师的蓝图,因为它使用了夹具文件。

有没有办法做到这一点?有什么方法可以告诉 Rails 它需要使用蓝图而不是固定装置?

4

1 回答 1

4

将此添加到 config/application.rb:

config.generators do |g|
  g.fixture_replacement :machinist
end

You can safely trash the old fixtures folder too, unless you want to keep them obviously!

于 2010-12-09T17:03:50.247 回答