diff options
Diffstat (limited to 'railties/test/application')
25 files changed, 150 insertions, 8 deletions
diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 98a702f134..b76dae8e18 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -1,8 +1,9 @@ require 'isolation/abstract_unit' +require 'active_support/core_ext/kernel/reporting' require 'rack/test' module ApplicationTests - class RoutingTest < Test::Unit::TestCase + class AssetsTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation include Rack::Test::Methods @@ -11,6 +12,10 @@ module ApplicationTests boot_rails end + def teardown + teardown_app + end + def app @app ||= Rails.application end @@ -30,6 +35,31 @@ module ApplicationTests assert_match "alert()", last_response.body end + test "assets are compiled properly" do + app_file "app/assets/javascripts/application.js", "alert();" + + capture(:stdout) do + Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + end + + file = Dir["#{app_path}/public/assets/application-*.js"][0] + assert_not_nil file, "Expected application.js asset to be generated, but none found" + assert_equal "alert();\n", File.read(file) + end + + test "assets are cleaned up properly" do + app_file "public/assets/application.js", "alert();" + app_file "public/assets/application.css", "a { color: green; }" + app_file "public/assets/subdir/broken.png", "not really an image file" + + capture(:stdout) do + Dir.chdir(app_path){ `bundle exec rake assets:clean` } + end + + files = Dir["#{app_path}/public/assets/**/*"] + assert_equal 0, files.length, "Expected no assets, but found #{files.join(', ')}" + end + test "does not stream session cookies back" do app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();" diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 0e27c9606d..2547863d12 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -35,9 +35,25 @@ module ApplicationTests end def teardown + teardown_app FileUtils.rm_rf(new_app) if File.directory?(new_app) end + test "Rails.groups returns available groups" do + require "rails" + + Rails.env = "development" + assert_equal [:default, "development"], Rails.groups + assert_equal [:default, "development", :assets], Rails.groups(:assets => [:development]) + assert_equal [:default, "development", :assets], Rails.groups(:assets => %w(development)) + + Rails.env = "test" + assert_equal [:default, "test"], Rails.groups(:assets => [:development]) + + ENV["RAILS_GROUPS"] = "javascripts,stylesheets" + assert_equal [:default, "test", "javascripts", "stylesheets"], Rails.groups + end + test "Rails.application is nil until app is initialized" do require 'rails' assert_nil Rails.application diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb index db8f1f2ac6..1528d5dd87 100644 --- a/railties/test/application/console_test.rb +++ b/railties/test/application/console_test.rb @@ -1,13 +1,17 @@ require 'isolation/abstract_unit' class ConsoleTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation + include ActiveSupport::Testing::Isolation def setup build_app boot_rails end + def teardown + teardown_app + end + def load_environment(sandbox = false) require "#{rails_root}/config/environment" Rails.application.sandbox = sandbox diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index 1ca9515335..4365d00b1f 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -9,6 +9,10 @@ module ApplicationTests boot_rails end + def teardown + teardown_app + end + def app_const @app_const ||= Class.new(Rails::Application) end diff --git a/railties/test/application/initializers/boot_test.rb b/railties/test/application/initializers/boot_test.rb index 5ec562f12f..b1e01dc13f 100644 --- a/railties/test/application/initializers/boot_test.rb +++ b/railties/test/application/initializers/boot_test.rb @@ -9,8 +9,12 @@ module ApplicationTests # boot_rails end + def teardown + # teardown_app + end + test "booting rails sets the load paths correctly" do # This test is pending reworking the boot process end end -end
\ No newline at end of file +end diff --git a/railties/test/application/initializers/check_ruby_version_test.rb b/railties/test/application/initializers/check_ruby_version_test.rb index 5b6196307d..df7e9696a9 100644 --- a/railties/test/application/initializers/check_ruby_version_test.rb +++ b/railties/test/application/initializers/check_ruby_version_test.rb @@ -9,6 +9,10 @@ module ApplicationTests boot_rails end + def teardown + teardown_app + end + test "rails initializes with ruby 1.8.7 or later, except for 1.9.1" do if RUBY_VERSION < '1.8.7' assert_rails_does_not_boot diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index 196d121c14..446c85d65a 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -10,6 +10,10 @@ module ApplicationTests FileUtils.rm_rf "#{app_path}/config/environments" end + def teardown + teardown_app + end + # AC & AM test "set load paths set only if action controller or action mailer are in use" do assert_nothing_raised NameError do diff --git a/railties/test/application/initializers/hooks_test.rb b/railties/test/application/initializers/hooks_test.rb index 198abbe861..8c7726339c 100644 --- a/railties/test/application/initializers/hooks_test.rb +++ b/railties/test/application/initializers/hooks_test.rb @@ -10,6 +10,10 @@ module ApplicationTests FileUtils.rm_rf "#{app_path}/config/environments" end + def teardown + teardown_app + end + test "load initializers" do app_file "config/initializers/foo.rb", "$foo = true" require "#{app_path}/config/environment" diff --git a/railties/test/application/initializers/i18n_test.rb b/railties/test/application/initializers/i18n_test.rb index 390f65ab5c..8c2c079fb8 100644 --- a/railties/test/application/initializers/i18n_test.rb +++ b/railties/test/application/initializers/i18n_test.rb @@ -11,6 +11,10 @@ module ApplicationTests require "rails/all" end + def teardown + teardown_app + end + def load_app require "#{app_path}/config/environment" end @@ -48,7 +52,7 @@ module ApplicationTests end test "locale files should be added to the load path" do - app_file "config/another_locale.yml", "" + app_file "config/another_locale.yml", "en:\nfoo: ~" add_to_config <<-RUBY config.i18n.load_path << config.root.join("config/another_locale.yml").to_s @@ -127,7 +131,7 @@ en: # Fallbacks test "not using config.i18n.fallbacks does not initialize I18n.fallbacks" do - I18n.backend = Class.new { include I18n::Backend::Base }.new + I18n.backend = Class.new(I18n::Backend::Simple).new load_app assert_no_fallbacks end @@ -141,7 +145,7 @@ en: test "config.i18n.fallbacks = true initializes I18n.fallbacks with default settings even when backend changes" do I18n::Railtie.config.i18n.fallbacks = true - I18n::Railtie.config.i18n.backend = Class.new { include I18n::Backend::Base }.new + I18n::Railtie.config.i18n.backend = Class.new(I18n::Backend::Simple).new load_app assert I18n.backend.class.included_modules.include?(I18n::Backend::Fallbacks) assert_fallbacks :de => [:de, :en] diff --git a/railties/test/application/initializers/load_path_test.rb b/railties/test/application/initializers/load_path_test.rb index 714d62311d..644b8208a9 100644 --- a/railties/test/application/initializers/load_path_test.rb +++ b/railties/test/application/initializers/load_path_test.rb @@ -10,6 +10,10 @@ module ApplicationTests FileUtils.rm_rf "#{app_path}/config/environments" end + def teardown + teardown_app + end + test "initializing an application adds the application paths to the load path" do add_to_config <<-RUBY config.root = "#{app_path}" diff --git a/railties/test/application/initializers/notifications_test.rb b/railties/test/application/initializers/notifications_test.rb index c87433db0d..b72c14eaf0 100644 --- a/railties/test/application/initializers/notifications_test.rb +++ b/railties/test/application/initializers/notifications_test.rb @@ -9,6 +9,10 @@ module ApplicationTests boot_rails end + def teardown + teardown_app + end + def instrument(*args, &block) ActiveSupport::Notifications.instrument(*args, &block) end diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb index c340465e87..47c6fd5c6e 100644 --- a/railties/test/application/loading_test.rb +++ b/railties/test/application/loading_test.rb @@ -8,6 +8,10 @@ class LoadingTest < Test::Unit::TestCase boot_rails end + def teardown + teardown_app + end + def app @app ||= Rails.application end diff --git a/railties/test/application/middleware/best_practices_test.rb b/railties/test/application/middleware/best_practices_test.rb index 5b722e7510..1c88b9bf06 100644 --- a/railties/test/application/middleware/best_practices_test.rb +++ b/railties/test/application/middleware/best_practices_test.rb @@ -12,6 +12,10 @@ module ApplicationTests simple_controller end + def teardown + teardown_app + end + test "simple controller in production mode returns best standards" do get '/foo' assert_equal "IE=Edge,chrome=1", last_response.headers["X-UA-Compatible"] diff --git a/railties/test/application/middleware/cache_test.rb b/railties/test/application/middleware/cache_test.rb index a8033d2b23..e656ada3c0 100644 --- a/railties/test/application/middleware/cache_test.rb +++ b/railties/test/application/middleware/cache_test.rb @@ -11,6 +11,10 @@ module ApplicationTests extend Rack::Test::Methods end + def teardown + teardown_app + end + def simple_controller controller :expires, <<-RUBY class ExpiresController < ApplicationController diff --git a/railties/test/application/middleware/remote_ip_test.rb b/railties/test/application/middleware/remote_ip_test.rb index f28302d70a..da291f061c 100644 --- a/railties/test/application/middleware/remote_ip_test.rb +++ b/railties/test/application/middleware/remote_ip_test.rb @@ -10,6 +10,10 @@ module ApplicationTests FileUtils.rm_rf "#{app_path}/config/environments" end + def teardown + teardown_app + end + def app @app ||= Rails.application end diff --git a/railties/test/application/middleware/sendfile_test.rb b/railties/test/application/middleware/sendfile_test.rb index 0128261cd4..c7a1c573f9 100644 --- a/railties/test/application/middleware/sendfile_test.rb +++ b/railties/test/application/middleware/sendfile_test.rb @@ -10,6 +10,10 @@ module ApplicationTests FileUtils.rm_rf "#{app_path}/config/environments" end + def teardown + teardown_app + end + def app @app ||= Rails.application end diff --git a/railties/test/application/middleware/show_exceptions_test.rb b/railties/test/application/middleware/show_exceptions_test.rb index 5487e41e0a..e3f27f63c3 100644 --- a/railties/test/application/middleware/show_exceptions_test.rb +++ b/railties/test/application/middleware/show_exceptions_test.rb @@ -10,6 +10,10 @@ module ApplicationTests FileUtils.rm_rf "#{app_path}/config/environments" end + def teardown + teardown_app + end + def app @app ||= Rails.application end diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 715798ca08..6a0a272073 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -11,6 +11,10 @@ module ApplicationTests FileUtils.rm_rf "#{app_path}/config/environments" end + def teardown + teardown_app + end + def app @app ||= Rails.application end @@ -200,4 +204,4 @@ module ApplicationTests AppTemplate::Application.middleware.map(&:klass).map(&:name) end end -end
\ No newline at end of file +end diff --git a/railties/test/application/paths_test.rb b/railties/test/application/paths_test.rb index 03e0247556..0d22d8c19a 100644 --- a/railties/test/application/paths_test.rb +++ b/railties/test/application/paths_test.rb @@ -20,6 +20,10 @@ module ApplicationTests @paths = Rails.application.config.paths end + def teardown + teardown_app + end + def root(*path) app_path(*path).to_s end diff --git a/railties/test/application/rack/logger_test.rb b/railties/test/application/rack/logger_test.rb index 715af5c642..8b2b2f1802 100644 --- a/railties/test/application/rack/logger_test.rb +++ b/railties/test/application/rack/logger_test.rb @@ -14,6 +14,10 @@ module ApplicationTests super end + def teardown + teardown_app + end + def logs @logs ||= @logger.logged(:info) end diff --git a/railties/test/application/rackup_test.rb b/railties/test/application/rackup_test.rb index b0a9925890..ff9cdcadc7 100644 --- a/railties/test/application/rackup_test.rb +++ b/railties/test/application/rackup_test.rb @@ -15,6 +15,10 @@ module ApplicationTests boot_rails end + def teardown + teardown_app + end + test "rails app is present" do assert File.exist?(app_path("config")) end diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index ab36ace5e5..44ac6615de 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -10,6 +10,10 @@ module ApplicationTests FileUtils.rm_rf("#{app_path}/config/environments") end + def teardown + teardown_app + end + def test_gems_tasks_are_loaded_first_than_application_ones app_file "lib/tasks/app.rake", <<-RUBY $task_loaded = Rake::Task.task_defined?("db:create:all") @@ -113,7 +117,7 @@ module ApplicationTests end require "#{rails_root}/config/environment" - + # loading a specific fixture errormsg = Dir.chdir(app_path) { `rake db:fixtures:load FIXTURES=products` } assert $?.success?, errormsg diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index e3a7f8a63c..3adf0ccd3e 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -11,6 +11,10 @@ module ApplicationTests boot_rails end + def teardown + teardown_app + end + test "rails/info/properties in development" do app("development") get "/rails/info/properties" diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb index 292d1e247f..4468fa295e 100644 --- a/railties/test/application/runner_test.rb +++ b/railties/test/application/runner_test.rb @@ -18,6 +18,14 @@ module ApplicationTests MODEL end + def teardown + teardown_app + end + + def test_should_include_runner_in_shebang_line_in_help_without_option + assert_match "/rails runner", Dir.chdir(app_path) { `bundle exec rails runner` } + end + def test_should_include_runner_in_shebang_line_in_help assert_match "/rails runner", Dir.chdir(app_path) { `bundle exec rails runner --help` } end diff --git a/railties/test/application/test_test.rb b/railties/test/application/test_test.rb index f96319f472..27a7959e84 100644 --- a/railties/test/application/test_test.rb +++ b/railties/test/application/test_test.rb @@ -9,6 +9,10 @@ module ApplicationTests boot_rails end + def teardown + teardown_app + end + test "truth" do app_file 'test/unit/foo_test.rb', <<-RUBY require 'test_helper' |