diff --git a/test/support/isolated_unit.rb b/test/support/isolated_unit.rb index 34f18661..d1d18eb6 100644 --- a/test/support/isolated_unit.rb +++ b/test/support/isolated_unit.rb @@ -46,6 +46,8 @@ require 'active_support/testing/isolation' module TestHelpers module Generation + module_function + # Make a very basic app, without creating the whole directory structure. # Is faster and simpler than generating a Rails app in a temp directory def make_basic_app diff --git a/test/support/rails_app.rb b/test/support/rails_app.rb index 7f74e4ba..bc2fc8d1 100644 --- a/test/support/rails_app.rb +++ b/test/support/rails_app.rb @@ -1,27 +1,34 @@ -class ActiveModelSerializers::RailsApplication < Rails::Application - if Rails::VERSION::MAJOR >= 4 - config.eager_load = false +require 'support/isolated_unit' +module ActiveModelSerializers + RailsApplication = TestHelpers::Generation.make_basic_app do |app| + app.configure do + config.secret_key_base = 'abc123' + config.active_support.test_order = :random + config.action_controller.perform_caching = true + ActionController::Base.cache_store = :memory_store + end - config.secret_key_base = 'abc123' - - config.active_support.test_order = :random - - config.logger = Logger.new(nil) - - config.action_controller.perform_caching = true - ActionController::Base.cache_store = :memory_store - - Rails.application.routes.default_url_options = { host: 'example.com' } + app.routes.default_url_options = { host: 'example.com' } end end -ActiveModelSerializers::RailsApplication.initialize! -module TestHelper - Routes = ActionDispatch::Routing::RouteSet.new - Routes.draw do - get ':controller(/:action(/:id))' - get ':controller(/:action)' +Routes = ActionDispatch::Routing::RouteSet.new +Routes.draw do + get ':controller(/:action(/:id))' + get ':controller(/:action)' +end +ActionController::Base.send :include, Routes.url_helpers +ActionController::TestCase.class_eval do + def setup + @routes = Routes end - ActionController::Base.send :include, Routes.url_helpers + # For Rails5 + # https://github.com/rails/rails/commit/ca83436d1b3b6cedd1eca2259f65661e69b01909#diff-b9bbf56e85d3fe1999f16317f2751e76L17 + def assigns(key = nil) + warn "DEPRECATION: Calling 'assigns(#{key})' from #{caller[0]}" + assigns = {}.with_indifferent_access + @controller.view_assigns.each { |k, v| assigns.regular_writer(k, v) } + key.nil? ? assigns : assigns[key] + end end diff --git a/test/support/test_case.rb b/test/support/test_case.rb deleted file mode 100644 index 8f1afe79..00000000 --- a/test/support/test_case.rb +++ /dev/null @@ -1,19 +0,0 @@ -ActionController::TestCase.class_eval do - def setup - @routes = TestHelper::Routes - end - - # For Rails5 - # https://github.com/rails/rails/commit/ca83436d1b3b6cedd1eca2259f65661e69b01909#diff-b9bbf56e85d3fe1999f16317f2751e76L17 - def assigns(key = nil) - assigns = {}.with_indifferent_access - @controller.view_assigns.each { |k, v| assigns.regular_writer(k, v) } - key.nil? ? assigns : assigns[key] - end - - # Rails5: Uncomment for debugging where the warnings come from - # def non_kwarg_request_warning - # super - # STDOUT.puts caller[2..3] - # end -end diff --git a/test/test_helper.rb b/test/test_helper.rb index 687bf0da..d0eba205 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -39,8 +39,6 @@ end require 'support/rails_app' -require 'support/test_case' - require 'support/serialization_testing' require 'support/rails5_shims'