From 4129449594ad3d8ff2f8fb4836104f25406a104f Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Fri, 25 Sep 2009 17:42:53 -0700 Subject: Start Rails::Application object --- railties/test/isolation/abstract_unit.rb | 107 +++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 railties/test/isolation/abstract_unit.rb (limited to 'railties/test/isolation') diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb new file mode 100644 index 0000000000..18ac745101 --- /dev/null +++ b/railties/test/isolation/abstract_unit.rb @@ -0,0 +1,107 @@ +# Note: +# It is important to keep this file as light as possible +# the goal for tests that require this is to test booting up +# rails from an empty state, so anything added here could +# hide potential failures +# +# It is also good to know what is the bare minimum to get +# Rails booted up. + +# TODO: Remove rubygems when possible +require 'rubygems' +require 'test/unit' + +# TODO: Remove setting this magic constant +RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../..") + +# These load paths usually get set inside of boot.rb +$:.unshift "#{RAILS_FRAMEWORK_ROOT}/railties/lib" +$:.unshift "#{RAILS_FRAMEWORK_ROOT}/actionpack/lib" + +# These files do not require any others and are needed +# to run the tests +require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/isolation" +require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/declarative" + +module TestHelpers + module Paths + module_function + + def tmp_path(*args) + File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. tmp] + args)) + end + + def app_path(*args) + tmp_path(*%w[app] + args) + end + end + + module Rack + def extract_body(response) + "".tap do |body| + response[2].each {|chunk| body << chunk } + end + end + + def get(path) + @app.call(::Rack::MockRequest.env_for(path)) + end + + def assert_welcome(resp) + assert_equal 200, resp[0] + assert resp[1]["Content-Type"] = "text/html" + assert extract_body(resp).match(/Welcome aboard/) + end + + def assert_success(resp) + assert_equal 202, resp[0] + end + + def assert_missing(resp) + assert_equal 404, resp[0] + end + + def assert_header(key, value, resp) + assert_equal value, resp[1][key.to_s] + end + + def assert_body(expected, resp) + assert_equal expected, extract_body(resp) + end + end + + module Generation + def build_app + FileUtils.cp_r(tmp_path('app_template'), app_path) + end + + def app_file(path, contents) + File.open(app_path(path), 'w') do |f| + f.puts contents + end + end + + def controller(name, contents) + app_file("app/controllers/#{name}_controller.rb", contents) + end + end +end + +class Test::Unit::TestCase + include TestHelpers::Paths + include TestHelpers::Rack + include TestHelpers::Generation + extend ActiveSupport::Testing::Declarative +end + +# Create a scope and build a fixture rails app +Module.new do + extend TestHelpers::Paths + # Build a rails app + 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')}` +end \ No newline at end of file -- cgit v1.2.3 From f14ad4145622f45e9bf7433b5fdef4ce427efe4b Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 25 Sep 2009 20:41:40 -0500 Subject: Revert "Start Rails::Application object" This reverts commit 4129449594ad3d8ff2f8fb4836104f25406a104f. --- railties/test/isolation/abstract_unit.rb | 107 ------------------------------- 1 file changed, 107 deletions(-) delete mode 100644 railties/test/isolation/abstract_unit.rb (limited to 'railties/test/isolation') diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb deleted file mode 100644 index 18ac745101..0000000000 --- a/railties/test/isolation/abstract_unit.rb +++ /dev/null @@ -1,107 +0,0 @@ -# Note: -# It is important to keep this file as light as possible -# the goal for tests that require this is to test booting up -# rails from an empty state, so anything added here could -# hide potential failures -# -# It is also good to know what is the bare minimum to get -# Rails booted up. - -# TODO: Remove rubygems when possible -require 'rubygems' -require 'test/unit' - -# TODO: Remove setting this magic constant -RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../..") - -# These load paths usually get set inside of boot.rb -$:.unshift "#{RAILS_FRAMEWORK_ROOT}/railties/lib" -$:.unshift "#{RAILS_FRAMEWORK_ROOT}/actionpack/lib" - -# These files do not require any others and are needed -# to run the tests -require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/isolation" -require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/declarative" - -module TestHelpers - module Paths - module_function - - def tmp_path(*args) - File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. tmp] + args)) - end - - def app_path(*args) - tmp_path(*%w[app] + args) - end - end - - module Rack - def extract_body(response) - "".tap do |body| - response[2].each {|chunk| body << chunk } - end - end - - def get(path) - @app.call(::Rack::MockRequest.env_for(path)) - end - - def assert_welcome(resp) - assert_equal 200, resp[0] - assert resp[1]["Content-Type"] = "text/html" - assert extract_body(resp).match(/Welcome aboard/) - end - - def assert_success(resp) - assert_equal 202, resp[0] - end - - def assert_missing(resp) - assert_equal 404, resp[0] - end - - def assert_header(key, value, resp) - assert_equal value, resp[1][key.to_s] - end - - def assert_body(expected, resp) - assert_equal expected, extract_body(resp) - end - end - - module Generation - def build_app - FileUtils.cp_r(tmp_path('app_template'), app_path) - end - - def app_file(path, contents) - File.open(app_path(path), 'w') do |f| - f.puts contents - end - end - - def controller(name, contents) - app_file("app/controllers/#{name}_controller.rb", contents) - end - end -end - -class Test::Unit::TestCase - include TestHelpers::Paths - include TestHelpers::Rack - include TestHelpers::Generation - extend ActiveSupport::Testing::Declarative -end - -# Create a scope and build a fixture rails app -Module.new do - extend TestHelpers::Paths - # Build a rails app - 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')}` -end \ No newline at end of file -- cgit v1.2.3 From accd9b4634f1a2f220bc3e38cf5c4add04186fe6 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 25 Sep 2009 21:32:28 -0500 Subject: Restore "Start Rails::Application object This reverts commit f14ad4145622f45e9bf7433b5fdef4ce427efe4b. --- railties/test/isolation/abstract_unit.rb | 107 +++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 railties/test/isolation/abstract_unit.rb (limited to 'railties/test/isolation') diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb new file mode 100644 index 0000000000..d3fc1f3395 --- /dev/null +++ b/railties/test/isolation/abstract_unit.rb @@ -0,0 +1,107 @@ +# Note: +# It is important to keep this file as light as possible +# the goal for tests that require this is to test booting up +# rails from an empty state, so anything added here could +# hide potential failures +# +# It is also good to know what is the bare minimum to get +# Rails booted up. + +# TODO: Remove rubygems when possible +require 'rubygems' +require 'test/unit' + +# TODO: Remove setting this magic constant +RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../..") + +# These load paths usually get set inside of boot.rb +$:.unshift "#{RAILS_FRAMEWORK_ROOT}/railties/lib" +$:.unshift "#{RAILS_FRAMEWORK_ROOT}/actionpack/lib" + +# These files do not require any others and are needed +# to run the tests +require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/isolation" +require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/declarative" + +module TestHelpers + module Paths + module_function + + def tmp_path(*args) + File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. tmp] + args)) + end + + def app_path(*args) + tmp_path(*%w[app] + args) + end + end + + module Rack + def extract_body(response) + "".tap do |body| + response[2].each {|chunk| body << chunk } + end + end + + def get(path) + @app.call(::Rack::MockRequest.env_for(path)) + end + + def assert_welcome(resp) + assert_equal 200, resp[0] + assert resp[1]["Content-Type"] = "text/html" + assert extract_body(resp).match(/Welcome aboard/) + end + + def assert_success(resp) + assert_equal 202, resp[0] + end + + def assert_missing(resp) + assert_equal 404, resp[0] + end + + def assert_header(key, value, resp) + assert_equal value, resp[1][key.to_s] + end + + def assert_body(expected, resp) + assert_equal expected, extract_body(resp) + end + end + + module Generation + def build_app + FileUtils.cp_r(tmp_path('app_template'), app_path) + end + + def app_file(path, contents) + File.open(app_path(path), 'w') do |f| + f.puts contents + end + end + + def controller(name, contents) + app_file("app/controllers/#{name}_controller.rb", contents) + end + end +end + +class Test::Unit::TestCase + include TestHelpers::Paths + include TestHelpers::Rack + include TestHelpers::Generation + extend ActiveSupport::Testing::Declarative +end + +# Create a scope and build a fixture rails app +Module.new do + extend TestHelpers::Paths + # Build a rails app + 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')}` +end -- cgit v1.2.3 From 6b086449bebc4ecbd11887c74f0c16c0c38089dc Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 29 Sep 2009 16:07:29 -0700 Subject: Fix the broken railties isolation tests --- railties/test/isolation/abstract_unit.rb | 38 +++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'railties/test/isolation') diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index d3fc1f3395..bc1b43acaa 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -14,10 +14,6 @@ require 'test/unit' # TODO: Remove setting this magic constant RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../..") -# These load paths usually get set inside of boot.rb -$:.unshift "#{RAILS_FRAMEWORK_ROOT}/railties/lib" -$:.unshift "#{RAILS_FRAMEWORK_ROOT}/actionpack/lib" - # These files do not require any others and are needed # to run the tests require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/isolation" @@ -71,8 +67,23 @@ module TestHelpers end module Generation - def build_app + def build_app(options = {}) + FileUtils.rm_rf(app_path) FileUtils.cp_r(tmp_path('app_template'), app_path) + + # Delete the initializers unless requested + unless options[:initializers] + Dir["#{app_path}/config/initializers/*.rb"].each do |initializer| + File.delete(initializer) + end + end + + environment = File.read("#{app_path}/config/environment.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 + end + end end def app_file(path, contents) @@ -84,6 +95,23 @@ module TestHelpers def controller(name, contents) app_file("app/controllers/#{name}_controller.rb", contents) end + + def boot_rails + # return if defined?(RAILS) + # TODO: Get this working with boot.rb + $:.unshift "#{RAILS_FRAMEWORK_ROOT}/railties/lib" + Object.class_eval <<-RUBY + RAILS_ROOT = "#{app_path}" + module ::Rails + def self.vendor_rails? + true + end + end + RUBY + require "rails" + Rails::Initializer.run(:install_gem_spec_stubs) + Rails::GemDependency.add_frozen_gem_path + end end end -- cgit v1.2.3 From 2370e87ae0babf0fb4b21254c8120f7a93189d40 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Wed, 30 Sep 2009 12:05:34 -0700 Subject: Remove all calls to Rails::Initializer from boot.rb This is starting a refactor of the rails initialization process. The boot.rb file will not remain the same. --- railties/test/isolation/abstract_unit.rb | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'railties/test/isolation') diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index bc1b43acaa..869e8429cf 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -97,20 +97,16 @@ module TestHelpers end def boot_rails - # return if defined?(RAILS) - # TODO: Get this working with boot.rb - $:.unshift "#{RAILS_FRAMEWORK_ROOT}/railties/lib" - Object.class_eval <<-RUBY - RAILS_ROOT = "#{app_path}" - module ::Rails - def self.vendor_rails? - true - end + # 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 end RUBY - require "rails" - Rails::Initializer.run(:install_gem_spec_stubs) - Rails::GemDependency.add_frozen_gem_path end end end -- cgit v1.2.3