diff options
Diffstat (limited to 'railties/test')
21 files changed, 218 insertions, 106 deletions
diff --git a/railties/test/application/asset_debugging_test.rb b/railties/test/application/asset_debugging_test.rb index 1eddfac664..b3b40448c0 100644 --- a/railties/test/application/asset_debugging_test.rb +++ b/railties/test/application/asset_debugging_test.rb @@ -48,7 +48,7 @@ module ApplicationTests assert_no_match(/<script src="\/assets\/xmlhr-([0-z]+)\.js"><\/script>/, last_response.body) end - test "assets aren't concatened when compile is true is on and debug_assets params is true" do + test "assets aren't concatenated when compile is true is on and debug_assets params is true" do add_to_env_config "production", "config.assets.compile = true" ENV["RAILS_ENV"] = "production" diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 638df8ca23..34432eac3a 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -41,6 +41,7 @@ module ApplicationTests end test "assets routes have higher priority" do + app_file "app/assets/images/rails.png", "notactuallyapng" app_file "app/assets/javascripts/demo.js.erb", "a = <%= image_path('rails.png').inspect %>;" app_file 'config/routes.rb', <<-RUBY @@ -86,8 +87,8 @@ module ApplicationTests def test_precompile_does_not_hit_the_database app_file "app/assets/javascripts/application.js", "alert();" app_file "app/assets/javascripts/foo/application.js", "alert();" - app_file "app/controllers/user_controller.rb", <<-eoruby - class UserController < ApplicationController; end + app_file "app/controllers/users_controller.rb", <<-eoruby + class UsersController < ApplicationController; end eoruby app_file "app/models/user.rb", <<-eoruby class User < ActiveRecord::Base; end @@ -221,7 +222,8 @@ module ApplicationTests assert !defined?(Uglifier) end - test "precompile properly refers files referenced with asset_path and and run in the provided RAILS_ENV" do + test "precompile properly refers files referenced with asset_path and runs in the provided RAILS_ENV" do + app_file "app/assets/images/rails.png", "notactuallyapng" app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" # digest is default in false, we must enable it for test environment add_to_env_config "test", "config.assets.digest = true" @@ -233,6 +235,8 @@ module ApplicationTests end test "precompile shouldn't use the digests present in manifest.json" do + app_file "app/assets/images/rails.png", "notactuallyapng" + app_file "app/assets/stylesheets/application.css.erb", "//= depend_on rails.png\np { url: <%= asset_path('rails.png') %> }" ENV["RAILS_ENV"] = "production" @@ -251,6 +255,7 @@ module ApplicationTests end test "precompile appends the md5 hash to files referenced with asset_path and run in production with digest true" do + app_file "app/assets/images/rails.png", "notactuallyapng" app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" add_to_config "config.assets.compile = true" add_to_config "config.assets.digest = true" @@ -272,7 +277,7 @@ module ApplicationTests manifest = Dir["#{app_path}/public/assets/manifest-*.json"].first assets = ActiveSupport::JSON.decode(File.read(manifest)) - assert asset_path = assets["assets"].find { |(k, _)| k !~ /rails.png/ && k =~ /.png/ }[1] + assert asset_path = assets["assets"].find { |(k, _)| k && k =~ /.png/ }[1] require "#{app_path}/config/environment" @@ -431,6 +436,7 @@ module ApplicationTests end test "asset urls should be protocol-relative if no request is in scope" do + app_file "app/assets/images/rails.png", "notreallyapng" app_file "app/assets/javascripts/image_loader.js.erb", 'var src="<%= image_path("rails.png") %>";' add_to_config "config.assets.precompile = %w{image_loader.js}" add_to_config "config.asset_host = 'example.com'" @@ -441,6 +447,7 @@ module ApplicationTests test "asset paths should use RAILS_RELATIVE_URL_ROOT by default" do ENV["RAILS_RELATIVE_URL_ROOT"] = "/sub/uri" + app_file "app/assets/images/rails.png", "notreallyapng" app_file "app/assets/javascripts/app.js.erb", 'var src="<%= image_path("rails.png") %>";' add_to_config "config.assets.precompile = %w{app.js}" diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 7b45623f6c..1acf03f35a 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -599,7 +599,7 @@ module ApplicationTests assert_equal :log, ActionController::Parameters.action_on_unpermitted_parameters end - test "config.action_controller.action_on_unpermitted_parameters is :log by defaul on test" do + test "config.action_controller.action_on_unpermitted_parameters is :log by default on test" do ENV["RAILS_ENV"] = "test" require "#{app_path}/config/environment" diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb index af495bb450..31bc003dcb 100644 --- a/railties/test/application/console_test.rb +++ b/railties/test/application/console_test.rb @@ -126,37 +126,28 @@ class FullStackConsoleTest < ActiveSupport::TestCase assert_output "> " end - def kill(pid) - Process.kill('QUIT', pid) - Process.wait(pid) - rescue Errno::ESRCH - end - def spawn_console - pid = Process.spawn( + Process.spawn( "#{app_path}/bin/rails console --sandbox", in: @slave, out: @slave, err: @slave ) assert_output "> ", 30 - pid end def test_sandbox - pid = spawn_console + spawn_console write_prompt "Post.count", "=> 0" write_prompt "Post.create" write_prompt "Post.count", "=> 1" + @master.puts "quit" - kill pid - - pid = spawn_console + spawn_console write_prompt "Post.count", "=> 0" write_prompt "Post.transaction { Post.create; raise }" write_prompt "Post.count", "=> 0" - ensure - kill pid if pid + @master.puts "quit" end end diff --git a/railties/test/application/initializers/i18n_test.rb b/railties/test/application/initializers/i18n_test.rb index 489b7ddb92..17d0b10b70 100644 --- a/railties/test/application/initializers/i18n_test.rb +++ b/railties/test/application/initializers/i18n_test.rb @@ -45,7 +45,7 @@ module ApplicationTests end # Load paths - test "no config locales dir present should return empty load path" do + test "no config locales directory present should return empty load path" do FileUtils.rm_rf "#{app_path}/config/locales" load_app assert_equal [], Rails.application.config.i18n.load_path diff --git a/railties/test/application/initializers/load_path_test.rb b/railties/test/application/initializers/load_path_test.rb index 31811e7f92..9b18c329ec 100644 --- a/railties/test/application/initializers/load_path_test.rb +++ b/railties/test/application/initializers/load_path_test.rb @@ -23,7 +23,7 @@ module ApplicationTests assert $:.include?("#{app_path}/app/models") end - test "initializing an application allows to load code on lib path inside application class definitation" do + test "initializing an application allows to load code on lib path inside application class definition" do app_file "lib/foo.rb", <<-RUBY module Foo; end RUBY diff --git a/railties/test/application/middleware/cookies_test.rb b/railties/test/application/middleware/cookies_test.rb index 18af7abafc..bbb7627be9 100644 --- a/railties/test/application/middleware/cookies_test.rb +++ b/railties/test/application/middleware/cookies_test.rb @@ -33,7 +33,7 @@ module ApplicationTests assert_equal false, ActionDispatch::Cookies::CookieJar.always_write_cookie end - test 'always_write_cookie can be overrided' do + test 'always_write_cookie can be overridden' do add_to_config <<-RUBY config.action_dispatch.always_write_cookie = false RUBY diff --git a/railties/test/application/middleware/remote_ip_test.rb b/railties/test/application/middleware/remote_ip_test.rb index f0d3438aa4..91c5807379 100644 --- a/railties/test/application/middleware/remote_ip_test.rb +++ b/railties/test/application/middleware/remote_ip_test.rb @@ -1,5 +1,4 @@ require 'isolation/abstract_unit' -# FIXME remove DummyKeyGenerator and this require in 4.1 require 'active_support/key_generator' module ApplicationTests @@ -10,7 +9,7 @@ module ApplicationTests remote_ip = nil env = Rack::MockRequest.env_for("/").merge(env).merge!( 'action_dispatch.show_exceptions' => false, - 'action_dispatch.key_generator' => ActiveSupport::DummyKeyGenerator.new('b3c631c314c0bbca50c1b2843150fe33') + 'action_dispatch.key_generator' => ActiveSupport::LegacyKeyGenerator.new('b3c631c314c0bbca50c1b2843150fe33') ) endpoint = Proc.new do |e| diff --git a/railties/test/application/middleware/session_test.rb b/railties/test/application/middleware/session_test.rb index a5fdfbf887..8cb0dfeb63 100644 --- a/railties/test/application/middleware/session_test.rb +++ b/railties/test/application/middleware/session_test.rb @@ -157,10 +157,6 @@ module ApplicationTests end RUBY - add_to_config <<-RUBY - config.session_store :encrypted_cookie_store, key: '_myapp_session' - RUBY - require "#{app_path}/config/environment" get '/foo/write_session' @@ -178,7 +174,7 @@ module ApplicationTests assert_equal 1, encryptor.decrypt_and_verify(last_response.body)['foo'] end - test "session using upgrade signature to encryption cookie store works the same way as encrypted cookie store" do + test "session upgrading signature to encryption cookie store works the same way as encrypted cookie store" do app_file 'config/routes.rb', <<-RUBY AppTemplate::Application.routes.draw do get ':controller(/:action)' @@ -208,7 +204,6 @@ module ApplicationTests add_to_config <<-RUBY config.secret_token = "3b7cd727ee24e8444053437c36cc66c4" - config.session_store :upgrade_signature_to_encryption_cookie_store, key: '_myapp_session' RUBY require "#{app_path}/config/environment" @@ -228,7 +223,7 @@ module ApplicationTests assert_equal 1, encryptor.decrypt_and_verify(last_response.body)['foo'] end - test "session using upgrade signature to encryption cookie store upgrades session to encrypted mode" do + test "session upgrading signature to encryption cookie store upgrades session to encrypted mode" do app_file 'config/routes.rb', <<-RUBY AppTemplate::Application.routes.draw do get ':controller(/:action)' @@ -264,7 +259,6 @@ module ApplicationTests add_to_config <<-RUBY config.secret_token = "3b7cd727ee24e8444053437c36cc66c4" - config.session_store :upgrade_signature_to_encryption_cookie_store, key: '_myapp_session' RUBY require "#{app_path}/config/environment" @@ -287,5 +281,63 @@ module ApplicationTests get '/foo/read_raw_cookie' assert_equal 2, encryptor.decrypt_and_verify(last_response.body)['foo'] end + + test "session upgrading legacy signed cookies to new signed cookies" do + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do + get ':controller(/:action)' + end + RUBY + + controller :foo, <<-RUBY + class FooController < ActionController::Base + def write_raw_session + # {"session_id"=>"1965d95720fffc123941bdfb7d2e6870", "foo"=>1} + cookies[:_myapp_session] = "BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJTE5NjVkOTU3MjBmZmZjMTIzOTQxYmRmYjdkMmU2ODcwBjsAVEkiCGZvbwY7AEZpBg==--315fb9931921a87ae7421aec96382f0294119749" + render nothing: true + end + + def write_session + session[:foo] = session[:foo] + 1 + render nothing: true + end + + def read_session + render text: session[:foo] + end + + def read_signed_cookie + render text: cookies.signed[:_myapp_session]['foo'] + end + + def read_raw_cookie + render text: cookies[:_myapp_session] + end + end + RUBY + + add_to_config <<-RUBY + config.secret_token = "3b7cd727ee24e8444053437c36cc66c4" + config.secret_key_base = nil + RUBY + + require "#{app_path}/config/environment" + + get '/foo/write_raw_session' + get '/foo/read_session' + assert_equal '1', last_response.body + + get '/foo/write_session' + get '/foo/read_session' + assert_equal '2', last_response.body + + get '/foo/read_signed_cookie' + assert_equal '2', last_response.body + + verifier = ActiveSupport::MessageVerifier.new(app.config.secret_token) + + get '/foo/read_raw_cookie' + assert_equal 2, verifier.verify(last_response.body)['foo'] + end end end diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index a9e0e1bcb7..eb590da678 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -84,20 +84,8 @@ module ApplicationTests Dir.chdir(app_path){ `rake stats` } end - def test_rake_test_error_output - Dir.chdir(app_path){ `rake db:migrate` } - - app_file "test/models/one_model_test.rb", <<-RUBY - raise 'models' - RUBY - - silence_stderr do - output = Dir.chdir(app_path) { `rake test 2>&1` } - assert_match 'models', output - end - end - def test_rake_test_uncommitted_always_find_git_in_parent_dir + return "FIXME :'(" app_name = File.basename(app_path) app_dir = File.dirname(app_path) moved_app_name = app_name + '_moved' @@ -129,13 +117,10 @@ module ApplicationTests Dir.chdir(app_path){ `rails generate scaffold user name:string` } Dir.chdir(app_path){ `rake db:migrate` } - %w(run recent uncommitted models helpers units controllers functionals integration).each do |test_suit_name| + %w(recent uncommitted).each do |test_suit_name| output = Dir.chdir(app_path) { `rake test:#{test_suit_name} 2>&1` } - assert_match /DEPRECATION WARNING: `rake test:#{test_suit_name}` is deprecated/, output + assert_match(/DEPRECATION WARNING: `rake test:#{test_suit_name}` is deprecated/, output) end - - assert_match /DEPRECATION WARNING: `rake test:single` is deprecated/, - Dir.chdir(app_path) { `rake test:single TEST=test/models/user_test.rb 2>&1` } end def test_rake_routes_calls_the_route_inspector diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index 56ca3bc1a9..1cf53aa4fb 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -15,14 +15,6 @@ module ApplicationTests teardown_app end - def test_should_not_display_heading - create_test_file - run_test_command.tap do |output| - assert_no_match "Run options:", output - assert_no_match "Running tests:", output - end - end - def test_run_in_test_environment app_file 'test/unit/env_test.rb', <<-RUBY require 'test_helper' @@ -37,14 +29,9 @@ module ApplicationTests assert_match "Current Environment: test", run_test_command('test/unit/env_test.rb') end - def test_run_shortcut - create_test_file :models, 'foo' - output = Dir.chdir(app_path) { `bundle exec rails t test/models/foo_test.rb` } - assert_match "1 tests, 1 assertions, 0 failures", output - end - def test_run_single_file create_test_file :models, 'foo' + create_test_file :models, 'bar' assert_match "1 tests, 1 assertions, 0 failures", run_test_command("test/models/foo_test.rb") end @@ -62,24 +49,14 @@ module ApplicationTests error_stream = Tempfile.new('error') redirect_stderr(error_stream) { run_test_command('test/models/error_test.rb') } - assert_match "SyntaxError", error_stream.read - end - - def test_invoke_rake_db_test_load - app_file "lib/tasks/test.rake", <<-RUBY - task 'db:test:load' do - puts "Hello World" - end - RUBY - create_test_file - assert_match "Hello World", run_test_command + assert_match "syntax error", error_stream.read end def test_run_models create_test_file :models, 'foo' create_test_file :models, 'bar' create_test_file :controllers, 'foobar_controller' - run_test_command("models").tap do |output| + run_test_models_command.tap do |output| assert_match "FooTest", output assert_match "BarTest", output assert_match "2 tests, 2 assertions, 0 failures", output @@ -90,7 +67,7 @@ module ApplicationTests create_test_file :helpers, 'foo_helper' create_test_file :helpers, 'bar_helper' create_test_file :controllers, 'foobar_controller' - run_test_command('helpers').tap do |output| + run_test_helpers_command.tap do |output| assert_match "FooHelperTest", output assert_match "BarHelperTest", output assert_match "2 tests, 2 assertions, 0 failures", output @@ -102,7 +79,7 @@ module ApplicationTests create_test_file :helpers, 'bar_helper' create_test_file :unit, 'baz_unit' create_test_file :controllers, 'foobar_controller' - run_test_command('units').tap do |output| + run_test_units_command.tap do |output| assert_match "FooTest", output assert_match "BarHelperTest", output assert_match "BazUnitTest", output @@ -114,7 +91,7 @@ module ApplicationTests create_test_file :controllers, 'foo_controller' create_test_file :controllers, 'bar_controller' create_test_file :models, 'foo' - run_test_command('controllers').tap do |output| + run_test_controllers_command.tap do |output| assert_match "FooControllerTest", output assert_match "BarControllerTest", output assert_match "2 tests, 2 assertions, 0 failures", output @@ -125,7 +102,7 @@ module ApplicationTests create_test_file :mailers, 'foo_mailer' create_test_file :mailers, 'bar_mailer' create_test_file :models, 'foo' - run_test_command('mailers').tap do |output| + run_test_mailers_command.tap do |output| assert_match "FooMailerTest", output assert_match "BarMailerTest", output assert_match "2 tests, 2 assertions, 0 failures", output @@ -137,7 +114,7 @@ module ApplicationTests create_test_file :controllers, 'bar_controller' create_test_file :functional, 'baz_functional' create_test_file :models, 'foo' - run_test_command('functionals').tap do |output| + run_test_functionals_command.tap do |output| assert_match "FooMailerTest", output assert_match "BarControllerTest", output assert_match "BazFunctionalTest", output @@ -148,7 +125,7 @@ module ApplicationTests def test_run_integration create_test_file :integration, 'foo_integration' create_test_file :models, 'foo' - run_test_command('integration').tap do |output| + run_test_integration_command.tap do |output| assert_match "FooIntegration", output assert_match "1 tests, 1 assertions, 0 failures", output end @@ -178,17 +155,31 @@ module ApplicationTests end RUBY - run_test_command('test/unit/chu_2_koi_test.rb -n test_rikka').tap do |output| + run_test_command('test/unit/chu_2_koi_test.rb test_rikka').tap do |output| assert_match "Rikka", output assert_no_match "Sanae", output end end - def test_not_load_fixtures_when_running_single_test - create_model_with_fixture - create_fixture_test :models, 'user' - assert_match "0 users", run_test_command('test/models/user_test.rb') - assert_match "3 users", run_test_command('test/models/user_test.rb -f') + def test_run_matched_test + app_file 'test/unit/chu_2_koi_test.rb', <<-RUBY + require 'test_helper' + + class Chu2KoiTest < ActiveSupport::TestCase + def test_rikka + puts 'Rikka' + end + + def test_sanae + puts 'Sanae' + end + end + RUBY + + run_test_command('test/unit/chu_2_koi_test.rb /rikka/').tap do |output| + assert_match "Rikka", output + assert_no_match "Sanae", output + end end def test_load_fixtures_when_running_test_suites @@ -199,11 +190,18 @@ module ApplicationTests suites.each do |suite, directory| directory ||= suite create_fixture_test directory - assert_match "3 users", run_test_command(suite) + assert_match "3 users", run_task(["test:#{suite}"]) Dir.chdir(app_path) { FileUtils.rm_f "test/#{directory}" } end end + def test_run_with_model + create_model_with_fixture + create_fixture_test 'models', 'user' + assert_match "3 users", run_task(["test models/user"]) + assert_match "3 users", run_task(["test app/models/user.rb"]) + end + def test_run_different_environment_using_env_var app_file 'test/unit/env_test.rb', <<-RUBY require 'test_helper' @@ -220,6 +218,7 @@ module ApplicationTests end def test_run_different_environment_using_e_tag + env = "development" app_file 'test/unit/env_test.rb', <<-RUBY require 'test_helper' @@ -230,7 +229,7 @@ module ApplicationTests end RUBY - assert_match "development", run_test_command('-e development test/unit/env_test.rb') + assert_match env, run_test_command("test/unit/env_test.rb RAILS_ENV=#{env}") end def test_generated_scaffold_works_with_rails_test @@ -239,8 +238,17 @@ module ApplicationTests end private + def run_task(tasks) + Dir.chdir(app_path) { `bundle exec rake #{tasks.join ' '}` } + end + def run_test_command(arguments = 'test/unit/test_test.rb') - Dir.chdir(app_path) { `bundle exec rails test #{arguments}` } + run_task ['test', arguments] + end + %w{ mailers models helpers units controllers functionals integration }.each do |type| + define_method("run_test_#{type}_command") do + run_task ["test:#{type}"] + end end def create_model_with_fixture diff --git a/railties/test/commands/console_test.rb b/railties/test/commands/console_test.rb index 3c784b43be..a34beaedb3 100644 --- a/railties/test/commands/console_test.rb +++ b/railties/test/commands/console_test.rb @@ -114,9 +114,10 @@ class Rails::ConsoleTest < ActiveSupport::TestCase assert_match('dev', options[:environment]) end - private - attr_reader :output + private :output + + private def start(argv = []) rails_console = Rails::Console.new(app, parse_arguments(argv)) diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb index 38fe8ca544..edb92b3aa2 100644 --- a/railties/test/commands/dbconsole_test.rb +++ b/railties/test/commands/dbconsole_test.rb @@ -172,8 +172,10 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase assert_match(/Usage:.*dbconsole/, stdout) end - private attr_reader :aborted, :output + private :aborted, :output + + private def dbconsole @dbconsole ||= Rails::DBConsole.new(nil) diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 0697035871..5fdf58c8ee 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -232,8 +232,8 @@ class AppGeneratorTest < Rails::Generators::TestCase end assert_file "Gemfile" do |content| assert_no_match(/sass-rails/, content) - assert_no_match(/coffee-rails/, content) assert_no_match(/uglifier/, content) + assert_match(/coffee-rails/, content) end assert_file "config/environments/development.rb" do |content| assert_no_match(/config\.assets\.debug = true/, content) @@ -276,7 +276,7 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_match %r{^//= require jquery}, contents assert_match %r{^//= require jquery_ujs}, contents end - assert_gem "jquery-rails" + assert_file "Gemfile", /^gem 'jquery-rails'/ end def test_other_javascript_libraries @@ -293,6 +293,9 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "app/assets/javascripts/application.js" do |contents| assert_no_match %r{^//=\s+require\s}, contents end + assert_file "Gemfile" do |content| + assert_match(/coffee-rails/, content) + end end def test_inclusion_of_debugger @@ -300,6 +303,11 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile", /# gem 'debugger'/ end + def test_inclusion_of_lazy_loaded_sdoc + run_generator + assert_file 'Gemfile', /gem 'sdoc', require: false/ + end + def test_template_from_dir_pwd FileUtils.cd(Rails.root) assert_match(/It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"])) @@ -338,7 +346,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_new_hash_style run_generator [destination_root] assert_file "config/initializers/session_store.rb" do |file| - assert_match(/config.session_store :encrypted_cookie_store, key: '_.+_session'/, file) + assert_match(/config.session_store :cookie_store, key: '_.+_session'/, file) end end diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 34441ef679..ac71fb5884 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -124,7 +124,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase run_generator [destination_root, "--skip_active_record"] assert_no_file "test/dummy/config/database.yml" assert_file "test/test_helper.rb" do |contents| - assert_no_match /ActiveRecord/, contents + assert_no_match(/ActiveRecord/, contents) end end @@ -292,7 +292,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase 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(/gem "rails", "~> #{Rails.version}"/, contents) assert_match(/group :development do\n gem "sqlite3"\nend/, contents) assert_no_match(/# gem "jquery-rails"/, contents) end @@ -303,7 +303,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase 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(/gem "rails", "~> #{Rails.version}"/, contents) assert_match(/group :development do\n gem "sqlite3"\nend/, contents) end end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index b29d1e018e..25f299118c 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -241,7 +241,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase def test_scaffold_generator_no_assets run_generator [ "posts", "--no-assets" ] - assert_file "app/assets/stylesheets/scaffold.css" + assert_no_file "app/assets/stylesheets/scaffold.css" assert_no_file "app/assets/javascripts/posts.js" assert_no_file "app/assets/stylesheets/posts.css" end diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 9953aa929b..361784f509 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -164,7 +164,7 @@ class GeneratorsTest < Rails::Generators::TestCase Rails::Generators.invoke "super_shoulda:model", ["Account"] end - def test_developer_options_are_overwriten_by_user_options + def test_developer_options_are_overwritten_by_user_options Rails::Generators.options[:with_options] = { generate: false } self.class.class_eval(<<-end_eval, __FILE__, __LINE__ + 1) diff --git a/railties/test/rails_info_test.rb b/railties/test/rails_info_test.rb index b9fb071d23..5b9088cb64 100644 --- a/railties/test/rails_info_test.rb +++ b/railties/test/rails_info_test.rb @@ -38,7 +38,7 @@ class InfoTest < ActiveSupport::TestCase end def test_framework_version - assert_property 'Active Support version', ActiveSupport::VERSION::STRING + assert_property 'Active Support version', ActiveSupport.version.to_s end def test_frameworks_exist diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 26b388b6f9..01fa2c6864 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -187,7 +187,7 @@ module RailtiesTest assert_equal "Hello bukkits\n", response[2].body end - test "adds its views to view paths with lower proriority than app ones" do + test "adds its views to view paths with lower priority than app ones" do @plugin.write "app/controllers/bukkit_controller.rb", <<-RUBY class BukkitController < ActionController::Base def index diff --git a/railties/test/railties/railtie_test.rb b/railties/test/railties/railtie_test.rb index c80b0f63af..0786b8f8c7 100644 --- a/railties/test/railties/railtie_test.rb +++ b/railties/test/railties/railtie_test.rb @@ -32,7 +32,7 @@ module RailtiesTest end end - test "railtie_name can be set manualy" do + test "railtie_name can be set manually" do class Foo < Rails::Railtie railtie_name "bar" end diff --git a/railties/test/test_info_test.rb b/railties/test/test_info_test.rb new file mode 100644 index 0000000000..d5463c11de --- /dev/null +++ b/railties/test/test_info_test.rb @@ -0,0 +1,59 @@ +require 'abstract_unit' +require 'rails/test_unit/sub_test_task' + +module Rails + class TestInfoTest < ActiveSupport::TestCase + def test_test_files + info = new_test_info ['test'] + assert_predicate info.files, :empty? + assert_nil info.opts + assert_equal ['test'], info.tasks + end + + def test_with_file + info = new_test_info ['test', __FILE__] + assert_equal [__FILE__], info.files + assert_nil info.opts + assert_equal ['test'], info.tasks + end + + def test_with_opts + info = new_test_info ['test', __FILE__, '/foo/'] + assert_equal [__FILE__], info.files + assert_equal '-n /foo/', info.opts + assert_equal ['test'], info.tasks + end + + def test_with_model_shorthand + info = new_test_info ['test', 'models/foo', '/foo/'] + + def info.test_file?(file) + file == "test/models/foo_test.rb" || super + end + + assert_equal ['test/models/foo_test.rb'], info.files + assert_equal '-n /foo/', info.opts + assert_equal ['test'], info.tasks + end + + def test_with_model_path + info = new_test_info ['test', 'app/models/foo.rb', '/foo/'] + + def info.test_file?(file) + file == "test/models/foo_test.rb" || super + end + + assert_equal ['test/models/foo_test.rb'], info.files + assert_equal '-n /foo/', info.opts + assert_equal ['test'], info.tasks + end + + def new_test_info(tasks) + Class.new(TestTask::TestInfo) { + def task_defined?(task) + task == "test" + end + }.new tasks + end + end +end |