Skip to content

Commit

Permalink
Change tests against all scope to base scope as all is now used as a …
Browse files Browse the repository at this point in the history
…finder alias
  • Loading branch information
dhh committed Apr 30, 2008
1 parent 1282dda commit 874603c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
28 changes: 14 additions & 14 deletions activerecord/test/cases/named_scope_test.rb
Expand Up @@ -11,15 +11,15 @@ class NamedScopeTest < ActiveRecord::TestCase
def test_implements_enumerable
assert !Topic.find(:all).empty?

assert_equal Topic.find(:all), Topic.all
assert_equal Topic.find(:all), Topic.all.to_a
assert_equal Topic.find(:first), Topic.all.first
assert_equal Topic.find(:all), Topic.all.each { |i| i }
assert_equal Topic.find(:all), Topic.base
assert_equal Topic.find(:all), Topic.base.to_a
assert_equal Topic.find(:first), Topic.base.first
assert_equal Topic.find(:all), Topic.base.each { |i| i }
end

def test_found_items_are_cached
Topic.columns
all_posts = Topic.all
all_posts = Topic.base

assert_queries(1) do
all_posts.collect
Expand All @@ -28,7 +28,7 @@ def test_found_items_are_cached
end

def test_reload_expires_cache_of_found_items
all_posts = Topic.all
all_posts = Topic.base
all_posts.inspect

new_post = Topic.create!
Expand All @@ -39,17 +39,17 @@ def test_reload_expires_cache_of_found_items
def test_delegates_finds_and_calculations_to_the_base_class
assert !Topic.find(:all).empty?

assert_equal Topic.find(:all), Topic.all.find(:all)
assert_equal Topic.find(:first), Topic.all.find(:first)
assert_equal Topic.count, Topic.all.count
assert_equal Topic.average(:replies_count), Topic.all.average(:replies_count)
assert_equal Topic.find(:all), Topic.base.find(:all)
assert_equal Topic.find(:first), Topic.base.find(:first)
assert_equal Topic.count, Topic.base.count
assert_equal Topic.average(:replies_count), Topic.base.average(:replies_count)
end

def test_subclasses_inherit_scopes
assert Topic.scopes.include?(:all)
assert Topic.scopes.include?(:base)

assert Reply.scopes.include?(:all)
assert_equal Reply.find(:all), Reply.all
assert Reply.scopes.include?(:base)
assert_equal Reply.find(:all), Reply.base
end

def test_scopes_with_options_limit_finds_to_those_matching_the_criteria_specified
Expand Down Expand Up @@ -104,7 +104,7 @@ def test_has_many_through_associations_have_access_to_named_scopes
def test_active_records_have_scope_named__all__
assert !Topic.find(:all).empty?

assert_equal Topic.find(:all), Topic.all
assert_equal Topic.find(:all), Topic.base
end

def test_active_records_have_scope_named__scoped__
Expand Down
2 changes: 2 additions & 0 deletions activerecord/test/models/reply.rb
@@ -1,6 +1,8 @@
require 'models/topic'

class Reply < Topic
named_scope :base

belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true
has_many :replies, :class_name => "SillyReply", :dependent => :destroy, :foreign_key => "parent_id"

Expand Down
1 change: 1 addition & 0 deletions activerecord/test/models/topic.rb
@@ -1,4 +1,5 @@
class Topic < ActiveRecord::Base
named_scope :base
named_scope :written_before, lambda { |time|
{ :conditions => ['written_on < ?', time] }
}
Expand Down

0 comments on commit 874603c

Please sign in to comment.