active_model_serializers/test/support/isolated_unit.rb
Benjamin Fleischer 6a7d864605 Fix CI on 0-10-stable (#2181)
* Loosen pry, pry-byebug depencency

```
Resolving dependencies...
byebug-9.1.0 requires ruby version >= 2.2.0, which is
incompatible with the current version, ruby 2.1.10p492
```

* Adjust nokogiri version constraint for CI

Update appveyor Ruby to 2.3 to work around:

```
Gem::InstallError: nokogiri requires Ruby version < 2.5, >= 2.2.

An error occurred while installing nokogiri (1.8.0), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.8.0'` succeeds before bundling.
```

and not 2.4 since:

https://ci.appveyor.com/project/bf4/active-model-serializers/build/1.0.1052-fix_ci/job/0q3itabsnvnxr83u

```
nokogiri-1.6.8.1-x86-mingw32 requires ruby version < 2.4, which is incompatible with the current version, ruby 2.4.1p111
```

* Include rails gem in Gemfile

(For Rails5)

In Rails5, checking for Rails::Railtie is better

* Rails5 test env requires Rails.application.class.name

rails-42d09f6b49da/railties/lib/rails/application.rb

```ruby
def secret_key_base
  if Rails.env.test? || Rails.env.development?
  Digest::MD5.hexdigest self.class.name
```

* Reformat exclude matrix to be easier to read

* Simplify jruby-travis config per rails/rails

* Organize .travis.yml per rails/rails

* Allow JRuby failure on Rails 5+; try rails-5 db adapter branch

https://github.com/jruby/activerecord-jdbc-adapter/issues/708

```
uninitialized constant ActiveRecord::ConnectionAdapters::Column::Format
```

see https://travis-ci.org/rails-api/active_model_serializers/jobs/277112008
2017-09-19 05:27:02 -04:00

85 lines
2.5 KiB
Ruby

# https://github.com/rails/rails/blob/v5.0.0.beta1/railties/test/isolation/abstract_unit.rb
# Usage Example:
#
# require 'support/isolated_unit'
#
# class RailtieTest < ActiveSupport::TestCase
# include ActiveSupport::Testing::Isolation
#
# class WithRailsDefinedOnLoad < RailtieTest
# setup do
# require 'rails'
# require 'active_model_serializers'
# make_basic_app
# end
#
# # some tests
# end
#
# class WithoutRailsDefinedOnLoad < RailtieTest
# setup do
# require 'active_model_serializers'
# make_basic_app
# end
#
# # some tests
# end
# end
#
# Note:
# It is important to keep this file as light as possible
# the goal for tests that require this is to test booting up
# rails from an empty state, so anything added here could
# hide potential failures
#
# It is also good to know what is the bare minimum to get
# Rails booted up.
require 'bundler/setup' unless defined?(Bundler)
require 'active_support'
require 'active_support/core_ext/string/access'
# These files do not require any others and are needed
# to run the tests
require 'active_support/testing/autorun'
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
require 'rails'
require 'action_controller/railtie'
app = Class.new(Rails::Application) do
config.eager_load = false
config.session_store :cookie_store, key: '_myapp_session'
config.active_support.deprecation = :log
config.active_support.test_order = :parallel
ActiveSupport::TestCase.respond_to?(:test_order=) && ActiveSupport::TestCase.test_order = :parallel
config.root = File.dirname(__FILE__)
config.log_level = :info
# Set a fake logger to avoid creating the log directory automatically
fake_logger = Logger.new(nil)
config.logger = fake_logger
Rails.application.routes.default_url_options = { host: 'example.com' }
end
def app.name; 'IsolatedRailsApp'; end # rubocop:disable Style/SingleLineMethods
app.respond_to?(:secrets) && app.secrets.secret_key_base = '3b7cd727ee24e8444053437c36cc66c4'
@app = app
yield @app if block_given?
@app.initialize!
end
end
end
module ActiveSupport
class TestCase
include TestHelpers::Generation
end
end