Ticket #8976: exists_should_use_count.patch
| File exists_should_use_count.patch, 1.3 kB (added by veader, 1 year ago) |
|---|
-
test/base_test.rb
old new 1704 1704 assert_equal %("#{t.written_on.to_s(:db)}"), t.attribute_for_inspect(:written_on) 1705 1705 assert_equal '"This is some really long content, longer than 50 ch..."', t.attribute_for_inspect(:content) 1706 1706 end 1707 1708 def test_exists_should_work_with_id 1709 t = topics(:first) 1710 assert Topic.exists?(t.id) 1711 end 1712 1713 def test_exists_should_work_with_conditions 1714 t = topics(:first) 1715 assert Topic.exists?(:title => t.title) 1716 end 1717 1718 def test_exists_should_return_false 1719 assert !Topic.exists?(800) 1720 end 1707 1721 1708 1722 private 1709 1723 def assert_readers(model, exceptions) -
lib/active_record/base.rb
old new 447 447 # Person.exists?(:name => "David") 448 448 # Person.exists?(['name LIKE ?', "%#{query}%"]) 449 449 def exists?(id_or_conditions) 450 !find(:first, :conditions => expand_id_conditions(id_or_conditions)).nil?450 count(:conditions => expand_id_conditions(id_or_conditions)) > 0 451 451 rescue ActiveRecord::ActiveRecordError 452 452 false 453 453 end