2014-04-09 21:11:13 +00:00
ENV [ " RAILS_ENV " ] = " test "
2014-02-13 16:41:50 +00:00
require 'simplecov'
2013-12-17 19:44:21 +00:00
require 'support/utilities'
2014-05-16 19:39:37 +00:00
require 'support/profile'
2014-07-20 02:11:16 +00:00
require 'support/maxmind'
2016-04-06 02:23:15 +00:00
require 'support/lesson_session'
2012-08-06 03:01:00 +00:00
require 'active_record'
2021-02-01 17:58:25 +00:00
#require 'jam_db'
2012-08-06 03:01:00 +00:00
require 'spec_db'
2013-02-13 01:56:40 +00:00
require 'uses_temp_files'
2014-01-11 04:57:07 +00:00
require 'resque_spec'
require 'resque_failed_job_mailer'
2016-04-06 02:23:15 +00:00
require 'stripe_mock'
2021-03-24 13:17:16 +00:00
require 'webmock/rspec'
2012-08-06 03:01:00 +00:00
2021-02-01 17:58:25 +00:00
2015-01-01 02:39:22 +00:00
# to prevent embedded resque code from forking
ENV [ 'FORK_PER_JOB' ] = 'false'
2015-07-20 17:56:47 +00:00
IS_BUILD_SERVER = ! ENV [ 'BUILD_SERVER' ] . nil?
2015-01-01 02:39:22 +00:00
2012-08-06 03:01:00 +00:00
# recreate test database and migrate it
2021-02-01 17:58:25 +00:00
#SpecDb::recreate_database
JamRuby :: TestSupport . recreate_database if ENV [ 'SKIP_DB_PREP' ] . nil?
2012-10-21 01:55:49 +00:00
2012-08-06 03:01:00 +00:00
# initialize ActiveRecord's db connection
ActiveRecord :: Base . establish_connection ( YAML :: load ( File . open ( 'config/database.yml' ) ) [ " test " ] )
2016-07-17 15:16:27 +00:00
ActiveRecord :: Base . raise_in_transactional_callbacks = true
2012-08-06 03:01:00 +00:00
2014-02-24 16:55:56 +00:00
# so jam_ruby models that use APP_CONFIG in metadata will load. this is later stubbed pre test run
APP_CONFIG = app_config
2012-08-06 03:01:00 +00:00
require 'jam_ruby'
require 'factory_girl'
require 'rubygems'
require 'spork'
require 'database_cleaner'
2012-08-18 18:48:43 +00:00
require 'factories'
2012-08-06 03:01:00 +00:00
2014-04-08 17:15:49 +00:00
require 'timecop'
require 'resque_spec/scheduler'
2013-07-03 01:11:04 +00:00
# uncomment this to see active record logs
2016-06-02 14:04:56 +00:00
# ActiveRecord::Base.logger = Logger.new(STDOUT) if defined?(ActiveRecord::Base)
2013-07-03 01:11:04 +00:00
2012-08-06 03:01:00 +00:00
include JamRuby
2013-03-15 04:22:31 +00:00
# manually register observers
ActiveRecord :: Base . add_observer InvitedUserObserver . instance
2013-05-10 12:10:33 +00:00
ActiveRecord :: Base . add_observer UserObserver . instance
2013-08-10 20:35:54 +00:00
ActiveRecord :: Base . add_observer FeedbackObserver . instance
2013-12-17 19:44:21 +00:00
ActiveRecord :: Base . add_observer RecordedTrackObserver . instance
2015-02-16 04:01:06 +00:00
ActiveRecord :: Base . add_observer RecordedBackingTrackObserver . instance
2014-10-23 04:10:49 +00:00
ActiveRecord :: Base . add_observer QuickMixObserver . instance
2013-05-10 12:10:33 +00:00
2014-04-09 21:11:13 +00:00
#RecordedTrack.observers.disable :all # only a few tests want this observer active
2012-08-06 03:01:00 +00:00
2012-11-11 01:07:17 +00:00
# put ActionMailer into test mode
ActionMailer :: Base . delivery_method = :test
2013-02-13 01:56:40 +00:00
# set up carrierwave to use file (instead of say, fog) for testing
CarrierWave . configure do | config |
config . storage = :file
config . enable_processing = false
end
2016-04-06 02:23:15 +00:00
Stripe . api_key = " sk_test_OkjoIF7FmdjunyNsdVqJD02D "
2018-04-21 16:33:18 +00:00
Recurly :: API . net_http = {
ssl_version : :TLSv1_2 ,
#...
}
2012-08-06 03:01:00 +00:00
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'
2014-07-20 02:11:16 +00:00
#Spork.prefork do
2012-08-06 03:01:00 +00:00
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
2014-01-25 20:03:14 +00:00
# This file is copied to spec/ when you run 'rails generate rspec:install'
2012-08-06 03:01:00 +00:00
#ENV["RAILS_ENV"] ||= 'test'
#require File.expand_path("../../config/environment", __FILE__)
require 'rspec/autorun'
#require 'rspec/rails'
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# Require this file using `require "spec_helper"` to ensure that it is only
# loaded once.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec . configure do | config |
2014-03-09 13:38:46 +00:00
2014-02-20 07:45:51 +00:00
config . color_enabled = true
2012-08-06 03:01:00 +00:00
config . treat_symbols_as_metadata_keys_with_true_values = true
config . run_all_when_everything_filtered = true
config . filter_run :focus
2015-07-20 17:56:47 +00:00
#config.formatter = :documentation
2015-07-15 17:12:29 +00:00
2013-06-24 21:31:40 +00:00
# you can mark a test as slow so that developers won't commonly hit it, but build server will http://blog.davidchelimsky.net/2010/06/14/filtering-examples-in-rspec-2/
2014-01-11 04:57:07 +00:00
config . filter_run_excluding slow : true unless run_tests? :slow
config . filter_run_excluding aws : true unless run_tests? :aws
2015-07-20 17:56:47 +00:00
config . filter_run_excluding intermittent : true if IS_BUILD_SERVER
2013-06-24 21:31:40 +00:00
2012-08-06 03:01:00 +00:00
config . before ( :suite ) do
2014-07-20 02:11:16 +00:00
DatabaseCleaner . strategy = :transaction
2016-04-06 02:23:15 +00:00
DatabaseCleaner . clean_with ( :deletion , { pre_count : true , reset_ids : false , :except = > %w[ gift_card_types lesson_package_types instruments languages subjects genres icecast_server_groups jamcompany jamisp geoipblocks geoipisp geoiplocations cities regions countries generic_state spatial_ref_sys ] } )
2012-08-06 03:01:00 +00:00
end
2014-07-20 02:35:48 +00:00
config . around ( :each ) do | example |
# set no_transaction: true as metadata on your test to use deletion strategy instead
if example . metadata [ :no_transaction ]
2016-04-06 02:23:15 +00:00
DatabaseCleaner . strategy = :deletion , { pre_count : true , reset_ids : false , :except = > %w[ gift_card_types lesson_package_types instruments languages subjects genres icecast_server_groups jamcompany jamisp geoipblocks geoipisp geoiplocations cities regions countries generic_state spatial_ref_sys ] }
2014-07-20 02:35:48 +00:00
else
DatabaseCleaner . strategy = :transaction
end
DatabaseCleaner . start
2021-02-15 04:32:27 +00:00
WebMock . allow_net_connect!
2014-07-20 02:35:48 +00:00
example . run
end
2012-08-06 03:01:00 +00:00
config . before ( :each ) do
2014-01-19 02:20:44 +00:00
stub_const ( " APP_CONFIG " , app_config )
2012-08-06 03:01:00 +00:00
end
config . after ( :each ) do
2016-05-23 17:26:32 +00:00
Timecop . return
2012-08-06 03:01:00 +00:00
DatabaseCleaner . clean
end
2014-01-07 19:40:26 +00:00
config . after ( :suite ) do
wipe_s3_test_bucket
end
2012-08-06 03:01:00 +00:00
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
#config.use_transactional_fixtures = true
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config . order = 'random'
2014-03-09 13:38:46 +00:00
REDIS_PID = " #{ Rails . root } /tmp/pids/redis-test.pid "
REDIS_CACHE_PATH = " #{ Rails . root } /tmp/cache/ "
config . before ( :suite ) do
redis_options = {
2014-04-08 17:15:49 +00:00
" --daemonize " = > 'yes' ,
" --pidfile " = > REDIS_PID ,
" --port " = > 9736 ,
" --timeout " = > 300 ,
" --save 900 " = > 1 ,
" --save 300 " = > 1 ,
" --save 60 " = > 10000 ,
" --dbfilename " = > " dump.rdb " ,
" --dir " = > REDIS_CACHE_PATH ,
" --loglevel " = > " debug " ,
" --logfile " = > " stdout " ,
" --databases " = > 16
} . map { | k , v | " #{ k } #{ v } " } . join ( " " )
` redis-server #{ redis_options } `
2014-03-09 13:38:46 +00:00
end
config . after ( :suite ) do
%x{
cat #{REDIS_PID} | xargs kill -QUIT
rm - f #{REDIS_CACHE_PATH}dump.rdb
}
end
2012-08-06 03:01:00 +00:00
end
2014-07-20 02:11:16 +00:00
#end
2012-08-06 03:01:00 +00:00
2014-07-20 02:11:16 +00:00
#Spork.each_run do
2012-08-06 03:01:00 +00:00
# This code will be run each time you run your specs.
2014-07-20 02:11:16 +00:00
#end