From 06185eec6245ef598e96f74a736eb2815c572abd Mon Sep 17 00:00:00 2001 From: Erik Andrejko Date: Mon, 16 Mar 2009 08:25:51 -0500 Subject: [PATCH] added failing tests --- activerecord/test/cases/method_scoping_test.rb | 10 ++++++++++ activerecord/test/cases/named_scope_test.rb | 14 ++++++++++++++ activerecord/test/fixtures/monks.yml | 16 ++++++++++++++++ activerecord/test/models/monk.rb | 10 ++++++++++ activerecord/test/schema/schema.rb | 6 ++++++ 5 files changed, 56 insertions(+), 0 deletions(-) create mode 100644 activerecord/test/fixtures/monks.yml create mode 100644 activerecord/test/models/monk.rb diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb index 3c34cde..3efc9ed 100644 --- a/activerecord/test/cases/method_scoping_test.rb +++ b/activerecord/test/cases/method_scoping_test.rb @@ -5,6 +5,7 @@ require 'models/project' require 'models/comment' require 'models/post' require 'models/category' +require 'models/monk' class MethodScopingTest < ActiveRecord::TestCase fixtures :authors, :developers, :projects, :comments, :posts, :developers_projects @@ -526,6 +527,15 @@ class NestedScopingTest < ActiveRecord::TestCase assert_equal 1, scoped_authors.size assert_equal authors(:david).attributes, scoped_authors.first.attributes end + + def test_scoping_with_multiple_order + expected = Monk.find(:all, :order => "birth_year, first_name").map{|m| m.full_name} + options = {:order => "birth_year"} + Monk.with_scope(:find => options) do + assert_equal expected, Monk.find(:all, :order => "first_name").map{|m| m.full_name} + end + end + end class HasManyScopingTest< ActiveRecord::TestCase diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index ae6a54a..76234eb 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -5,6 +5,7 @@ require 'models/comment' require 'models/reply' require 'models/author' require 'models/developer' +require 'models/monk' class NamedScopeTest < ActiveRecord::TestCase fixtures :posts, :authors, :topics, :comments, :author_addresses @@ -336,6 +337,19 @@ class NamedScopeTest < ActiveRecord::TestCase end end end + + def test_single_named_scope_overrides_default_scope_order + expected = Monk.find(:all, :order => "last_name asc").collect {|m| m.id} + received = Monk.by_last_name.collect {|m| m.id} + assert_equal expected, received + end + + def test_nested_scopes_orders_combined + expected = Monk.find(:all, :order => "last_name asc, first_name asc").collect {|m| m.last_name + ", " + m.first_name} + received = Monk.by_last_name.by_first_name.collect {|m| m.last_name + ", " + m.first_name} + assert_equal expected, received + end + end class DynamicScopeMatchTest < ActiveRecord::TestCase diff --git a/activerecord/test/fixtures/monks.yml b/activerecord/test/fixtures/monks.yml new file mode 100644 index 0000000..fe92a68 --- /dev/null +++ b/activerecord/test/fixtures/monks.yml @@ -0,0 +1,16 @@ +baabot: + first_name: Baker + last_name: Aabot + birth_year: 1958 +aaabot: + first_name: Abel + last_name: Aabot + birth_year: 1960 +caabot: + first_name: Cain + last_name: Aabot + birth_year: 1960 +daabot: + first_name: Damous + last_name: Aabot + birth_year: 1963 diff --git a/activerecord/test/models/monk.rb b/activerecord/test/models/monk.rb new file mode 100644 index 0000000..c401880 --- /dev/null +++ b/activerecord/test/models/monk.rb @@ -0,0 +1,10 @@ +class Monk < ActiveRecord::Base + default_scope :order => "birth_year desc" + named_scope :by_last_name, :order => "last_name asc" + named_scope :by_first_name, :order => "first_name asc" + named_scope :by_birth_year, :order => "birth-year asc" + + def full_name + "#{last_name}, #{first_name}" + end +end \ No newline at end of file diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index ea848a2..79b920a 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -229,6 +229,12 @@ ActiveRecord::Schema.define do t.string :name end + create_table :monks, :force => true do |t| + t.string :first_name + t.string :last_name + t.string :birth_year + end + create_table :references, :force => true do |t| t.integer :person_id t.integer :job_id -- 1.5.5.1