Skip to content

Commit

Permalink
Ensure AssociationCollection#size considers all unsaved record. [#305
Browse files Browse the repository at this point in the history
…state:resolved] [sds]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
lifo committed Jul 2, 2008
1 parent 7378e23 commit 474d425
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Expand Up @@ -187,7 +187,7 @@ def size
if @owner.new_record? || (loaded? && !@reflection.options[:uniq])
@target.size
elsif !loaded? && !@reflection.options[:uniq] && @target.is_a?(Array)
unsaved_records = Array(@target.detect { |r| r.new_record? })
unsaved_records = @target.select { |r| r.new_record? }
unsaved_records.size + count_records
else
count_records
Expand Down
Expand Up @@ -384,6 +384,13 @@ def test_build
assert_equal 2, company.clients_of_firm(true).size
end

def test_collection_size_after_building
company = companies(:first_firm) # company already has one client
company.clients_of_firm.build("name" => "Another Client")
company.clients_of_firm.build("name" => "Yet Another Client")
assert_equal 3, company.clients_of_firm.size
end

def test_build_many
company = companies(:first_firm)
new_clients = assert_no_queries { company.clients_of_firm.build([{"name" => "Another Client"}, {"name" => "Another Client II"}]) }
Expand Down

0 comments on commit 474d425

Please sign in to comment.