2017-12-10 23:05:11 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-30 00:58:26 -04:00
|
|
|
ENV["RAILS_ENV"] ||= "test"
|
|
|
|
ENV["DB"] ||= "sqlite"
|
|
|
|
|
2017-10-27 11:42:43 -04:00
|
|
|
require "byebug"
|
|
|
|
|
2017-06-10 01:28:48 -04:00
|
|
|
unless File.exist?(File.expand_path("dummy_app/config/database.yml", __dir__))
|
2018-05-29 18:26:19 -04:00
|
|
|
warn "No database.yml detected for the dummy app, please run `rake prepare` first"
|
2017-05-30 00:58:26 -04:00
|
|
|
end
|
|
|
|
|
2013-04-10 13:58:39 -04:00
|
|
|
RSpec.configure do |config|
|
2018-02-25 21:40:46 -05:00
|
|
|
config.example_status_persistence_file_path = ".rspec_results"
|
2014-10-09 15:04:17 -04:00
|
|
|
config.expect_with :rspec do |expectations|
|
|
|
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
|
|
end
|
|
|
|
config.mock_with :rspec do |mocks|
|
|
|
|
mocks.verify_partial_doubles = true
|
|
|
|
end
|
2017-05-21 01:41:20 -04:00
|
|
|
config.filter_run :focus
|
|
|
|
config.run_all_when_everything_filtered = true
|
|
|
|
config.disable_monkey_patching!
|
2017-05-21 01:29:58 -04:00
|
|
|
config.warnings = false
|
2017-05-21 01:41:20 -04:00
|
|
|
if config.files_to_run.one?
|
|
|
|
config.default_formatter = "doc"
|
|
|
|
end
|
2017-05-21 01:47:53 -04:00
|
|
|
config.order = :random
|
|
|
|
Kernel.srand config.seed
|
2013-04-10 13:58:39 -04:00
|
|
|
end
|
2016-01-11 22:07:57 -05:00
|
|
|
|
2016-02-15 18:27:57 -05:00
|
|
|
def active_record_gem_version
|
|
|
|
Gem::Version.new(ActiveRecord::VERSION::STRING)
|
|
|
|
end
|
|
|
|
|
2016-01-11 22:07:57 -05:00
|
|
|
# Wrap args in a hash to support the ActionController::TestCase and
|
|
|
|
# ActionDispatch::Integration HTTP request method switch to keyword args
|
|
|
|
# (see https://github.com/rails/rails/blob/master/actionpack/CHANGELOG.md)
|
|
|
|
def params_wrapper(args)
|
2016-03-05 17:07:32 -05:00
|
|
|
if defined?(::Rails) && active_record_gem_version >= Gem::Version.new("5.0.0.beta1")
|
2016-01-11 22:07:57 -05:00
|
|
|
{ params: args }
|
|
|
|
else
|
|
|
|
args
|
|
|
|
end
|
2016-02-15 18:27:57 -05:00
|
|
|
end
|
2017-05-30 00:58:26 -04:00
|
|
|
|
2018-03-27 18:32:52 -04:00
|
|
|
require File.expand_path("dummy_app/config/environment", __dir__)
|
2017-05-30 00:58:26 -04:00
|
|
|
require "rspec/rails"
|
|
|
|
require "paper_trail/frameworks/rspec"
|
|
|
|
require "ffaker"
|
|
|
|
|
2018-03-23 19:37:47 -04:00
|
|
|
# Migrate
|
|
|
|
require_relative "support/paper_trail_spec_migrator"
|
|
|
|
::PaperTrailSpecMigrator.
|
|
|
|
new(::File.expand_path("dummy_app/db/migrate/", __dir__)).
|
|
|
|
migrate
|
2017-05-30 00:58:26 -04:00
|
|
|
|
|
|
|
RSpec.configure do |config|
|
|
|
|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
2017-12-20 22:47:55 -05:00
|
|
|
end
|
2017-05-30 00:58:26 -04:00
|
|
|
|
2017-12-20 22:47:55 -05:00
|
|
|
# In rails < 5, some tests seem to require DatabaseCleaner-truncation.
|
|
|
|
# Truncation is about three times slower than transaction rollback, so it'll
|
|
|
|
# be nice when we can drop support for rails < 5.
|
|
|
|
if active_record_gem_version < ::Gem::Version.new("5")
|
|
|
|
require "database_cleaner"
|
|
|
|
DatabaseCleaner.strategy = :truncation
|
|
|
|
RSpec.configure do |config|
|
|
|
|
config.use_transactional_fixtures = false
|
2017-09-18 23:56:07 -04:00
|
|
|
config.before { DatabaseCleaner.start }
|
|
|
|
config.after { DatabaseCleaner.clean }
|
2017-05-30 00:58:26 -04:00
|
|
|
end
|
2017-12-20 22:47:55 -05:00
|
|
|
else
|
|
|
|
RSpec.configure do |config|
|
|
|
|
config.use_transactional_fixtures = true
|
|
|
|
end
|
2017-05-30 00:58:26 -04:00
|
|
|
end
|