mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Only call railtie when Rails is defined; assume controller loaded
Isolated Testing - Rake test inspired by https://github.com/rails/rails/blob/v5.0.0.beta1/activejob/Rakefile - Isolated unit inspired by - https://github.com/rails/rails/blob/v5.0.0.beta1/railties/test/isolation/abstract_unit.rb - https://github.com/rails/rails/blob/v5.0.0.beta1/activemodel/test/cases/railtie_test.rb Misc - Turns out `mattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }` was always nil until the Railtie was loaded, since mattr_accessor block defaults don't really work on modules, but on the classes that include them. - Commented on important on Rails being required first for caching to work. - In isolated tests, `active_support/core_ext/object/with_options` is required.
This commit is contained in:
27
Rakefile
27
Rakefile
@@ -44,7 +44,32 @@ Rake::TestTask.new do |t|
|
||||
t.verbose = true
|
||||
end
|
||||
|
||||
task default: [:test, :rubocop]
|
||||
desc 'Run isolated tests'
|
||||
task isolated: ['test:isolated:railtie']
|
||||
namespace :test do
|
||||
namespace :isolated do
|
||||
desc 'Run isolated tests for Railtie'
|
||||
task :railtie do
|
||||
dir = File.dirname(__FILE__)
|
||||
file = "#{dir}/test/active_model_serializers/railtie_test_isolated.rb"
|
||||
|
||||
# https://github.com/rails/rails/blob/3d590add45/railties/lib/rails/generators/app_base.rb#L345-L363
|
||||
_bundle_command = Gem.bin_path('bundler', 'bundle')
|
||||
require 'bundler'
|
||||
Bundler.with_clean_env do
|
||||
command = "-w -I#{dir}/lib -I#{dir}/test #{file}"
|
||||
full_command = %("#{Gem.ruby}" #{command})
|
||||
system(full_command) or fail 'Failures' # rubocop:disable Style/AndOr
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if ENV['RAILS_VERSION'].to_s > '4.0' && RUBY_ENGINE == 'ruby'
|
||||
task default: [:isolated, :test, :rubocop]
|
||||
else
|
||||
task default: [:test, :rubocop]
|
||||
end
|
||||
|
||||
desc 'CI test task'
|
||||
task :ci => [:default]
|
||||
|
||||
Reference in New Issue
Block a user