From 88d6ef72c35485756b5243c75259b05b0ceaabcc Mon Sep 17 00:00:00 2001 From: Yaroslav Markin Date: Mon, 16 Mar 2009 21:55:30 +0300 Subject: [PATCH] Failing tests for default_scope vs named_scope/scoped --- activerecord/test/cases/named_scope_test.rb | 8 ++++++++ activerecord/test/models/topic.rb | 6 +++++- 2 files changed, 13 insertions(+), 1 deletions(-) diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index ae6a54a..b7d3b1b 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -319,6 +319,14 @@ class NamedScopeTest < ActiveRecord::TestCase assert_equal [posts(:sti_comments)], Post.with_special_comments.with_post(4).all.uniq end + def test_chaining_named_scope_should_work_with_default_scope + assert_equal Topic.find(4), Topic.ordered_by_author_name.first + end + + def test_chaining_scoped_should_work_with_default_scope + assert_equal Topic.find(4), Topic.scoped(:order => "author_name ASC").first + end + def test_methods_invoked_within_scopes_should_respect_scope assert_equal [], Topic.approved.by_rejected_ids.proxy_options[:conditions][:id] end diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb index 51012d2..499fbbe 100644 --- a/activerecord/test/models/topic.rb +++ b/activerecord/test/models/topic.rb @@ -1,4 +1,6 @@ class Topic < ActiveRecord::Base + default_scope :order => "topics.title ASC" + named_scope :base named_scope :written_before, lambda { |time| if time @@ -9,6 +11,8 @@ class Topic < ActiveRecord::Base named_scope :rejected, :conditions => {:approved => false} named_scope :by_lifo, :conditions => {:author_name => 'lifo'} + + named_scope :ordered_by_author_name, :order => "author_name ASC" named_scope :approved_as_hash_condition, :conditions => {:topics => {:approved => true}} named_scope 'approved_as_string', :conditions => {:approved => true} @@ -78,4 +82,4 @@ module Web class Topic < ActiveRecord::Base has_many :replies, :dependent => :destroy, :foreign_key => "parent_id", :class_name => 'Web::Reply' end -end \ No newline at end of file +end -- 1.5.6.3