Permalink
Browse files

Fixed AssociationCollection#<< resulting in unexpected values in @target

 when :uniq => true

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information...
1 parent 06e4eb4 commit 7f6e7ba1f7e8735f1c3f30ba125b5432f00d2a70 @ernie ernie committed with NZKoz Aug 2, 2008
@@ -344,7 +344,7 @@ def add_record_to_target_with_callbacks(record)
callback(:before_add, record)
yield(record) if block_given?
@target ||= [] unless loaded?
- @target << record
+ @target << record unless @reflection.options[:uniq] && @target.include?(record)
callback(:after_add, record)
record
end
@@ -299,6 +299,17 @@ def test_uniq_before_the_fact
assert_equal 3, projects(:active_record, :reload).developers.size
end
+ def test_uniq_option_prevents_duplicate_push
+ project = projects(:active_record)
+ project.developers << developers(:jamis)
+ project.developers << developers(:david)
+ assert_equal 3, project.developers.size
+
+ project.developers << developers(:david)
+ project.developers << developers(:jamis)
+ assert_equal 3, project.developers.size
+ end
+
def test_deleting
david = Developer.find(1)
active_record = Project.find(1)

0 comments on commit 7f6e7ba

Please sign in to comment.