Skip to content

Commit b89553c

Browse files
author
Francesco Rodriguez
committed
Add tests to delete by fixnum or string id with has many through associations
1 parent 8795ac5 commit b89553c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

activerecord/test/cases/associations/join_model_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,26 @@ def test_deleting_junk_from_has_many_through_should_raise_type_mismatch
581581
assert_raise(ActiveRecord::AssociationTypeMismatch) { posts(:thinking).tags.delete(Object.new) }
582582
end
583583

584+
def test_deleting_by_fixnum_id_from_has_many_through
585+
post = posts(:thinking)
586+
587+
assert_difference 'post.tags.count', -1 do
588+
assert_equal 1, post.tags.delete(1).size
589+
end
590+
591+
assert_equal 0, post.tags.size
592+
end
593+
594+
def test_deleting_by_string_id_from_has_many_through
595+
post = posts(:thinking)
596+
597+
assert_difference 'post.tags.count', -1 do
598+
assert_equal 1, post.tags.delete('1').size
599+
end
600+
601+
assert_equal 0, post.tags.size
602+
end
603+
584604
def test_has_many_through_sum_uses_calculations
585605
assert_nothing_raised { authors(:david).comments.sum(:post_id) }
586606
end

0 commit comments

Comments
 (0)