File: test_helper.rb

package info (click to toggle)
ruby-active-model-serializers 0.10.8-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,692 kB
  • sloc: ruby: 12,915; sh: 53; makefile: 10
file content (70 lines) | stat: -rw-r--r-- 1,821 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Configure Rails Environment
ENV['RAILS_ENV'] = 'test'
#require 'bundler/setup'

begin
  require 'simplecov'
  AppCoverage.start
rescue LoadError
  STDERR.puts 'Running without SimpleCov'
end

require 'pry'
require 'timecop'
require 'rails'
require 'action_controller'
require 'action_controller/test_case'
require 'action_controller/railtie'
require 'active_model_serializers'
# For now, we only restrict the options to serializable_hash/as_json/to_json
# in tests, to ensure developers don't add any unsupported options.
# There's no known benefit, at this time, to having the filtering run in
# production when the excluded options would simply not be used.
#
# However, for documentation purposes, the constant
# ActiveModel::Serializer::SERIALIZABLE_HASH_VALID_KEYS is defined
# in the Serializer.
ActiveModelSerializers::Adapter::Base.class_eval do
  alias_method :original_serialization_options, :serialization_options

  def serialization_options(options)
    original_serialization_options(options)
      .slice(*ActiveModel::Serializer::SERIALIZABLE_HASH_VALID_KEYS)
  end
end
require 'fileutils'
FileUtils.mkdir_p(File.expand_path('../../tmp/cache', __FILE__))

gem 'minitest'
require 'minitest'
require 'minitest/autorun'
Minitest.backtrace_filter = Minitest::BacktraceFilter.new

module TestHelper
  module_function

  def silence_warnings
    original_verbose = $VERBOSE
    $VERBOSE = nil
    yield
  ensure
    $VERBOSE = original_verbose
  end
end

require 'support/rails_app'

# require "rails/test_help"

require 'support/serialization_testing'

require 'support/rails5_shims'

require 'fixtures/active_record'

require 'fixtures/poro'

ActiveSupport.on_load(:action_controller) do
  $action_controller_logger = ActiveModelSerializers.logger
  ActiveModelSerializers.logger = Logger.new(IO::NULL)
end