天道酬勤,学无止境

fabrication-gem

从关联创建的重复记录(Duplicate Records created from Association)

问题 "Gang of 13", :type => :custom})]

2022-02-17 05:31:27    分类:技术分享    ruby-on-rails   unit-testing   mongoid   fabrication-gem

Duplicate Records created from Association

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 I get 4, but when I do @user1.joined_groups.map(&:name), I get 8 records: #<PolcoGroup _id: 1

2022-02-16 18:01:31    分类:问答    ruby-on-rails   unit-testing   mongoid   fabrication-gem

具有 hstore 属性的制造商(fabricator with hstore attribute)

问题 我正在尝试使用带有 hstore 属性的“fabrication”、“2.8.1”来构建制造商。 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 这是我在使用此制造商运行测试时收到的错误消息。 我已将问题隔离为 hstore 属性:属性更改。 Failure/Error: attr = Fabricate.attributes_for(:inventory_item_change) ArgumentError: bad value for range 任何人都可以帮助识别正确的语法,或其他合适的解决方案来制造具有 hstore 属性的对象吗? 回答1 看看github上的以下问题: https://github.com/paulelliott/fabrication/issues/202 似乎您不能直接传递散列,因为它随后被视为选项参数。 对您来说正确的语法是: Fabricator(:inventory_item_change) do attribute_changes

2021-09-13 18:07:31    分类:技术分享    ruby-on-rails   rspec   hstore   fabrication-gem

fabricator with hstore attribute

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) ArgumentError: bad value for range Can anyone assist in identifying the correct syntax, or another suitable

2021-09-03 05:51:28    分类:问答    ruby-on-rails   rspec   hstore   fabrication-gem

How do you define trait using Fabrication

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

2021-08-10 18:52:48    分类:问答    ruby-on-rails   ruby   factory-bot   fabrication-gem

How to fabricate Mongoid document with embedded document using Fabrication?

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,

2021-05-17 08:32:29    分类:问答    ruby-on-rails-3   mongoid   fabrication-gem