Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@

ENV['RAILS_ENV'] = 'test'
require 'rails'
ENV['RAILS'] = Rails.version
ENV['RAILS_ROOT'] = File.expand_path("../rails/rails-#{ENV['RAILS']}", __FILE__)

# Create the test app if it doesn't exist
system 'rake setup' unless File.exist?(ENV['RAILS_ROOT'])
require 'fileutils'
require_relative 'support/test_app_paths'
ENV['RAILS_ROOT'] = TestAppPaths.app_root

# Create the test app if it doesn't exist. rails new creates the target
# directory before the template runs, so a template that fails halfway leaves
# the directory behind and every later run would skip regeneration and die on
# config/environment.rb instead of reporting the real error. Check the file the
# suite actually loads, and refuse to continue if the build did not succeed.
unless File.exist?(File.join(ENV['RAILS_ROOT'], 'config', 'environment.rb'))
FileUtils.rm_rf(ENV['RAILS_ROOT'])
abort 'rake setup failed; dummy app not built' unless system('rake setup')
end

require 'active_model'
# require ActiveRecord to ensure that Ransack loads correctly
Expand Down
19 changes: 19 additions & 0 deletions spec/support/test_app_paths.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'rails/version'

# Where the generated dummy app lives, and under what name.
#
# The name has to carry every input that changes what gets generated.
# Keying on the Rails version alone meant `AA=3.2.0 rspec` silently reused an
# app whose active_admin:install had been run by a different Active Admin, so
# the leg reported on a build it never produced.
module TestAppPaths
module_function

def app_dir_name
"rails-#{Rails::VERSION::STRING}-aa#{ENV['AA'] || 'default'}"
end

def app_root
File.expand_path("../rails/#{app_dir_name}", __dir__)
end
end
8 changes: 6 additions & 2 deletions tasks/test.rake
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require_relative '../spec/support/test_app_paths'

desc 'Creates a test rails app for the specs to run against'
task :setup do
require 'rails/version'

rails_new_args = %w[
--skip-turbolinks
Expand All @@ -10,5 +11,8 @@ task :setup do
spec/support/rails_template.rb
].join(' ')

system "bundle exec rails new spec/rails/rails-#{Rails::VERSION::STRING} #{rails_new_args}"
puts "[setup] Rails #{Rails::VERSION::STRING} / Active Admin #{ENV['AA'] || '(Gemfile default)'}"

abort 'rails new failed' unless
system("bundle exec rails new spec/rails/#{TestAppPaths.app_dir_name} #{rails_new_args}")
end
Loading