test/editor/test_helper.rb in ecrire-0.23.0 vs test/editor/test_helper.rb in ecrire-0.24.0

- old
+ new

@@ -1,30 +1,34 @@ -require 'rails/all' -require 'ecrire' -require 'rails/test_help' - class ActiveSupport::TestCase - ActiveSupport.test_order = :sorted - self.fixture_path = "#{Dir.pwd}/test/fixtures" - fixtures :all + begin + # ActiveRecord's configuration assignation is done at the same time as the connection is tried + # If it fails, the configurations aren't set in AR::Base. + # This is why this is set here + ActiveRecord::Base.configurations = Rails.application.config.database_configuration - # Need to quick boot an instance of Ecrire to check if a user - # exists. It creates a new user if none exists so the editor can be launched - pid = fork do - Dir.chdir Dir.pwd + '/test/themes/template' do - Ecrire::Application.initialize! - ::User.first_or_create!(email: 'test@test.ca', password: 123456) - + path = Rails.application.paths['db/migrate'].existent + ActiveRecord::Migrator.migrations_paths = path + if ActiveRecord::Migrator.needs_migration? + ActiveRecord::Migrator.migrate(path) end - exit! + rescue ActiveRecord::NoDatabaseError + puts 'Database does not exist. Creating...' + ActiveRecord::Tasks::DatabaseTasks.create_current + puts 'Database created, migrating now...' + ActiveRecord::Migrator.migrate(path) + puts "Migration completed." + ensure + ActiveRecord::Migration.maintain_test_schema! + include ActiveRecord::TestFixtures + self.fixture_path = "#{Dir.pwd}/test/fixtures/" + fixtures :all + Post.reset_column_information end - Process.wait2(pid) - Dir.chdir Dir.pwd + '/test/themes/template' do - Ecrire::Application.initialize! - Rails.application.secrets['s3'] ||= {} - end +end - include Warden::Test::Helpers +ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path +def create_fixtures(*fixture_set_names, &block) + FixtureSet.create_fixtures(ActiveSupport::TestCase.fixture_path, fixture_set_names, {}, &block) end