From d6f10126eb12e08ad670f803d237b942ebae5018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 20 Nov 2009 09:29:35 -0200 Subject: Also load generators at lib/rails_generators. Signed-off-by: Yehuda Katz --- .../fixtures/vendor/plugins/mspec/lib/generators/mspec_generator.rb | 2 -- .../vendor/plugins/mspec/lib/rails_generators/mspec_generator.rb | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 railties/test/fixtures/vendor/plugins/mspec/lib/generators/mspec_generator.rb create mode 100644 railties/test/fixtures/vendor/plugins/mspec/lib/rails_generators/mspec_generator.rb (limited to 'railties/test') diff --git a/railties/test/fixtures/vendor/plugins/mspec/lib/generators/mspec_generator.rb b/railties/test/fixtures/vendor/plugins/mspec/lib/generators/mspec_generator.rb deleted file mode 100644 index 191bdbf2fc..0000000000 --- a/railties/test/fixtures/vendor/plugins/mspec/lib/generators/mspec_generator.rb +++ /dev/null @@ -1,2 +0,0 @@ -class MspecGenerator < Rails::Generators::NamedBase -end diff --git a/railties/test/fixtures/vendor/plugins/mspec/lib/rails_generators/mspec_generator.rb b/railties/test/fixtures/vendor/plugins/mspec/lib/rails_generators/mspec_generator.rb new file mode 100644 index 0000000000..191bdbf2fc --- /dev/null +++ b/railties/test/fixtures/vendor/plugins/mspec/lib/rails_generators/mspec_generator.rb @@ -0,0 +1,2 @@ +class MspecGenerator < Rails::Generators::NamedBase +end -- cgit v1.2.3 From d0aa0cfbd76a919e536e76d65419930fb7fe31da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 20 Nov 2009 12:16:01 -0200 Subject: Ensure generator fallbacks work even when a context is given. Signed-off-by: Yehuda Katz --- railties/test/generators_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index a8716d9992..4b7b80c7f5 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -150,6 +150,13 @@ class GeneratorsTest < GeneratorsTestCase assert_equal "test_unit:generators:plugin", klass.namespace end + def test_fallbacks_for_generators_on_find_by_namespace_with_context + Rails::Generators.fallbacks[:remarkable] = :test_unit + klass = Rails::Generators.find_by_namespace(:remarkable, :rails, :plugin) + assert klass + assert_equal "test_unit:generators:plugin", klass.namespace + end + def test_fallbacks_for_generators_on_invoke Rails::Generators.fallbacks[:shoulda] = :test_unit TestUnit::Generators::ModelGenerator.expects(:start).with(["Account"], {}) -- cgit v1.2.3 From c102db9367690af992786d2a62bbf8caeec88742 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Mon, 23 Nov 2009 17:04:32 -0800 Subject: Updates notifications tests in railties to reflect changes to the notifications API --- railties/test/application/notifications_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/notifications_test.rb b/railties/test/application/notifications_test.rb index 62ed4f4ad4..28dfdfcd83 100644 --- a/railties/test/application/notifications_test.rb +++ b/railties/test/application/notifications_test.rb @@ -10,13 +10,15 @@ module ApplicationTests def initialize @events = [] @subscribers = [] + @listeners = [] end def publish(name, *args) @events << name end - def subscribe(pattern=nil, &block) + def subscribe(listener, pattern=nil, &block) + @listeners << listener @subscribers << pattern end end -- cgit v1.2.3 From 15ab3a98a1b6f9b829060ba974048b33466f6814 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 23 Nov 2009 20:20:50 -0600 Subject: Find all controllers in memory to use for routing --- railties/test/rails_info_controller_test.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'railties/test') diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index a0484c0868..39f23fa0be 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -14,17 +14,12 @@ class InfoControllerTest < ActionController::TestCase tests Rails::InfoController def setup - ActionController::Routing.use_controllers!(['rails/info']) ActionController::Routing::Routes.draw do |map| map.connect ':controller/:action/:id' end @controller.stubs(:consider_all_requests_local => false, :local_request? => true) end - def teardown - ActionController::Routing.use_controllers! nil - end - test "info controller does not allow remote requests" do @controller.stubs(:consider_all_requests_local => false, :local_request? => false) get :properties -- cgit v1.2.3 From 530b8ff5ae811e0dd5e1343b478f42eed6fffdbd Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Tue, 24 Nov 2009 13:03:24 -0800 Subject: Have script/* and Rakefile use the application object --- railties/test/application/load_test.rb | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/load_test.rb b/railties/test/application/load_test.rb index 3da51c4355..dc5d03b323 100644 --- a/railties/test/application/load_test.rb +++ b/railties/test/application/load_test.rb @@ -7,21 +7,8 @@ module ApplicationTests include ActiveSupport::Testing::Isolation def rackup - config = "#{app_path}/config.ru" - # Copied from ActionDispatch::Utils.parse_config - # ActionDispatch is not necessarily available at this point. - require 'rack' - if config =~ /\.ru$/ - cfgfile = ::File.read(config) - if cfgfile[/^#\\(.*)/] - opts.parse! $1.split(/\s+/) - end - inner_app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app", - nil, config - else - require config - inner_app = Object.const_get(::File.basename(config, '.rb').capitalize) - end + require "rack" + Rack::Builder.parse_file("#{app_path}/config.ru") end def setup @@ -40,14 +27,14 @@ module ApplicationTests test "Rails.application is available after config.ru has been racked up" do rackup - assert Rails.application < Rails::Application + assert Rails.application.is_a?(Rails::Application) end # Passenger still uses AC::Dispatcher, so we need to # keep it working for now test "deprecated ActionController::Dispatcher still works" do rackup - assert ActionController::Dispatcher.new < Rails::Application + assert ActionController::Dispatcher.new.is_a?(Rails::Application) end test "the config object is available on the application object" do -- cgit v1.2.3 From 25b8e996bd29384d37df9939cd651b550e709ee7 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Wed, 25 Nov 2009 14:45:12 -0800 Subject: Fix the rackup test to correctly use Rack::Builder.parse_file --- railties/test/application/load_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/load_test.rb b/railties/test/application/load_test.rb index dc5d03b323..e17f1ebdb0 100644 --- a/railties/test/application/load_test.rb +++ b/railties/test/application/load_test.rb @@ -8,7 +8,8 @@ module ApplicationTests def rackup require "rack" - Rack::Builder.parse_file("#{app_path}/config.ru") + app, options = Rack::Builder.parse_file("#{app_path}/config.ru") + app end def setup -- cgit v1.2.3 From 4f2a04cc085b9117e8af8079a95a063f671d7a3d Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 28 Nov 2009 12:49:07 -0800 Subject: Notifications: extract central Notifier, cordon off the internal Fanout implementation, and segregate instrumentation concerns --- railties/test/application/notifications_test.rb | 30 +++++-------------------- 1 file changed, 6 insertions(+), 24 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/notifications_test.rb b/railties/test/application/notifications_test.rb index 28dfdfcd83..71e406f2c1 100644 --- a/railties/test/application/notifications_test.rb +++ b/railties/test/application/notifications_test.rb @@ -5,21 +5,8 @@ module ApplicationTests include ActiveSupport::Testing::Isolation class MyQueue - attr_reader :events, :subscribers - - def initialize - @events = [] - @subscribers = [] - @listeners = [] - end - def publish(name, *args) - @events << name - end - - def subscribe(listener, pattern=nil, &block) - @listeners << listener - @subscribers << pattern + raise name end end @@ -28,21 +15,16 @@ module ApplicationTests boot_rails require "rails" require "active_support/notifications" + @events = [] Rails::Initializer.run do |c| - c.notifications.queue = MyQueue.new - c.notifications.subscribe(/listening/) do - puts "Cool" - end + c.notifications.notifier = ActiveSupport::Notifications::Notifier.new(MyQueue.new) end end test "new queue is set" do - ActiveSupport::Notifications.instrument(:foo) - assert_equal :foo, ActiveSupport::Notifications.queue.events.first - end - - test "configuration subscribers are loaded" do - assert_equal 1, ActiveSupport::Notifications.queue.subscribers.count { |s| s == /listening/ } + assert_raise RuntimeError do + ActiveSupport::Notifications.publish('foo') + end end end end -- cgit v1.2.3 From 30ae3538a3e281be3d6e8ca337a0790c71f8a9b2 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 1 Dec 2009 21:19:20 -0600 Subject: Some basic route discovery tests --- railties/test/application/routing_test.rb | 85 +++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 railties/test/application/routing_test.rb (limited to 'railties/test') diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb new file mode 100644 index 0000000000..1bfec3805b --- /dev/null +++ b/railties/test/application/routing_test.rb @@ -0,0 +1,85 @@ +require 'isolation/abstract_unit' +require 'rack/test' + +module ApplicationTests + class RoutingTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + include Rack::Test::Methods + + def setup + build_app + end + + def app + @app ||= begin + boot_rails + require "#{app_path}/config/environment" + + Rails.application + end + end + + test "simple controller" do + controller :foo, <<-RUBY + class FooController < ActionController::Base + def index + render :text => "foo" + end + end + RUBY + + get '/foo' + assert_equal 'foo', last_response.body + end + + test "multiple controllers" do + controller :foo, <<-RUBY + class FooController < ActionController::Base + def index + render :text => "foo" + end + end + RUBY + + controller :bar, <<-RUBY + class BarController < ActionController::Base + def index + render :text => "bar" + end + end + RUBY + + get '/foo' + assert_equal 'foo', last_response.body + + get '/bar' + assert_equal 'bar', last_response.body + end + + test "nested controller" do + controller 'foo', <<-RUBY + class FooController < ActionController::Base + def index + render :text => "foo" + end + end + RUBY + + controller 'admin/foo', <<-RUBY + module Admin + class FooController < ActionController::Base + def index + render :text => "admin::foo" + end + end + end + RUBY + + get '/foo' + assert_equal 'foo', last_response.body + + get '/admin/foo' + assert_equal 'admin::foo', last_response.body + end + end +end -- cgit v1.2.3 From abfc4dad3ebb17eccd32d1f1eb8a3e9c0f6e6e4e Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Mon, 30 Nov 2009 15:58:38 -0800 Subject: Remove global Rails initializers --- railties/test/application/generators_test.rb | 26 ++++++++++++++-------- railties/test/application/initializer_test.rb | 16 ------------- .../test/initializer/check_ruby_version_test.rb | 7 ++---- 3 files changed, 19 insertions(+), 30 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index ccbcd84176..2ed49d1057 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -11,8 +11,16 @@ module ApplicationTests require "rails/generators" end + def app_const + @app_const ||= Class.new(Rails::Application) + end + + def with_config + yield app_const.config + end + test "generators default values" do - Rails::Initializer.run do |c| + with_config do |c| assert_equal(true, c.generators.colorize_logging) assert_equal({}, c.generators.aliases) assert_equal({}, c.generators.options) @@ -20,7 +28,7 @@ module ApplicationTests end test "generators set rails options" do - Rails::Initializer.run do |c| + with_config do |c| c.generators.orm = :datamapper c.generators.test_framework = :rspec c.generators.helper = false @@ -30,7 +38,7 @@ module ApplicationTests end test "generators set rails aliases" do - Rails::Initializer.run do |c| + with_config do |c| c.generators.aliases = { :rails => { :test_framework => "-w" } } expected = { :rails => { :test_framework => "-w" } } assert_equal expected, c.generators.aliases @@ -38,14 +46,14 @@ module ApplicationTests end test "generators aliases and options on initialization" do - Rails::Initializer.run do |c| + application = with_config do |c| c.frameworks = [] c.generators.rails :aliases => { :test_framework => "-w" } c.generators.orm :datamapper c.generators.test_framework :rspec end # Initialize the application - Rails.initialize! + app_const.initialize! Rails::Generators.configure! assert_equal :rspec, Rails::Generators.options[:rails][:test_framework] @@ -53,19 +61,19 @@ module ApplicationTests end test "generators no color on initialization" do - Rails::Initializer.run do |c| + with_config do |c| c.frameworks = [] c.generators.colorize_logging = false end # Initialize the application - Rails.initialize! + app_const.initialize! Rails::Generators.configure! assert_equal Thor::Base.shell, Thor::Shell::Basic end test "generators with hashes for options and aliases" do - Rails::Initializer.run do |c| + with_config do |c| c.generators do |g| g.orm :datamapper, :migration => false g.plugin :aliases => { :generator => "-g" }, @@ -84,7 +92,7 @@ module ApplicationTests end test "generators with hashes are deep merged" do - Rails::Initializer.run do |c| + with_config do |c| c.generators do |g| g.orm :datamapper, :migration => false g.plugin :aliases => { :generator => "-g" }, diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 719520bf68..1b319e8a6d 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -10,22 +10,6 @@ module ApplicationTests require "rails" end - test "initializing an application initializes rails" do - Rails::Initializer.run do |config| - config.root = app_path - end - - if RUBY_VERSION < '1.9' - $KCODE = '' - Rails.initialize! - assert_equal 'UTF8', $KCODE - else - Encoding.default_external = Encoding::US_ASCII - Rails.initialize! - assert_equal Encoding::UTF_8, Encoding.default_external - end - end - test "initializing an application adds the application paths to the load path" do Rails::Initializer.run do |config| config.root = app_path diff --git a/railties/test/initializer/check_ruby_version_test.rb b/railties/test/initializer/check_ruby_version_test.rb index 97d884e1be..0691caad9d 100644 --- a/railties/test/initializer/check_ruby_version_test.rb +++ b/railties/test/initializer/check_ruby_version_test.rb @@ -7,7 +7,6 @@ module InitializerTests def setup build_app boot_rails - require "rails" end test "rails does not initialize with ruby version 1.8.1" do @@ -50,8 +49,7 @@ module InitializerTests def assert_rails_boots(version = nil) set_ruby_version(version) if version assert_nothing_raised "It appears that rails does not boot" do - Rails::Initializer.run { |c| c.frameworks = [] } - Rails.initialize! + require "rails" end end @@ -59,8 +57,7 @@ module InitializerTests set_ruby_version(version) $stderr = File.open("/dev/null", "w") assert_raises(SystemExit) do - Rails::Initializer.run { |c| c.frameworks = [] } - Rails.initialize! + require "rails" end end end -- cgit v1.2.3 From 39034997d1bd1fbaf33ddf1d6e3996b3c298a409 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 2 Dec 2009 10:14:02 -0800 Subject: Add support for bare ActiveSupport via config.active_support.bare --- railties/test/application/configuration_test.rb | 9 +++++++++ railties/test/application/initializer_test.rb | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index a3e1916494..fc21d4e5fd 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -44,5 +44,14 @@ module ApplicationTests assert_equal Pathname.new("#{app_path}/app"), Rails.application.root end end + + test "config.active_support.bare does not require all of ActiveSupport" do + add_to_config "config.frameworks = []; config.active_support.bare = true" + + Dir.chdir("#{app_path}/app") do + require "#{app_path}/config/environment" + assert_raises(NoMethodError, /day/) { 1.day } + end + end end end \ No newline at end of file diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 1b319e8a6d..56582c5772 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -25,7 +25,9 @@ module ApplicationTests config.frameworks << :action_foo end - assert_raises RuntimeError do + require "active_support/core_ext/load_error" + + assert_raises MissingSourceFile do Rails.initialize! end end -- cgit v1.2.3 From c1304098cca8a9247a9ad1461a1a343354650843 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 2 Dec 2009 20:01:01 -0800 Subject: Reorganize autoloads: * A new module (ActiveSupport::Autoload) is provide that extends autoloading with new behavior. * All autoloads in modules that have extended ActiveSupport::Autoload will be eagerly required in threadsafe environments * Autoloads can optionally leave off the path if the path is the same as full_constant_name.underscore * It is possible to specify that a group of autoloads live under an additional path. For instance, all of ActionDispatch's middlewares are ActionDispatch::MiddlewareName, but they live under "action_dispatch/middlewares/middleware_name" * It is possible to specify that a group of autoloads are all found at the same path. For instance, a number of exceptions might all be declared there. * One consequence of this is that testing-related constants are not autoloaded. To get the testing helpers for a given component, require "component_name/test_case". For instance, "action_controller/test_case". * test_help.rb, which is automatically required by a Rails application's test helper, requires the test_case.rb for all active components, so this change will not be disruptive in existing or new applications. --- railties/test/rails_info_controller_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/test') diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index 39f23fa0be..558109ba1b 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'action_controller' +require 'action_controller/test_case' require 'rails/info' require 'rails/info_controller' -- cgit v1.2.3 From adc2115132f22cbb772716c167f75346ab6d6c36 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 6 Dec 2009 17:23:43 -0800 Subject: Remove assert_raises usage that only test-unit 1 supports. Breaks minitest and test-unit 2. --- railties/test/application/configuration_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index fc21d4e5fd..1fcab8c651 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -50,8 +50,8 @@ module ApplicationTests Dir.chdir("#{app_path}/app") do require "#{app_path}/config/environment" - assert_raises(NoMethodError, /day/) { 1.day } + assert_raises(NoMethodError) { 1.day } end end end -end \ No newline at end of file +end -- cgit v1.2.3 From 0fec53f243079a60df817cab55100a136fafc1c9 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 9 Dec 2009 18:57:16 -0600 Subject: Scaffolding generates new routing dsl examples --- railties/test/fixtures/plugins/engines/engine/config/routes.rb | 2 +- railties/test/generators/actions_test.rb | 2 +- railties/test/generators/resource_generator_test.rb | 6 +++--- railties/test/generators/scaffold_generator_test.rb | 4 ++-- railties/test/rails_info_controller_test.rb | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) (limited to 'railties/test') diff --git a/railties/test/fixtures/plugins/engines/engine/config/routes.rb b/railties/test/fixtures/plugins/engines/engine/config/routes.rb index cca8d1b146..da44595693 100644 --- a/railties/test/fixtures/plugins/engines/engine/config/routes.rb +++ b/railties/test/fixtures/plugins/engines/engine/config/routes.rb @@ -1,3 +1,3 @@ ActionController::Routing::Routes.draw do |map| - map.connect '/engine', :controller => "engine" + match '/engine', :to => "engine" end diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 7d03a37f2a..b69f23c965 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -171,7 +171,7 @@ class ActionsTest < GeneratorsTestCase def test_route_should_add_data_to_the_routes_block_in_config_routes run_generator - route_command = "map.route '/login', :controller => 'sessions', :action => 'new'" + route_command = "route '/login', :controller => 'sessions', :action => 'new'" action :route, route_command assert_file 'config/routes.rb', /#{Regexp.escape(route_command)}/ end diff --git a/railties/test/generators/resource_generator_test.rb b/railties/test/generators/resource_generator_test.rb index 886af01b22..dff3908ea1 100644 --- a/railties/test/generators/resource_generator_test.rb +++ b/railties/test/generators/resource_generator_test.rb @@ -62,7 +62,7 @@ class ResourceGeneratorTest < GeneratorsTestCase run_generator assert_file "config/routes.rb" do |route| - assert_match /map\.resources :accounts$/, route + assert_match /resources :accounts$/, route end end @@ -70,7 +70,7 @@ class ResourceGeneratorTest < GeneratorsTestCase run_generator ["account", "--singleton"] assert_file "config/routes.rb" do |route| - assert_match /map\.resource :account$/, route + assert_match /resource :account$/, route end end @@ -93,7 +93,7 @@ class ResourceGeneratorTest < GeneratorsTestCase run_generator ["account"], :behavior => :revoke assert_file "config/routes.rb" do |route| - assert_no_match /map\.resources :accounts$/, route + assert_no_match /resources :accounts$/, route end end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index c0652c034f..0b961cee19 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -25,7 +25,7 @@ class ScaffoldGeneratorTest < GeneratorsTestCase # Route assert_file "config/routes.rb" do |route| - assert_match /map\.resources :product_lines$/, route + assert_match /resources :product_lines$/, route end # Controller @@ -99,7 +99,7 @@ class ScaffoldGeneratorTest < GeneratorsTestCase # Route assert_file "config/routes.rb" do |route| - assert_no_match /map\.resources :product_lines$/, route + assert_no_match /resources :product_lines$/, route end # Controller diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index 558109ba1b..435bd34925 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -16,7 +16,7 @@ class InfoControllerTest < ActionController::TestCase def setup ActionController::Routing::Routes.draw do |map| - map.connect ':controller/:action/:id' + match ':controller/:action' end @controller.stubs(:consider_all_requests_local => false, :local_request? => true) end -- cgit v1.2.3 From ec99eca013ce96fa1fa628510038a9eafa46d3c5 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 14 Dec 2009 16:51:13 -0600 Subject: Fix loading plugin and engine route sets --- railties/test/application/routing_test.rb | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 1bfec3805b..752218b943 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -81,5 +81,43 @@ module ApplicationTests get '/admin/foo' assert_equal 'admin::foo', last_response.body end + + test "merges with plugin routes" do + controller 'foo', <<-RUBY + class FooController < ActionController::Base + def index + render :text => "foo" + end + end + RUBY + + app_file 'config/routes.rb', <<-RUBY + ActionController::Routing::Routes.draw do |map| + match 'foo', :to => 'foo#index' + end + RUBY + + plugin 'bar', 'require File.dirname(__FILE__) + "/app/controllers/bar"' do |plugin| + plugin.write 'app/controllers/bar.rb', <<-RUBY + class BarController < ActionController::Base + def index + render :text => "bar" + end + end + RUBY + + plugin.write 'config/routes.rb', <<-RUBY + ActionController::Routing::Routes.draw do |map| + match 'bar', :to => 'bar#index' + end + RUBY + end + + get '/foo' + assert_equal 'foo', last_response.body + + get '/bar' + assert_equal 'bar', last_response.body + end end end -- cgit v1.2.3 From f0bbc647c2086e9536c9d2b4ea7c4c18fe2edd3e Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 15 Dec 2009 10:48:56 -0600 Subject: Procs don't call themselves Fixes dev mode reloading [#3574 state:resolved] --- railties/test/application/routing_test.rb | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 752218b943..decde056fd 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -119,5 +119,37 @@ module ApplicationTests get '/bar' assert_equal 'bar', last_response.body end + + test "reloads routes when configuration is changed" do + controller :foo, <<-RUBY + class FooController < ActionController::Base + def bar + render :text => "bar" + end + + def baz + render :text => "baz" + end + end + RUBY + + app_file 'config/routes.rb', <<-RUBY + ActionController::Routing::Routes.draw do |map| + match 'foo', :to => 'foo#bar' + end + RUBY + + get '/foo' + assert_equal 'bar', last_response.body + + app_file 'config/routes.rb', <<-RUBY + ActionController::Routing::Routes.draw do |map| + match 'foo', :to => 'foo#baz' + end + RUBY + + get '/foo' + assert_equal 'baz', last_response.body + end end end -- cgit v1.2.3 From 1b27f5c4f72384081083fa025b6b10e5ab02ae5e Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 15 Dec 2009 22:07:12 -0800 Subject: Add the ability for plugins to set default configuration settings. --- railties/test/application/configuration_test.rb | 21 +++++++++++++++ railties/test/application/initializer_test.rb | 1 + railties/test/plugins/configuration_test.rb | 36 +++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 railties/test/plugins/configuration_test.rb (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 1fcab8c651..89337b7f66 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -53,5 +53,26 @@ module ApplicationTests assert_raises(NoMethodError) { 1.day } end end + + test "marking the application as threadsafe sets the correct config variables" do + add_to_config <<-RUBY + config.threadsafe! + RUBY + + require "#{app_path}/config/application" + assert AppTemplate.configuration.action_controller.allow_concurrency + end + + test "the application can be marked as threadsafe when there are no frameworks" do + FileUtils.rm_rf("#{app_path}/config/environments") + add_to_config <<-RUBY + config.frameworks = [] + config.threadsafe! + RUBY + + assert_nothing_raised do + require "#{app_path}/config/application" + end + end end end diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 56582c5772..fa00d287ca 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -6,6 +6,7 @@ module ApplicationTests def setup build_app + FileUtils.rm_rf("#{app_path}/config/environments") boot_rails require "rails" end diff --git a/railties/test/plugins/configuration_test.rb b/railties/test/plugins/configuration_test.rb new file mode 100644 index 0000000000..edf8bb37f5 --- /dev/null +++ b/railties/test/plugins/configuration_test.rb @@ -0,0 +1,36 @@ +require "isolation/abstract_unit" + +module PluginsTest + class ConfigurationTest < Test::Unit::TestCase + def setup + build_app + boot_rails + require "rails" + end + + test "config is available to plugins" do + class Foo < Rails::Plugin ; end + assert_nil Foo.config.action_controller.foo + end + + test "a config name is available for the plugin" do + class Foo < Rails::Plugin ; config.foo.greetings = "hello" ; end + assert_equal "hello", Foo.config.foo.greetings + end + + test "plugin configurations are available in the application" do + class Foo < Rails::Plugin ; config.foo.greetings = "hello" ; end + require "#{app_path}/config/application" + assert_equal "hello", AppTemplate.config.foo.greetings + end + + test "plugin config merges are deep" do + class Foo < Rails::Plugin ; config.foo.greetings = 'hello' ; end + class MyApp < Rails::Application + config.foo.bar = "bar" + end + assert_equal "hello", MyApp.config.foo.greetings + assert_equal "bar", MyApp.config.foo.bar + end + end +end \ No newline at end of file -- cgit v1.2.3 From 880688a499b4066d6654a4cd11b76d14cc62865e Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 21 Dec 2009 17:47:03 -0600 Subject: Default route was removed from default route config, patch up failing tests. --- railties/test/application/routing_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index decde056fd..1add941ee0 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -28,6 +28,12 @@ module ApplicationTests end RUBY + app_file 'config/routes.rb', <<-RUBY + ActionController::Routing::Routes.draw do |map| + match ':controller(/:action)' + end + RUBY + get '/foo' assert_equal 'foo', last_response.body end @@ -49,6 +55,12 @@ module ApplicationTests end RUBY + app_file 'config/routes.rb', <<-RUBY + ActionController::Routing::Routes.draw do |map| + match ':controller(/:action)' + end + RUBY + get '/foo' assert_equal 'foo', last_response.body @@ -75,6 +87,12 @@ module ApplicationTests end RUBY + app_file 'config/routes.rb', <<-RUBY + ActionController::Routing::Routes.draw do |map| + match ':controller(/:action)' + end + RUBY + get '/foo' assert_equal 'foo', last_response.body -- cgit v1.2.3 From b0b4ae970c1cb586235bcfbc669d43475c7fe684 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Mon, 21 Dec 2009 16:03:20 -0800 Subject: test.rb, dev.rb, and production.rb just reopen the Application class; no more hax required --- railties/test/initializer/initialize_i18n_test.rb | 11 +++++------ railties/test/initializer/path_test.rb | 8 ++++---- railties/test/isolation/abstract_unit.rb | 7 +++++++ 3 files changed, 16 insertions(+), 10 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb index 076816d73b..472566378d 100644 --- a/railties/test/initializer/initialize_i18n_test.rb +++ b/railties/test/initializer/initialize_i18n_test.rb @@ -7,16 +7,15 @@ module InitializerTests def setup build_app boot_rails - require "rails" end # test_config_defaults_and_settings_should_be_added_to_i18n_defaults test "i18n config defaults and settings should be added to i18n defaults" do - Rails::Initializer.run do |c| - c.root = app_path - c.i18n.load_path << "my/other/locale.yml" - end - Rails.initialize! + add_to_config <<-RUBY + config.root = "#{app_path}" + config.i18n.load_path << "my/other/locale.yml" + RUBY + require "#{app_path}/config/environment" #{RAILS_FRAMEWORK_ROOT}/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml assert_equal %W( diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index 1b58a58555..fa66ebcd83 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -7,14 +7,14 @@ class PathsTest < Test::Unit::TestCase build_app boot_rails require "rails" - Rails::Initializer.run do |config| - config.root = app_path + add_to_config <<-RUBY + config.root = "#{app_path}" config.frameworks = [:action_controller, :action_view, :action_mailer, :active_record] config.after_initialize do ActionController::Base.session_store = nil end - end - Rails.initialize! + RUBY + require "#{app_path}/config/environment" @paths = Rails.application.config.paths end diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index ba8b35d5cc..6562a31d9e 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -89,6 +89,13 @@ module TestHelpers end end + routes = File.read("#{app_path}/config/routes.rb") + if routes =~ /(\n\s*end\s*)\Z/ + File.open("#{app_path}/config/routes.rb", 'w') do |f| + f.puts $` + "\nmatch ':controller(/:action(/:id))(.:format)'\n" + $1 + end + end + add_to_config 'config.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }' end -- cgit v1.2.3 From 2e571e8f99e5e2712c0bc2558df8d62996204b03 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 21 Dec 2009 16:57:23 -0800 Subject: Blog -> Blog::Application. Leave the toplevel module up for grabs. --- railties/test/application/configuration_test.rb | 2 +- railties/test/isolation/abstract_unit.rb | 2 +- railties/test/plugins/configuration_test.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 89337b7f66..83e1401993 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -60,7 +60,7 @@ module ApplicationTests RUBY require "#{app_path}/config/application" - assert AppTemplate.configuration.action_controller.allow_concurrency + assert AppTemplate::Application.configuration.action_controller.allow_concurrency end test "the application can be marked as threadsafe when there are no frameworks" do diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 6562a31d9e..c169c80bea 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -135,7 +135,7 @@ module TestHelpers def add_to_config(str) environment = File.read("#{app_path}/config/application.rb") - if environment =~ /(\n\s*end\s*)\Z/ + if environment =~ /(\n\s*end\s*end\s*)\Z/ File.open("#{app_path}/config/application.rb", 'w') do |f| f.puts $` + "\n#{str}\n" + $1 end diff --git a/railties/test/plugins/configuration_test.rb b/railties/test/plugins/configuration_test.rb index edf8bb37f5..5786316d1d 100644 --- a/railties/test/plugins/configuration_test.rb +++ b/railties/test/plugins/configuration_test.rb @@ -21,7 +21,7 @@ module PluginsTest test "plugin configurations are available in the application" do class Foo < Rails::Plugin ; config.foo.greetings = "hello" ; end require "#{app_path}/config/application" - assert_equal "hello", AppTemplate.config.foo.greetings + assert_equal "hello", AppTemplate::Application.config.foo.greetings end test "plugin config merges are deep" do @@ -33,4 +33,4 @@ module PluginsTest assert_equal "bar", MyApp.config.foo.bar end end -end \ No newline at end of file +end -- cgit v1.2.3 From 426348b48403f664cc10e8ec545b640e56c1c090 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 21 Dec 2009 20:15:27 -0600 Subject: Update routes.rb template to use App name --- railties/test/application/initializer_test.rb | 10 ++++++++++ railties/test/application/routing_test.rb | 14 +++++++------- railties/test/initializer/initialize_i18n_test.rb | 1 + railties/test/initializer/path_test.rb | 1 + railties/test/paths_test.rb | 3 +-- 5 files changed, 20 insertions(+), 9 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index fa00d287ca..031fdc2e9f 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -15,6 +15,7 @@ module ApplicationTests Rails::Initializer.run do |config| config.root = app_path end + Object.const_set(:AppTemplate, Rails.application) Rails.initialize! assert $:.include?("#{app_path}/app/models") @@ -45,6 +46,7 @@ module ApplicationTests config.root = app_path config.eager_load_paths = "#{app_path}/lib" end + Object.const_set(:AppTemplate, Rails.application) Rails.initialize! @@ -55,6 +57,7 @@ module ApplicationTests app_file "config/environments/development.rb", "$initialize_test_set_from_env = 'success'" assert_nil $initialize_test_set_from_env Rails::Initializer.run { |config| config.root = app_path } + Object.const_set(:AppTemplate, Rails.application) Rails.initialize! assert_equal "success", $initialize_test_set_from_env end @@ -75,6 +78,7 @@ module ApplicationTests config.after_initialize { $test_after_initialize_block1 = "success" } config.after_initialize { $test_after_initialize_block2 = "congratulations" } end + Object.const_set(:AppTemplate, Rails.application) Rails.initialize! assert_equal "success", $test_after_initialize_block1 @@ -88,6 +92,7 @@ module ApplicationTests config.after_initialize # don't pass a block, this is what we're testing! config.after_initialize { $test_after_initialize_block2 = "congratulations" } end + Object.const_set(:AppTemplate, Rails.application) Rails.initialize! assert_equal "success", $test_after_initialize_block1 @@ -100,6 +105,7 @@ module ApplicationTests config.root = app_path config.i18n.default_locale = :de end + Object.const_set(:AppTemplate, Rails.application) Rails.initialize! assert_equal :de, I18n.default_locale @@ -137,6 +143,7 @@ module ApplicationTests config.root = app_path config.action_controller.session_store = :cookie_store end + Object.const_set(:AppTemplate, Rails.application) Rails.initialize! assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore) @@ -155,6 +162,7 @@ module ApplicationTests c.root = app_path c.action_controller.session_store = :active_record_store end + Object.const_set(:AppTemplate, Rails.application) Rails.initialize! expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore] @@ -179,6 +187,7 @@ module ApplicationTests c.root = app_path c.frameworks -= [:action_view] end + Object.const_set(:AppTemplate, Rails.application) Rails.initialize! assert_equal nil, ActionMailer::Base.template_root @@ -189,6 +198,7 @@ module ApplicationTests Rails::Initializer.run do |c| c.root = app_path end + Object.const_set(:AppTemplate, Rails.application) Rails.initialize! assert_instance_of Pathname, Rails.root end diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 1add941ee0..7803794307 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -29,7 +29,7 @@ module ApplicationTests RUBY app_file 'config/routes.rb', <<-RUBY - ActionController::Routing::Routes.draw do |map| + AppTemplate.routes.draw do |map| match ':controller(/:action)' end RUBY @@ -56,7 +56,7 @@ module ApplicationTests RUBY app_file 'config/routes.rb', <<-RUBY - ActionController::Routing::Routes.draw do |map| + AppTemplate.routes.draw do |map| match ':controller(/:action)' end RUBY @@ -88,7 +88,7 @@ module ApplicationTests RUBY app_file 'config/routes.rb', <<-RUBY - ActionController::Routing::Routes.draw do |map| + AppTemplate.routes.draw do |map| match ':controller(/:action)' end RUBY @@ -110,7 +110,7 @@ module ApplicationTests RUBY app_file 'config/routes.rb', <<-RUBY - ActionController::Routing::Routes.draw do |map| + AppTemplate.routes.draw do |map| match 'foo', :to => 'foo#index' end RUBY @@ -125,7 +125,7 @@ module ApplicationTests RUBY plugin.write 'config/routes.rb', <<-RUBY - ActionController::Routing::Routes.draw do |map| + AppTemplate.routes.draw do |map| match 'bar', :to => 'bar#index' end RUBY @@ -152,7 +152,7 @@ module ApplicationTests RUBY app_file 'config/routes.rb', <<-RUBY - ActionController::Routing::Routes.draw do |map| + AppTemplate.routes.draw do |map| match 'foo', :to => 'foo#bar' end RUBY @@ -161,7 +161,7 @@ module ApplicationTests assert_equal 'bar', last_response.body app_file 'config/routes.rb', <<-RUBY - ActionController::Routing::Routes.draw do |map| + AppTemplate.routes.draw do |map| match 'foo', :to => 'foo#baz' end RUBY diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb index 076816d73b..4642e53cfc 100644 --- a/railties/test/initializer/initialize_i18n_test.rb +++ b/railties/test/initializer/initialize_i18n_test.rb @@ -16,6 +16,7 @@ module InitializerTests c.root = app_path c.i18n.load_path << "my/other/locale.yml" end + Object.const_set(:AppTemplate, Rails.application) Rails.initialize! #{RAILS_FRAMEWORK_ROOT}/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index 1b58a58555..3724655c0f 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -14,6 +14,7 @@ class PathsTest < Test::Unit::TestCase ActionController::Base.session_store = nil end end + Object.const_set(:AppTemplate, Rails.application) Rails.initialize! @paths = Rails.application.config.paths end diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index c724799d64..d60d6177f6 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -2,7 +2,6 @@ require 'abstract_unit' require 'rails/paths' class PathsTest < ActiveSupport::TestCase - def setup @root = Rails::Application::Root.new("/foo/bar") end @@ -228,4 +227,4 @@ class PathsTest < ActiveSupport::TestCase @root.app.eager_load! assert_equal ["/foo/bar/app"], @root.load_paths end -end \ No newline at end of file +end -- cgit v1.2.3 From dc677f7665e5ec74b5a313ba656bba19dc0f853d Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Tue, 22 Dec 2009 17:03:23 -0800 Subject: tests pass with requiring the frameworks in rails.rb --- railties/test/application/configuration_test.rb | 41 +++++++++++++------------ railties/test/application/generators_test.rb | 30 +++++++++--------- railties/test/application/initializer_test.rb | 26 ---------------- railties/test/application/load_test.rb | 2 -- railties/test/isolation/abstract_unit.rb | 8 +++++ 5 files changed, 46 insertions(+), 61 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 83e1401993..0f702c7014 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -4,7 +4,16 @@ module ApplicationTests class InitializerTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation + def new_app + File.expand_path("#{app_path}/../new_app") + end + + def copy_app + FileUtils.cp_r(app_path, new_app) + end + def setup + FileUtils.rm_rf(new_app) if File.directory?(new_app) build_app boot_rails end @@ -15,42 +24,36 @@ module ApplicationTests end test "the application root can be set" do - FileUtils.mkdir_p("#{app_path}/hello") + copy_app add_to_config <<-RUBY - config.frameworks = [] - config.root = '#{app_path}/hello' + config.root = '#{new_app}' RUBY - require "#{app_path}/config/environment" - assert_equal Pathname.new("#{app_path}/hello"), Rails.application.root - end - test "the application root is detected as where config.ru is located" do - add_to_config <<-RUBY - config.frameworks = [] - RUBY - FileUtils.mv "#{app_path}/config.ru", "#{app_path}/config/config.ru" + use_frameworks [] + require "#{app_path}/config/environment" - assert_equal Pathname.new("#{app_path}/config"), Rails.application.root + assert_equal Pathname.new(new_app), Rails.application.root end test "the application root is Dir.pwd if there is no config.ru" do File.delete("#{app_path}/config.ru") - add_to_config <<-RUBY - config.frameworks = [] - RUBY - Dir.chdir("#{app_path}/app") do + use_frameworks [] + + Dir.chdir("#{app_path}") do require "#{app_path}/config/environment" - assert_equal Pathname.new("#{app_path}/app"), Rails.application.root + assert_equal Pathname.new("#{app_path}"), Rails.application.root end end test "config.active_support.bare does not require all of ActiveSupport" do - add_to_config "config.frameworks = []; config.active_support.bare = true" + add_to_config "config.active_support.bare = true" + + use_frameworks [] Dir.chdir("#{app_path}/app") do require "#{app_path}/config/environment" - assert_raises(NoMethodError) { 1.day } + assert_raises(NoMethodError) { [1,2,3].rand } end end diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index 2ed49d1057..7b27c780aa 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -7,8 +7,6 @@ module ApplicationTests def setup build_app boot_rails - require "rails" - require "rails/generators" end def app_const @@ -16,6 +14,8 @@ module ApplicationTests end def with_config + require "rails" + require "rails/generators" yield app_const.config end @@ -46,14 +46,15 @@ module ApplicationTests end test "generators aliases and options on initialization" do - application = with_config do |c| - c.frameworks = [] - c.generators.rails :aliases => { :test_framework => "-w" } - c.generators.orm :datamapper - c.generators.test_framework :rspec - end + add_to_config <<-RUBY + config.generators.rails :aliases => { :test_framework => "-w" } + config.generators.orm :datamapper + config.generators.test_framework :rspec + RUBY + + require "#{app_path}/config/environment" # Initialize the application - app_const.initialize! + require "rails/generators" Rails::Generators.configure! assert_equal :rspec, Rails::Generators.options[:rails][:test_framework] @@ -61,12 +62,13 @@ module ApplicationTests end test "generators no color on initialization" do - with_config do |c| - c.frameworks = [] - c.generators.colorize_logging = false - end + add_to_config <<-RUBY + config.generators.colorize_logging = false + RUBY + # Initialize the application - app_const.initialize! + require "#{app_path}/config/environment" + require "rails/generators" Rails::Generators.configure! assert_equal Thor::Base.shell, Thor::Shell::Basic diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index b3eff1deb9..8ed8e11c8f 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -19,19 +19,6 @@ module ApplicationTests assert $:.include?("#{app_path}/app/models") end - test "adding an unknown framework raises an error" do - add_to_config <<-RUBY - config.root = "#{app_path}" - config.frameworks << :action_foo - RUBY - - require "active_support/core_ext/load_error" - - assert_raises MissingSourceFile do - require "#{app_path}/config/environment" - end - end - test "eager loading loads parent classes before children" do app_file "lib/zoo.rb", <<-ZOO class Zoo ; include ReptileHouse ; end @@ -180,19 +167,6 @@ module ApplicationTests assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore) end - - # Pathview test - test "load view paths doesn't perform anything when action_view not in frameworks" do - add_to_config <<-RUBY - config.root = "#{app_path}" - config.frameworks -= [:action_view] - RUBY - require "#{app_path}/config/environment" - - assert_equal nil, ActionMailer::Base.template_root - assert_equal [], ActionController::Base.view_paths - end - test "Rails.root should be a Pathname" do add_to_config <<-RUBY config.root = "#{app_path}" diff --git a/railties/test/application/load_test.rb b/railties/test/application/load_test.rb index e17f1ebdb0..689bc77ecf 100644 --- a/railties/test/application/load_test.rb +++ b/railties/test/application/load_test.rb @@ -1,6 +1,4 @@ require "isolation/abstract_unit" -# require "rails" -# require 'action_dispatch' module ApplicationTests class LoadTest < Test::Unit::TestCase diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index c169c80bea..ee0a812b47 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -153,6 +153,14 @@ module TestHelpers app_file("app/controllers/#{name}_controller.rb", contents) end + def use_frameworks(arr) + to_remove = [:actionmailer, + :activemodel, + :activerecord, + :activeresource] - arr + $:.reject! {|path| path =~ %r'/(#{to_remove.join('|')})/' } + end + def boot_rails root = File.expand_path('../../../..', __FILE__) begin -- cgit v1.2.3 From fa8dfc7d014f6768599077b79a874894e13d317f Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 23 Dec 2009 13:45:55 -0800 Subject: Raise an exception if an initializer is defined without a block --- railties/test/initializable_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties/test') diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb index a9e60680ac..e308cbcb0e 100644 --- a/railties/test/initializable_test.rb +++ b/railties/test/initializable_test.rb @@ -150,6 +150,16 @@ module InitializableTests Word.run_initializers assert_equal "bird", $word end + + test "creating initializer without a block raises an error" do + assert_raise(ArgumentError) do + Class.new do + include Rails::Initializable + + initializer :foo + end + end + end end class BeforeAfter < ActiveSupport::TestCase -- cgit v1.2.3 From 38aeb1528c376f7a058beea6db0a328720b85f01 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 23 Dec 2009 14:55:12 -0800 Subject: Moving out some framework specific initializers into the framework libraries. --- railties/test/application/initializer_test.rb | 40 ++++++++++------------- railties/test/plugins/framework_extension_test.rb | 18 ++++++++++ 2 files changed, 35 insertions(+), 23 deletions(-) create mode 100644 railties/test/plugins/framework_extension_test.rb (limited to 'railties/test') diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 8ed8e11c8f..2ecc3e9e2d 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -135,21 +135,9 @@ module ApplicationTests assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore) end - test "database middleware doesn't initialize when activerecord is not in frameworks" do - add_to_config <<-RUBY - config.root = "#{app_path}" - config.frameworks = [] - RUBY - require "#{app_path}/config/environment" - - assert_equal [], Rails.application.config.middleware - end - test "database middleware initializes when session store is active record" do - add_to_config <<-RUBY - config.root = "#{app_path}" - config.action_controller.session_store = :active_record_store - RUBY + add_to_config "config.action_controller.session_store = :active_record_store" + require "#{app_path}/config/environment" expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore] @@ -157,22 +145,28 @@ module ApplicationTests assert_equal expects, middleware & expects end - test "ensure database middleware doesn't use action_controller on initializing" do + test "Rails.root should be a Pathname" do add_to_config <<-RUBY config.root = "#{app_path}" - config.frameworks -= [:action_controller] - config.action_controller.session_store = :active_record_store RUBY require "#{app_path}/config/environment" + assert_instance_of Pathname, Rails.root + end + end - assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore) + class InitializerCustomFrameworkExtensionsTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails end - test "Rails.root should be a Pathname" do - add_to_config <<-RUBY - config.root = "#{app_path}" - RUBY + + test "database middleware doesn't initialize when activerecord is not in frameworks" do + use_frameworks [] require "#{app_path}/config/environment" - assert_instance_of Pathname, Rails.root + + assert !defined?(ActiveRecord) end end end \ No newline at end of file diff --git a/railties/test/plugins/framework_extension_test.rb b/railties/test/plugins/framework_extension_test.rb new file mode 100644 index 0000000000..87e19cadce --- /dev/null +++ b/railties/test/plugins/framework_extension_test.rb @@ -0,0 +1,18 @@ +require "isolation/abstract_unit" + +module PluginsTest + class FrameworkExtensionTest < Test::Unit::TestCase + def setup + build_app + boot_rails + end + + test "active_record extensions are applied to ActiveRecord" do + add_to_config "config.active_record.table_name_prefix = 'tbl_'" + + require "#{app_path}/config/environment" + + assert_equal 'tbl_', ActiveRecord::Base.table_name_prefix + end + end +end \ No newline at end of file -- cgit v1.2.3 From 83be262b4b2e415fe9be319eb6b187bcf415fb6d Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 23 Dec 2009 16:14:34 -0800 Subject: Isolation tests intentionally avoid loading any state (because they're often testing things that have their own load path semantics that should not be polluted), so rack/test is not yet on the load path. Moving require "rack/test" into the setup means and after boot_rails means that it'll be required after the laod path has been altered to add in the Rails vendor/gems --- railties/test/application/routing_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 7b1df7f45d..ece9b13f8a 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -1,18 +1,18 @@ require 'isolation/abstract_unit' -require 'rack/test' module ApplicationTests class RoutingTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation - include Rack::Test::Methods def setup build_app + boot_rails + require 'rack/test' + extend Rack::Test::Methods end def app @app ||= begin - boot_rails require "#{app_path}/config/environment" Rails.application -- cgit v1.2.3 From 61af34b001b295af36c346d245a65d74de0e1f97 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 23 Dec 2009 16:26:10 -0800 Subject: Make /rails/info/properties work again. Also, the mocked up tests were passing so we added a test that actually tested this functionality. --- railties/test/application/routing_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index ece9b13f8a..49c548ad5c 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -19,6 +19,11 @@ module ApplicationTests end end + test "rails/info/properties" do + get "/rails/info/properties" + assert_equal 200, last_response.status + end + test "simple controller" do controller :foo, <<-RUBY class FooController < ActionController::Base -- cgit v1.2.3 From d2bd71a145ddc5e3e3750edc9a09eab742aaf02a Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 23 Dec 2009 17:01:07 -0800 Subject: Finish moving config.frameworks-dependent code to the framework plugin --- railties/test/application/routing_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 49c548ad5c..725dd06929 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -171,6 +171,8 @@ module ApplicationTests end RUBY + sleep 0.1 + get '/foo' assert_equal 'baz', last_response.body end -- cgit v1.2.3 From d926fb62e83d22b34d58f27a6d743cfa5f4c5c7b Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 23 Dec 2009 16:14:34 -0800 Subject: Isolation tests intentionally avoid loading any state (because they're often testing things that have their own load path semantics that should not be polluted), so rack/test is not yet on the load path. Moving require "rack/test" into the setup means and after boot_rails means that it'll be required after the laod path has been altered to add in the Rails vendor/gems --- railties/test/application/routing_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 7b1df7f45d..ece9b13f8a 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -1,18 +1,18 @@ require 'isolation/abstract_unit' -require 'rack/test' module ApplicationTests class RoutingTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation - include Rack::Test::Methods def setup build_app + boot_rails + require 'rack/test' + extend Rack::Test::Methods end def app @app ||= begin - boot_rails require "#{app_path}/config/environment" Rails.application -- cgit v1.2.3 From 7a6f73e79b850e05d8d9639310159679ef872fb7 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 23 Dec 2009 17:47:38 -0800 Subject: Fix reference to Application#configuration to use #config --- railties/test/application/configuration_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 83e1401993..d60e0b904c 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -60,7 +60,7 @@ module ApplicationTests RUBY require "#{app_path}/config/application" - assert AppTemplate::Application.configuration.action_controller.allow_concurrency + assert AppTemplate::Application.config.action_controller.allow_concurrency end test "the application can be marked as threadsafe when there are no frameworks" do -- cgit v1.2.3 From af5c3c852e43fc95b4c4344f61c9c8fc2210b0ca Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 23 Dec 2009 19:00:20 -0800 Subject: Require active_support/all unless specifically requested to be left out. --- railties/test/application/configuration_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 0f702c7014..e71b4c0cdb 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -46,6 +46,12 @@ module ApplicationTests end end + test "if there's no config.active_support.bare, all of ActiveSupport is required" do + use_frameworks [] + require "#{app_path}/config/environment" + assert_nothing_raised { [1,2,3].rand } + end + test "config.active_support.bare does not require all of ActiveSupport" do add_to_config "config.active_support.bare = true" -- cgit v1.2.3 From c4d6d50a46a0fe53f75aadc306212b5437e22ed8 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 23 Dec 2009 19:10:44 -0800 Subject: Rackup config.ru from the correct directory --- railties/test/application/load_test.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/load_test.rb b/railties/test/application/load_test.rb index 689bc77ecf..1c5811b07a 100644 --- a/railties/test/application/load_test.rb +++ b/railties/test/application/load_test.rb @@ -20,8 +20,10 @@ module ApplicationTests end test "config.ru can be racked up" do - @app = rackup - assert_welcome get("/") + Dir.chdir app_path do + @app = rackup + assert_welcome get("/") + end end test "Rails.application is available after config.ru has been racked up" do -- cgit v1.2.3 From 7e8b7f46bfc086a36db996420fbee93348c5268e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 27 Dec 2009 13:31:36 +0100 Subject: Add config.action_controller.include behavior to plugins. --- railties/test/plugins/configuration_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'railties/test') diff --git a/railties/test/plugins/configuration_test.rb b/railties/test/plugins/configuration_test.rb index 5786316d1d..0843d05577 100644 --- a/railties/test/plugins/configuration_test.rb +++ b/railties/test/plugins/configuration_test.rb @@ -8,6 +8,10 @@ module PluginsTest require "rails" end + module Bar; end + module Baz; end + module All; end + test "config is available to plugins" do class Foo < Rails::Plugin ; end assert_nil Foo.config.action_controller.foo @@ -24,6 +28,18 @@ module PluginsTest assert_equal "hello", AppTemplate::Application.config.foo.greetings end + test "plugin configurations allow modules to be given" do + class Foo < Rails::Plugin ; config.foo.include(Bar, Baz) ; end + assert_equal [Bar, Baz], Foo.config.foo.includes + end + + test "plugin includes given modules in given class" do + class Foo < Rails::Plugin ; config.foo.include(Bar, "PluginsTest::ConfigurationTest::Baz") ; include_modules_in All ; end + Foo.new.run_initializers(Foo) + assert All.ancestors.include?(Bar) + assert All.ancestors.include?(Baz) + end + test "plugin config merges are deep" do class Foo < Rails::Plugin ; config.foo.greetings = 'hello' ; end class MyApp < Rails::Application -- cgit v1.2.3 From 4691cc43ee184414e2366340c3227e6fdf2aba7d Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 28 Dec 2009 11:40:23 -0800 Subject: Fix ruby version test --- .../test/initializer/check_ruby_version_test.rb | 49 ++++------------------ 1 file changed, 9 insertions(+), 40 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer/check_ruby_version_test.rb b/railties/test/initializer/check_ruby_version_test.rb index 0691caad9d..a2c07ece75 100644 --- a/railties/test/initializer/check_ruby_version_test.rb +++ b/railties/test/initializer/check_ruby_version_test.rb @@ -1,7 +1,7 @@ require "isolation/abstract_unit" module InitializerTests - class PathsTest < Test::Unit::TestCase + class CheckRubyVersionTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation def setup @@ -9,52 +9,21 @@ module InitializerTests boot_rails end - test "rails does not initialize with ruby version 1.8.1" do - assert_rails_does_not_boot "1.8.1" - end - - test "rails does not initialize with ruby version 1.8.2" do - assert_rails_does_not_boot "1.8.2" - end - - test "rails does not initialize with ruby version 1.8.3" do - assert_rails_does_not_boot "1.8.3" - end - - test "rails does not initialize with ruby version 1.8.4" do - assert_rails_does_not_boot "1.8.4" - end - - test "rails does not initializes with ruby version 1.8.5" do - assert_rails_does_not_boot "1.8.5" - end - - test "rails does not initialize with ruby version 1.8.6" do - assert_rails_does_not_boot "1.8.6" - end - - test "rails initializes with ruby version 1.8.7" do - assert_rails_boots "1.8.7" - end - - test "rails initializes with the current version of Ruby" do - assert_rails_boots - end - - def set_ruby_version(version) - $-w = nil - Object.const_set(:RUBY_VERSION, version.freeze) + test "rails initializes with ruby 1.8.7 or later" do + if RUBY_VERSION < '1.8.7' + assert_rails_does_not_boot + else + assert_rails_boots + end end - def assert_rails_boots(version = nil) - set_ruby_version(version) if version + def assert_rails_boots assert_nothing_raised "It appears that rails does not boot" do require "rails" end end - def assert_rails_does_not_boot(version) - set_ruby_version(version) + def assert_rails_does_not_boot $stderr = File.open("/dev/null", "w") assert_raises(SystemExit) do require "rails" -- cgit v1.2.3 From f95fcdd3af95c4819322e00100831f12f95a8e62 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 28 Dec 2009 11:40:34 -0800 Subject: Fix copy/pasted test class name --- railties/test/initializer/path_test.rb | 196 +++++++++++++++++---------------- 1 file changed, 99 insertions(+), 97 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index fa66ebcd83..3bbf9617a0 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -1,101 +1,103 @@ require "isolation/abstract_unit" -class PathsTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - boot_rails - require "rails" - add_to_config <<-RUBY - config.root = "#{app_path}" - config.frameworks = [:action_controller, :action_view, :action_mailer, :active_record] - config.after_initialize do - ActionController::Base.session_store = nil - end - RUBY - require "#{app_path}/config/environment" - @paths = Rails.application.config.paths - end - - def root(*path) - app_path(*path).to_s - end - - def assert_path(paths, *dir) - assert_equal [root(*dir)], paths.paths - end - - def assert_in_load_path(*path) - assert $:.any? { |p| File.expand_path(p) == root(*path) }, "Load path does not include '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----" - end - - def assert_not_in_load_path(*path) - assert !$:.any? { |p| File.expand_path(p) == root(*path) }, "Load path includes '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----" - end - - test "booting up Rails yields a valid paths object" do - assert_path @paths.app, "app" - assert_path @paths.app.metals, "app", "metal" - assert_path @paths.app.models, "app", "models" - assert_path @paths.app.helpers, "app", "helpers" - assert_path @paths.app.services, "app", "services" - assert_path @paths.lib, "lib" - assert_path @paths.vendor, "vendor" - assert_path @paths.vendor.plugins, "vendor", "plugins" - assert_path @paths.tmp, "tmp" - assert_path @paths.tmp.cache, "tmp", "cache" - assert_path @paths.config, "config" - assert_path @paths.config.locales, "config", "locales" - assert_path @paths.config.environments, "config", "environments" - - assert_equal root("app", "controllers"), @paths.app.controllers.to_a.first - assert_equal Pathname.new(File.dirname(__FILE__)).join("..", "..", "builtin", "rails_info").expand_path, - Pathname.new(@paths.app.controllers.to_a[1]).expand_path - end +module InitializerTests + class PathTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + require "rails" + add_to_config <<-RUBY + config.root = "#{app_path}" + config.frameworks = [:action_controller, :action_view, :action_mailer, :active_record] + config.after_initialize do + ActionController::Base.session_store = nil + end + RUBY + require "#{app_path}/config/environment" + @paths = Rails.application.config.paths + end + + def root(*path) + app_path(*path).to_s + end + + def assert_path(paths, *dir) + assert_equal [root(*dir)], paths.paths + end + + def assert_in_load_path(*path) + assert $:.any? { |p| File.expand_path(p) == root(*path) }, "Load path does not include '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----" + end + + def assert_not_in_load_path(*path) + assert !$:.any? { |p| File.expand_path(p) == root(*path) }, "Load path includes '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----" + end + + test "booting up Rails yields a valid paths object" do + assert_path @paths.app, "app" + assert_path @paths.app.metals, "app", "metal" + assert_path @paths.app.models, "app", "models" + assert_path @paths.app.helpers, "app", "helpers" + assert_path @paths.app.services, "app", "services" + assert_path @paths.lib, "lib" + assert_path @paths.vendor, "vendor" + assert_path @paths.vendor.plugins, "vendor", "plugins" + assert_path @paths.tmp, "tmp" + assert_path @paths.tmp.cache, "tmp", "cache" + assert_path @paths.config, "config" + assert_path @paths.config.locales, "config", "locales" + assert_path @paths.config.environments, "config", "environments" + + assert_equal root("app", "controllers"), @paths.app.controllers.to_a.first + assert_equal Pathname.new(File.dirname(__FILE__)).join("..", "..", "builtin", "rails_info").expand_path, + Pathname.new(@paths.app.controllers.to_a[1]).expand_path + end + + test "booting up Rails yields a list of paths that are eager" do + assert @paths.app.models.eager_load? + assert @paths.app.controllers.eager_load? + assert @paths.app.helpers.eager_load? + assert @paths.app.metals.eager_load? + end + + test "environments has a glob equal to the current environment" do + assert_equal "#{RAILS_ENV}.rb", @paths.config.environments.glob + end + + test "load path includes each of the paths in config.paths as long as the directories exist" do + assert_in_load_path "app" + assert_in_load_path "app", "controllers" + assert_in_load_path "app", "models" + assert_in_load_path "app", "helpers" + assert_in_load_path "lib" + assert_in_load_path "vendor" + + assert_not_in_load_path "app", "views" + assert_not_in_load_path "app", "metal" + assert_not_in_load_path "app", "services" + assert_not_in_load_path "config" + assert_not_in_load_path "config", "locales" + assert_not_in_load_path "config", "environments" + assert_not_in_load_path "tmp" + assert_not_in_load_path "tmp", "cache" + end + + test "controller paths include builtin in development mode" do + RAILS_ENV.replace "development" + assert Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ } + end + + test "controller paths does not have builtin_directories in test mode" do + RAILS_ENV.replace "test" + assert !Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ } + end + + test "controller paths does not have builtin_directories in production mode" do + RAILS_ENV.replace "production" + assert !Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ } + end - test "booting up Rails yields a list of paths that are eager" do - assert @paths.app.models.eager_load? - assert @paths.app.controllers.eager_load? - assert @paths.app.helpers.eager_load? - assert @paths.app.metals.eager_load? end - - test "environments has a glob equal to the current environment" do - assert_equal "#{RAILS_ENV}.rb", @paths.config.environments.glob - end - - test "load path includes each of the paths in config.paths as long as the directories exist" do - assert_in_load_path "app" - assert_in_load_path "app", "controllers" - assert_in_load_path "app", "models" - assert_in_load_path "app", "helpers" - assert_in_load_path "lib" - assert_in_load_path "vendor" - - assert_not_in_load_path "app", "views" - assert_not_in_load_path "app", "metal" - assert_not_in_load_path "app", "services" - assert_not_in_load_path "config" - assert_not_in_load_path "config", "locales" - assert_not_in_load_path "config", "environments" - assert_not_in_load_path "tmp" - assert_not_in_load_path "tmp", "cache" - end - - test "controller paths include builtin in development mode" do - RAILS_ENV.replace "development" - assert Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ } - end - - test "controller paths does not have builtin_directories in test mode" do - RAILS_ENV.replace "test" - assert !Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ } - end - - test "controller paths does not have builtin_directories in production mode" do - RAILS_ENV.replace "production" - assert !Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ } - end - -end \ No newline at end of file +end -- cgit v1.2.3 From c02f2782631a1893e2e880e3ccc65fb9a734567a Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Mon, 28 Dec 2009 16:21:48 -0800 Subject: Add the ability to have plugins load rake tasks. --- railties/test/plugins/framework_extension_test.rb | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'railties/test') diff --git a/railties/test/plugins/framework_extension_test.rb b/railties/test/plugins/framework_extension_test.rb index 87e19cadce..5e4ecf30dd 100644 --- a/railties/test/plugins/framework_extension_test.rb +++ b/railties/test/plugins/framework_extension_test.rb @@ -2,6 +2,33 @@ require "isolation/abstract_unit" module PluginsTest class FrameworkExtensionTest < Test::Unit::TestCase + def setup + build_app + boot_rails + require "rails" + end + + test "rake_tasks block is executed when MyApp.load_tasks is called" do + $ran_block = false + + class MyPlugin < Rails::Plugin + rake_tasks do + $ran_block = true + end + end + + require "#{app_path}/config/environment" + + assert !$ran_block + require 'rake' + require 'rake/testtask' + require 'rake/rdoctask' + AppTemplate::Application.load_tasks + assert $ran_block + end + end + + class ActiveRecordExtensionTest < Test::Unit::TestCase def setup build_app boot_rails -- cgit v1.2.3 From 4ee70643b3c352a582069267ddb02186da8a86f7 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Mon, 28 Dec 2009 17:45:17 -0800 Subject: Don't require initializer.rb in core.rb --- railties/test/abstract_unit.rb | 4 +++- railties/test/application/notifications_test.rb | 28 +++++++++++++++-------- railties/test/plugins/framework_extension_test.rb | 5 ++++ 3 files changed, 26 insertions(+), 11 deletions(-) (limited to 'railties/test') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index 47013d7797..66ab5a08c3 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -22,6 +22,8 @@ require 'active_support/test_case' require 'action_controller' require 'rails' -Rails::Initializer.run do |config| +# TODO: Remove these hacks +class TestApp < Rails::Application config.root = File.dirname(__FILE__) end +Rails.application = TestApp diff --git a/railties/test/application/notifications_test.rb b/railties/test/application/notifications_test.rb index 71e406f2c1..8229e83147 100644 --- a/railties/test/application/notifications_test.rb +++ b/railties/test/application/notifications_test.rb @@ -1,27 +1,35 @@ require "isolation/abstract_unit" module ApplicationTests - class NotificationsTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation + class MyQueue + def publish(name, *args) + raise name + end - class MyQueue - def publish(name, *args) - raise name - end + # Not a full queue implementation + def method_missing(name, *args, &blk) + self end + end + + class NotificationsTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation def setup build_app boot_rails - require "rails" require "active_support/notifications" @events = [] - Rails::Initializer.run do |c| - c.notifications.notifier = ActiveSupport::Notifications::Notifier.new(MyQueue.new) - end + + add_to_config <<-RUBY + config.notifications.notifier = ActiveSupport::Notifications::Notifier.new(ApplicationTests::MyQueue.new) + RUBY end test "new queue is set" do + use_frameworks [] + require "#{app_path}/config/environment" + assert_raise RuntimeError do ActiveSupport::Notifications.publish('foo') end diff --git a/railties/test/plugins/framework_extension_test.rb b/railties/test/plugins/framework_extension_test.rb index 5e4ecf30dd..a6c7b753f8 100644 --- a/railties/test/plugins/framework_extension_test.rb +++ b/railties/test/plugins/framework_extension_test.rb @@ -2,6 +2,8 @@ require "isolation/abstract_unit" module PluginsTest class FrameworkExtensionTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + def setup build_app boot_rails @@ -23,12 +25,15 @@ module PluginsTest require 'rake' require 'rake/testtask' require 'rake/rdoctask' + AppTemplate::Application.load_tasks assert $ran_block end end class ActiveRecordExtensionTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + def setup build_app boot_rails -- cgit v1.2.3 From 3cb7e047637e57349ed9e4c81d4f7b3157045661 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 29 Dec 2009 13:20:10 -0800 Subject: Finally remove rails/initializer.rb --- railties/test/metal_test.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/metal_test.rb b/railties/test/metal_test.rb index 2256b191e2..91f55c2b5e 100644 --- a/railties/test/metal_test.rb +++ b/railties/test/metal_test.rb @@ -1,5 +1,4 @@ require 'abstract_unit' -require 'rails/initializer' class MetalTest < Test::Unit::TestCase def test_metals_should_return_list_of_found_metal_apps -- cgit v1.2.3 From 1a4d909c6845c091a04e2533ab89502de4130c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 29 Dec 2009 11:52:06 +0100 Subject: Add rails app --edge and rails app --dev --- railties/test/generators/app_generator_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 10d0bc6bc2..567555fdc5 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -149,6 +149,19 @@ class AppGeneratorTest < GeneratorsTestCase assert_file 'lib/test_file.rb', 'heres test data' end + def test_dev_option + run_generator ["--dev"] + rails_path = File.expand_path('../../..', Rails.root) + dev_gem = %(gem "rails", :path => #{rails_path.inspect}) + assert_file 'Gemfile', /^#{Regexp.escape(dev_gem)}$/ + end + + def test_edge_option + run_generator ["--edge"] + edge_gem = %(gem "rails", :git => "git://github.com/rails/rails.git") + assert_file 'Gemfile', /^#{Regexp.escape(edge_gem)}$/ + end + protected def run_generator(args=[]) -- cgit v1.2.3 From e5c88434dbb7dc0690a474ae7c913453bf289328 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 29 Dec 2009 19:04:14 -0800 Subject: Use the correct method for eager loading autoloads --- railties/test/application/configuration_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 4d9da525d7..ece41f9de8 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -83,5 +83,21 @@ module ApplicationTests require "#{app_path}/config/application" end end + + test "Frameworks are not preloaded by default" do + require "#{app_path}/config/environment" + + assert ActionController.autoload?(:RecordIdentifier) + end + + test "frameworks are preloaded with config.preload_frameworks is set" do + add_to_config <<-RUBY + config.preload_frameworks = true + RUBY + + require "#{app_path}/config/environment" + + assert !ActionController.autoload?(:RecordIdentifier) + end end end -- cgit v1.2.3 From 1fbd02e44618f1f56e1d9d0af85c6a4108a66532 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 30 Dec 2009 19:33:32 -0800 Subject: Revert "Add config.action_controller.include behavior to plugins." This reverts commit 7e8b7f46bfc086a36db996420fbee93348c5268e. Conflicts: railties/lib/rails/plugin.rb --- railties/test/plugins/configuration_test.rb | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'railties/test') diff --git a/railties/test/plugins/configuration_test.rb b/railties/test/plugins/configuration_test.rb index 0843d05577..5786316d1d 100644 --- a/railties/test/plugins/configuration_test.rb +++ b/railties/test/plugins/configuration_test.rb @@ -8,10 +8,6 @@ module PluginsTest require "rails" end - module Bar; end - module Baz; end - module All; end - test "config is available to plugins" do class Foo < Rails::Plugin ; end assert_nil Foo.config.action_controller.foo @@ -28,18 +24,6 @@ module PluginsTest assert_equal "hello", AppTemplate::Application.config.foo.greetings end - test "plugin configurations allow modules to be given" do - class Foo < Rails::Plugin ; config.foo.include(Bar, Baz) ; end - assert_equal [Bar, Baz], Foo.config.foo.includes - end - - test "plugin includes given modules in given class" do - class Foo < Rails::Plugin ; config.foo.include(Bar, "PluginsTest::ConfigurationTest::Baz") ; include_modules_in All ; end - Foo.new.run_initializers(Foo) - assert All.ancestors.include?(Bar) - assert All.ancestors.include?(Baz) - end - test "plugin config merges are deep" do class Foo < Rails::Plugin ; config.foo.greetings = 'hello' ; end class MyApp < Rails::Application -- cgit v1.2.3 From 16f1a2b57350cf8764235740f23c1dbcc5e91b23 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 30 Dec 2009 23:20:57 -0800 Subject: Clarify assertion --- railties/test/application/initializer_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 2ecc3e9e2d..42fc416faa 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -166,7 +166,7 @@ module ApplicationTests use_frameworks [] require "#{app_path}/config/environment" - assert !defined?(ActiveRecord) + assert_nil defined?(ActiveRecord) end end -end \ No newline at end of file +end -- cgit v1.2.3 From 1e41097294b6f966f65909db5c56c9fc21b665f7 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 31 Dec 2009 10:36:24 -0800 Subject: Fully remove config.frameworks in favor of requires in boot.rb --- railties/test/application/configuration_test.rb | 3 ++- railties/test/application/initializer_test.rb | 4 ++-- railties/test/generators/app_generator_test.rb | 9 +++++---- railties/test/initializer/path_test.rb | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index ece41f9de8..a7df1e09ab 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -75,10 +75,11 @@ module ApplicationTests test "the application can be marked as threadsafe when there are no frameworks" do FileUtils.rm_rf("#{app_path}/config/environments") add_to_config <<-RUBY - config.frameworks = [] config.threadsafe! RUBY + use_frameworks [] + assert_nothing_raised do require "#{app_path}/config/application" end diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 42fc416faa..e03f9ffb00 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -7,7 +7,6 @@ module ApplicationTests def setup build_app boot_rails - require "rails" end test "initializing an application adds the application paths to the load path" do @@ -51,8 +50,9 @@ module ApplicationTests assert_nothing_raised NameError do add_to_config <<-RUBY config.root = "#{app_path}" - config.frameworks = [] RUBY + + use_frameworks [] require "#{app_path}/config/environment" end end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 567555fdc5..2cba42551e 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -63,10 +63,11 @@ class AppGeneratorTest < GeneratorsTestCase assert_no_file "config/database.yml" end - def test_activerecord_is_removed_from_frameworks_if_skip_activerecord_is_given - run_generator ["--skip-activerecord"] - assert_file "config/application.rb", /config\.frameworks \-= \[ :active_record \]/ - end + # TODO: Bring this back using requires + # def test_activerecord_is_removed_from_frameworks_if_skip_activerecord_is_given + # run_generator ["--skip-activerecord"] + # assert_file "config/application.rb", /config\.frameworks \-= \[ :active_record \]/ + # end def test_prototype_and_test_unit_are_added_by_default run_generator diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index 3bbf9617a0..73d1b1a125 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -7,14 +7,14 @@ module InitializerTests def setup build_app boot_rails - require "rails" add_to_config <<-RUBY config.root = "#{app_path}" - config.frameworks = [:action_controller, :action_view, :action_mailer, :active_record] config.after_initialize do ActionController::Base.session_store = nil end RUBY + use_frameworks [:action_controller, :action_view, :action_mailer, :active_record] + require "rails" require "#{app_path}/config/environment" @paths = Rails.application.config.paths end -- cgit v1.2.3 From 2f8643955a780f0c2fe46d0ae68db8d51b76fbbf Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 31 Dec 2009 11:57:48 -0800 Subject: Raise a helpful error if config.frameworks is used --- railties/test/application/configuration_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index a7df1e09ab..1f04eb9f75 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -100,5 +100,21 @@ module ApplicationTests assert !ActionController.autoload?(:RecordIdentifier) end + + test "runtime error is raised if config.frameworks= is used" do + add_to_config "config.frameworks = []" + + assert_raises RuntimeError do + require "#{app_path}/config/environment" + end + end + + test "runtime error is raised if config.frameworks is used" do + add_to_config "config.frameworks -= []" + + assert_raises RuntimeError do + require "#{app_path}/config/environment" + end + end end end -- cgit v1.2.3 From e749424dfa38a0300a621b772eae96f9cc5d2555 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 31 Dec 2009 12:28:48 -0800 Subject: Rename rails.rb -> rails/all.rb and rails/core.rb -> rails.rb --- railties/test/abstract_unit.rb | 2 +- railties/test/application/generators_test.rb | 2 +- railties/test/initializer/check_ruby_version_test.rb | 4 ++-- railties/test/initializer/path_test.rb | 2 +- railties/test/isolation/abstract_unit.rb | 2 +- railties/test/plugins/configuration_test.rb | 2 +- railties/test/plugins/framework_extension_test.rb | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) (limited to 'railties/test') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index 66ab5a08c3..2d6983076a 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -20,7 +20,7 @@ require 'active_support/core_ext/logger' require 'active_support/test_case' require 'action_controller' -require 'rails' +require 'rails/all' # TODO: Remove these hacks class TestApp < Rails::Application diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index 7b27c780aa..0c858d6394 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -14,7 +14,7 @@ module ApplicationTests end def with_config - require "rails" + require "rails/all" require "rails/generators" yield app_const.config end diff --git a/railties/test/initializer/check_ruby_version_test.rb b/railties/test/initializer/check_ruby_version_test.rb index a2c07ece75..311f19a28a 100644 --- a/railties/test/initializer/check_ruby_version_test.rb +++ b/railties/test/initializer/check_ruby_version_test.rb @@ -19,14 +19,14 @@ module InitializerTests def assert_rails_boots assert_nothing_raised "It appears that rails does not boot" do - require "rails" + require "rails/all" end end def assert_rails_does_not_boot $stderr = File.open("/dev/null", "w") assert_raises(SystemExit) do - require "rails" + require "rails/all" end end end diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index 73d1b1a125..26663d0f47 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -14,7 +14,7 @@ module InitializerTests end RUBY use_frameworks [:action_controller, :action_view, :action_mailer, :active_record] - require "rails" + require "rails/all" require "#{app_path}/config/environment" @paths = Rails.application.config.paths end diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index ee0a812b47..dc5fddb19d 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -207,6 +207,6 @@ Module.new do `#{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'" + f.puts "require 'rails/all'" end end diff --git a/railties/test/plugins/configuration_test.rb b/railties/test/plugins/configuration_test.rb index 5786316d1d..9616d1b2d0 100644 --- a/railties/test/plugins/configuration_test.rb +++ b/railties/test/plugins/configuration_test.rb @@ -5,7 +5,7 @@ module PluginsTest def setup build_app boot_rails - require "rails" + require "rails/all" end test "config is available to plugins" do diff --git a/railties/test/plugins/framework_extension_test.rb b/railties/test/plugins/framework_extension_test.rb index a6c7b753f8..86e5cebfcd 100644 --- a/railties/test/plugins/framework_extension_test.rb +++ b/railties/test/plugins/framework_extension_test.rb @@ -7,7 +7,7 @@ module PluginsTest def setup build_app boot_rails - require "rails" + require "rails/all" end test "rake_tasks block is executed when MyApp.load_tasks is called" do -- cgit v1.2.3 From ae7ada1fde1648a5c81b9e6adf74d515e0bbe0a5 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 31 Dec 2009 13:11:54 -0800 Subject: Some railties cleanup: * Rename /rails.rb -> /railtie.rb * Rails::Plugin -> Rails::Railtie * Rails::Plugin::Vendored -> Rails::Plugin --- railties/test/application/configuration_test.rb | 1 + railties/test/application/initializer_test.rb | 2 ++ railties/test/application/notifications_test.rb | 1 + railties/test/initializer/path_test.rb | 2 +- railties/test/plugins/configuration_test.rb | 8 ++++---- railties/test/plugins/framework_extension_test.rb | 4 +++- 6 files changed, 12 insertions(+), 6 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 1f04eb9f75..adb867ca6d 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -16,6 +16,7 @@ module ApplicationTests FileUtils.rm_rf(new_app) if File.directory?(new_app) build_app boot_rails + FileUtils.rm_rf("#{app_path}/config/environments") end test "the application root is set correctly" do diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index e03f9ffb00..3fd0b0e5df 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -7,6 +7,7 @@ module ApplicationTests def setup build_app boot_rails + FileUtils.rm_rf "#{app_path}/config/environments" end test "initializing an application adds the application paths to the load path" do @@ -160,6 +161,7 @@ module ApplicationTests def setup build_app boot_rails + FileUtils.rm_rf "#{app_path}/config/environments" end test "database middleware doesn't initialize when activerecord is not in frameworks" do diff --git a/railties/test/application/notifications_test.rb b/railties/test/application/notifications_test.rb index 8229e83147..b57e829cca 100644 --- a/railties/test/application/notifications_test.rb +++ b/railties/test/application/notifications_test.rb @@ -18,6 +18,7 @@ module ApplicationTests def setup build_app boot_rails + FileUtils.rm_rf("#{app_path}/config/environments") require "active_support/notifications" @events = [] diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index 26663d0f47..bfb1887d11 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -7,6 +7,7 @@ module InitializerTests def setup build_app boot_rails + FileUtils.rm_rf("#{app_path}/config/environments") add_to_config <<-RUBY config.root = "#{app_path}" config.after_initialize do @@ -14,7 +15,6 @@ module InitializerTests end RUBY use_frameworks [:action_controller, :action_view, :action_mailer, :active_record] - require "rails/all" require "#{app_path}/config/environment" @paths = Rails.application.config.paths end diff --git a/railties/test/plugins/configuration_test.rb b/railties/test/plugins/configuration_test.rb index 9616d1b2d0..25bf24eb3b 100644 --- a/railties/test/plugins/configuration_test.rb +++ b/railties/test/plugins/configuration_test.rb @@ -9,23 +9,23 @@ module PluginsTest end test "config is available to plugins" do - class Foo < Rails::Plugin ; end + class Foo < Rails::Railtie ; end assert_nil Foo.config.action_controller.foo end test "a config name is available for the plugin" do - class Foo < Rails::Plugin ; config.foo.greetings = "hello" ; end + class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end assert_equal "hello", Foo.config.foo.greetings end test "plugin configurations are available in the application" do - class Foo < Rails::Plugin ; config.foo.greetings = "hello" ; end + class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end require "#{app_path}/config/application" assert_equal "hello", AppTemplate::Application.config.foo.greetings end test "plugin config merges are deep" do - class Foo < Rails::Plugin ; config.foo.greetings = 'hello' ; end + class Foo < Rails::Railtie ; config.foo.greetings = 'hello' ; end class MyApp < Rails::Application config.foo.bar = "bar" end diff --git a/railties/test/plugins/framework_extension_test.rb b/railties/test/plugins/framework_extension_test.rb index 86e5cebfcd..c920db77aa 100644 --- a/railties/test/plugins/framework_extension_test.rb +++ b/railties/test/plugins/framework_extension_test.rb @@ -7,13 +7,14 @@ module PluginsTest def setup build_app boot_rails + FileUtils.rm_rf("#{app_path}/config/environments") require "rails/all" end test "rake_tasks block is executed when MyApp.load_tasks is called" do $ran_block = false - class MyPlugin < Rails::Plugin + class MyTie < Rails::Railtie rake_tasks do $ran_block = true end @@ -37,6 +38,7 @@ module PluginsTest def setup build_app boot_rails + FileUtils.rm_rf("#{app_path}/config/environments") end test "active_record extensions are applied to ActiveRecord" do -- cgit v1.2.3 From 106d8f76888e76096f83e884f55dbcd536a0c1d7 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sat, 2 Jan 2010 22:49:40 -0800 Subject: AppName::Application.root should work --- railties/test/application/configuration_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index adb867ca6d..79dfacdcdb 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -24,6 +24,11 @@ module ApplicationTests assert_equal Pathname.new(app_path), Rails.application.root end + test "the application root can be seen from the application singleton" do + require "#{app_path}/config/environment" + assert_equal Pathname.new(app_path), AppTemplate::Application.root + end + test "the application root can be set" do copy_app add_to_config <<-RUBY -- cgit v1.2.3 From 6716e4bc0c201d9375fa07b44c1a96b6948fc6ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 3 Jan 2010 12:01:29 +0100 Subject: Use regexp in lookups instead of traversing namespaces. This removes the need of special cases. --- railties/test/generators_test.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 4b7b80c7f5..2df218debc 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -9,6 +9,11 @@ class GeneratorsTest < GeneratorsTestCase Gem.stubs(:respond_to?).with(:loaded_specs).returns(false) end + def test_invoke_add_generators_to_raw_lookups + TestUnit::Generators::ModelGenerator.expects(:start).with(["Account"], {}) + Rails::Generators.invoke("test_unit:model", ["Account"]) + end + def test_invoke_when_generator_is_not_found output = capture(:stdout){ Rails::Generators.invoke :unknown } assert_equal "Could not find generator unknown.\n", output @@ -51,12 +56,6 @@ class GeneratorsTest < GeneratorsTestCase assert_equal "foobar:foobar", klass.namespace end - def test_find_by_namespace_add_generators_to_raw_lookups - klass = Rails::Generators.find_by_namespace("test_unit:model") - assert klass - assert_equal "test_unit:generators:model", klass.namespace - end - def test_find_by_namespace_lookup_to_the_rails_root_folder klass = Rails::Generators.find_by_namespace(:fixjour) assert klass @@ -96,7 +95,7 @@ class GeneratorsTest < GeneratorsTestCase end def test_builtin_generators - assert Rails::Generators.builtin.include? %w(rails model) + assert Rails::Generators.builtin.include?("rails:model") end def test_rails_generators_help_with_builtin_information @@ -107,7 +106,7 @@ class GeneratorsTest < GeneratorsTestCase def test_rails_generators_with_others_information output = capture(:stdout){ Rails::Generators.help }.split("\n").last - assert_equal "Others: active_record:fixjour, fixjour, foobar, mspec, rails:javascripts.", output + assert_equal "Others: active_record:fixjour, fixjour, foobar:foobar, mspec, rails:javascripts, xspec.", output end def test_warning_is_shown_if_generator_cant_be_loaded @@ -178,6 +177,8 @@ class GeneratorsTest < GeneratorsTestCase end assert_equal false, klass.class_options[:generate].default + ensure + Rails::Generators.subclasses.delete(klass) end def test_source_paths_for_not_namespaced_generators -- cgit v1.2.3 From e88ea3255ff90baa28d30908e1fcb5fa7f7133a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 3 Jan 2010 13:01:18 +0100 Subject: Assert for valid application names. [#3556 status:resolved] --- railties/test/generators/app_generator_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 2cba42551e..235da530f9 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -53,6 +53,16 @@ class AppGeneratorTest < GeneratorsTestCase assert_match /Invalid value for \-\-database option/, content end + def test_invalid_application_name_raises_an_error + content = capture(:stderr){ Rails::Generators::AppGenerator.start [File.join(destination_root, "43-things")] } + assert_equal "Invalid application name 43-things. Please give a name which does not start with numbers.\n", content + end + + def test_invalid_application_name_is_fixed + silence(:stdout){ Rails::Generators::AppGenerator.start [File.join(destination_root, "things-43")] } + assert_file "things-43/config/environment.rb", /Things43::Application/ + end + def test_config_database_is_added_by_default run_generator assert_file "config/database.yml", /sqlite3/ -- cgit v1.2.3 From 441227a10f42fcd28b65ab416495ff8f4fc45b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 3 Jan 2010 15:13:54 +0100 Subject: Create Rails::Generators::TestCase. --- .../test/generators/controller_generator_test.rb | 6 +- railties/test/generators/generators_test_helper.rb | 90 ++-------------------- .../test/generators/migration_generator_test.rb | 8 +- railties/test/generators/model_generator_test.rb | 6 +- .../test/generators/resource_generator_test.rb | 4 +- .../scaffold_controller_generator_test.rb | 18 ++--- .../test/generators/scaffold_generator_test.rb | 14 ++-- 7 files changed, 35 insertions(+), 111 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index 56bc688ad0..78cbe8f97b 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -6,7 +6,7 @@ class ControllerGeneratorTest < GeneratorsTestCase def test_help_does_not_show_invoked_generators_options_if_they_already_exist content = run_generator ["--help"] - assert_no_match /Helper options:/, content + assert_no_match /Helper options\:/, content end def test_controller_skeleton_is_created @@ -66,8 +66,8 @@ class ControllerGeneratorTest < GeneratorsTestCase run_generator assert_file "app/controllers/account_controller.rb" do |controller| - assert_instance_method controller, :foo - assert_instance_method controller, :bar + assert_instance_method :foo, controller + assert_instance_method :bar, controller end end diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb index 4ce48a453b..b3a810634e 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -10,93 +10,17 @@ end Rails.application.config.root = Rails.root require 'rails/generators' +require 'rails/generators/test_case' + require 'rubygems' require 'active_record' require 'action_dispatch' -CURRENT_PATH = File.expand_path(Dir.pwd) -Rails::Generators.no_color! - -class GeneratorsTestCase < ActiveSupport::TestCase - include FileUtils - - def destination_root - File.join(Rails.root, "tmp") - end - - def setup - cd CURRENT_PATH - rm_rf(destination_root) - mkdir_p(destination_root) - end +class GeneratorsTestCase < Rails::Generators::TestCase + destination File.join(Rails.root, "tmp") + setup :prepare_destination def test_truth - # don't complain, test/unit - end - - def capture(stream) - begin - stream = stream.to_s - eval "$#{stream} = StringIO.new" - yield - result = eval("$#{stream}").string - ensure - eval("$#{stream} = #{stream.upcase}") - end - - result + # Don't cry test unit end - alias :silence :capture - - def assert_file(relative, *contents) - absolute = File.join(destination_root, relative) - assert File.exists?(absolute), "Expected file #{relative.inspect} to exist, but does not" - - read = File.read(absolute) if block_given? || !contents.empty? - yield read if block_given? - - contents.each do |content| - case content - when String - assert_equal content, read - when Regexp - assert_match content, read - end - end - end - - def assert_no_file(relative) - absolute = File.join(destination_root, relative) - assert !File.exists?(absolute), "Expected file #{relative.inspect} to not exist, but does" - end - - def assert_migration(relative, *contents, &block) - file_name = migration_file_name(relative) - assert file_name, "Expected migration #{relative} to exist, but was not found" - assert_file File.join(File.dirname(relative), file_name), *contents, &block - end - - def assert_no_migration(relative) - file_name = migration_file_name(relative) - assert_nil file_name, "Expected migration #{relative} to not exist, but found #{file_name}" - end - - def assert_class_method(content, method, &block) - assert_instance_method content, "self.#{method}", &block - end - - def assert_instance_method(content, method) - assert content =~ /def #{method}(\(.+\))?(.*?)\n end/m, "Expected to have method #{method}" - yield $2.strip if block_given? - end - - protected - - def migration_file_name(relative) - absolute = File.join(destination_root, relative) - dirname, file_name = File.dirname(absolute), File.basename(absolute).sub(/\.rb$/, '') - - migration = Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first - File.basename(migration) if migration - end -end +end \ No newline at end of file diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index 35172a8be4..f8273f8a1a 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -21,12 +21,12 @@ class MigrationGeneratorTest < GeneratorsTestCase run_generator [@migration, "title:string", "body:text"] assert_migration "db/migrate/#{@migration}.rb" do |content| - assert_class_method content, :up do |up| + assert_class_method :up, content do |up| assert_match /add_column :posts, :title, :string/, up assert_match /add_column :posts, :body, :text/, up end - assert_class_method content, :down do |down| + assert_class_method :down, content do |down| assert_match /remove_column :posts, :title/, down assert_match /remove_column :posts, :body/, down end @@ -38,12 +38,12 @@ class MigrationGeneratorTest < GeneratorsTestCase run_generator [@migration, "title:string", "body:text"] assert_migration "db/migrate/#{@migration}.rb" do |content| - assert_class_method content, :up do |up| + assert_class_method :up, content do |up| assert_match /remove_column :posts, :title/, up assert_match /remove_column :posts, :body/, up end - assert_class_method content, :down do |down| + assert_class_method :down, content do |down| assert_match /add_column :posts, :title, :string/, down assert_match /add_column :posts, :body, :text/, down end diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index e073b11e1e..58737a81fc 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -84,13 +84,13 @@ class ModelGeneratorTest < GeneratorsTestCase run_generator ["product", "name:string", "supplier_id:integer"] assert_migration "db/migrate/create_products.rb" do |m| - assert_class_method m, :up do |up| + assert_class_method :up, m do |up| assert_match /create_table :products/, up assert_match /t\.string :name/, up assert_match /t\.integer :supplier_id/, up end - assert_class_method m, :down do |down| + assert_class_method :down, m do |down| assert_match /drop_table :products/, down end end @@ -126,7 +126,7 @@ class ModelGeneratorTest < GeneratorsTestCase run_generator ["account", "--no-timestamps"] assert_migration "db/migrate/create_accounts.rb" do |m| - assert_class_method m, :up do |up| + assert_class_method :up, m do |up| assert_no_match /t.timestamps/, up end end diff --git a/railties/test/generators/resource_generator_test.rb b/railties/test/generators/resource_generator_test.rb index dff3908ea1..136795bf3d 100644 --- a/railties/test/generators/resource_generator_test.rb +++ b/railties/test/generators/resource_generator_test.rb @@ -50,8 +50,8 @@ class ResourceGeneratorTest < GeneratorsTestCase run_generator ["account", "--actions", "index", "new"] assert_file "app/controllers/accounts_controller.rb" do |controller| - assert_instance_method controller, :index - assert_instance_method controller, :new + assert_instance_method :index, controller + assert_instance_method :new, controller end assert_file "app/views/accounts/index.html.erb" diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index 02155c295c..96fc0750f4 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -15,35 +15,35 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase assert_file "app/controllers/users_controller.rb" do |content| assert_match /class UsersController < ApplicationController/, content - assert_instance_method content, :index do |m| + assert_instance_method :index, content do |m| assert_match /@users = User\.all/, m end - assert_instance_method content, :show do |m| + assert_instance_method :show, content do |m| assert_match /@user = User\.find\(params\[:id\]\)/, m end - assert_instance_method content, :new do |m| + assert_instance_method :new, content do |m| assert_match /@user = User\.new/, m end - assert_instance_method content, :edit do |m| + assert_instance_method :edit, content do |m| assert_match /@user = User\.find\(params\[:id\]\)/, m end - assert_instance_method content, :create do |m| + assert_instance_method :create, content do |m| assert_match /@user = User\.new\(params\[:user\]\)/, m assert_match /@user\.save/, m assert_match /@user\.errors/, m end - assert_instance_method content, :update do |m| + assert_instance_method :update, content do |m| assert_match /@user = User\.find\(params\[:id\]\)/, m assert_match /@user\.update_attributes\(params\[:user\]\)/, m assert_match /@user\.errors/, m end - assert_instance_method content, :destroy do |m| + assert_instance_method :destroy, content do |m| assert_match /@user = User\.find\(params\[:id\]\)/, m assert_match /@user\.destroy/, m end @@ -108,7 +108,7 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase assert_file "app/controllers/users_controller.rb" do |content| assert_match /class UsersController < ApplicationController/, content - assert_instance_method content, :index do |m| + assert_instance_method :index, content do |m| assert_match /@users = User\.all/, m end end @@ -127,7 +127,7 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase assert_file "app/controllers/users_controller.rb" do |content| assert_match /class UsersController < ApplicationController/, content - assert_instance_method content, :index do |m| + assert_instance_method :index, content do |m| assert_match /@users = User\.find\(:all\)/, m assert_no_match /@users = User\.all/, m end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index 0b961cee19..a37e629d20 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -32,35 +32,35 @@ class ScaffoldGeneratorTest < GeneratorsTestCase assert_file "app/controllers/product_lines_controller.rb" do |content| assert_match /class ProductLinesController < ApplicationController/, content - assert_instance_method content, :index do |m| + assert_instance_method :index, content do |m| assert_match /@product_lines = ProductLine\.all/, m end - assert_instance_method content, :show do |m| + assert_instance_method :show, content do |m| assert_match /@product_line = ProductLine\.find\(params\[:id\]\)/, m end - assert_instance_method content, :new do |m| + assert_instance_method :new, content do |m| assert_match /@product_line = ProductLine\.new/, m end - assert_instance_method content, :edit do |m| + assert_instance_method :edit, content do |m| assert_match /@product_line = ProductLine\.find\(params\[:id\]\)/, m end - assert_instance_method content, :create do |m| + assert_instance_method :create, content do |m| assert_match /@product_line = ProductLine\.new\(params\[:product_line\]\)/, m assert_match /@product_line\.save/, m assert_match /@product_line\.errors/, m end - assert_instance_method content, :update do |m| + assert_instance_method :update, content do |m| assert_match /@product_line = ProductLine\.find\(params\[:id\]\)/, m assert_match /@product_line\.update_attributes\(params\[:product_line\]\)/, m assert_match /@product_line\.errors/, m end - assert_instance_method content, :destroy do |m| + assert_instance_method :destroy, content do |m| assert_match /@product_line = ProductLine\.find\(params\[:id\]\)/, m assert_match /@product_line\.destroy/, m end -- cgit v1.2.3 From 271e7c803f116b77f0df48115036421242eb9b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 3 Jan 2010 16:34:32 +0100 Subject: Move all generators tests to use new test case syntax. --- railties/test/generators/actions_test.rb | 12 ++------ railties/test/generators/app_generator_test.rb | 29 ++++++++----------- .../test/generators/controller_generator_test.rb | 9 +----- .../test/generators/generator_generator_test.rb | 9 +----- railties/test/generators/generators_test_helper.rb | 6 ++-- railties/test/generators/helper_generator_test.rb | 9 +----- .../generators/integration_test_generator_test.rb | 9 +----- railties/test/generators/mailer_generator_test.rb | 9 +----- railties/test/generators/metal_generator_test.rb | 9 +----- .../test/generators/migration_generator_test.rb | 33 ++++++++-------------- railties/test/generators/model_generator_test.rb | 9 +----- railties/test/generators/named_base_test.rb | 8 +++--- .../test/generators/observer_generator_test.rb | 9 +----- .../generators/performance_test_generator_test.rb | 9 +----- railties/test/generators/plugin_generator_test.rb | 9 +----- .../test/generators/resource_generator_test.rb | 9 +----- .../scaffold_controller_generator_test.rb | 9 +----- .../test/generators/scaffold_generator_test.rb | 14 ++------- .../generators/session_migration_generator_test.rb | 9 ------ .../test/generators/stylesheets_generator_test.rb | 11 +------- 20 files changed, 49 insertions(+), 181 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index b69f23c965..27b6a49566 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -1,8 +1,10 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/app/app_generator' class ActionsTest < GeneratorsTestCase + tests Rails::Generators::AppGenerator + arguments [destination_root] + def setup super @git_plugin_uri = 'git://github.com/technoweenie/restful-authentication.git' @@ -178,14 +180,6 @@ class ActionsTest < GeneratorsTestCase protected - def run_generator - silence(:stdout) { Rails::Generators::AppGenerator.start [destination_root] } - end - - def generator(config={}) - @generator ||= Rails::Generators::Base.new([], {}, { :destination_root => destination_root }.merge!(config)) - end - def action(*args, &block) silence(:stdout){ generator.send(*args, &block) } end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 235da530f9..7dd798db75 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -3,6 +3,7 @@ require 'generators/generators_test_helper' require 'rails/generators/rails/app/app_generator' class AppGeneratorTest < GeneratorsTestCase + arguments [destination_root] def setup super @@ -49,7 +50,7 @@ class AppGeneratorTest < GeneratorsTestCase end def test_invalid_database_option_raises_an_error - content = capture(:stderr){ run_generator(["-d", "unknown"]) } + content = capture(:stderr){ run_generator([destination_root, "-d", "unknown"]) } assert_match /Invalid value for \-\-database option/, content end @@ -69,7 +70,7 @@ class AppGeneratorTest < GeneratorsTestCase end def test_config_database_is_not_added_if_skip_activerecord_is_given - run_generator ["--skip-activerecord"] + run_generator [destination_root, "--skip-activerecord"] assert_no_file "config/database.yml" end @@ -86,13 +87,13 @@ class AppGeneratorTest < GeneratorsTestCase end def test_prototype_and_test_unit_are_skipped_if_required - run_generator ["--skip-prototype", "--skip-testunit"] + run_generator [destination_root, "--skip-prototype", "--skip-testunit"] assert_no_file "public/javascripts/prototype.js" assert_no_file "test" end def test_shebang_is_added_to_files - run_generator ["--ruby", "foo/bar/baz"] + run_generator [destination_root, "--ruby", "foo/bar/baz"] %w( about @@ -107,7 +108,7 @@ class AppGeneratorTest < GeneratorsTestCase end def test_shebang_when_is_the_same_as_default_use_env - run_generator ["--ruby", Thor::Util.ruby_command] + run_generator [destination_root, "--ruby", Thor::Util.ruby_command] %w( about @@ -123,11 +124,11 @@ class AppGeneratorTest < GeneratorsTestCase def test_template_from_dir_pwd FileUtils.cd(Rails.root) - assert_match /It works from file!/, run_generator(["-m", "lib/template.rb"]) + assert_match /It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"]) end def test_template_raises_an_error_with_invalid_path - content = capture(:stderr){ run_generator(["-m", "non/existant/path"]) } + content = capture(:stderr){ run_generator([destination_root, "-m", "non/existant/path"]) } assert_match /The template \[.*\] could not be loaded/, content assert_match /non\/existant\/path/, content end @@ -137,7 +138,7 @@ class AppGeneratorTest < GeneratorsTestCase template = %{ say "It works!" } template.instance_eval "def read; self; end" # Make the string respond to read - generator(:template => path, :database => "sqlite3").expects(:open).with(path).returns(template) + generator([destination_root], :template => path, :database => "sqlite3").expects(:open).with(path).returns(template) assert_match /It works!/, silence(:stdout){ generator.invoke } end @@ -161,28 +162,20 @@ class AppGeneratorTest < GeneratorsTestCase end def test_dev_option - run_generator ["--dev"] + run_generator [destination_root, "--dev"] rails_path = File.expand_path('../../..', Rails.root) dev_gem = %(gem "rails", :path => #{rails_path.inspect}) assert_file 'Gemfile', /^#{Regexp.escape(dev_gem)}$/ end def test_edge_option - run_generator ["--edge"] + run_generator [destination_root, "--edge"] edge_gem = %(gem "rails", :git => "git://github.com/rails/rails.git") assert_file 'Gemfile', /^#{Regexp.escape(edge_gem)}$/ end protected - def run_generator(args=[]) - silence(:stdout) { Rails::Generators::AppGenerator.start [destination_root].concat(args) } - end - - def generator(options={}) - @generator ||= Rails::Generators::AppGenerator.new([destination_root], options, :destination_root => destination_root) - end - def action(*args, &block) silence(:stdout){ generator.send(*args, &block) } end diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index 78cbe8f97b..8e2fd3b9ed 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/controller/controller_generator' class ControllerGeneratorTest < GeneratorsTestCase + arguments %w(Account foo bar) def test_help_does_not_show_invoked_generators_options_if_they_already_exist content = run_generator ["--help"] @@ -70,11 +70,4 @@ class ControllerGeneratorTest < GeneratorsTestCase assert_instance_method :bar, controller end end - - protected - - def run_generator(args=["Account", "foo", "bar"]) - silence(:stdout) { Rails::Generators::ControllerGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/generator_generator_test.rb b/railties/test/generators/generator_generator_test.rb index aea3f4da51..28377f23b0 100644 --- a/railties/test/generators/generator_generator_test.rb +++ b/railties/test/generators/generator_generator_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/generator/generator_generator' class GeneratorGeneratorTest < GeneratorsTestCase + arguments %w(awesome) def test_generator_skeleton_is_created run_generator @@ -16,11 +16,4 @@ class GeneratorGeneratorTest < GeneratorsTestCase assert_file "lib/generators/awesome/awesome_generator.rb", /class AwesomeGenerator < Rails::Generators::NamedBase/ end - - protected - - def run_generator(args=["awesome"], config={}) - silence(:stdout) { Rails::Generators::GeneratorGenerator.start args, config.merge(:destination_root => destination_root) } - end - end diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb index b3a810634e..fcd0989fd7 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -20,7 +20,9 @@ class GeneratorsTestCase < Rails::Generators::TestCase destination File.join(Rails.root, "tmp") setup :prepare_destination - def test_truth - # Don't cry test unit + def self.inherited(base) + base.tests Rails::Generators.const_get(base.name.sub(/Test$/, '')) + rescue + # Do nothing. end end \ No newline at end of file diff --git a/railties/test/generators/helper_generator_test.rb b/railties/test/generators/helper_generator_test.rb index f8bfc517a2..cf18782986 100644 --- a/railties/test/generators/helper_generator_test.rb +++ b/railties/test/generators/helper_generator_test.rb @@ -1,4 +1,3 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/helper/helper_generator' @@ -6,6 +5,7 @@ ObjectHelper = Class.new AnotherObjectHelperTest = Class.new class HelperGeneratorTest < GeneratorsTestCase + arguments %w(admin) def test_helper_skeleton_is_created run_generator @@ -50,11 +50,4 @@ class HelperGeneratorTest < GeneratorsTestCase end end end - - protected - - def run_generator(args=["admin"]) - silence(:stdout) { Rails::Generators::HelperGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/integration_test_generator_test.rb b/railties/test/generators/integration_test_generator_test.rb index 6a504ceea2..88e18be5b2 100644 --- a/railties/test/generators/integration_test_generator_test.rb +++ b/railties/test/generators/integration_test_generator_test.rb @@ -1,18 +1,11 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/integration_test/integration_test_generator' class IntegrationTestGeneratorTest < GeneratorsTestCase + arguments %w(integration) def test_integration_test_skeleton_is_created run_generator assert_file "test/integration/integration_test.rb", /class IntegrationTest < ActionController::IntegrationTest/ end - - protected - - def run_generator(args=["integration"]) - silence(:stdout) { Rails::Generators::IntegrationTestGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb index 251474ad16..ee4346eb71 100644 --- a/railties/test/generators/mailer_generator_test.rb +++ b/railties/test/generators/mailer_generator_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/mailer/mailer_generator' class MailerGeneratorTest < GeneratorsTestCase + arguments %w(notifier foo bar) def test_mailer_skeleton_is_created run_generator @@ -42,11 +42,4 @@ class MailerGeneratorTest < GeneratorsTestCase assert_file "app/models/notifier.rb", /def foo/ assert_file "app/models/notifier.rb", /def bar/ end - - protected - - def run_generator(args=["notifier", "foo", "bar"]) - silence(:stdout) { Rails::Generators::MailerGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/metal_generator_test.rb b/railties/test/generators/metal_generator_test.rb index 80bf342892..5d6a277561 100644 --- a/railties/test/generators/metal_generator_test.rb +++ b/railties/test/generators/metal_generator_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/metal/metal_generator' class MetalGeneratorTest < GeneratorsTestCase + arguments %w(foo) def test_metal_skeleton_is_created run_generator @@ -13,11 +13,4 @@ class MetalGeneratorTest < GeneratorsTestCase content = capture(:stderr){ run_generator ["object"] } assert_match /The name 'Object' is either already used in your application or reserved/, content end - - protected - - def run_generator(args=["foo"]) - silence(:stdout) { Rails::Generators::MetalGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index f8273f8a1a..2fd3e5c056 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -1,26 +1,24 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/migration/migration_generator' class MigrationGeneratorTest < GeneratorsTestCase - def test_migration - @migration = "change_title_body_from_posts" - run_generator - assert_migration "db/migrate/#{@migration}.rb", /class ChangeTitleBodyFromPosts < ActiveRecord::Migration/ + migration = "change_title_body_from_posts" + run_generator [migration] + assert_migration "db/migrate/#{migration}.rb", /class ChangeTitleBodyFromPosts < ActiveRecord::Migration/ end def test_migration_with_class_name - @migration = "ChangeTitleBodyFromPosts" - run_generator - assert_migration "db/migrate/change_title_body_from_posts.rb", /class #{@migration} < ActiveRecord::Migration/ + migration = "ChangeTitleBodyFromPosts" + run_generator [migration] + assert_migration "db/migrate/change_title_body_from_posts.rb", /class #{migration} < ActiveRecord::Migration/ end def test_add_migration_with_attributes - @migration = "add_title_body_to_posts" - run_generator [@migration, "title:string", "body:text"] + migration = "add_title_body_to_posts" + run_generator [migration, "title:string", "body:text"] - assert_migration "db/migrate/#{@migration}.rb" do |content| + assert_migration "db/migrate/#{migration}.rb" do |content| assert_class_method :up, content do |up| assert_match /add_column :posts, :title, :string/, up assert_match /add_column :posts, :body, :text/, up @@ -34,10 +32,10 @@ class MigrationGeneratorTest < GeneratorsTestCase end def test_remove_migration_with_attributes - @migration = "remove_title_body_from_posts" - run_generator [@migration, "title:string", "body:text"] + migration = "remove_title_body_from_posts" + run_generator [migration, "title:string", "body:text"] - assert_migration "db/migrate/#{@migration}.rb" do |content| + assert_migration "db/migrate/#{migration}.rb" do |content| assert_class_method :up, content do |up| assert_match /remove_column :posts, :title/, up assert_match /remove_column :posts, :body/, up @@ -49,11 +47,4 @@ class MigrationGeneratorTest < GeneratorsTestCase end end end - - protected - - def run_generator(args=[@migration]) - silence(:stdout) { Rails::Generators::MigrationGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index 58737a81fc..051a43706b 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/model/model_generator' class ModelGeneratorTest < GeneratorsTestCase + arguments %w(Account name:string age:integer) def test_help_shows_invoked_generators_options content = run_generator ["--help"] @@ -171,11 +171,4 @@ class ModelGeneratorTest < GeneratorsTestCase content = capture(:stderr){ run_generator ["object"] } assert_match /The name 'Object' is either already used in your application or reserved/, content end - - protected - - def run_generator(args=["Account", "name:string", "age:integer"], config={}) - silence(:stdout) { Rails::Generators::ModelGenerator.start args, config.merge(:destination_root => destination_root) } - end - end diff --git a/railties/test/generators/named_base_test.rb b/railties/test/generators/named_base_test.rb index 98cbf9b8f6..8c1df3b992 100644 --- a/railties/test/generators/named_base_test.rb +++ b/railties/test/generators/named_base_test.rb @@ -1,4 +1,3 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator' @@ -13,9 +12,10 @@ module ActiveRecord end class NamedBaseTest < GeneratorsTestCase + tests Rails::Generators::ScaffoldControllerGenerator def test_named_generator_attributes - g = Rails::Generators::ScaffoldControllerGenerator.new ["admin/foo"] + g = generator ["admin/foo"] assert_equal 'admin/foo', g.name assert_equal %w(admin), g.class_path assert_equal 1, g.class_nesting_depth @@ -28,12 +28,12 @@ class NamedBaseTest < GeneratorsTestCase def test_named_generator_attributes_without_pluralized ActiveRecord::Base.pluralize_table_names = false - g = Rails::Generators::ScaffoldControllerGenerator.new ["admin/foo"] + g = generator ["admin/foo"] assert_equal "admin_#{g.singular_name}", g.table_name end def test_scaffold_plural_names - g = Rails::Generators::ScaffoldControllerGenerator.new ["ProductLine"] + g = generator ["ProductLine"] assert_equal "ProductLines", g.controller_name assert_equal "ProductLines", g.controller_class_name assert_equal "product_lines", g.controller_file_name diff --git a/railties/test/generators/observer_generator_test.rb b/railties/test/generators/observer_generator_test.rb index 6fed2998dd..44d9e4a9f3 100644 --- a/railties/test/generators/observer_generator_test.rb +++ b/railties/test/generators/observer_generator_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/observer/observer_generator' class ObserverGeneratorTest < GeneratorsTestCase + arguments %w(account) def test_invokes_default_orm run_generator @@ -23,11 +23,4 @@ class ObserverGeneratorTest < GeneratorsTestCase content = run_generator ["account", "--test-framework=rspec"] assert_match /rspec \[not found\]/, content end - - protected - - def run_generator(args=["account"]) - silence(:stdout) { Rails::Generators::ObserverGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/performance_test_generator_test.rb b/railties/test/generators/performance_test_generator_test.rb index d19128f79a..099575ea1d 100644 --- a/railties/test/generators/performance_test_generator_test.rb +++ b/railties/test/generators/performance_test_generator_test.rb @@ -1,18 +1,11 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/performance_test/performance_test_generator' class PerformanceTestGeneratorTest < GeneratorsTestCase + arguments %w(performance) def test_performance_test_skeleton_is_created run_generator assert_file "test/performance/performance_test.rb", /class PerformanceTest < ActionController::PerformanceTest/ end - - protected - - def run_generator(args=["performance"]) - silence(:stdout) { Rails::Generators::PerformanceTestGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index f5b8b6ffb6..f84b8b6d50 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/plugin/plugin_generator' class PluginGeneratorTest < GeneratorsTestCase + arguments %w(plugin_fu) def test_plugin_skeleton_is_created run_generator @@ -46,11 +46,4 @@ class PluginGeneratorTest < GeneratorsTestCase run_generator run_generator ["plugin_fu"], :behavior => :revoke end - - protected - - def run_generator(args=["plugin_fu"], config={}) - silence(:stdout) { Rails::Generators::PluginGenerator.start args, config.merge(:destination_root => destination_root) } - end - end diff --git a/railties/test/generators/resource_generator_test.rb b/railties/test/generators/resource_generator_test.rb index 136795bf3d..15c0ca0f01 100644 --- a/railties/test/generators/resource_generator_test.rb +++ b/railties/test/generators/resource_generator_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/resource/resource_generator' class ResourceGeneratorTest < GeneratorsTestCase + arguments %w(account) def setup super @@ -96,11 +96,4 @@ class ResourceGeneratorTest < GeneratorsTestCase assert_no_match /resources :accounts$/, route end end - - protected - - def run_generator(args=["account"], config={}) - silence(:stdout) { Rails::Generators::ResourceGenerator.start args, config.merge(:destination_root => destination_root) } - end - end diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index 96fc0750f4..7593c14dd9 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -1,4 +1,3 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator' @@ -8,6 +7,7 @@ module Unknown end class ScaffoldControllerGeneratorTest < GeneratorsTestCase + arguments %w(User name:string age:integer) def test_controller_skeleton_is_created run_generator @@ -135,11 +135,4 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase ensure Unknown::Generators.send :remove_const, :ActiveModel end - - protected - - def run_generator(args=["User", "name:string", "age:integer"]) - silence(:stdout) { Rails::Generators::ScaffoldControllerGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index a37e629d20..4ddc7b1c89 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/scaffold/scaffold_generator' class ScaffoldGeneratorTest < GeneratorsTestCase + arguments %w(product_line title:string price:integer) def setup super @@ -89,7 +89,7 @@ class ScaffoldGeneratorTest < GeneratorsTestCase def test_scaffold_on_revoke run_generator - run_generator :behavior => :revoke + run_generator ["product_line"], :behavior => :revoke # Model assert_no_file "app/models/product_line.rb" @@ -117,14 +117,4 @@ class ScaffoldGeneratorTest < GeneratorsTestCase # Stylesheets (should not be removed) assert_file "public/stylesheets/scaffold.css" end - - protected - - def run_generator(config={}) - silence(:stdout) do - Rails::Generators::ScaffoldGenerator.start ["product_line", "title:string", "price:integer"], - config.merge(:destination_root => destination_root) - end - end - end diff --git a/railties/test/generators/session_migration_generator_test.rb b/railties/test/generators/session_migration_generator_test.rb index 34fb996b7f..251ffb19ed 100644 --- a/railties/test/generators/session_migration_generator_test.rb +++ b/railties/test/generators/session_migration_generator_test.rb @@ -1,9 +1,7 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/session_migration/session_migration_generator' class SessionMigrationGeneratorTest < GeneratorsTestCase - def test_session_migration_with_default_name run_generator assert_migration "db/migrate/add_sessions_table.rb", /class AddSessionsTable < ActiveRecord::Migration/ @@ -24,11 +22,4 @@ class SessionMigrationGeneratorTest < GeneratorsTestCase ensure ActiveRecord::SessionStore::Session.table_name = "sessions" end - - protected - - def run_generator(args=[]) - silence(:stdout) { Rails::Generators::SessionMigrationGenerator.start args, :destination_root => destination_root } - end - end diff --git a/railties/test/generators/stylesheets_generator_test.rb b/railties/test/generators/stylesheets_generator_test.rb index 15263d4bb8..d9079327ba 100644 --- a/railties/test/generators/stylesheets_generator_test.rb +++ b/railties/test/generators/stylesheets_generator_test.rb @@ -1,9 +1,7 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/stylesheets/stylesheets_generator' class StylesheetsGeneratorTest < GeneratorsTestCase - def test_copy_stylesheets run_generator assert_file "public/stylesheets/scaffold.css" @@ -11,14 +9,7 @@ class StylesheetsGeneratorTest < GeneratorsTestCase def test_stylesheets_are_not_deleted_on_revoke run_generator - run_generator :behavior => :revoke + run_generator [], :behavior => :revoke assert_file "public/stylesheets/scaffold.css" end - - protected - - def run_generator(config={}) - silence(:stdout) { Rails::Generators::StylesheetsGenerator.start [], config.merge(:destination_root => destination_root) } - end - end -- cgit v1.2.3