diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb index a27e2e7..a167fe5 100644 --- a/activerecord/test/cases/relation_scoping_test.rb +++ b/activerecord/test/cases/relation_scoping_test.rb @@ -322,6 +322,28 @@ class DefaultScopingTest < ActiveRecord::TestCase assert_equal expected, received end + def test_default_scope_with_lambda_chained_with_named_scope_using_order_method + expected = Post.find_all_by_author_id(2) + PostForAuthor.selected_author = 2 + received = PostForAuthor.sorted + assert_equal expected, received + expected = Post.find_all_by_author_id(1) + PostForAuthor.selected_author = 1 + received = PostForAuthor.sorted + assert_equal expected, received + end + + def test_default_scope_with_lambda_chained_with_named_scope_using_order_hash + expected = Post.find_all_by_author_id(2) + PostForAuthor.selected_author = 2 + received = PostForAuthor.also_sorted + assert_equal expected, received + expected = Post.find_all_by_author_id(1) + PostForAuthor.selected_author = 1 + received = PostForAuthor.also_sorted + assert_equal expected, received + end + def test_default_scope_with_thing_that_responds_to_call klass = Class.new(ActiveRecord::Base) do self.table_name = 'posts' diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 61e782f..09e8fee 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -118,4 +118,6 @@ class PostForAuthor < ActiveRecord::Base self.table_name = 'posts' cattr_accessor :selected_author default_scope lambda { where(:author_id => PostForAuthor.selected_author) } + scope :sorted, order( 'posts.author_id ASC' ) + scope :also_sorted, :order => 'posts.author_id ASC' end