mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Solve the RAILS_ENV problem in the railties tests in a more generic way
This commit is contained in:
parent
2d3ba54b86
commit
62570e8626
31 changed files with 117 additions and 22 deletions
|
@ -11,6 +11,10 @@ module ApplicationTests
|
|||
boot_rails
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def app
|
||||
@app ||= Rails.application
|
||||
end
|
||||
|
|
|
@ -34,6 +34,10 @@ module ApplicationTests
|
|||
FileUtils.rm_rf("#{app_path}/config/environments")
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def teardown
|
||||
FileUtils.rm_rf(new_app) if File.directory?(new_app)
|
||||
end
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
require 'isolation/abstract_unit'
|
||||
|
||||
class ConsoleTest < Test::Unit::TestCase
|
||||
include ActiveSupport::Testing::Isolation
|
||||
include ActiveSupport::Testing::Isolation
|
||||
|
||||
def setup
|
||||
@prev_rails_env = ENV['RAILS_ENV']
|
||||
ENV['RAILS_ENV'] = 'development'
|
||||
build_app
|
||||
boot_rails
|
||||
end
|
||||
|
||||
def teardown
|
||||
ENV['RAILS_ENV'] = @prev_rails_env
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def load_environment(sandbox = false)
|
||||
|
|
|
@ -9,6 +9,10 @@ module ApplicationTests
|
|||
boot_rails
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def app_const
|
||||
@app_const ||= Class.new(Rails::Application)
|
||||
end
|
||||
|
|
|
@ -9,8 +9,12 @@ module ApplicationTests
|
|||
# boot_rails
|
||||
end
|
||||
|
||||
def teardown
|
||||
# teardown_app
|
||||
end
|
||||
|
||||
test "booting rails sets the load paths correctly" do
|
||||
# This test is pending reworking the boot process
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,6 +9,10 @@ module ApplicationTests
|
|||
boot_rails
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
test "rails initializes with ruby 1.8.7 or later, except for 1.9.1" do
|
||||
if RUBY_VERSION < '1.8.7'
|
||||
assert_rails_does_not_boot
|
||||
|
|
|
@ -5,15 +5,13 @@ module ApplicationTests
|
|||
include ActiveSupport::Testing::Isolation
|
||||
|
||||
def setup
|
||||
@prev_rails_env = ENV['RAILS_ENV']
|
||||
ENV['RAILS_ENV'] = 'development'
|
||||
build_app
|
||||
boot_rails
|
||||
FileUtils.rm_rf "#{app_path}/config/environments"
|
||||
end
|
||||
|
||||
def teardown
|
||||
ENV['RAILS_ENV'] = @prev_rails_env
|
||||
teardown_app
|
||||
end
|
||||
|
||||
# AC & AM
|
||||
|
|
|
@ -10,6 +10,10 @@ module ApplicationTests
|
|||
FileUtils.rm_rf "#{app_path}/config/environments"
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
test "load initializers" do
|
||||
app_file "config/initializers/foo.rb", "$foo = true"
|
||||
require "#{app_path}/config/environment"
|
||||
|
|
|
@ -11,6 +11,10 @@ module ApplicationTests
|
|||
require "rails/all"
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def load_app
|
||||
require "#{app_path}/config/environment"
|
||||
end
|
||||
|
|
|
@ -5,15 +5,13 @@ module ApplicationTests
|
|||
include ActiveSupport::Testing::Isolation
|
||||
|
||||
def setup
|
||||
@prev_rails_env = ENV['RAILS_ENV']
|
||||
ENV['RAILS_ENV'] = 'development'
|
||||
build_app
|
||||
boot_rails
|
||||
FileUtils.rm_rf "#{app_path}/config/environments"
|
||||
end
|
||||
|
||||
def teardown
|
||||
ENV['RAILS_ENV'] = @prev_rails_env
|
||||
teardown_app
|
||||
end
|
||||
|
||||
test "initializing an application adds the application paths to the load path" do
|
||||
|
|
|
@ -9,6 +9,10 @@ module ApplicationTests
|
|||
boot_rails
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def instrument(*args, &block)
|
||||
ActiveSupport::Notifications.instrument(*args, &block)
|
||||
end
|
||||
|
|
|
@ -4,14 +4,12 @@ class LoadingTest < Test::Unit::TestCase
|
|||
include ActiveSupport::Testing::Isolation
|
||||
|
||||
def setup
|
||||
@prev_rails_env = ENV['RAILS_ENV']
|
||||
ENV['RAILS_ENV'] = 'development'
|
||||
build_app
|
||||
boot_rails
|
||||
end
|
||||
|
||||
def teardown
|
||||
ENV['RAILS_ENV'] = @prev_rails_env
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def app
|
||||
|
|
|
@ -12,6 +12,10 @@ module ApplicationTests
|
|||
simple_controller
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
test "simple controller in production mode returns best standards" do
|
||||
get '/foo'
|
||||
assert_equal "IE=Edge,chrome=1", last_response.headers["X-UA-Compatible"]
|
||||
|
|
|
@ -11,6 +11,10 @@ module ApplicationTests
|
|||
extend Rack::Test::Methods
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def simple_controller
|
||||
controller :expires, <<-RUBY
|
||||
class ExpiresController < ApplicationController
|
||||
|
|
|
@ -10,6 +10,10 @@ module ApplicationTests
|
|||
FileUtils.rm_rf "#{app_path}/config/environments"
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def app
|
||||
@app ||= Rails.application
|
||||
end
|
||||
|
|
|
@ -10,6 +10,10 @@ module ApplicationTests
|
|||
FileUtils.rm_rf "#{app_path}/config/environments"
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def app
|
||||
@app ||= Rails.application
|
||||
end
|
||||
|
|
|
@ -10,6 +10,10 @@ module ApplicationTests
|
|||
FileUtils.rm_rf "#{app_path}/config/environments"
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def app
|
||||
@app ||= Rails.application
|
||||
end
|
||||
|
|
|
@ -11,6 +11,10 @@ module ApplicationTests
|
|||
FileUtils.rm_rf "#{app_path}/config/environments"
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def app
|
||||
@app ||= Rails.application
|
||||
end
|
||||
|
@ -200,4 +204,4 @@ module ApplicationTests
|
|||
AppTemplate::Application.middleware.map(&:klass).map(&:name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,6 +20,10 @@ module ApplicationTests
|
|||
@paths = Rails.application.config.paths
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def root(*path)
|
||||
app_path(*path).to_s
|
||||
end
|
||||
|
|
|
@ -14,6 +14,10 @@ module ApplicationTests
|
|||
super
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def logs
|
||||
@logs ||= @logger.logged(:info)
|
||||
end
|
||||
|
|
|
@ -11,14 +11,12 @@ module ApplicationTests
|
|||
end
|
||||
|
||||
def setup
|
||||
@prev_rails_env = ENV['RAILS_ENV']
|
||||
ENV['RAILS_ENV'] = 'development'
|
||||
build_app
|
||||
boot_rails
|
||||
end
|
||||
|
||||
def teardown
|
||||
ENV['RAILS_ENV'] = @prev_rails_env
|
||||
teardown_app
|
||||
end
|
||||
|
||||
test "rails app is present" do
|
||||
|
|
|
@ -10,6 +10,10 @@ module ApplicationTests
|
|||
FileUtils.rm_rf("#{app_path}/config/environments")
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def test_gems_tasks_are_loaded_first_than_application_ones
|
||||
app_file "lib/tasks/app.rake", <<-RUBY
|
||||
$task_loaded = Rake::Task.task_defined?("db:create:all")
|
||||
|
@ -113,7 +117,7 @@ module ApplicationTests
|
|||
end
|
||||
|
||||
require "#{rails_root}/config/environment"
|
||||
|
||||
|
||||
# loading a specific fixture
|
||||
errormsg = Dir.chdir(app_path) { `rake db:fixtures:load FIXTURES=products` }
|
||||
assert $?.success?, errormsg
|
||||
|
|
|
@ -11,6 +11,10 @@ module ApplicationTests
|
|||
boot_rails
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
test "rails/info/properties in development" do
|
||||
app("development")
|
||||
get "/rails/info/properties"
|
||||
|
|
|
@ -18,6 +18,10 @@ module ApplicationTests
|
|||
MODEL
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def test_should_include_runner_in_shebang_line_in_help
|
||||
assert_match "/rails runner", Dir.chdir(app_path) { `bundle exec rails runner --help` }
|
||||
end
|
||||
|
|
|
@ -9,6 +9,10 @@ module ApplicationTests
|
|||
boot_rails
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
test "truth" do
|
||||
app_file 'test/unit/foo_test.rb', <<-RUBY
|
||||
require 'test_helper'
|
||||
|
|
|
@ -91,6 +91,8 @@ module TestHelpers
|
|||
module Generation
|
||||
# Build an application by invoking the generator and going through the whole stack.
|
||||
def build_app(options = {})
|
||||
@prev_rails_env = ENV.delete('RAILS_ENV')
|
||||
|
||||
FileUtils.rm_rf(app_path)
|
||||
FileUtils.cp_r(tmp_path('app_template'), app_path)
|
||||
|
||||
|
@ -115,6 +117,10 @@ module TestHelpers
|
|||
add_to_config 'config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"; config.session_store :cookie_store, :key => "_myapp_session"; config.active_support.deprecation = :log'
|
||||
end
|
||||
|
||||
def teardown_app
|
||||
ENV['RAILS_ENV'] = @prev_rails_env if @prev_rails_env
|
||||
end
|
||||
|
||||
# Make a very basic app, without creating the whole directory structure.
|
||||
# This is faster and simpler than the method above.
|
||||
def make_basic_app
|
||||
|
|
|
@ -25,6 +25,10 @@ module RailtiesTest
|
|||
end
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
test "Rails::Engine itself does not respond to config" do
|
||||
boot_rails
|
||||
assert !Rails::Engine.respond_to?(:config)
|
||||
|
|
|
@ -106,6 +106,10 @@ module ApplicationTests
|
|||
boot_rails
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def app
|
||||
@app ||= begin
|
||||
require "#{app_path}/config/environment"
|
||||
|
@ -116,7 +120,7 @@ module ApplicationTests
|
|||
def reset_script_name!
|
||||
Rails.application.routes.default_url_options = {}
|
||||
end
|
||||
|
||||
|
||||
def script_name(script_name)
|
||||
Rails.application.routes.default_url_options = {:script_name => script_name}
|
||||
end
|
||||
|
@ -171,4 +175,3 @@ module ApplicationTests
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -12,6 +12,10 @@ module RailtiesTest
|
|||
plugin "c_plugin", "$arr << :c"
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def boot_rails
|
||||
super
|
||||
require "#{app_path}/config/environment"
|
||||
|
@ -69,4 +73,4 @@ module RailtiesTest
|
|||
assert $bar
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,6 +15,10 @@ module RailtiesTest
|
|||
end
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
test "Rails::Plugin itself does not respond to config" do
|
||||
boot_rails
|
||||
assert !Rails::Plugin.respond_to?(:config)
|
||||
|
|
|
@ -11,6 +11,10 @@ module RailtiesTest
|
|||
require "rails/all"
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
|
||||
def app
|
||||
@app ||= Rails.application
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue