aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2018-09-12 20:57:52 -0400
committerRafael Mendonça França <rafaelmfranca@gmail.com>2018-09-12 20:57:52 -0400
commita8359d837cc0f5ef0237aaf78459ad7dafae1988 (patch)
tree25241cd49aed8d221aa853b1d101db696bdb4364 /railties
parentb79f3cc96bc917d3390105ebea83770dd2934d10 (diff)
downloadrails-a8359d837cc0f5ef0237aaf78459ad7dafae1988.tar.gz
rails-a8359d837cc0f5ef0237aaf78459ad7dafae1988.tar.bz2
rails-a8359d837cc0f5ef0237aaf78459ad7dafae1988.zip
Add a test that exercice better the behavior we expect in the query cache
In production the query cache was already being loaded before the first request even without #33856, so added a test to make sure of it. This new test is passing even if #33856 is reverted.
Diffstat (limited to 'railties')
-rw-r--r--railties/test/application/loading_test.rb45
1 files changed, 43 insertions, 2 deletions
diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb
index d7f4f09665..bfa66770bd 100644
--- a/railties/test/application/loading_test.rb
+++ b/railties/test/application/loading_test.rb
@@ -371,7 +371,7 @@ class LoadingTest < ActiveSupport::TestCase
end
end
- test "active record query cache hooks are installed before first request" do
+ test "active record query cache hooks are installed before first request in production" do
app_file "app/controllers/omg_controller.rb", <<-RUBY
begin
class OmgController < ActionController::Metal
@@ -395,7 +395,40 @@ class LoadingTest < ActiveSupport::TestCase
end
RUBY
- require "#{rails_root}/config/environment"
+ boot_app "production"
+
+ require "rack/test"
+ extend Rack::Test::Methods
+
+ get "/omg/show"
+ assert_equal "Query cache is enabled.", last_response.body
+ end
+
+ test "active record query cache hooks are installed before first request in development" do
+ app_file "app/controllers/omg_controller.rb", <<-RUBY
+ begin
+ class OmgController < ActionController::Metal
+ ActiveSupport.run_load_hooks(:action_controller, self)
+ def show
+ if ActiveRecord::Base.connection.query_cache_enabled
+ self.response_body = ["Query cache is enabled."]
+ else
+ self.response_body = ["Expected ActiveRecord::Base.connection.query_cache_enabled to be true"]
+ end
+ end
+ end
+ rescue => e
+ puts "Error loading metal: \#{e.class} \#{e.message}"
+ end
+ RUBY
+
+ app_file "config/routes.rb", <<-RUBY
+ Rails.application.routes.draw do
+ get "/:controller(/:action)"
+ end
+ RUBY
+
+ boot_app "development"
require "rack/test"
extend Rack::Test::Methods
@@ -415,4 +448,12 @@ class LoadingTest < ActiveSupport::TestCase
end
end
end
+
+ def boot_app(env = "development")
+ ENV["RAILS_ENV"] = env
+
+ require "#{app_path}/config/environment"
+ ensure
+ ENV.delete "RAILS_ENV"
+ end
end