diff options
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/application/assets_test.rb | 41 | ||||
-rw-r--r-- | railties/test/application/configuration_test.rb | 2 | ||||
-rw-r--r-- | railties/test/commands/console_test.rb | 89 | ||||
-rw-r--r-- | railties/test/commands/dbconsole_test.rb | 22 | ||||
-rw-r--r-- | railties/test/commands/server_test.rb | 4 | ||||
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 2 | ||||
-rw-r--r-- | railties/test/generators/namespaced_generators_test.rb | 4 | ||||
-rw-r--r-- | railties/test/generators/plugin_new_generator_test.rb | 44 | ||||
-rw-r--r-- | railties/test/railties/engine_test.rb | 4 |
9 files changed, 146 insertions, 66 deletions
diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index e23a19d69c..4243a79b58 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -17,9 +17,21 @@ module ApplicationTests teardown_app end - def precompile! + def precompile!(env = nil) quietly do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + precompile_task = 'bundle exec rake assets:precompile' + precompile_task += ' ' + env if env + out = Dir.chdir(app_path){ %x[ #{precompile_task} ] } + assert $?.exitstatus == 0, + "#{precompile_task} has failed: #{out}.\ + Probably you didn't install JavaScript runtime." + return out + end + end + + def clean_assets! + quietly do + assert Dir.chdir(app_path){ system('bundle exec rake assets:clean') } end end @@ -253,9 +265,8 @@ module ApplicationTests # digest is default in false, we must enable it for test environment add_to_env_config "test", "config.assets.digest = true" - quietly do - Dir.chdir(app_path){ `bundle exec rake assets:precompile RAILS_ENV=test` } - end + precompile!('RAILS_ENV=test') + file = Dir["#{app_path}/public/assets/application.css"].first assert_match(/\/assets\/rails\.png/, File.read(file)) file = Dir["#{app_path}/public/assets/application-*.css"].first @@ -285,9 +296,9 @@ module ApplicationTests add_to_config "config.assets.compile = true" ENV["RAILS_ENV"] = nil - quietly do - Dir.chdir(app_path){ `bundle exec rake assets:precompile RAILS_GROUPS=assets` } - end + + precompile!('RAILS_GROUPS=assets') + file = Dir["#{app_path}/public/assets/application-*.css"].first assert_match(/\/assets\/rails-([0-z]+)\.png/, File.read(file)) end @@ -310,9 +321,7 @@ module ApplicationTests app_file "public/assets/application.css", "a { color: green; }" app_file "public/assets/subdir/broken.png", "not really an image file" - quietly do - Dir.chdir(app_path){ `bundle exec rake assets:clean` } - end + clean_assets! files = Dir["#{app_path}/public/assets/**/*", "#{app_path}/tmp/cache/assets/*"] assert_equal 0, files.length, "Expected no assets, but found #{files.join(', ')}" @@ -440,9 +449,8 @@ module ApplicationTests add_to_config "config.assets.compile = true" add_to_config "config.assets.digest = true" - quietly do - Dir.chdir(app_path){ `bundle exec rake assets:clean assets:precompile` } - end + clean_assets! + precompile! files = Dir["#{app_path}/public/assets/application-*.js"] assert_equal 1, files.length, "Expected digested application.js asset to be generated, but none found" @@ -453,9 +461,8 @@ module ApplicationTests add_to_env_config "production", "config.assets.prefix = 'production_assets'" ENV["RAILS_ENV"] = nil - quietly do - Dir.chdir(app_path){ `bundle exec rake assets:clean` } - end + + clean_assets! files = Dir["#{app_path}/public/production_assets/application.js"] assert_equal 0, files.length, "Expected application.js asset to be removed, but still exists" diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 8579a942dd..75190372ab 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -376,7 +376,7 @@ module ApplicationTests assert_equal ActiveModel::MassAssignmentSecurity::WhiteList, ActiveRecord::Base.active_authorizers[:default].class - assert_equal [""], ActiveRecord::Base.active_authorizers[:default].to_a + assert_equal [], ActiveRecord::Base.active_authorizers[:default].to_a end test "registers interceptors with ActionMailer" do diff --git a/railties/test/commands/console_test.rb b/railties/test/commands/console_test.rb index 78648a16b3..91ede1cb68 100644 --- a/railties/test/commands/console_test.rb +++ b/railties/test/commands/console_test.rb @@ -3,47 +3,44 @@ require 'rails/commands/console' class Rails::ConsoleTest < ActiveSupport::TestCase class FakeConsole + def self.start; end end def setup end def test_sandbox_option - console = Rails::Console.new(app, ["--sandbox"]) + console = Rails::Console.new(app, parse_arguments(["--sandbox"])) assert console.sandbox? end def test_short_version_of_sandbox_option - console = Rails::Console.new(app, ["-s"]) + console = Rails::Console.new(app, parse_arguments(["-s"])) assert console.sandbox? end def test_debugger_option - console = Rails::Console.new(app, ["--debugger"]) + console = Rails::Console.new(app, parse_arguments(["--debugger"])) assert console.debugger? end def test_no_options - console = Rails::Console.new(app, []) + console = Rails::Console.new(app, parse_arguments([])) assert !console.debugger? assert !console.sandbox? end def test_start - app.expects(:sandbox=).with(nil) FakeConsole.expects(:start) - start - assert_match(/Loading \w+ environment \(Rails/, output) end def test_start_with_debugger - app.expects(:sandbox=).with(nil) + rails_console = Rails::Console.new(app, parse_arguments(["--debugger"])) rails_console.expects(:require_debugger).returns(nil) - FakeConsole.expects(:start) - start ["--debugger"] + silence_stream(STDOUT) { rails_console.start } end def test_start_with_sandbox @@ -56,42 +53,63 @@ class Rails::ConsoleTest < ActiveSupport::TestCase end def test_console_with_environment - app.expects(:sandbox=).with(nil) - FakeConsole.expects(:start) - start ["-e production"] + assert_match(/\sproduction\s/, output) + end + + def test_console_defaults_to_IRB + config = mock("config", :console => nil) + app = mock("app", :config => config) + app.expects(:load_console).returns(nil) - assert_match(/production/, output) + assert_equal IRB, Rails::Console.new(app).console end - def test_console_with_rails_environment - app.expects(:sandbox=).with(nil) - FakeConsole.expects(:start) + def test_default_environment_with_no_rails_env + with_rails_env nil do + start + assert_match /\sdevelopment\s/, output + end + end - start ["RAILS_ENV=production"] + def test_default_environment_with_rails_env + with_rails_env 'special-production' do + start + assert_match /\sspecial-production\s/, output + end + end + + def test_e_option + start ['-e', 'special-production'] + assert_match /\sspecial-production\s/, output + end - assert_match(/production/, output) + def test_environment_option + start ['--environment=special-production'] + assert_match /\sspecial-production\s/, output end + def test_rails_env_is_production_when_first_argument_is_p + start ['p'] + assert_match /\sproduction\s/, output + end - def test_console_defaults_to_IRB - config = mock("config", :console => nil) - app = mock("app", :config => config) - app.expects(:load_console).returns(nil) + def test_rails_env_is_test_when_first_argument_is_t + start ['t'] + assert_match /\stest\s/, output + end - assert_equal IRB, Rails::Console.new(app).console + def test_rails_env_is_development_when_argument_is_d + start ['d'] + assert_match /\sdevelopment\s/, output end private attr_reader :output - def rails_console - @rails_console ||= Rails::Console.new(app) - end - def start(argv = []) - rails_console.stubs(:arguments => argv) + rails_console = Rails::Console.new(app, parse_arguments(argv)) @output = output = capture(:stdout) { rails_console.start } end @@ -99,8 +117,21 @@ class Rails::ConsoleTest < ActiveSupport::TestCase @app ||= begin config = mock("config", :console => FakeConsole) app = mock("app", :config => config) + app.stubs(:sandbox=).returns(nil) app.expects(:load_console) app end end + + def parse_arguments(args) + Rails::Console.parse_arguments(args) + end + + def with_rails_env(env) + original_rails_env = ENV['RAILS_ENV'] + ENV['RAILS_ENV'] = env + yield + ensure + ENV['RAILS_ENV'] = original_rails_env + end end diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb index 562b83713b..d45bdaabf5 100644 --- a/railties/test/commands/dbconsole_test.rb +++ b/railties/test/commands/dbconsole_test.rb @@ -10,35 +10,37 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase Rails::DBConsole.const_set(:APP_PATH, "erb") app_config({}) - capture_abort { Rails::DBConsole.config } + capture_abort { Rails::DBConsole.new.config } assert aborted assert_match(/No database is configured for the environment '\w+'/, output) app_config(test: "with_init") - assert_equal Rails::DBConsole.config, "with_init" + assert_equal Rails::DBConsole.new.config, "with_init" app_db_file("test:\n without_init") - assert_equal Rails::DBConsole.config, "without_init" + assert_equal Rails::DBConsole.new.config, "without_init" app_db_file("test:\n <%= Rails.something_app_specific %>") - assert_equal Rails::DBConsole.config, "with_init" + assert_equal Rails::DBConsole.new.config, "with_init" app_db_file("test:\n\ninvalid") - assert_equal Rails::DBConsole.config, "with_init" + assert_equal Rails::DBConsole.new.config, "with_init" end def test_env - assert_equal Rails::DBConsole.env, "test" + assert_equal Rails::DBConsole.new.environment, "test" + + ENV['RAILS_ENV'] = nil + ENV['RACK_ENV'] = nil Rails.stubs(:respond_to?).with(:env).returns(false) - assert_equal Rails::DBConsole.env, "test" + assert_equal Rails::DBConsole.new.environment, "development" - ENV['RAILS_ENV'] = nil ENV['RACK_ENV'] = "rack_env" - assert_equal Rails::DBConsole.env, "rack_env" + assert_equal Rails::DBConsole.new.environment, "rack_env" ENV['RAILS_ENV'] = "rails_env" - assert_equal Rails::DBConsole.env, "rails_env" + assert_equal Rails::DBConsole.new.environment, "rails_env" ensure ENV['RAILS_ENV'] = "test" end diff --git a/railties/test/commands/server_test.rb b/railties/test/commands/server_test.rb index 8039aec873..4a3ea82e3d 100644 --- a/railties/test/commands/server_test.rb +++ b/railties/test/commands/server_test.rb @@ -4,14 +4,14 @@ require 'rails/commands/server' class Rails::ServerTest < ActiveSupport::TestCase def test_environment_with_server_option - args = ["thin", "RAILS_ENV=production"] + args = ["thin", "-e", "production"] options = Rails::Server::Options.new.parse!(args) assert_equal 'production', options[:environment] assert_equal 'thin', options[:server] end def test_environment_without_server_option - args = ["RAILS_ENV=production"] + args = ["-e", "production"] options = Rails::Server::Options.new.parse!(args) assert_equal 'production', options[:environment] assert_nil options[:server] diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 26e912fd9e..5534476a6d 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -246,7 +246,7 @@ class AppGeneratorTest < Rails::Generators::TestCase if defined?(JRUBY_VERSION) assert_gem "therubyrhino" else - assert_file "Gemfile", /# gem\s+["']therubyracer["']+, platform: :ruby$/ + assert_file "Gemfile", /# gem\s+["']therubyracer["']+, platforms: :ruby$/ end end diff --git a/railties/test/generators/namespaced_generators_test.rb b/railties/test/generators/namespaced_generators_test.rb index 09169ef2d2..2ae9dc61a7 100644 --- a/railties/test/generators/namespaced_generators_test.rb +++ b/railties/test/generators/namespaced_generators_test.rb @@ -38,7 +38,9 @@ class NamespacedControllerGeneratorTest < NamespacedGeneratorTestCase def test_namespaced_controller_with_additional_namespace run_generator ["admin/account"] - assert_file "app/controllers/test_app/admin/account_controller.rb", /module TestApp/, / class Admin::AccountController < ApplicationController/ + assert_file "app/controllers/test_app/admin/account_controller.rb", /module TestApp/, / class Admin::AccountController < ApplicationController/ do |contents| + assert_match %r(require_dependency "test_app/application_controller"), contents + end end def test_helpr_is_also_namespaced diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 58740978aa..0a235b56d5 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -58,6 +58,14 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_file "test/integration/navigation_test.rb", /ActionDispatch::IntegrationTest/ end + def test_generating_test_files_in_full_mode_without_unit_test_files + run_generator [destination_root, "-T", "--full"] + + assert_no_directory "test/integration/" + assert_no_file "test" + assert_no_match(/APP_RAKEFILE/, File.read(File.join(destination_root, "Rakefile"))) + end + def test_ensure_that_plugin_options_are_not_passed_to_app_generator FileUtils.cd(Rails.root) assert_no_match(/It works from file!.*It works_from_file/, run_generator([destination_root, "-m", "lib/template.rb"])) @@ -82,6 +90,14 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_file "bukkits.gemspec", /mysql/ end + def test_dont_generate_development_dependency + run_generator [destination_root, "--skip-active-record"] + + assert_file "bukkits.gemspec" do |contents| + assert_no_match(/s.add_development_dependency "sqlite3"/, contents) + end + end + def test_active_record_is_removed_from_frameworks_if_skip_active_record_is_given run_generator [destination_root, "--skip-active-record"] assert_file "test/dummy/config/application.rb", /#\s+require\s+["']active_record\/railtie["']/ @@ -269,6 +285,32 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_skipping_gemspec run_generator [destination_root, "--skip-gemspec"] assert_no_file "bukkits.gemspec" + assert_file "Gemfile" do |contents| + assert_no_match('gemspec', contents) + assert_match(/gem "rails", "~> #{Rails::VERSION::STRING}"/, contents) + assert_match(/group :development do\n gem "sqlite3"\nend/, contents) + assert_no_match(/# gem "jquery-rails"/, contents) + end + end + + def test_skipping_gemspec_in_full_mode + run_generator [destination_root, "--skip-gemspec", "--full"] + assert_no_file "bukkits.gemspec" + assert_file "Gemfile" do |contents| + assert_no_match('gemspec', contents) + assert_match(/gem "rails", "~> #{Rails::VERSION::STRING}"/, contents) + assert_match(/group :development do\n gem "sqlite3"\nend/, contents) + assert_match(/# gem "jquery-rails"/, contents) + assert_no_match(/# jquery-rails is used by the dummy application\ngem "jquery-rails"/, contents) + end + end + + def test_skipping_gemspec_in_full_mode_with_javascript_option + run_generator [destination_root, "--skip-gemspec", "--full", "--javascript=prototype"] + assert_file "Gemfile" do |contents| + assert_match(/# gem "prototype-rails"/, contents) + assert_match(/# jquery-rails is used by the dummy application\ngem "jquery-rails"/, contents) + end end def test_creating_plugin_in_app_directory_adds_gemfile_entry @@ -303,12 +345,10 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase protected - def action(*args, &block) silence(:stdout){ generator.send(*args, &block) } end -protected def default_files ::DEFAULT_PLUGIN_FILES end diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 4437e2c8af..52c7fae6c6 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -1009,9 +1009,7 @@ YAML boot_rails - methods = Bukkits::Engine.helpers.public_instance_methods.collect(&:to_s).sort - expected = ["bar", "baz"] - assert_equal expected, methods + assert_equal [:bar, :baz], Bukkits::Engine.helpers.public_instance_methods.sort end test "setting priority for engines with config.railties_order" do |