mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
7925c47653
Closes #1202 We have fixed the bulk of the RuboCop TODOs. The main TODO remaining (line length) involves a large number of files, and I don't think it is worth trying to update them all at once. I did fix a few of the worst offenders so we could bring the max down a bit. We can gradually bring this number down as we fix more of the violations.
32 lines
880 B
Ruby
32 lines
880 B
Ruby
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
|
|
post = FactoryBot.create(:post, comments_attributes: [FactoryBot.attributes_for(:comment)])
|
|
|
|
expect(post.comments.count).to eq 1
|
|
end
|
|
end
|