diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2011-03-29 15:08:40 +0100 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2011-03-29 17:21:21 +0100 |
commit | a9dafbb28de3e34c31ebf184fbc4e2042c7ff207 (patch) | |
tree | c203ba38afca1b4d521ef1ce0de513a27f49aa5c /activerecord/test | |
parent | e8d20b858d004e26c3b8c25aae099fce2eca6857 (diff) | |
download | rails-a9dafbb28de3e34c31ebf184fbc4e2042c7ff207.tar.gz rails-a9dafbb28de3e34c31ebf184fbc4e2042c7ff207.tar.bz2 rails-a9dafbb28de3e34c31ebf184fbc4e2042c7ff207.zip |
Delegate first!, last!, any? and many? to scoped
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 16 | ||||
-rw-r--r-- | activerecord/test/cases/named_scope_test.rb | 17 |
2 files changed, 32 insertions, 1 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 316113634b..1ec00b15b2 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -208,6 +208,14 @@ class FinderTest < ActiveRecord::TestCase end end + def test_model_class_responds_to_first_bang + assert_equal topics(:first), Topic.first! + assert_raises ActiveRecord::RecordNotFound do + Topic.delete_all + Topic.first! + end + end + def test_last_bang_present assert_nothing_raised do assert_equal topics(:second), Topic.where("title = 'The Second Topic of the day'").last! @@ -220,6 +228,14 @@ class FinderTest < ActiveRecord::TestCase end end + def test_model_class_responds_to_last_bang + assert_equal topics(:fourth), Topic.last! + assert_raises ActiveRecord::RecordNotFound do + Topic.delete_all + Topic.last! + end + end + def test_unexisting_record_exception_handling assert_raise(ActiveRecord::RecordNotFound) { Topic.find(1).parent diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index fb050c3e52..9b20ea08de 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -64,7 +64,7 @@ class NamedScopeTest < ActiveRecord::TestCase assert Reply.scopes.include?(:base) assert_equal Reply.find(:all), Reply.base end - + def test_classes_dont_inherit_subclasses_scopes assert !ActiveRecord::Base.scopes.include?(:base) end @@ -246,6 +246,12 @@ class NamedScopeTest < ActiveRecord::TestCase assert_no_queries { assert topics.any? } end + def test_model_class_should_respond_to_any + assert Topic.any? + Topic.delete_all + assert !Topic.any? + end + def test_many_should_not_load_results topics = Topic.base assert_queries(2) do @@ -280,6 +286,15 @@ class NamedScopeTest < ActiveRecord::TestCase assert Topic.base.many? end + def test_model_class_should_respond_to_many + Topic.delete_all + assert !Topic.many? + Topic.create! + assert !Topic.many? + Topic.create! + assert Topic.many? + end + def test_should_build_on_top_of_scope topic = Topic.approved.build({}) assert topic.approved |