aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/finder_test.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-02-06 02:25:55 +0000
committerPratik Naik <pratiknaik@gmail.com>2009-02-06 02:25:55 +0000
commitb9ba2fe55059a6d9f141d1d502e16bdfd46f26cb (patch)
tree491c3ce7d406a723e5c06e3bccf4559a0de86199 /activerecord/test/cases/finder_test.rb
parent97612394672203eefd04e3b1947273a3ab4ec930 (diff)
parent96d610553e5fdaabc923835ab1f194070ddb4477 (diff)
downloadrails-b9ba2fe55059a6d9f141d1d502e16bdfd46f26cb.tar.gz
rails-b9ba2fe55059a6d9f141d1d502e16bdfd46f26cb.tar.bz2
rails-b9ba2fe55059a6d9f141d1d502e16bdfd46f26cb.zip
Merge commit 'mainstream/master'
Conflicts: railties/guides/files/javascripts/code_highlighter.js railties/guides/files/javascripts/guides.js railties/guides/files/javascripts/highlighters.js railties/guides/files/stylesheets/main.css railties/guides/files/stylesheets/print.css railties/guides/files/stylesheets/reset.css railties/guides/files/stylesheets/style.css railties/guides/files/stylesheets/syntax.css railties/guides/rails_guides/indexer.rb railties/guides/source/2_2_release_notes.textile railties/guides/source/2_3_release_notes.textile railties/guides/source/action_controller_overview.textile railties/guides/source/action_mailer_basics.textile railties/guides/source/active_record_basics.textile railties/guides/source/activerecord_validations_callbacks.textile railties/guides/source/association_basics.textile railties/guides/source/caching_with_rails.textile railties/guides/source/command_line.textile railties/guides/source/debugging_rails_applications.textile railties/guides/source/form_helpers.textile railties/guides/source/getting_started.textile railties/guides/source/i18n.textile railties/guides/source/layout.html.erb railties/guides/source/layouts_and_rendering.textile railties/guides/source/migrations.textile railties/guides/source/performance_testing.textile railties/guides/source/plugins.textile railties/guides/source/rails_on_rack.textile railties/guides/source/routing.textile railties/guides/source/security.textile railties/guides/source/testing.textile
Diffstat (limited to 'activerecord/test/cases/finder_test.rb')
-rw-r--r--activerecord/test/cases/finder_test.rb39
1 files changed, 26 insertions, 13 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index d4d770b04e..ee8f4901f9 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -94,7 +94,16 @@ class FinderTest < ActiveRecord::TestCase
assert_raise(NoMethodError) { Topic.exists?([1,2]) }
end
-
+
+ def test_exists_returns_true_with_one_record_and_no_args
+ assert Topic.exists?
+ end
+
+ def test_does_not_exist_with_empty_table_and_no_args_given
+ Topic.delete_all
+ assert !Topic.exists?
+ end
+
def test_exists_with_aggregate_having_three_mappings
existing_address = customers(:david).address
assert Customer.exists?(:address => existing_address)
@@ -298,6 +307,12 @@ class FinderTest < ActiveRecord::TestCase
assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1, :conditions => { :id => 2..3 }) }
end
+ def test_find_on_hash_conditions_with_end_exclusive_range
+ assert_equal [1,2,3], Topic.find(:all, :conditions => { :id => 1..3 }).map(&:id).sort
+ assert_equal [1,2], Topic.find(:all, :conditions => { :id => 1...3 }).map(&:id).sort
+ assert_raises(ActiveRecord::RecordNotFound) { Topic.find(3, :conditions => { :id => 2...3 }) }
+ end
+
def test_find_on_hash_conditions_with_multiple_ranges
assert_equal [1,2,3], Comment.find(:all, :conditions => { :id => 1..3, :post_id => 1..2 }).map(&:id).sort
assert_equal [1], Comment.find(:all, :conditions => { :id => 1..1, :post_id => 1..10 }).map(&:id).sort
@@ -507,21 +522,19 @@ class FinderTest < ActiveRecord::TestCase
assert_equal(2, Entrant.count_by_sql(["SELECT COUNT(*) FROM entrants WHERE id > ?", 1]))
end
- uses_mocha('test_dynamic_finder_should_go_through_the_find_class_method') do
- def test_dynamic_finders_should_go_through_the_find_class_method
- Topic.expects(:find).with(:first, :conditions => { :title => 'The First Topic!' })
- Topic.find_by_title("The First Topic!")
+ def test_dynamic_finders_should_go_through_the_find_class_method
+ Topic.expects(:find).with(:first, :conditions => { :title => 'The First Topic!' })
+ Topic.find_by_title("The First Topic!")
- Topic.expects(:find).with(:last, :conditions => { :title => 'The Last Topic!' })
- Topic.find_last_by_title("The Last Topic!")
+ Topic.expects(:find).with(:last, :conditions => { :title => 'The Last Topic!' })
+ Topic.find_last_by_title("The Last Topic!")
- Topic.expects(:find).with(:all, :conditions => { :title => 'A Topic.' })
- Topic.find_all_by_title("A Topic.")
+ Topic.expects(:find).with(:all, :conditions => { :title => 'A Topic.' })
+ Topic.find_all_by_title("A Topic.")
- Topic.expects(:find).with(:first, :conditions => { :title => 'Does not exist yet for sure!' }).times(2)
- Topic.find_or_initialize_by_title('Does not exist yet for sure!')
- Topic.find_or_create_by_title('Does not exist yet for sure!')
- end
+ Topic.expects(:find).with(:first, :conditions => { :title => 'Does not exist yet for sure!' }).times(2)
+ Topic.find_or_initialize_by_title('Does not exist yet for sure!')
+ Topic.find_or_create_by_title('Does not exist yet for sure!')
end
def test_find_by_one_attribute