Sha256: 15712b8acaa724e777f7b594301843c00377af317d003fd6d55780d2df579278
Contents?: true
Size: 895 Bytes
Versions: 2
Compression:
Stored size: 895 Bytes
Contents
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 FactoryGirl.define do factory :post do comments_attributes { [FactoryGirl.attributes_for(:comment), FactoryGirl.attributes_for(:comment)] } end factory :comment do sequence(:body) {|n| "Body #{n}" } end end end it "assigns the correct amount of comments" do FactoryGirl.create(:post).comments.count.should == 2 end it "assigns the correct amount of comments when overridden" do FactoryGirl.create(:post, :comments_attributes => [FactoryGirl.attributes_for(:comment)]).comments.count.should == 1 end end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
judge-2.0.5 | vendor/bundle/ruby/2.1.0/gems/factory_girl-2.6.4/spec/acceptance/nested_attributes_spec.rb |
factory_girl-2.6.4 | spec/acceptance/nested_attributes_spec.rb |