fabrication-gem

Duplicate Records created from Association

与世无争的帅哥 提交于 2019-12-14 04:06:09
问题 I am using Mongoid, Rails and Fabrications and at a total loss with how this is happening. Any thoughts very appreciated, but I know this pretty complicated. I just want to fabricate a user and have only four joined groups, but I keep getting eight loaded. Here is the relevant section of my code @user1 = Fabricate.build(:registered) @user1.joined_groups << [common_group, cali_group, ca46, Fabricate(:polco_group, {:name => "Gang of 13", :type => :custom})] When I run @user1.joined_groups.size

fabricator with hstore attribute

雨燕双飞 提交于 2019-12-11 02:59:57
问题 I am trying to build a fabricator using 'fabrication', '2.8.1' with a hstore attribute. Fabricator(:inventory_item_change) do attribute_changes Hash.new("num_units" => "to:50") state "scheduled" change_code 1 execution_at Time.now.advance(days: 3) inventory_item end This is the error message I am receiving when running tests with this fabricator. I've isolated the problem to be the hstore attribute: attribute changes. Failure/Error: attr = Fabricate.attributes_for(:inventory_item_change)

How do you define trait using Fabrication

五迷三道 提交于 2019-12-10 20:27:57
问题 I am learning how to use fabrication in Rails and we have decided to replace all our factory_girl code with fabrication. Suppose we have this code in factory_girl FactoryGirl.define do factory :user do trait(:no_credits) { credits 0 } trait(:with_credits) { credits 300 } How will you define this in Fabrication? I have gone through their website but couldn't find anything regarding this. Will appreciate your help 回答1: Seems that your are looking for Fabricator inheritance, this is what the

How to fabricate Mongoid document with embedded document using Fabrication?

狂风中的少年 提交于 2019-12-03 07:30:02
问题 I use Mongoid and Fabrication gems. I have switched to Mongoid.rc7 from beta20 and now I can't fabricate document with embedded document: #Models class User include Mongoid::Document embeds_many :roles end class Role include Mongoid::Document field :name, :type => String embedded_in :user, :inverse_of => :roles end #Fabricators Fabricator(:role) do name { "role" } end Fabricator(:user) do email { Faker::Internet.email } password { "password" } password_confirmation { |user| user.password }

How to fabricate Mongoid document with embedded document using Fabrication?

这一生的挚爱 提交于 2019-12-02 21:00:47
I use Mongoid and Fabrication gems. I have switched to Mongoid.rc7 from beta20 and now I can't fabricate document with embedded document: #Models class User include Mongoid::Document embeds_many :roles end class Role include Mongoid::Document field :name, :type => String embedded_in :user, :inverse_of => :roles end #Fabricators Fabricator(:role) do name { "role" } end Fabricator(:user) do email { Faker::Internet.email } password { "password" } password_confirmation { |user| user.password } roles { [] } end Fabricator(:admin_user, :from => :user) do roles(:count => 1) { |user| Fabricate(:role,