diff options
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/application/generators_test.rb | 18 | ||||
-rw-r--r-- | railties/test/application/routing_test.rb | 12 | ||||
-rw-r--r-- | railties/test/commands/dbconsole_test.rb | 35 | ||||
-rw-r--r-- | railties/test/configuration/middleware_stack_proxy_test.rb | 59 | ||||
-rw-r--r-- | railties/test/generators/actions_test.rb | 8 | ||||
-rw-r--r-- | railties/test/generators/assets_generator_test.rb | 1 | ||||
-rw-r--r-- | railties/test/generators/namespaced_generators_test.rb | 17 | ||||
-rw-r--r-- | railties/test/generators/plugin_new_generator_test.rb | 4 | ||||
-rw-r--r-- | railties/test/generators/shared_generator_tests.rb | 1 | ||||
-rw-r--r-- | railties/test/paths_test.rb | 4 | ||||
-rw-r--r-- | railties/test/rails_info_controller_test.rb | 17 | ||||
-rw-r--r-- | railties/test/railties/engine_test.rb | 8 |
12 files changed, 151 insertions, 33 deletions
diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index bf58bb3f74..b80244f1d2 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -45,10 +45,10 @@ module ApplicationTests test "generators set rails options" do with_bare_config do |c| - c.generators.orm = :datamapper + c.generators.orm = :data_mapper c.generators.test_framework = :rspec c.generators.helper = false - expected = { :rails => { :orm => :datamapper, :test_framework => :rspec, :helper => false } } + expected = { :rails => { :orm => :data_mapper, :test_framework => :rspec, :helper => false } } assert_equal(expected, c.generators.options) end end @@ -64,7 +64,7 @@ module ApplicationTests test "generators aliases, options, templates and fallbacks on initialization" do add_to_config <<-RUBY config.generators.rails :aliases => { :test_framework => "-w" } - config.generators.orm :datamapper + config.generators.orm :data_mapper config.generators.test_framework :rspec config.generators.fallbacks[:shoulda] = :test_unit config.generators.templates << "some/where" @@ -95,15 +95,15 @@ module ApplicationTests test "generators with hashes for options and aliases" do with_bare_config do |c| c.generators do |g| - g.orm :datamapper, :migration => false + g.orm :data_mapper, :migration => false g.plugin :aliases => { :generator => "-g" }, :generator => true end expected = { - :rails => { :orm => :datamapper }, + :rails => { :orm => :data_mapper }, :plugin => { :generator => true }, - :datamapper => { :migration => false } + :data_mapper => { :migration => false } } assert_equal expected, c.generators.options @@ -114,12 +114,12 @@ module ApplicationTests test "generators with string and hash for options should generate symbol keys" do with_bare_config do |c| c.generators do |g| - g.orm 'datamapper', :migration => false + g.orm 'data_mapper', :migration => false end expected = { - :rails => { :orm => :datamapper }, - :datamapper => { :migration => false } + :rails => { :orm => :data_mapper }, + :data_mapper => { :migration => false } } assert_equal expected, c.generators.options diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 977a5fc7e8..d1373ba202 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -15,12 +15,24 @@ module ApplicationTests teardown_app end + test "rails/info/routes in development" do + app("development") + get "/rails/info/routes" + assert_equal 200, last_response.status + end + test "rails/info/properties in development" do app("development") get "/rails/info/properties" assert_equal 200, last_response.status end + test "rails/info/routes in production" do + app("production") + get "/rails/info/routes" + assert_equal 404, last_response.status + end + test "rails/info/properties in production" do app("production") get "/rails/info/properties" diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb index 85a7edfacd..6d0f5ca073 100644 --- a/railties/test/commands/dbconsole_test.rb +++ b/railties/test/commands/dbconsole_test.rb @@ -92,20 +92,25 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase end def test_sqlite3 - dbconsole.expects(:find_cmd_and_exec).with('sqlite3', 'db') - start(adapter: 'sqlite3', database: 'db') + dbconsole.expects(:find_cmd_and_exec).with('sqlite3', Rails.root.join('db.sqlite3').to_s) + start(adapter: 'sqlite3', database: 'db.sqlite3') assert !aborted end def test_sqlite3_mode - dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '-html', 'db') - start({adapter: 'sqlite3', database: 'db'}, ['--mode', 'html']) + dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '-html', Rails.root.join('db.sqlite3').to_s) + start({adapter: 'sqlite3', database: 'db.sqlite3'}, ['--mode', 'html']) assert !aborted end def test_sqlite3_header - dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '-header', 'db') - start({adapter: 'sqlite3', database: 'db'}, ['--header']) + dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '-header', Rails.root.join('db.sqlite3').to_s) + start({adapter: 'sqlite3', database: 'db.sqlite3'}, ['--header']) + end + + def test_sqlite3_db_absolute_path + dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '/tmp/db.sqlite3') + start(adapter: 'sqlite3', database: '/tmp/db.sqlite3') assert !aborted end @@ -127,6 +132,24 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase assert_match /Unknown command-line client for db/, output end + def test_print_help_short + stdout = capture(:stdout) do + start({}, ['-h']) + end + assert aborted + assert_equal '', output + assert_match /Usage:.*dbconsole/, stdout + end + + def test_print_help_long + stdout = capture(:stdout) do + start({}, ['--help']) + end + assert aborted + assert_equal '', output + assert_match /Usage:.*dbconsole/, stdout + end + private attr_reader :aborted, :output diff --git a/railties/test/configuration/middleware_stack_proxy_test.rb b/railties/test/configuration/middleware_stack_proxy_test.rb new file mode 100644 index 0000000000..5984c0b425 --- /dev/null +++ b/railties/test/configuration/middleware_stack_proxy_test.rb @@ -0,0 +1,59 @@ +require 'minitest/autorun' +require 'rails/configuration' +require 'active_support/test_case' + +module Rails + module Configuration + class MiddlewareStackProxyTest < ActiveSupport::TestCase + def setup + @stack = MiddlewareStackProxy.new + end + + def test_playback_insert_before + @stack.insert_before :foo + assert_playback :insert_before, :foo + end + + def test_playback_insert_after + @stack.insert_after :foo + assert_playback :insert_after, :foo + end + + def test_playback_swap + @stack.swap :foo + assert_playback :swap, :foo + end + + def test_playback_use + @stack.use :foo + assert_playback :use, :foo + end + + def test_playback_delete + @stack.delete :foo + assert_playback :delete, :foo + end + + def test_order + @stack.swap :foo + @stack.delete :foo + + mock = MiniTest::Mock.new + mock.expect :send, nil, [:swap, :foo] + mock.expect :send, nil, [:delete, :foo] + + @stack.merge_into mock + mock.verify + end + + private + + def assert_playback(msg_name, args) + mock = MiniTest::Mock.new + mock.expect :send, nil, [msg_name, args] + @stack.merge_into(mock) + mock.verify + end + end + end +end diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index a8c8fcd5b7..bc086c5986 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -67,6 +67,14 @@ class ActionsTest < Rails::Generators::TestCase assert_file 'Gemfile', /^gem "rspec-rails"$/ end + def test_gem_should_include_options + run_generator + + action :gem, 'rspec', github: 'dchelimsky/rspec', tag: '1.2.9.rc1' + + assert_file 'Gemfile', /gem "rspec", github: "dchelimsky\/rspec", tag: "1\.2\.9\.rc1"/ + end + def test_gem_group_should_wrap_gems_in_a_group run_generator diff --git a/railties/test/generators/assets_generator_test.rb b/railties/test/generators/assets_generator_test.rb index d6338bd3da..a2b94f2e50 100644 --- a/railties/test/generators/assets_generator_test.rb +++ b/railties/test/generators/assets_generator_test.rb @@ -1,7 +1,6 @@ require 'generators/generators_test_helper' require 'rails/generators/rails/assets/assets_generator' -# FIXME: Silence the 'Could not find task "using_coffee?"' message in tests due to the public stub class AssetsGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper arguments %w(posts) diff --git a/railties/test/generators/namespaced_generators_test.rb b/railties/test/generators/namespaced_generators_test.rb index c495258343..09169ef2d2 100644 --- a/railties/test/generators/namespaced_generators_test.rb +++ b/railties/test/generators/namespaced_generators_test.rb @@ -20,8 +20,14 @@ class NamespacedControllerGeneratorTest < NamespacedGeneratorTestCase def test_namespaced_controller_skeleton_is_created run_generator - assert_file "app/controllers/test_app/account_controller.rb", /module TestApp/, / class AccountController < ApplicationController/ - assert_file "test/functional/test_app/account_controller_test.rb", /module TestApp/, / class AccountControllerTest/ + assert_file "app/controllers/test_app/account_controller.rb", + /require_dependency "test_app\/application_controller"/, + /module TestApp/, + / class AccountController < ApplicationController/ + + assert_file "test/functional/test_app/account_controller_test.rb", + /module TestApp/, + / class AccountControllerTest/ end def test_skipping_namespace @@ -227,9 +233,10 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase end # Controller - assert_file "app/controllers/test_app/product_lines_controller.rb" do |content| - assert_match(/module TestApp\n class ProductLinesController < ApplicationController/, content) - end + assert_file "app/controllers/test_app/product_lines_controller.rb", + /require_dependency "test_app\/application_controller"/, + /module TestApp/, + /class ProductLinesController < ApplicationController/ assert_file "test/functional/test_app/product_lines_controller_test.rb", /module TestApp\n class ProductLinesControllerTest < ActionController::TestCase/ diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 51374e5f3f..58740978aa 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -279,7 +279,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase run_generator [destination_root] - assert_file gemfile_path, /gem 'bukkits', :path => 'tmp\/bukkits'/ + assert_file gemfile_path, /gem 'bukkits', path: 'tmp\/bukkits'/ ensure Object.send(:remove_const, 'APP_PATH') FileUtils.rm gemfile_path @@ -294,7 +294,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase run_generator [destination_root, "--skip-gemfile-entry"] assert_file gemfile_path do |contents| - assert_no_match(/gem 'bukkits', :path => 'tmp\/bukkits'/, contents) + assert_no_match(/gem 'bukkits', path: 'tmp\/bukkits'/, contents) end ensure Object.send(:remove_const, 'APP_PATH') diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index 6dc72f0fc0..e78e67725d 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -1,5 +1,6 @@ # # Tests, setup, and teardown common to the application and plugin generator suites. +# module SharedGeneratorTests def setup Rails.application = TestApp::Application diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index aa04cad033..5d6b6f9f72 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -29,7 +29,7 @@ class PathsTest < ActiveSupport::TestCase test "creating a root level path" do @root.add "app" assert_equal ["/foo/bar/app"], @root["app"].to_a - assert_equal [Pathname.new("/foo/bar/app")], @root["app"].paths + assert_equal ["/foo/bar/app"], @root["app"].paths end test "creating a root level path with options" do @@ -192,7 +192,7 @@ class PathsTest < ActiveSupport::TestCase @root["app"] = "/app" @root["app"].glob = "*.rb" assert_equal "*.rb", @root["app"].glob - assert_equal [Pathname.new("/app")], @root["app"].paths + assert_equal ["/foo/bar/app"], @root["app"].paths end test "it should be possible to override a path's default glob without assignment" do diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index f7a30a16d2..cfb32b7d35 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -12,29 +12,28 @@ class InfoControllerTest < ActionController::TestCase def setup Rails.application.routes.draw do get '/rails/info/properties' => "rails/info#properties" + get '/rails/info/routes' => "rails/info#routes" end - @request.stubs(:local? => true) - @controller.stubs(:consider_all_requests_local? => false) + @controller.stubs(:local_request? => true) @routes = Rails.application.routes Rails::InfoController.send(:include, @routes.url_helpers) end test "info controller does not allow remote requests" do - @request.stubs(:local? => false) + @controller.stubs(:local_request? => false) get :properties assert_response :forbidden end test "info controller renders an error message when request was forbidden" do - @request.stubs(:local? => false) + @controller.stubs(:local_request? => false) get :properties assert_select 'p' end test "info controller allows requests when all requests are considered local" do - @request.stubs(:local? => false) - @controller.stubs(:consider_all_requests_local? => true) + @controller.stubs(:local_request? => true) get :properties assert_response :success end @@ -48,4 +47,10 @@ class InfoControllerTest < ActionController::TestCase get :properties assert_select 'table' end + + test "info controller renders with routes" do + get :routes + assert_select 'pre' + end + end diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 55f72f532f..4437e2c8af 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -882,7 +882,7 @@ YAML module Bukkits class Engine < ::Rails::Engine config.generators do |g| - g.orm :datamapper + g.orm :data_mapper g.template_engine :haml g.test_framework :rspec end @@ -910,7 +910,7 @@ YAML assert_equal :test_unit, app_generators[:test_framework] generators = Bukkits::Engine.config.generators.options[:rails] - assert_equal :datamapper, generators[:orm] + assert_equal :data_mapper, generators[:orm] assert_equal :haml , generators[:template_engine] assert_equal :rspec , generators[:test_framework] end @@ -1098,6 +1098,10 @@ YAML get("/assets/bar.js") assert_equal "// App's bar js\n;", last_response.body.strip + + # ensure that railties are not added twice + railties = Rails.application.ordered_railties.map(&:class) + assert_equal railties, railties.uniq end test "railties_order adds :all with lowest priority if not given" do |