aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/loading_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test/application/loading_test.rb')
-rw-r--r--railties/test/application/loading_test.rb64
1 files changed, 52 insertions, 12 deletions
diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb
index 457e81e174..e0286502f3 100644
--- a/railties/test/application/loading_test.rb
+++ b/railties/test/application/loading_test.rb
@@ -20,6 +20,7 @@ class LoadingTest < ActiveSupport::TestCase
app_file "app/models/post.rb", <<-MODEL
class Post < ActiveRecord::Base
validates_acceptance_of :title, :accept => "omg"
+ attr_accessible :title
end
MODEL
@@ -63,7 +64,7 @@ class LoadingTest < ActiveSupport::TestCase
assert ::AppTemplate::Application.config.loaded
end
- test "descendants are cleaned on each request without cache classes" do
+ test "descendants loaded after framework initialization are cleaned on each request without cache classes" do
add_to_config <<-RUBY
config.cache_classes = false
config.reload_classes_only_on_change = false
@@ -76,8 +77,8 @@ class LoadingTest < ActiveSupport::TestCase
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do
- match '/load', :to => lambda { |env| [200, {}, Post.all] }
- match '/unload', :to => lambda { |env| [200, {}, []] }
+ get '/load', :to => lambda { |env| [200, {}, Post.all] }
+ get '/unload', :to => lambda { |env| [200, {}, []] }
end
RUBY
@@ -87,14 +88,14 @@ class LoadingTest < ActiveSupport::TestCase
require "#{rails_root}/config/environment"
setup_ar!
- assert_equal [], ActiveRecord::Base.descendants
+ assert_equal [ActiveRecord::SchemaMigration], ActiveRecord::Base.descendants
get "/load"
- assert_equal [Post], ActiveRecord::Base.descendants
+ assert_equal [ActiveRecord::SchemaMigration, Post], ActiveRecord::Base.descendants
get "/unload"
- assert_equal [], ActiveRecord::Base.descendants
+ assert_equal [ActiveRecord::SchemaMigration], ActiveRecord::Base.descendants
end
- test "initialize_cant_be_called_twice" do
+ test "initialize cant be called twice" do
require "#{app_path}/config/environment"
assert_raise(RuntimeError) { ::AppTemplate::Application.initialize! }
end
@@ -106,7 +107,7 @@ class LoadingTest < ActiveSupport::TestCase
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do
- match '/c', :to => lambda { |env| [200, {"Content-Type" => "text/plain"}, [User.counter.to_s]] }
+ get '/c', :to => lambda { |env| [200, {"Content-Type" => "text/plain"}, [User.counter.to_s]] }
end
RUBY
@@ -145,7 +146,7 @@ class LoadingTest < ActiveSupport::TestCase
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do
- match '/c', :to => lambda { |env| [200, {"Content-Type" => "text/plain"}, [User.counter.to_s]] }
+ get '/c', :to => lambda { |env| [200, {"Content-Type" => "text/plain"}, [User.counter.to_s]] }
end
RUBY
@@ -181,7 +182,7 @@ class LoadingTest < ActiveSupport::TestCase
app_file 'config/routes.rb', <<-RUBY
$counter = 0
AppTemplate::Application.routes.draw do
- match '/c', :to => lambda { |env| User; [200, {"Content-Type" => "text/plain"}, [$counter.to_s]] }
+ get '/c', :to => lambda { |env| User; [200, {"Content-Type" => "text/plain"}, [$counter.to_s]] }
end
RUBY
@@ -212,8 +213,8 @@ class LoadingTest < ActiveSupport::TestCase
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do
- match '/title', :to => lambda { |env| [200, {"Content-Type" => "text/plain"}, [Post.new.title]] }
- match '/body', :to => lambda { |env| [200, {"Content-Type" => "text/plain"}, [Post.new.body]] }
+ get '/title', :to => lambda { |env| [200, {"Content-Type" => "text/plain"}, [Post.new.title]] }
+ get '/body', :to => lambda { |env| [200, {"Content-Type" => "text/plain"}, [Post.new.body]] }
end
RUBY
@@ -255,6 +256,45 @@ class LoadingTest < ActiveSupport::TestCase
assert_equal "BODY", last_response.body
end
+ test "AC load hooks can be used with metal" do
+ app_file "app/controllers/omg_controller.rb", <<-RUBY
+ begin
+ class OmgController < ActionController::Metal
+ ActiveSupport.run_load_hooks(:action_controller, self)
+ def show
+ self.response_body = ["OK"]
+ end
+ end
+ rescue => e
+ puts "Error loading metal: \#{e.class} \#{e.message}"
+ end
+ RUBY
+
+ app_file "config/routes.rb", <<-RUBY
+ AppTemplate::Application.routes.draw do
+ get "/:controller(/:action)"
+ end
+ RUBY
+
+ require "#{rails_root}/config/environment"
+
+ require 'rack/test'
+ extend Rack::Test::Methods
+
+ get '/omg/show'
+ assert_equal 'OK', last_response.body
+ end
+
+ def test_initialize_can_be_called_at_any_time
+ require "#{app_path}/config/application"
+
+ assert !Rails.initialized?
+ assert !AppTemplate::Application.initialized?
+ Rails.initialize!
+ assert Rails.initialized?
+ assert AppTemplate::Application.initialized?
+ end
+
protected
def setup_ar!