Ruby on rails 使用factory girl进行Ruby on Rails 4测试的属性

Ruby on rails 使用factory girl进行Ruby on Rails 4测试的属性,ruby-on-rails,ruby,rspec,factory-bot,Ruby On Rails,Ruby,Rspec,Factory Bot,我正在尝试测试简单的POST-controller#create方法 it "saves the new object in the DB" do object = build(:object_with_association) expect { post :create, object: object.attributes }.to change(SomeObject, :count).by(1) end 这是对象。属性是最好的方法吗?我尝试将属性_用于(:object_与_关联),

我正在尝试测试简单的POST-controller#create方法

it "saves the new object in the DB" do
  object = build(:object_with_association)
  expect { post :create, object: object.attributes }.to change(SomeObject, :count).by(1)
end
这是对象。属性是最好的方法吗?我尝试将属性_用于(:object_与_关联),但它返回一个完全没有关联的散列。可能有一些有用的方法可以做到这一点吗? 我的工厂:

factory :obj do
  name "A"
  association :first, factory: :first
  association :second, factory: :second

  factory :obj_with_association do
    transient do
      nested_count 5
    end

    after(:build) do |obj, evaluator|
      create_list(:nested, evaluator.nested_count, obj: obj)
    end
  end
end

:first和:second is的关联属于,因为:nested is有许多

您可以分别创建属性并将它们合并,或者您可以尝试与FactoryGirl的特征

请查看这两个SO问题以了解详细信息: