From 67582f08bf86ec71a27363554bc550e929a007f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 29 Jun 2010 19:47:04 +0200 Subject: [PATCH] Push a failing test for issues [#4994] and [#5003]. --- activerecord/test/cases/named_scope_test.rb | 6 ++++++ activerecord/test/models/without_table.rb | 3 +++ railties/test/application/loading_test.rb | 15 ++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 activerecord/test/models/without_table.rb diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index 6574e4cfc0..dc85b395d3 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -450,6 +450,12 @@ def test_named_scopes_are_reset_on_association_reload assert before.object_id != post.comments.containing_the_letter_e.object_id, "AssociationCollection##{method} should reset the named scopes cache" end end + + def test_named_scoped_are_lazy_loaded_if_table_still_does_not_exist + assert_nothing_raised do + require "models/without_table" + end + end end class DynamicScopeMatchTest < ActiveRecord::TestCase diff --git a/activerecord/test/models/without_table.rb b/activerecord/test/models/without_table.rb new file mode 100644 index 0000000000..87f80911e1 --- /dev/null +++ b/activerecord/test/models/without_table.rb @@ -0,0 +1,3 @@ +class WithoutTable < ActiveRecord::Base + default_scope where(:published => true) +end \ No newline at end of file diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb index b337d3fc6e..340ce67511 100644 --- a/railties/test/application/loading_test.rb +++ b/railties/test/application/loading_test.rb @@ -12,7 +12,7 @@ def app @app ||= Rails.application end - def test_load_should_load_constants + def test_constants_in_app_are_autoloaded app_file "app/models/post.rb", <<-MODEL class Post < ActiveRecord::Base validates_acceptance_of :title, :accept => "omg" @@ -29,6 +29,19 @@ class Post < ActiveRecord::Base assert_equal 'omg', p.title end + def test_models_without_table_do_not_panic_on_scope_definitions_when_loaded + app_file "app/models/user.rb", <<-MODEL + class User < ActiveRecord::Base + default_scope where(:published => true) + end + MODEL + + require "#{rails_root}/config/environment" + setup_ar! + + User + end + def test_descendants_are_cleaned_on_each_request_without_cache_classes add_to_config <<-RUBY config.cache_classes = false -- GitLab