问题描述: – 我设置了factory_girl_rails但是每当我尝试加载一个工厂,它试图加载它多次。 Environment: – rails (3.2.1) – factory_girl (2.5.2) – factory_girl_rails (1.6.0) – ruby-1.9.3-p0 [ x86_64 ] > rake spec –trace ** Execute environment — Creating User Factory — Creating User Factory rake aborted! Factory already registered: user 我改变的另外一件事是:/config/initializers/generator.rb Rails.application.config.generators do |g| g.test_framework = :rspec g.fixture_replacement :factory_girl end 的Gemfile gem 'rails', '3.2.1' # Bundle […]
假设您有以下mongoid文档: class User include Mongoid::Document embeds_one :name end class UserName include Mongoid::Document field :first field :last_initial embedded_in :user end 如何创build一个初始化embedded式名字和最后一个字母的工厂女孩工厂? 另外你怎么做embeds_many关系?
我试图使用factory_girl来创build一个“用户”工厂(RSpec),但它似乎并没有在事务上运行,显然是因为testing数据库中以前的testing的残留数据而失败。 Factory.define :user do |user| user.name "Joe Blow" user.email "joe@blow.com" user.password 'password' user.password_confirmation 'password' end @user = Factory.create(:user) 运行第一组testing是好的: spec spec/ … Finished in 2.758806 seconds 60 examples, 0 failures, 11 pending 一切顺利,如预期的那样,再次运行testing: spec spec/ … /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/validations.rb:1102:in `save_without_dirty!': Validation failed: Email has already been taken (ActiveRecord::RecordInvalid) from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/dirty.rb:87:in `save_without_transactions!' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/transactions.rb:200:in `save!' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction' […]