2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "isolation/abstract_unit"
|
2010-06-19 11:51:29 -04:00
|
|
|
|
2012-01-05 20:30:17 -05:00
|
|
|
class LoadingTest < ActiveSupport::TestCase
|
2010-06-19 11:51:29 -04:00
|
|
|
include ActiveSupport::Testing::Isolation
|
|
|
|
|
|
|
|
def setup
|
|
|
|
build_app
|
|
|
|
end
|
|
|
|
|
2011-06-05 15:25:24 -04:00
|
|
|
def teardown
|
2011-06-06 08:54:05 -04:00
|
|
|
teardown_app
|
2011-06-05 15:25:24 -04:00
|
|
|
end
|
|
|
|
|
2010-06-19 11:51:29 -04:00
|
|
|
def app
|
|
|
|
@app ||= Rails.application
|
|
|
|
end
|
|
|
|
|
2011-12-13 03:19:58 -05:00
|
|
|
test "constants in app are autoloaded" do
|
2010-06-19 11:51:29 -04:00
|
|
|
app_file "app/models/post.rb", <<-MODEL
|
|
|
|
class Post < ActiveRecord::Base
|
2012-10-14 06:03:39 -04:00
|
|
|
validates_acceptance_of :title, accept: "omg"
|
2010-06-19 11:51:29 -04:00
|
|
|
end
|
|
|
|
MODEL
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2010-06-19 11:51:29 -04:00
|
|
|
require "#{rails_root}/config/environment"
|
|
|
|
setup_ar!
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
p = Post.create(title: "omg")
|
2010-06-19 11:51:29 -04:00
|
|
|
assert_equal 1, Post.count
|
2016-08-06 13:16:09 -04:00
|
|
|
assert_equal "omg", p.title
|
2010-06-19 11:51:29 -04:00
|
|
|
p = Post.first
|
2016-08-06 13:16:09 -04:00
|
|
|
assert_equal "omg", p.title
|
2010-06-19 11:51:29 -04:00
|
|
|
end
|
|
|
|
|
2019-02-18 14:06:28 -05:00
|
|
|
test "constants without a matching file raise NameError" do
|
|
|
|
app_file "app/models/post.rb", <<-RUBY
|
|
|
|
class Post
|
|
|
|
NON_EXISTING_CONSTANT
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
boot_app
|
|
|
|
|
|
|
|
e = assert_raise(NameError) { User }
|
|
|
|
assert_equal "uninitialized constant #{self.class}::User", e.message
|
|
|
|
|
|
|
|
e = assert_raise(NameError) { Post }
|
|
|
|
assert_equal "uninitialized constant Post::NON_EXISTING_CONSTANT", e.message
|
|
|
|
end
|
|
|
|
|
2014-12-26 12:29:53 -05:00
|
|
|
test "concerns in app are autoloaded" do
|
|
|
|
app_file "app/controllers/concerns/trackable.rb", <<-CONCERN
|
|
|
|
module Trackable
|
|
|
|
end
|
|
|
|
CONCERN
|
|
|
|
|
|
|
|
app_file "app/mailers/concerns/email_loggable.rb", <<-CONCERN
|
|
|
|
module EmailLoggable
|
|
|
|
end
|
|
|
|
CONCERN
|
|
|
|
|
|
|
|
app_file "app/models/concerns/orderable.rb", <<-CONCERN
|
|
|
|
module Orderable
|
|
|
|
end
|
|
|
|
CONCERN
|
|
|
|
|
|
|
|
app_file "app/validators/concerns/matchable.rb", <<-CONCERN
|
|
|
|
module Matchable
|
|
|
|
end
|
|
|
|
CONCERN
|
|
|
|
|
|
|
|
require "#{rails_root}/config/environment"
|
|
|
|
|
2016-02-19 23:05:49 -05:00
|
|
|
assert_nothing_raised { Trackable }
|
|
|
|
assert_nothing_raised { EmailLoggable }
|
|
|
|
assert_nothing_raised { Orderable }
|
|
|
|
assert_nothing_raised { Matchable }
|
2014-12-26 12:29:53 -05:00
|
|
|
end
|
|
|
|
|
2011-12-13 03:19:58 -05:00
|
|
|
test "models without table do not panic on scope definitions when loaded" do
|
2010-06-29 13:47:04 -04:00
|
|
|
app_file "app/models/user.rb", <<-MODEL
|
|
|
|
class User < ActiveRecord::Base
|
2013-07-01 23:24:51 -04:00
|
|
|
default_scope { where(published: true) }
|
2010-06-29 13:47:04 -04:00
|
|
|
end
|
|
|
|
MODEL
|
|
|
|
|
|
|
|
require "#{rails_root}/config/environment"
|
|
|
|
setup_ar!
|
|
|
|
|
|
|
|
User
|
|
|
|
end
|
|
|
|
|
2010-07-18 17:23:54 -04:00
|
|
|
test "load config/environments/environment before Bootstrap initializers" do
|
|
|
|
app_file "config/environments/development.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.configure do
|
2010-07-18 17:23:54 -04:00
|
|
|
config.development_environment_loaded = true
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.before_initialize do
|
|
|
|
config.loaded = config.development_environment_loaded
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
require "#{app_path}/config/environment"
|
2013-06-03 23:57:01 -04:00
|
|
|
assert ::Rails.application.config.loaded
|
2010-07-18 17:23:54 -04:00
|
|
|
end
|
|
|
|
|
2012-01-15 10:37:46 -05:00
|
|
|
test "descendants loaded after framework initialization are cleaned on each request without cache classes" do
|
2010-06-19 11:51:29 -04:00
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.cache_classes = false
|
2011-12-12 16:51:33 -05:00
|
|
|
config.reload_classes_only_on_change = false
|
2010-06-19 11:51:29 -04:00
|
|
|
RUBY
|
|
|
|
|
|
|
|
app_file "app/models/post.rb", <<-MODEL
|
2019-06-03 15:58:22 -04:00
|
|
|
class Post < ApplicationRecord
|
2010-06-19 11:51:29 -04:00
|
|
|
end
|
|
|
|
MODEL
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-10-14 06:03:39 -04:00
|
|
|
get '/load', to: lambda { |env| [200, {}, Post.all] }
|
|
|
|
get '/unload', to: lambda { |env| [200, {}, []] }
|
2010-06-19 11:51:29 -04:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "rack/test"
|
2010-06-19 11:51:29 -04:00
|
|
|
extend Rack::Test::Methods
|
|
|
|
|
|
|
|
require "#{rails_root}/config/environment"
|
|
|
|
setup_ar!
|
|
|
|
|
2019-05-30 08:25:05 -04:00
|
|
|
initial = [ActiveStorage::Blob, ActiveStorage::Attachment, ActiveRecord::SchemaMigration, ActiveRecord::InternalMetadata, ApplicationRecord, "primary::SchemaMigration"].collect(&:to_s).sort
|
|
|
|
assert_equal initial, ActiveRecord::Base.descendants.collect(&:to_s).sort
|
2010-06-19 11:51:29 -04:00
|
|
|
get "/load"
|
2019-05-30 08:25:05 -04:00
|
|
|
assert_equal [Post].collect(&:to_s).sort, ActiveRecord::Base.descendants.collect(&:to_s).sort - initial
|
2010-06-19 11:51:29 -04:00
|
|
|
get "/unload"
|
2019-05-30 08:25:05 -04:00
|
|
|
assert_equal ["ActiveRecord::InternalMetadata", "ActiveRecord::SchemaMigration", "primary::SchemaMigration"], ActiveRecord::Base.descendants.collect(&:to_s).sort.uniq
|
2010-06-19 11:51:29 -04:00
|
|
|
end
|
|
|
|
|
2012-03-15 03:48:38 -04:00
|
|
|
test "initialize cant be called twice" do
|
2010-07-22 06:07:45 -04:00
|
|
|
require "#{app_path}/config/environment"
|
2013-06-03 23:57:01 -04:00
|
|
|
assert_raise(RuntimeError) { Rails.application.initialize! }
|
2010-07-22 06:07:45 -04:00
|
|
|
end
|
|
|
|
|
2011-12-13 03:19:58 -05:00
|
|
|
test "reload constants on development" do
|
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.cache_classes = false
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-10-14 06:03:39 -04:00
|
|
|
get '/c', to: lambda { |env| [200, {"Content-Type" => "text/plain"}, [User.counter.to_s]] }
|
2011-12-13 03:19:58 -05:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
app_file "app/models/user.rb", <<-MODEL
|
|
|
|
class User
|
|
|
|
def self.counter; 1; end
|
|
|
|
end
|
|
|
|
MODEL
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "rack/test"
|
2011-12-13 03:19:58 -05:00
|
|
|
extend Rack::Test::Methods
|
|
|
|
|
|
|
|
require "#{rails_root}/config/environment"
|
|
|
|
|
|
|
|
get "/c"
|
|
|
|
assert_equal "1", last_response.body
|
|
|
|
|
|
|
|
app_file "app/models/user.rb", <<-MODEL
|
|
|
|
class User
|
|
|
|
def self.counter; 2; end
|
|
|
|
end
|
|
|
|
MODEL
|
|
|
|
|
|
|
|
get "/c"
|
|
|
|
assert_equal "2", last_response.body
|
|
|
|
end
|
|
|
|
|
|
|
|
test "does not reload constants on development if custom file watcher always returns false" do
|
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.cache_classes = false
|
|
|
|
config.file_watcher = Class.new do
|
|
|
|
def initialize(*); end
|
|
|
|
def updated?; false; end
|
2015-12-02 14:00:01 -05:00
|
|
|
def execute; end
|
|
|
|
def execute_if_updated; false; end
|
2011-12-13 03:19:58 -05:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-10-14 06:03:39 -04:00
|
|
|
get '/c', to: lambda { |env| [200, {"Content-Type" => "text/plain"}, [User.counter.to_s]] }
|
2011-12-13 03:19:58 -05:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
app_file "app/models/user.rb", <<-MODEL
|
|
|
|
class User
|
|
|
|
def self.counter; 1; end
|
|
|
|
end
|
|
|
|
MODEL
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "rack/test"
|
2011-12-13 03:19:58 -05:00
|
|
|
extend Rack::Test::Methods
|
|
|
|
|
|
|
|
require "#{rails_root}/config/environment"
|
|
|
|
|
|
|
|
get "/c"
|
|
|
|
assert_equal "1", last_response.body
|
|
|
|
|
|
|
|
app_file "app/models/user.rb", <<-MODEL
|
|
|
|
class User
|
|
|
|
def self.counter; 2; end
|
|
|
|
end
|
|
|
|
MODEL
|
|
|
|
|
|
|
|
get "/c"
|
|
|
|
assert_equal "1", last_response.body
|
|
|
|
end
|
|
|
|
|
2011-12-15 12:48:10 -05:00
|
|
|
test "added files (like db/schema.rb) also trigger reloading" do
|
2011-12-13 05:23:21 -05:00
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.cache_classes = false
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-06 17:04:26 -04:00
|
|
|
$counter ||= 0
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2015-05-05 00:18:32 -04:00
|
|
|
get '/c', to: lambda { |env| User.name; [200, {"Content-Type" => "text/plain"}, [$counter.to_s]] }
|
2011-12-13 05:23:21 -05:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
app_file "app/models/user.rb", <<-MODEL
|
|
|
|
class User
|
|
|
|
$counter += 1
|
|
|
|
end
|
|
|
|
MODEL
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "rack/test"
|
2011-12-13 05:23:21 -05:00
|
|
|
extend Rack::Test::Methods
|
|
|
|
|
|
|
|
require "#{rails_root}/config/environment"
|
|
|
|
|
|
|
|
get "/c"
|
|
|
|
assert_equal "1", last_response.body
|
|
|
|
|
|
|
|
app_file "db/schema.rb", ""
|
|
|
|
|
|
|
|
get "/c"
|
|
|
|
assert_equal "2", last_response.body
|
|
|
|
end
|
|
|
|
|
2013-06-06 17:04:26 -04:00
|
|
|
test "dependencies reloading is followed by routes reloading" do
|
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.cache_classes = false
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-06 17:04:26 -04:00
|
|
|
$counter ||= 1
|
|
|
|
$counter *= 2
|
2013-06-09 22:47:07 -04:00
|
|
|
Rails.application.routes.draw do
|
2015-05-05 00:18:32 -04:00
|
|
|
get '/c', to: lambda { |env| User.name; [200, {"Content-Type" => "text/plain"}, [$counter.to_s]] }
|
2013-06-06 17:04:26 -04:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
app_file "app/models/user.rb", <<-MODEL
|
|
|
|
class User
|
|
|
|
$counter += 1
|
|
|
|
end
|
|
|
|
MODEL
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "rack/test"
|
2013-06-06 17:04:26 -04:00
|
|
|
extend Rack::Test::Methods
|
|
|
|
|
|
|
|
require "#{rails_root}/config/environment"
|
|
|
|
|
|
|
|
get "/c"
|
|
|
|
assert_equal "3", last_response.body
|
|
|
|
|
|
|
|
app_file "db/schema.rb", ""
|
|
|
|
|
|
|
|
get "/c"
|
|
|
|
assert_equal "7", last_response.body
|
|
|
|
end
|
|
|
|
|
2011-12-15 12:48:10 -05:00
|
|
|
test "columns migrations also trigger reloading" do
|
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.cache_classes = false
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-10-14 06:03:39 -04:00
|
|
|
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]] }
|
2011-12-15 12:48:10 -05:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
app_file "app/models/post.rb", <<-MODEL
|
|
|
|
class Post < ActiveRecord::Base
|
|
|
|
end
|
|
|
|
MODEL
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "rack/test"
|
2011-12-15 12:48:10 -05:00
|
|
|
extend Rack::Test::Methods
|
|
|
|
|
|
|
|
app_file "db/migrate/1_create_posts.rb", <<-MIGRATION
|
2015-12-05 15:14:22 -05:00
|
|
|
class CreatePosts < ActiveRecord::Migration::Current
|
2011-12-15 12:48:10 -05:00
|
|
|
def change
|
|
|
|
create_table :posts do |t|
|
2012-10-14 06:03:39 -04:00
|
|
|
t.string :title, default: "TITLE"
|
2011-12-15 12:48:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
MIGRATION
|
|
|
|
|
2017-09-14 05:28:57 -04:00
|
|
|
rails("db:migrate")
|
2011-12-15 12:48:10 -05:00
|
|
|
require "#{rails_root}/config/environment"
|
|
|
|
|
|
|
|
get "/title"
|
|
|
|
assert_equal "TITLE", last_response.body
|
|
|
|
|
|
|
|
app_file "db/migrate/2_add_body_to_posts.rb", <<-MIGRATION
|
2015-12-05 15:14:22 -05:00
|
|
|
class AddBodyToPosts < ActiveRecord::Migration::Current
|
2011-12-15 12:48:10 -05:00
|
|
|
def change
|
2012-10-14 06:03:39 -04:00
|
|
|
add_column :posts, :body, :text, default: "BODY"
|
2011-12-15 12:48:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
MIGRATION
|
|
|
|
|
2017-09-14 05:28:57 -04:00
|
|
|
rails("db:migrate")
|
2011-12-15 12:48:10 -05:00
|
|
|
|
|
|
|
get "/body"
|
|
|
|
assert_equal "BODY", last_response.body
|
|
|
|
end
|
|
|
|
|
2012-03-15 03:48:38 -04:00
|
|
|
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
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-04-24 23:32:09 -04:00
|
|
|
get "/:controller(/:action)"
|
2012-03-15 03:48:38 -04:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
require "#{rails_root}/config/environment"
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "rack/test"
|
2012-03-15 03:48:38 -04:00
|
|
|
extend Rack::Test::Methods
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/omg/show"
|
|
|
|
assert_equal "OK", last_response.body
|
2012-03-15 03:48:38 -04:00
|
|
|
end
|
|
|
|
|
2011-08-15 04:11:11 -04:00
|
|
|
def test_initialize_can_be_called_at_any_time
|
|
|
|
require "#{app_path}/config/application"
|
|
|
|
|
2018-01-25 18:14:09 -05:00
|
|
|
assert_not_predicate Rails, :initialized?
|
|
|
|
assert_not_predicate Rails.application, :initialized?
|
2011-08-15 04:11:11 -04:00
|
|
|
Rails.initialize!
|
2018-01-25 18:14:09 -05:00
|
|
|
assert_predicate Rails, :initialized?
|
|
|
|
assert_predicate Rails.application, :initialized?
|
2011-08-15 04:11:11 -04:00
|
|
|
end
|
|
|
|
|
2018-02-24 19:54:27 -05:00
|
|
|
test "frameworks aren't loaded during initialization" do
|
|
|
|
app_file "config/initializers/raise_when_frameworks_load.rb", <<-RUBY
|
|
|
|
%i(action_controller action_mailer active_job active_record).each do |framework|
|
|
|
|
ActiveSupport.on_load(framework) { raise "\#{framework} loaded!" }
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
assert_nothing_raised do
|
|
|
|
require "#{app_path}/config/environment"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-12 20:57:52 -04:00
|
|
|
test "active record query cache hooks are installed before first request in production" do
|
2018-09-12 10:09:59 -04:00
|
|
|
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
|
|
|
|
|
2018-09-12 20:57:52 -04:00
|
|
|
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"
|
2018-09-12 10:09:59 -04:00
|
|
|
|
|
|
|
require "rack/test"
|
|
|
|
extend Rack::Test::Methods
|
|
|
|
|
|
|
|
get "/omg/show"
|
|
|
|
assert_equal "Query cache is enabled.", last_response.body
|
|
|
|
end
|
|
|
|
|
2016-12-23 09:45:39 -05:00
|
|
|
private
|
2016-08-06 13:55:02 -04:00
|
|
|
def setup_ar!
|
|
|
|
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
|
|
|
|
ActiveRecord::Migration.verbose = false
|
|
|
|
ActiveRecord::Schema.define(version: 1) do
|
|
|
|
create_table :posts do |t|
|
|
|
|
t.string :title
|
|
|
|
end
|
2010-06-19 11:51:29 -04:00
|
|
|
end
|
|
|
|
end
|
2018-09-12 20:57:52 -04:00
|
|
|
|
|
|
|
def boot_app(env = "development")
|
|
|
|
ENV["RAILS_ENV"] = env
|
|
|
|
|
|
|
|
require "#{app_path}/config/environment"
|
|
|
|
ensure
|
|
|
|
ENV.delete "RAILS_ENV"
|
|
|
|
end
|
2010-06-19 11:51:29 -04:00
|
|
|
end
|