diff options
Diffstat (limited to 'railties/test/application')
-rw-r--r-- | railties/test/application/assets_test.rb | 30 | ||||
-rw-r--r-- | railties/test/application/configuration_test.rb | 55 | ||||
-rw-r--r-- | railties/test/application/initializers/boot_test.rb | 2 | ||||
-rw-r--r-- | railties/test/application/initializers/frameworks_test.rb | 20 | ||||
-rw-r--r-- | railties/test/application/initializers/hooks_test.rb | 10 | ||||
-rw-r--r-- | railties/test/application/middleware/cache_test.rb | 2 | ||||
-rw-r--r-- | railties/test/application/middleware/exceptions_test.rb | 14 | ||||
-rw-r--r-- | railties/test/application/middleware/remote_ip_test.rb | 14 | ||||
-rw-r--r-- | railties/test/application/middleware_test.rb | 8 | ||||
-rw-r--r-- | railties/test/application/queue_test.rb | 13 | ||||
-rw-r--r-- | railties/test/application/rack/logger_test.rb | 8 | ||||
-rw-r--r-- | railties/test/application/rake_test.rb | 23 | ||||
-rw-r--r-- | railties/test/application/routes_inspect_test.rb | 168 |
13 files changed, 97 insertions, 270 deletions
diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 4243a79b58..c29fa4d95f 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -106,20 +106,28 @@ module ApplicationTests precompile! images_should_compile.each do |filename| - assert File.exists?("#{app_path}/public/assets/#{filename}") + assert_file_exists "#{app_path}/public/assets/#{filename}" end - assert File.exists?("#{app_path}/public/assets/application.js") - assert File.exists?("#{app_path}/public/assets/application.css") + assert_file_exists("#{app_path}/public/assets/application.js") + assert_file_exists("#{app_path}/public/assets/application.css") + + assert_no_file_exists("#{app_path}/public/assets/someapplication.js") + assert_no_file_exists("#{app_path}/public/assets/someapplication.css") - assert !File.exists?("#{app_path}/public/assets/someapplication.js") - assert !File.exists?("#{app_path}/public/assets/someapplication.css") + assert_no_file_exists("#{app_path}/public/assets/something.min.js") + assert_no_file_exists("#{app_path}/public/assets/something.min.css") - assert !File.exists?("#{app_path}/public/assets/something.min.js") - assert !File.exists?("#{app_path}/public/assets/something.min.css") + assert_no_file_exists("#{app_path}/public/assets/something.else.js") + assert_no_file_exists("#{app_path}/public/assets/something.else.css") + end + + def assert_file_exists(filename) + assert File.exists?(filename), "missing #{filename}" + end - assert !File.exists?("#{app_path}/public/assets/something.else.js") - assert !File.exists?("#{app_path}/public/assets/something.else.css") + def assert_no_file_exists(filename) + assert !File.exists?(filename), "#{filename} does exist" end test "asset pipeline should use a Sprockets::Index when config.assets.digest is true" do @@ -233,7 +241,7 @@ module ApplicationTests get '/posts' assert_match(/AssetNotPrecompiledError/, last_response.body) - assert_match(/app.js isn't precompiled/, last_response.body) + assert_match(/app.js isn't precompiled/, last_response.body) end test "assets raise AssetNotPrecompiledError when manifest file is present and requested file isn't precompiled if digest is disabled" do @@ -257,7 +265,7 @@ module ApplicationTests get '/posts' assert_match(/AssetNotPrecompiledError/, last_response.body) - assert_match(/app.js isn't precompiled/, last_response.body) + assert_match(/app.js isn't precompiled/, last_response.body) end test "precompile properly refers files referenced with asset_path and and run in the provided RAILS_ENV" do diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index c813defe93..039b08c723 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -139,22 +139,19 @@ module ApplicationTests assert_instance_of Pathname, Rails.root end - test "marking the application as threadsafe sets the correct config variables" do + test "initialize an eager loaded, cache classes app" do add_to_config <<-RUBY - config.threadsafe! + config.eager_load = true + config.cache_classes = true RUBY require "#{app_path}/config/application" - assert AppTemplate::Application.config.allow_concurrency + assert AppTemplate::Application.initialize! end - test "initialize a threadsafe app" do - add_to_config <<-RUBY - config.threadsafe! - RUBY - + test "application is always added to eager_load namespaces" do require "#{app_path}/config/application" - assert AppTemplate::Application.initialize! + assert AppTemplate::Application, AppTemplate::Application.config.eager_load_namespaces end test "asset_path defaults to nil for application" do @@ -162,10 +159,11 @@ module ApplicationTests assert_equal nil, AppTemplate::Application.config.asset_path end - test "the application can be marked as threadsafe when there are no frameworks" do + test "the application can be eager loaded even when there are no frameworks" do FileUtils.rm_rf("#{app_path}/config/environments") add_to_config <<-RUBY - config.threadsafe! + config.eager_load = true + config.cache_classes = true RUBY use_frameworks [] @@ -175,22 +173,6 @@ module ApplicationTests end end - test "frameworks are not preloaded by default" do - require "#{app_path}/config/environment" - - assert ActionController.autoload?(:Caching) - 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 !ActionView.autoload?(:AssetPaths) - end - test "filter_parameters should be able to set via config.filter_parameters" do add_to_config <<-RUBY config.filter_parameters += [ :foo, 'bar', lambda { |key, value| @@ -648,5 +630,24 @@ module ApplicationTests ActiveRecord::Base assert defined?(FooObserver) end + + test "config.session_store with :active_record_store with activerecord-session_store gem" do + begin + make_basic_app do |app| + ActionDispatch::Session::ActiveRecordStore = Class.new(ActionDispatch::Session::CookieStore) + app.config.session_store :active_record_store + end + ensure + ActionDispatch::Session.send :remove_const, :ActiveRecordStore + end + end + + test "config.session_store with :active_record_store without activerecord-session_store gem" do + assert_raise RuntimeError, /activerecord-session_store/ do + make_basic_app do |app| + app.config.session_store :active_record_store + end + end + end end end diff --git a/railties/test/application/initializers/boot_test.rb b/railties/test/application/initializers/boot_test.rb index 04c46058cb..7eda15894e 100644 --- a/railties/test/application/initializers/boot_test.rb +++ b/railties/test/application/initializers/boot_test.rb @@ -1,7 +1,7 @@ require "isolation/abstract_unit" module ApplicationTests - class GemBooting < ActiveSupport::TestCase + class BootTest < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation def setup diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index c2d4a0f2c8..d3bbac811c 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -163,26 +163,6 @@ module ApplicationTests end # AR - test "database middleware doesn't initialize when session store is not active_record" do - add_to_config <<-RUBY - config.root = "#{app_path}" - config.session_store :cookie_store, { :key => "blahblahblah" } - RUBY - require "#{app_path}/config/environment" - - assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore) - end - - test "database middleware initializes when session store is active record" do - add_to_config "config.session_store :active_record_store" - - require "#{app_path}/config/environment" - - expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore] - middleware = Rails.application.config.middleware.map { |m| m.klass } - assert_equal expects, middleware & expects - 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" diff --git a/railties/test/application/initializers/hooks_test.rb b/railties/test/application/initializers/hooks_test.rb index 7b3e6844fd..b2cea0a8e1 100644 --- a/railties/test/application/initializers/hooks_test.rb +++ b/railties/test/application/initializers/hooks_test.rb @@ -1,7 +1,7 @@ require "isolation/abstract_unit" module ApplicationTests - class InitializersTest < ActiveSupport::TestCase + class HooksTest < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation def setup @@ -20,11 +20,11 @@ module ApplicationTests assert $foo end - test "hooks block works correctly without cache classes (before_eager_load is not called)" do + test "hooks block works correctly without eager_load (before_eager_load is not called)" do add_to_config <<-RUBY $initialization_callbacks = [] config.root = "#{app_path}" - config.cache_classes = false + config.eager_load = false config.before_configuration { $initialization_callbacks << 1 } config.before_initialize { $initialization_callbacks << 2 } config.before_eager_load { Boom } @@ -35,11 +35,11 @@ module ApplicationTests assert_equal [1,2,3], $initialization_callbacks end - test "hooks block works correctly with cache classes" do + test "hooks block works correctly with eager_load" do add_to_config <<-RUBY $initialization_callbacks = [] config.root = "#{app_path}" - config.cache_classes = true + config.eager_load = true config.before_configuration { $initialization_callbacks << 1 } config.before_initialize { $initialization_callbacks << 2 } config.before_eager_load { $initialization_callbacks << 3 } diff --git a/railties/test/application/middleware/cache_test.rb b/railties/test/application/middleware/cache_test.rb index 54b18542c2..19d3f3a397 100644 --- a/railties/test/application/middleware/cache_test.rb +++ b/railties/test/application/middleware/cache_test.rb @@ -1,7 +1,7 @@ require 'isolation/abstract_unit' module ApplicationTests - class RoutingTest < ActiveSupport::TestCase + class CacheTest < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation def setup diff --git a/railties/test/application/middleware/exceptions_test.rb b/railties/test/application/middleware/exceptions_test.rb index d1a614e181..42096cfec4 100644 --- a/railties/test/application/middleware/exceptions_test.rb +++ b/railties/test/application/middleware/exceptions_test.rb @@ -88,9 +88,6 @@ module ApplicationTests end test "displays diagnostics message when exception raised in template that contains UTF-8" do - app.config.action_dispatch.show_exceptions = true - app.config.consider_all_requests_local = true - controller :foo, <<-RUBY class FooController < ActionController::Base def index @@ -98,18 +95,15 @@ module ApplicationTests end RUBY + app.config.action_dispatch.show_exceptions = true + app.config.consider_all_requests_local = true + app_file 'app/views/foo/index.html.erb', <<-ERB <% raise 'boooom' %> ✓測試テスト시험 ERB - app_file 'config/routes.rb', <<-RUBY - AppTemplate::Application.routes.draw do - post ':controller(/:action)' - end - RUBY - - post '/foo', :utf8 => '✓' + get '/foo', :utf8 => '✓' assert_match(/boooom/, last_response.body) assert_match(/測試テスト시험/, last_response.body) end diff --git a/railties/test/application/middleware/remote_ip_test.rb b/railties/test/application/middleware/remote_ip_test.rb index 066f0c1c84..9d97bae9ae 100644 --- a/railties/test/application/middleware/remote_ip_test.rb +++ b/railties/test/application/middleware/remote_ip_test.rb @@ -4,20 +4,6 @@ module ApplicationTests class RemoteIpTest < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation - def setup - build_app - boot_rails - FileUtils.rm_rf "#{app_path}/config/environments" - end - - def teardown - teardown_app - end - - def app - @app ||= Rails.application - end - def remote_ip(env = {}) remote_ip = nil env = Rack::MockRequest.env_for("/").merge(env).merge!( diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index ba747bc633..3e096e99f2 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -1,6 +1,4 @@ require 'isolation/abstract_unit' -require 'stringio' -require 'rack/test' module ApplicationTests class MiddlewareTest < ActiveSupport::TestCase @@ -45,7 +43,7 @@ module ApplicationTests "ActionDispatch::Session::CookieStore", "ActionDispatch::Flash", "ActionDispatch::ParamsParser", - "ActionDispatch::Head", + "Rack::Head", "Rack::ConditionalGet", "Rack::ETag", "ActionDispatch::BestStandardsSupport" @@ -87,8 +85,8 @@ module ApplicationTests assert !middleware.include?("ActiveRecord::QueryCache") end - test "removes lock if allow concurrency is set" do - add_to_config "config.allow_concurrency = true" + test "removes lock if cache classes is set" do + add_to_config "config.cache_classes = true" boot! assert !middleware.include?("Rack::Lock") end diff --git a/railties/test/application/queue_test.rb b/railties/test/application/queue_test.rb index 22d6c20404..c856089540 100644 --- a/railties/test/application/queue_test.rb +++ b/railties/test/application/queue_test.rb @@ -1,8 +1,7 @@ require 'isolation/abstract_unit' -require 'rack/test' module ApplicationTests - class GeneratorsTest < ActiveSupport::TestCase + class QueueTest < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation def setup @@ -20,14 +19,14 @@ module ApplicationTests test "the queue is a TestQueue in test mode" do app("test") - assert_kind_of Rails::Queueing::TestQueue, Rails.application.queue - assert_kind_of Rails::Queueing::TestQueue, Rails.queue + assert_kind_of Rails::Queueing::TestQueue, Rails.application.queue[:default] + assert_kind_of Rails::Queueing::TestQueue, Rails.queue[:default] end test "the queue is a Queue in development mode" do app("development") - assert_kind_of Rails::Queueing::Queue, Rails.application.queue - assert_kind_of Rails::Queueing::Queue, Rails.queue + assert_kind_of Rails::Queueing::Queue, Rails.application.queue[:default] + assert_kind_of Rails::Queueing::Queue, Rails.queue[:default] end class ThreadTrackingJob @@ -144,7 +143,7 @@ module ApplicationTests test "a custom queue implementation can be provided" do setup_custom_queue - assert_kind_of MyQueue, Rails.queue + assert_kind_of MyQueue, Rails.queue[:default] job = Struct.new(:id, :ran) do def run diff --git a/railties/test/application/rack/logger_test.rb b/railties/test/application/rack/logger_test.rb index 46fd09cb26..2f5bd3a764 100644 --- a/railties/test/application/rack/logger_test.rb +++ b/railties/test/application/rack/logger_test.rb @@ -26,12 +26,18 @@ module ApplicationTests @logs ||= @logger.logged(:info) end - test "logger logs proper HTTP verb and path" do + test "logger logs proper HTTP GET verb and path" do get "/blah" wait assert_match(/^Started GET "\/blah"/, logs[0]) end + test "logger logs proper HTTP HEAD verb and path" do + head "/blah" + wait + assert_match(/^Started HEAD "\/blah"/, logs[0]) + end + test "logger logs HTTP verb override" do post "/", {:_method => 'put'} wait diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index a450f90dbf..b05fe3aed5 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -55,6 +55,29 @@ module ApplicationTests assert_match "Doing something...", output end + def test_does_not_explode_when_accessing_a_model_with_eager_load + add_to_config <<-RUBY + config.eager_load = true + + rake_tasks do + task :do_nothing => :environment do + Hello.new.world + end + end + RUBY + + app_file "app/models/hello.rb", <<-RUBY + class Hello + def world + puts "Hello world" + end + end + RUBY + + output = Dir.chdir(app_path){ `rake do_nothing` } + assert_match "Hello world", output + end + def test_code_statistics_sanity assert_match "Code LOC: 5 Test LOC: 0 Code to Test Ratio: 1:0.0", Dir.chdir(app_path){ `rake stats` } diff --git a/railties/test/application/routes_inspect_test.rb b/railties/test/application/routes_inspect_test.rb deleted file mode 100644 index 68a8afc93e..0000000000 --- a/railties/test/application/routes_inspect_test.rb +++ /dev/null @@ -1,168 +0,0 @@ -require 'minitest/autorun' -require 'rails/application/routes_inspector' -require 'action_controller' -require 'rails/engine' - -module ApplicationTests - class RoutesInspectTest < ActiveSupport::TestCase - def setup - @set = ActionDispatch::Routing::RouteSet.new - @inspector = Rails::Application::RoutesInspector.new - app = ActiveSupport::OrderedOptions.new - app.config = ActiveSupport::OrderedOptions.new - app.config.assets = ActiveSupport::OrderedOptions.new - app.config.assets.prefix = '/sprockets' - Rails.stubs(:application).returns(app) - Rails.stubs(:env).returns("development") - end - - def draw(&block) - @set.draw(&block) - @inspector.format(@set.routes) - end - - def test_displaying_routes_for_engines - engine = Class.new(Rails::Engine) do - def self.to_s - "Blog::Engine" - end - end - engine.routes.draw do - get '/cart', :to => 'cart#show' - end - - output = draw do - get '/custom/assets', :to => 'custom_assets#show' - mount engine => "/blog", :as => "blog" - end - - expected = [ - "custom_assets GET /custom/assets(.:format) custom_assets#show", - " blog /blog Blog::Engine", - "\nRoutes for Blog::Engine:", - "cart GET /cart(.:format) cart#show" - ] - assert_equal expected, output - end - - def test_cart_inspect - output = draw do - get '/cart', :to => 'cart#show' - end - assert_equal ["cart GET /cart(.:format) cart#show"], output - end - - def test_inspect_shows_custom_assets - output = draw do - get '/custom/assets', :to => 'custom_assets#show' - end - assert_equal ["custom_assets GET /custom/assets(.:format) custom_assets#show"], output - end - - def test_inspect_routes_shows_resources_route - output = draw do - resources :articles - end - expected = [ - " articles GET /articles(.:format) articles#index", - " POST /articles(.:format) articles#create", - " new_article GET /articles/new(.:format) articles#new", - "edit_article GET /articles/:id/edit(.:format) articles#edit", - " article GET /articles/:id(.:format) articles#show", - " PATCH /articles/:id(.:format) articles#update", - " PUT /articles/:id(.:format) articles#update", - " DELETE /articles/:id(.:format) articles#destroy" ] - assert_equal expected, output - end - - def test_inspect_routes_shows_root_route - output = draw do - root :to => 'pages#main' - end - assert_equal ["root GET / pages#main"], output - end - - def test_inspect_routes_shows_dynamic_action_route - output = draw do - get 'api/:action' => 'api' - end - assert_equal [" GET /api/:action(.:format) api#:action"], output - end - - def test_inspect_routes_shows_controller_and_action_only_route - output = draw do - get ':controller/:action' - end - assert_equal [" GET /:controller/:action(.:format) :controller#:action"], output - end - - def test_inspect_routes_shows_controller_and_action_route_with_constraints - output = draw do - get ':controller(/:action(/:id))', :id => /\d+/ - end - assert_equal [" GET /:controller(/:action(/:id))(.:format) :controller#:action {:id=>/\\d+/}"], output - end - - def test_rake_routes_shows_route_with_defaults - output = draw do - get 'photos/:id' => 'photos#show', :defaults => {:format => 'jpg'} - end - assert_equal [%Q[ GET /photos/:id(.:format) photos#show {:format=>"jpg"}]], output - end - - def test_rake_routes_shows_route_with_constraints - output = draw do - get 'photos/:id' => 'photos#show', :id => /[A-Z]\d{5}/ - end - assert_equal [" GET /photos/:id(.:format) photos#show {:id=>/[A-Z]\\d{5}/}"], output - end - - class RackApp - def self.call(env) - end - end - - def test_rake_routes_shows_route_with_rack_app - output = draw do - get 'foo/:id' => RackApp, :id => /[A-Z]\d{5}/ - end - assert_equal [" GET /foo/:id(.:format) #{RackApp.name} {:id=>/[A-Z]\\d{5}/}"], output - end - - def test_rake_routes_shows_route_with_rack_app_nested_with_dynamic_constraints - constraint = Class.new do - def to_s - "( my custom constraint )" - end - end - - output = draw do - scope :constraint => constraint.new do - mount RackApp => '/foo' - end - end - - assert_equal [" /foo #{RackApp.name} {:constraint=>( my custom constraint )}"], output - end - - def test_rake_routes_dont_show_app_mounted_in_assets_prefix - output = draw do - get '/sprockets' => RackApp - end - assert_no_match(/RackApp/, output.first) - assert_no_match(/\/sprockets/, output.first) - end - - def test_redirect - output = draw do - get "/foo" => redirect("/foo/bar"), :constraints => { :subdomain => "admin" } - get "/bar" => redirect(path: "/foo/bar", status: 307) - get "/foobar" => redirect{ "/foo/bar" } - end - - assert_equal " foo GET /foo(.:format) redirect(301, /foo/bar) {:subdomain=>\"admin\"}", output[0] - assert_equal " bar GET /bar(.:format) redirect(307, path: /foo/bar)", output[1] - assert_equal "foobar GET /foobar(.:format) redirect(301)", output[2] - end - end -end |