Skip to content
This repository
Browse code

Refactored railties' isolation tests to be able to run script/* scripts.

  • Loading branch information...
commit 8a0f4564432bef9dde815dd6b768d088cfad16ed 1 parent 3e35d30
authored October 21, 2009
17  railties/test/isolation/abstract_unit.rb
@@ -81,7 +81,6 @@ module Generation
81 81
     def build_app(options = {})
82 82
       FileUtils.rm_rf(app_path)
83 83
       FileUtils.cp_r(tmp_path('app_template'), app_path)
84  
-      FileUtils.ln_s(RAILS_FRAMEWORK_ROOT, app_path('vendor/rails'))
85 84
 
86 85
       # Delete the initializers unless requested
87 86
       unless options[:initializers]
@@ -93,6 +92,12 @@ def build_app(options = {})
93 92
       add_to_config 'config.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }'
94 93
     end
95 94
 
  95
+    def script(script)
  96
+      Dir.chdir(app_path) do
  97
+        `#{Gem.ruby} #{app_path}/script/#{script}`
  98
+      end
  99
+    end
  100
+
96 101
     def add_to_config(str)
97 102
       environment = File.read("#{app_path}/config/application.rb")
98 103
       if environment =~ /(\n\s*end\s*)\Z/
@@ -149,8 +154,12 @@ class Test::Unit::TestCase
149 154
   if File.exist?(tmp_path)
150 155
     FileUtils.rm_rf(tmp_path)
151 156
   end
152  
-
153 157
   FileUtils.mkdir(tmp_path)
154  
-  root = File.expand_path('../../../..', __FILE__)
155  
-  `#{Gem.ruby} -r #{root}/vendor/gems/environment #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}`
  158
+
  159
+  environment = File.expand_path('../../../../vendor/gems/environment', __FILE__)
  160
+
  161
+  `#{Gem.ruby} -r #{environment} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}`
  162
+  File.open("#{tmp_path}/app_template/config/boot.rb", 'w') do |f|
  163
+    f.puts "require '#{environment}' ; require 'rails'"
  164
+  end
156 165
 end
19  railties/test/plugins/vendored_test.rb
... ...
@@ -0,0 +1,19 @@
  1
+require "isolation/abstract_unit"
  2
+
  3
+module ApplicationTests
  4
+  class PluginTest < Test::Unit::TestCase
  5
+    include ActiveSupport::Testing::Isolation
  6
+
  7
+    def setup
  8
+      build_app
  9
+    end
  10
+
  11
+    test "generates the plugin" do
  12
+      script "generate plugin my_plugin"
  13
+      File.open("#{app_path}/vendor/plugins/my_plugin/init.rb", 'w') do |f|
  14
+        f.puts "OMG = 'hello'"
  15
+      end
  16
+      require "#{app_path}/config/environment"
  17
+    end
  18
+  end
  19
+end

0 notes on commit 8a0f456

Please sign in to comment.
Something went wrong with that request. Please try again.