Skip to content

Commit 874b8ca

Browse files
author
Yohan Robert
committed
Merge pull request #1630 from bf4/cleanup_test_app
Clean up test app
2 parents 355e0f6 + ff8c6f9 commit 874b8ca

File tree

4 files changed

+29
-41
lines changed

4 files changed

+29
-41
lines changed

test/support/isolated_unit.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646

4747
module TestHelpers
4848
module Generation
49+
module_function
50+
4951
# Make a very basic app, without creating the whole directory structure.
5052
# Is faster and simpler than generating a Rails app in a temp directory
5153
def make_basic_app

test/support/rails_app.rb

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
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
410

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' }
1512
end
1613
end
17-
ActiveModelSerializers::RailsApplication.initialize!
1814

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
2424
end
2525

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
2734
end

test/support/test_case.rb

Lines changed: 0 additions & 19 deletions
This file was deleted.

test/test_helper.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939

4040
require 'support/rails_app'
4141

42-
require 'support/test_case'
43-
4442
require 'support/serialization_testing'
4543

4644
require 'support/rails5_shims'

0 commit comments

Comments
 (0)