mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Refactored railties' isolation tests to be able to run script/* scripts.
This commit is contained in:
@@ -81,7 +81,6 @@ module TestHelpers
|
||||
def build_app(options = {})
|
||||
FileUtils.rm_rf(app_path)
|
||||
FileUtils.cp_r(tmp_path('app_template'), app_path)
|
||||
FileUtils.ln_s(RAILS_FRAMEWORK_ROOT, app_path('vendor/rails'))
|
||||
|
||||
# Delete the initializers unless requested
|
||||
unless options[:initializers]
|
||||
@@ -93,6 +92,12 @@ module TestHelpers
|
||||
add_to_config 'config.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }'
|
||||
end
|
||||
|
||||
def script(script)
|
||||
Dir.chdir(app_path) do
|
||||
`#{Gem.ruby} #{app_path}/script/#{script}`
|
||||
end
|
||||
end
|
||||
|
||||
def add_to_config(str)
|
||||
environment = File.read("#{app_path}/config/application.rb")
|
||||
if environment =~ /(\n\s*end\s*)\Z/
|
||||
@@ -149,8 +154,12 @@ Module.new do
|
||||
if File.exist?(tmp_path)
|
||||
FileUtils.rm_rf(tmp_path)
|
||||
end
|
||||
|
||||
FileUtils.mkdir(tmp_path)
|
||||
root = File.expand_path('../../../..', __FILE__)
|
||||
`#{Gem.ruby} -r #{root}/vendor/gems/environment #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}`
|
||||
|
||||
environment = File.expand_path('../../../../vendor/gems/environment', __FILE__)
|
||||
|
||||
`#{Gem.ruby} -r #{environment} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}`
|
||||
File.open("#{tmp_path}/app_template/config/boot.rb", 'w') do |f|
|
||||
f.puts "require '#{environment}' ; require 'rails'"
|
||||
end
|
||||
end
|
||||
|
||||
19
railties/test/plugins/vendored_test.rb
Normal file
19
railties/test/plugins/vendored_test.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
require "isolation/abstract_unit"
|
||||
|
||||
module ApplicationTests
|
||||
class PluginTest < Test::Unit::TestCase
|
||||
include ActiveSupport::Testing::Isolation
|
||||
|
||||
def setup
|
||||
build_app
|
||||
end
|
||||
|
||||
test "generates the plugin" do
|
||||
script "generate plugin my_plugin"
|
||||
File.open("#{app_path}/vendor/plugins/my_plugin/init.rb", 'w') do |f|
|
||||
f.puts "OMG = 'hello'"
|
||||
end
|
||||
require "#{app_path}/config/environment"
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user