1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
thoughtbot--factory_bot/spec/acceptance/nested_attributes_spec.rb
Avielle c716ce01b4 Replace 'girl' with 'bot' everywhere (#1051)
Also: add a deprecation warning to factory_girl, asking users to switch to
factory_bot

https://github.com/thoughtbot/factory_girl/issues/921
2017-10-20 15:20:28 -04:00

32 lines
889 B
Ruby

require "spec_helper"
describe "association assignment from nested attributes" do
before do
define_model("Post", title: :string) do
has_many :comments
accepts_nested_attributes_for :comments
end
define_model("Comment", post_id: :integer, body: :text) do
belongs_to :post
end
FactoryBot.define do
factory :post do
comments_attributes { [FactoryBot.attributes_for(:comment), FactoryBot.attributes_for(:comment)] }
end
factory :comment do
sequence(:body) { |n| "Body #{n}" }
end
end
end
it "assigns the correct amount of comments" do
expect(FactoryBot.create(:post).comments.count).to eq 2
end
it "assigns the correct amount of comments when overridden" do
expect(FactoryBot.create(:post, :comments_attributes => [FactoryBot.attributes_for(:comment)]).comments.count).to eq 1
end
end