|
1 | | -class ActiveModelSerializers::RailsApplication < Rails::Application |
2 | | - if Rails::VERSION::MAJOR >= 4 |
3 | | - config.eager_load = false |
| 1 | +require 'support/isolated_unit' |
| 2 | +module ActiveModelSerializers |
| 3 | + RailsApplication = TestHelpers::Generation.make_basic_app do |app| |
| 4 | + app.configure do |
| 5 | + config.secret_key_base = 'abc123' |
| 6 | + config.active_support.test_order = :random |
| 7 | + config.action_controller.perform_caching = true |
| 8 | + ActionController::Base.cache_store = :memory_store |
| 9 | + end |
4 | 10 |
|
5 | | - config.secret_key_base = 'abc123' |
6 | | - |
7 | | - config.active_support.test_order = :random |
8 | | - |
9 | | - config.logger = Logger.new(nil) |
10 | | - |
11 | | - config.action_controller.perform_caching = true |
12 | | - ActionController::Base.cache_store = :memory_store |
13 | | - |
14 | | - Rails.application.routes.default_url_options = { host: 'example.com' } |
| 11 | + app.routes.default_url_options = { host: 'example.com' } |
15 | 12 | end |
16 | 13 | end |
17 | | -ActiveModelSerializers::RailsApplication.initialize! |
18 | 14 |
|
19 | | -module TestHelper |
20 | | - Routes = ActionDispatch::Routing::RouteSet.new |
21 | | - Routes.draw do |
22 | | - get ':controller(/:action(/:id))' |
23 | | - get ':controller(/:action)' |
| 15 | +Routes = ActionDispatch::Routing::RouteSet.new |
| 16 | +Routes.draw do |
| 17 | + get ':controller(/:action(/:id))' |
| 18 | + get ':controller(/:action)' |
| 19 | +end |
| 20 | +ActionController::Base.send :include, Routes.url_helpers |
| 21 | +ActionController::TestCase.class_eval do |
| 22 | + def setup |
| 23 | + @routes = Routes |
24 | 24 | end |
25 | 25 |
|
26 | | - ActionController::Base.send :include, Routes.url_helpers |
| 26 | + # For Rails5 |
| 27 | + # https://github.com/rails/rails/commit/ca83436d1b3b6cedd1eca2259f65661e69b01909#diff-b9bbf56e85d3fe1999f16317f2751e76L17 |
| 28 | + def assigns(key = nil) |
| 29 | + warn "DEPRECATION: Calling 'assigns(#{key})' from #{caller[0]}" |
| 30 | + assigns = {}.with_indifferent_access |
| 31 | + @controller.view_assigns.each { |k, v| assigns.regular_writer(k, v) } |
| 32 | + key.nil? ? assigns : assigns[key] |
| 33 | + end |
27 | 34 | end |
0 commit comments