diff options
Diffstat (limited to 'railties/test/isolation/abstract_unit.rb')
-rw-r--r-- | railties/test/isolation/abstract_unit.rb | 87 |
1 files changed, 71 insertions, 16 deletions
diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index f83e0151a4..ba8b35d5cc 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -6,7 +6,6 @@ # # It is also good to know what is the bare minimum to get # Rails booted up. - require 'fileutils' # TODO: Remove rubygems when possible @@ -25,8 +24,10 @@ module TestHelpers module Paths module_function + TMP_PATH = File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. tmp])) + def tmp_path(*args) - File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. tmp] + args)) + File.join(TMP_PATH, *args) end def app_path(*args) @@ -88,10 +89,48 @@ module TestHelpers end end - environment = File.read("#{app_path}/config/environment.rb") + add_to_config 'config.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }' + end + + class Bukkit + def initialize(path) + @path = path + end + + def write(file, string) + path = "#{@path}/#{file}" + FileUtils.mkdir_p(File.dirname(path)) + File.open(path, "w") {|f| f.puts string } + end + + def delete(file) + File.delete("#{@path}/#{file}") + end + end + + def plugin(name, string = "") + dir = "#{app_path}/vendor/plugins/#{name}" + FileUtils.mkdir_p(dir) + File.open("#{dir}/init.rb", 'w') do |f| + f.puts "::#{name.upcase} = 'loaded'" + f.puts string + end + Bukkit.new(dir).tap do |bukkit| + yield bukkit if block_given? + end + 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/ - File.open("#{app_path}/config/environment.rb", 'w') do |f| - f.puts $` + %'\nconfig.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }\n' + $1 + File.open("#{app_path}/config/application.rb", 'w') do |f| + f.puts $` + "\n#{str}\n" + $1 end end end @@ -108,16 +147,23 @@ module TestHelpers end def boot_rails - # TMP mega hax to prevent boot.rb from actually booting - Object.class_eval <<-RUBY, __FILE__, __LINE__+1 - module Rails - Initializer = 'lol' - require "#{app_path}/config/boot" - remove_const(:Initializer) - booter = VendorBoot.new - booter.run + root = File.expand_path('../../../..', __FILE__) + begin + require "#{root}/vendor/gems/environment" + rescue LoadError + %w( + actionmailer/lib + actionpack/lib + activemodel/lib + activerecord/lib + activeresource/lib + activesupport/lib + railties/lib + railties + ).reverse_each do |path| + $:.unshift "#{root}/#{path}" end - RUBY + end end end end @@ -136,7 +182,16 @@ Module.new do if File.exist?(tmp_path) FileUtils.rm_rf(tmp_path) end - FileUtils.mkdir(tmp_path) - `#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}` + + environment = File.expand_path('../../../../vendor/gems/environment', __FILE__) + if File.exist?("#{environment}.rb") + require_environment = "-r #{environment}" + end + + `#{Gem.ruby} #{require_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}'" if require_environment + f.puts "require 'rails'" + end end |