diff options
author | Prem Sichanugrist <s@sikachu.com> | 2011-07-17 22:49:04 -0400 |
---|---|---|
committer | Prem Sichanugrist <s@sikachu.com> | 2011-07-18 00:37:06 -0400 |
commit | 4443905169b54845090b7f8f863dfc820513e469 (patch) | |
tree | ba196b756af1123df56fc16cbd98dea53fd18eed /activerecord/test | |
parent | 1ccca1b9cb4c360b6d9784663da542df34ed3773 (diff) | |
download | rails-4443905169b54845090b7f8f863dfc820513e469.tar.gz rails-4443905169b54845090b7f8f863dfc820513e469.tar.bz2 rails-4443905169b54845090b7f8f863dfc820513e469.zip |
Refactor test case to use anonymous class - Thank you @tenderlove
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/named_scope_test.rb | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index 01893e4dc3..ed0240cada 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -498,28 +498,23 @@ class DynamicScopeTest < ActiveRecord::TestCase fixtures :posts def setup - # Ensure we start with a clean model with no generated class method - Post.methods.select{ |c| c =~ /scoped_by_/ }.each do |method_name| - Post.class_eval <<-RUBY - class << self - remove_method :#{method_name} - end - RUBY + @test_klass = Class.new(Post) do + def self.name; "Post"; end end end def test_dynamic_scope - assert_equal Post.scoped_by_author_id(1).find(1), Post.find(1) - assert_equal Post.scoped_by_author_id_and_title(1, "Welcome to the weblog").first, Post.find(:first, :conditions => { :author_id => 1, :title => "Welcome to the weblog"}) + assert_equal @test_klass.scoped_by_author_id(1).find(1), @test_klass.find(1) + assert_equal @test_klass.scoped_by_author_id_and_title(1, "Welcome to the weblog").first, @test_klass.find(:first, :conditions => { :author_id => 1, :title => "Welcome to the weblog"}) end def test_dynamic_scope_should_create_methods_after_hitting_method_missing - assert_blank Developer.methods.grep(/scoped_by_created_at/) - Developer.scoped_by_created_at(nil) - assert_present Developer.methods.grep(/scoped_by_created_at/) + assert_blank @test_klass.methods.grep(/scoped_by_type/) + @test_klass.scoped_by_type(nil) + assert_present @test_klass.methods.grep(/scoped_by_type/) end def test_dynamic_scope_with_less_number_of_arguments - assert_raise(ArgumentError){ Post.scoped_by_author_id_and_title(1) } + assert_raise(ArgumentError){ @test_klass.scoped_by_author_id_and_title(1) } end end |