aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/application/asset_debugging_test.rb11
-rw-r--r--railties/test/application/assets_test.rb201
-rw-r--r--railties/test/application/configuration_test.rb109
-rw-r--r--railties/test/application/generators_test.rb30
-rw-r--r--railties/test/application/initializers/frameworks_test.rb7
-rw-r--r--railties/test/application/initializers/i18n_test.rb14
-rw-r--r--railties/test/application/initializers/notifications_test.rb2
-rw-r--r--railties/test/application/loading_test.rb28
-rw-r--r--railties/test/application/middleware/cache_test.rb36
-rw-r--r--railties/test/application/middleware/session_test.rb2
-rw-r--r--railties/test/application/middleware_test.rb18
-rw-r--r--railties/test/application/queue_test.rb79
-rw-r--r--railties/test/application/rake/notes_test.rb4
-rw-r--r--railties/test/application/rake_test.rb22
-rw-r--r--railties/test/application/routing_test.rb28
-rw-r--r--railties/test/application/url_generation_test.rb7
-rw-r--r--railties/test/commands/console_test.rb22
-rw-r--r--railties/test/fixtures/lib/plugin_builders/spec_builder.rb2
-rw-r--r--railties/test/generators/actions_test.rb36
-rw-r--r--railties/test/generators/app_generator_test.rb17
-rw-r--r--railties/test/generators/controller_generator_test.rb8
-rw-r--r--railties/test/generators/helper_generator_test.rb2
-rw-r--r--railties/test/generators/mailer_generator_test.rb2
-rw-r--r--railties/test/generators/model_generator_test.rb12
-rw-r--r--railties/test/generators/namespaced_generators_test.rb116
-rw-r--r--railties/test/generators/observer_generator_test.rb2
-rw-r--r--railties/test/generators/orm_test.rb4
-rw-r--r--railties/test/generators/plugin_new_generator_test.rb2
-rw-r--r--railties/test/generators/resource_generator_test.rb12
-rw-r--r--railties/test/generators/scaffold_controller_generator_test.rb8
-rw-r--r--railties/test/generators/scaffold_generator_test.rb30
-rw-r--r--railties/test/generators/shared_generator_tests.rb14
-rw-r--r--railties/test/generators_test.rb8
-rw-r--r--railties/test/initializable_test.rb18
-rw-r--r--railties/test/isolation/abstract_unit.rb8
-rw-r--r--railties/test/paths_test.rb28
-rw-r--r--railties/test/rails_info_controller_test.rb6
-rw-r--r--railties/test/railties/engine_test.rb42
-rw-r--r--railties/test/railties/generators_test.rb2
-rw-r--r--railties/test/railties/mounted_engine_test.rb38
40 files changed, 472 insertions, 565 deletions
diff --git a/railties/test/application/asset_debugging_test.rb b/railties/test/application/asset_debugging_test.rb
index ecacb34cb2..1eddfac664 100644
--- a/railties/test/application/asset_debugging_test.rb
+++ b/railties/test/application/asset_debugging_test.rb
@@ -7,7 +7,7 @@ module ApplicationTests
include Rack::Test::Methods
def setup
- build_app(:initializers => true)
+ build_app(initializers: true)
app_file "app/assets/javascripts/application.js", "//= require_tree ."
app_file "app/assets/javascripts/xmlhr.js", "function f1() { alert(); }"
@@ -15,7 +15,7 @@ module ApplicationTests
app_file "config/routes.rb", <<-RUBY
AppTemplate::Application.routes.draw do
- get '/posts', :to => "posts#index"
+ get '/posts', to: "posts#index"
end
RUBY
@@ -36,9 +36,8 @@ module ApplicationTests
test "assets are concatenated when debug is off and compile is off either if debug_assets param is provided" do
# config.assets.debug and config.assets.compile are false for production environment
ENV["RAILS_ENV"] = "production"
- capture(:stdout) do
- Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
- end
+ output = Dir.chdir(app_path){ `bundle exec rake assets:precompile --trace 2>&1` }
+ assert $?.success?, output
require "#{app_path}/config/environment"
class ::PostsController < ActionController::Base ; end
@@ -50,7 +49,7 @@ module ApplicationTests
end
test "assets aren't concatened when compile is true is on and debug_assets params is true" do
- app_file "config/initializers/compile.rb", "Rails.application.config.assets.compile = true"
+ add_to_env_config "production", "config.assets.compile = true"
ENV["RAILS_ENV"] = "production"
require "#{app_path}/config/environment"
diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb
index 12223287ba..1311194ea6 100644
--- a/railties/test/application/assets_test.rb
+++ b/railties/test/application/assets_test.rb
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
require 'isolation/abstract_unit'
require 'rack/test'
+require 'active_support/json'
module ApplicationTests
class AssetsTest < ActiveSupport::TestCase
@@ -8,7 +9,7 @@ module ApplicationTests
include Rack::Test::Methods
def setup
- build_app(:initializers => true)
+ build_app(initializers: true)
boot_rails
end
@@ -18,7 +19,7 @@ module ApplicationTests
def precompile!(env = nil)
quietly do
- precompile_task = "bundle exec rake assets:precompile #{env} 2>&1"
+ precompile_task = "bundle exec rake assets:precompile #{env} --trace 2>&1"
output = Dir.chdir(app_path) { %x[ #{precompile_task} ] }
assert $?.success?, output
output
@@ -27,12 +28,12 @@ module ApplicationTests
def clean_assets!
quietly do
- assert Dir.chdir(app_path) { system('bundle exec rake assets:clean') }
+ assert Dir.chdir(app_path) { system('bundle exec rake assets:clobber') }
end
end
def assert_file_exists(filename)
- assert File.exists?(filename), "missing #{filename}"
+ assert Dir[filename].first, "missing #{filename}"
end
def assert_no_file_exists(filename)
@@ -44,7 +45,7 @@ module ApplicationTests
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do
- get '*path', :to => lambda { |env| [200, { "Content-Type" => "text/html" }, "Not an asset"] }
+ get '*path', to: lambda { |env| [200, { "Content-Type" => "text/html" }, "Not an asset"] }
end
RUBY
@@ -75,12 +76,10 @@ module ApplicationTests
precompile!
files = Dir["#{app_path}/public/assets/application-*.js"]
- files << Dir["#{app_path}/public/assets/application.js"].first
files << Dir["#{app_path}/public/assets/foo/application-*.js"].first
- files << Dir["#{app_path}/public/assets/foo/application.js"].first
files.each do |file|
assert_not_nil file, "Expected application.js asset to be generated, but none found"
- assert_equal "alert();", File.read(file)
+ assert_equal "alert();\n", File.read(file)
end
end
@@ -108,21 +107,26 @@ module ApplicationTests
precompile!
+ images_should_compile = ["a-*.png", "happyface-*.png", "happy_face-*.png", "happy.face-*.png",
+ "happy-face-*.png", "happy.happy_face-*.png", "happy_happy.face-*.png",
+ "happy.happy.face-*.png", "-happy-*.png", "-happy.face-*.png",
+ "_happy.face-*.png", "_happy-*.png"]
+
images_should_compile.each do |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_no_file_exists("#{app_path}/public/assets/someapplication-*.js")
+ assert_no_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_no_file_exists("#{app_path}/public/assets/something.min-*.js")
+ assert_no_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")
+ assert_no_file_exists("#{app_path}/public/assets/something.else-*.js")
+ assert_no_file_exists("#{app_path}/public/assets/something.else-*.css")
end
test "precompile something.js for directory containing index file" do
@@ -131,7 +135,7 @@ module ApplicationTests
precompile!
- assert_file_exists("#{app_path}/public/assets/something.js")
+ assert_file_exists("#{app_path}/public/assets/something-*.js")
end
test "asset pipeline should use a Sprockets::Index when config.assets.digest is true" do
@@ -151,11 +155,11 @@ module ApplicationTests
add_to_config "config.assets.digest = true"
precompile!
- manifest = "#{app_path}/public/assets/manifest.yml"
+ manifest = Dir["#{app_path}/public/assets/manifest-*.json"].first
- assets = YAML.load_file(manifest)
- assert_match(/application-([0-z]+)\.js/, assets["application.js"])
- assert_match(/application-([0-z]+)\.css/, assets["application.css"])
+ assets = ActiveSupport::JSON.decode(File.read(manifest))
+ assert_match(/application-([0-z]+)\.js/, assets["assets"]["application.js"])
+ assert_match(/application-([0-z]+)\.css/, assets["assets"]["application.css"])
end
test "the manifest file should be saved by default in the same assets folder" do
@@ -166,26 +170,9 @@ module ApplicationTests
precompile!
- manifest = "#{app_path}/public/x/manifest.yml"
- assets = YAML.load_file(manifest)
- assert_match(/application-([0-z]+)\.js/, assets["application.js"])
- end
-
- test "precompile does not append asset digests when config.assets.digest is false" do
- app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
- app_file "app/assets/javascripts/application.js", "alert();"
- add_to_config "config.assets.digest = false"
-
- precompile!
-
- assert_file_exists("#{app_path}/public/assets/application.js")
- assert_file_exists("#{app_path}/public/assets/application.css")
-
- manifest = "#{app_path}/public/assets/manifest.yml"
-
- assets = YAML.load_file(manifest)
- assert_equal "application.js", assets["application.js"]
- assert_equal "application.css", assets["application.css"]
+ manifest = Dir["#{app_path}/public/x/manifest-*.json"].first
+ assets = ActiveSupport::JSON.decode(File.read(manifest))
+ assert_match(/application-([0-z]+)\.js/, assets["assets"]["application.js"])
end
test "assets do not require any assets group gem when manifest file is present" do
@@ -195,9 +182,9 @@ module ApplicationTests
ENV["RAILS_ENV"] = "production"
precompile!
- manifest = "#{app_path}/public/assets/manifest.yml"
- assets = YAML.load_file(manifest)
- asset_path = assets["application.js"]
+ manifest = Dir["#{app_path}/public/assets/manifest-*.json"].first
+ assets = ActiveSupport::JSON.decode(File.read(manifest))
+ asset_path = assets["assets"]["application.js"]
require "#{app_path}/config/environment"
@@ -208,58 +195,6 @@ module ApplicationTests
assert !defined?(Uglifier)
end
- test "assets raise AssetNotPrecompiledError when manifest file is present and requested file isn't precompiled" do
- app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'app' %>"
-
- app_file "config/routes.rb", <<-RUBY
- AppTemplate::Application.routes.draw do
- get '/posts', :to => "posts#index"
- end
- RUBY
-
- ENV["RAILS_ENV"] = "production"
- precompile!
-
- # Create file after of precompile
- app_file "app/assets/javascripts/app.js", "alert();"
-
- require "#{app_path}/config/environment"
- class ::PostsController < ActionController::Base
- def show_detailed_exceptions?() true end
- end
-
- get '/posts'
- assert_match(/AssetNotPrecompiledError/, last_response.body)
- assert_match(/app\.js isn&#39;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
- app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'app' %>"
- add_to_config "config.assets.compile = false"
- add_to_config "config.assets.digest = false"
-
- app_file "config/routes.rb", <<-RUBY
- AppTemplate::Application.routes.draw do
- get '/posts', :to => "posts#index"
- end
- RUBY
-
- ENV["RAILS_ENV"] = "production"
- precompile!
-
- # Create file after of precompile
- app_file "app/assets/javascripts/app.js", "alert();"
-
- require "#{app_path}/config/environment"
- class ::PostsController < ActionController::Base
- def show_detailed_exceptions?() true end
- end
-
- get '/posts'
- assert_match(/AssetNotPrecompiledError/, last_response.body)
- assert_match(/app\.js isn&#39;t precompiled/, last_response.body)
- end
-
test "precompile properly refers files referenced with asset_path and and run in the provided RAILS_ENV" do
app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
# digest is default in false, we must enable it for test environment
@@ -267,33 +202,32 @@ module ApplicationTests
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
assert_match(/\/assets\/rails-([0-z]+)\.png/, File.read(file))
end
- test "precompile shouldn't use the digests present in manifest.yml" do
- app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
+ test "precompile shouldn't use the digests present in manifest.json" do
+ app_file "app/assets/stylesheets/application.css.erb", "//= depend_on rails.png\np { url: <%= asset_path('rails.png') %> }"
ENV["RAILS_ENV"] = "production"
precompile!
- manifest = "#{app_path}/public/assets/manifest.yml"
- assets = YAML.load_file(manifest)
- asset_path = assets["application.css"]
+ manifest = Dir["#{app_path}/public/assets/manifest-*.json"].first
+ assets = ActiveSupport::JSON.decode(File.read(manifest))
+ asset_path = assets["assets"]["application.css"]
- app_file "app/assets/images/rails.png", "image changed"
+ app_file "app/assets/images/rails.png", "p { url: change }"
precompile!
- assets = YAML.load_file(manifest)
+ assets = ActiveSupport::JSON.decode(File.read(manifest))
- assert_not_equal asset_path, assets["application.css"]
+ assert_not_equal asset_path, assets["assets"]["application.css"]
end
- test "precompile appends the md5 hash to files referenced with asset_path and run in production as default even using RAILS_GROUPS=assets" do
+ test "precompile appends the md5 hash to files referenced with asset_path and run in production with digest true" do
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"
ENV["RAILS_ENV"] = nil
@@ -309,11 +243,16 @@ module ApplicationTests
add_to_config "config.assets.precompile = [ /\.png$/, /application.(css|js)$/ ]"
precompile!
+
+ manifest = Dir["#{app_path}/public/assets/manifest-*.json"].first
+ assets = ActiveSupport::JSON.decode(File.read(manifest))
+ assert asset_path = assets["assets"].find { |(k, v)| k !~ /rails.png/ && k =~ /.png/ }[1]
+
require "#{app_path}/config/environment"
- get "/assets/#{URI.parser.escape(filename)}"
+ get "/assets/#{URI.parser.escape(asset_path)}"
assert_match "not a image really", last_response.body
- assert_file_exists("#{app_path}/public/assets/#{filename}")
+ assert_file_exists("#{app_path}/public/assets/#{asset_path}")
end
test "assets are cleaned up properly" do
@@ -353,7 +292,7 @@ module ApplicationTests
class ::OmgController < ActionController::Base
def index
flash[:cool_story] = true
- render :text => "ok"
+ render text: "ok"
end
end
@@ -396,21 +335,6 @@ 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
- app_with_assets_in_view
- add_to_env_config "production", "config.assets.compile = true"
- add_to_env_config "production", "config.assets.allow_debugging = true"
-
- ENV["RAILS_ENV"] = "production"
- require "#{app_path}/config/environment"
-
- class ::PostsController < ActionController::Base ; end
-
- get '/posts?debug_assets=true'
- assert_match(/<script src="\/assets\/application-([0-z]+)\.js\?body=1"><\/script>/, last_response.body)
- assert_match(/<script src="\/assets\/xmlhr-([0-z]+)\.js\?body=1"><\/script>/, last_response.body)
- end
-
test "assets can access model information when precompiling" do
app_file "app/models/post.rb", "class Post; end"
app_file "app/assets/javascripts/application.js", "//= require_tree ."
@@ -418,7 +342,7 @@ module ApplicationTests
add_to_config "config.assets.digest = false"
precompile!
- assert_equal "Post;\n", File.read("#{app_path}/public/assets/application.js")
+ assert_equal "Post;\n", File.read(Dir["#{app_path}/public/assets/application-*.js"].first)
end
test "assets can't access model information when precompiling if not initializing the app" do
@@ -430,7 +354,7 @@ module ApplicationTests
add_to_config "config.assets.initialize_on_precompile = false"
precompile!
- assert_equal "NoPost;\n", File.read("#{app_path}/public/assets/application.js")
+ assert_equal "NoPost;\n", File.read(Dir["#{app_path}/public/assets/application-*.js"].first)
end
test "initialization on the assets group should set assets_dir" do
@@ -464,7 +388,7 @@ module ApplicationTests
clean_assets!
- files = Dir["#{app_path}/public/production_assets/application.js"]
+ files = Dir["#{app_path}/public/production_assets/application-*.js"]
assert_equal 0, files.length, "Expected application.js asset to be removed, but still exists"
end
@@ -486,7 +410,7 @@ module ApplicationTests
add_to_config "config.asset_host = 'example.com'"
precompile!
- assert_match 'src="//example.com/assets/rails.png"', File.read("#{app_path}/public/assets/image_loader.js")
+ assert_match 'src="//example.com/assets/rails.png"', File.read(Dir["#{app_path}/public/assets/image_loader-*.js"].first)
end
test "asset paths should use RAILS_RELATIVE_URL_ROOT by default" do
@@ -496,19 +420,7 @@ module ApplicationTests
add_to_config "config.assets.precompile = %w{app.js}"
precompile!
- assert_match 'src="/sub/uri/assets/rails.png"', File.read("#{app_path}/public/assets/app.js")
- end
-
- test "html assets are compiled when executing precompile" do
- app_file "app/assets/pages/page.html.erb", "<%= javascript_include_tag :application %>"
- ENV["RAILS_ENV"] = "production"
- ENV["RAILS_GROUP"] = "assets"
-
- quietly do
- Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
- end
-
- assert_file_exists("#{app_path}/public/assets/page.html")
+ assert_match 'src="/sub/uri/assets/rails.png"', File.read(Dir["#{app_path}/public/assets/app-*.js"].first)
end
test "assets:cache:clean should clean cache" do
@@ -516,11 +428,10 @@ module ApplicationTests
precompile!
quietly do
- Dir.chdir(app_path){ `bundle exec rake assets:cache:clean` }
+ Dir.chdir(app_path){ `bundle exec rake assets:clobber` }
end
- require "#{app_path}/config/environment"
- assert_equal 0, Dir.entries(Rails.application.assets.cache.cache_path).size - 2 # reject [".", ".."]
+ assert !File.exist?("#{app_path}/tmp/cache/assets")
end
private
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index d014e5e362..c4c1100f19 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -56,14 +56,6 @@ module ApplicationTests
assert_match "ActiveRecord::PendingMigrationError", last_response.body
end
- test "multiple queue construction is possible" do
- require 'rails'
- require "#{app_path}/config/environment"
- mail_queue = Rails.application.build_queue
- image_processing_queue = Rails.application.build_queue
- assert_not_equal mail_queue, image_processing_queue
- end
-
test "Rails.groups returns available groups" do
require "rails"
@@ -139,6 +131,14 @@ module ApplicationTests
assert_instance_of Pathname, Rails.root
end
+ test "Rails.public_path should be a Pathname" do
+ add_to_config <<-RUBY
+ config.paths["public"] = "somewhere"
+ RUBY
+ require "#{app_path}/config/environment"
+ assert_instance_of Pathname, Rails.public_path
+ end
+
test "initialize an eager loaded, cache classes app" do
add_to_config <<-RUBY
config.eager_load = true
@@ -154,11 +154,6 @@ module ApplicationTests
assert AppTemplate::Application, AppTemplate::Application.config.eager_load_namespaces
end
- test "asset_path defaults to nil for application" do
- require "#{app_path}/config/environment"
- assert_equal nil, AppTemplate::Application.config.asset_path
- end
-
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
@@ -227,7 +222,7 @@ module ApplicationTests
RUBY
require "#{app_path}/config/application"
- assert_equal File.join(app_path, "somewhere"), Rails.public_path
+ assert_equal Pathname.new(app_path).join("somewhere"), Rails.public_path
end
test "config.secret_token is sent in env" do
@@ -239,7 +234,7 @@ module ApplicationTests
class ::OmgController < ActionController::Base
def index
cookies.signed[:some_key] = "some_value"
- render :text => env["action_dispatch.secret_token"]
+ render text: env["action_dispatch.secret_token"]
end
end
@@ -252,7 +247,7 @@ module ApplicationTests
class ::OmgController < ActionController::Base
def index
- render :inline => "<%= csrf_meta_tags %>"
+ render inline: "<%= csrf_meta_tags %>"
end
end
@@ -272,11 +267,11 @@ module ApplicationTests
app_file 'app/controllers/posts_controller.rb', <<-RUBY
class PostsController < ApplicationController
def show
- render :inline => "<%= begin; form_for(Post.new) {}; rescue => e; e.to_s; end %>"
+ render inline: "<%= begin; form_for(Post.new) {}; rescue => e; e.to_s; end %>"
end
def update
- render :text => "update"
+ render text: "update"
end
end
RUBY
@@ -291,7 +286,7 @@ module ApplicationTests
token = "cf50faa3fe97702ca1ae"
PostsController.any_instance.stubs(:form_authenticity_token).returns(token)
- params = {:authenticity_token => token}
+ params = {authenticity_token: token}
get "/posts/1"
assert_match(/patch/, last_response.body)
@@ -316,7 +311,7 @@ module ApplicationTests
class ::OmgController < ActionController::Base
def index
- render :inline => "<%= csrf_meta_tags %>"
+ render inline: "<%= csrf_meta_tags %>"
end
end
@@ -324,27 +319,6 @@ module ApplicationTests
assert last_response.body =~ /_xsrf_token_here/
end
- test "config.action_controller.perform_caching = true" do
- make_basic_app do |app|
- app.config.action_controller.perform_caching = true
- end
-
- class ::OmgController < ActionController::Base
- @@count = 0
-
- caches_action :index
- def index
- @@count += 1
- render :text => @@count
- end
- end
-
- get "/"
- res = last_response.body
- get "/"
- assert_equal res, last_response.body # value should be unchanged
- end
-
test "sets ActionDispatch.test_app" do
make_basic_app
assert_equal Rails.application, ActionDispatch.test_app
@@ -454,42 +428,6 @@ module ApplicationTests
end
end
- test "config.action_controller.perform_caching = false" do
- make_basic_app do |app|
- app.config.action_controller.perform_caching = false
- end
-
- class ::OmgController < ActionController::Base
- @@count = 0
-
- caches_action :index
- def index
- @@count += 1
- render :text => @@count
- end
- end
-
- get "/"
- res = last_response.body
- get "/"
- assert_not_equal res, last_response.body
- end
-
- test "config.asset_path is not passed through env" do
- make_basic_app do |app|
- app.config.asset_path = "/omg%s"
- end
-
- class ::OmgController < ActionController::Base
- def index
- render :inline => "<%= image_path('foo.jpg') %>"
- end
- end
-
- get "/"
- assert_equal "/omg/images/foo.jpg", last_response.body
- end
-
test "config.action_view.cache_template_loading with cache_classes default" do
add_to_config "config.cache_classes = true"
require "#{app_path}/config/environment"
@@ -535,7 +473,7 @@ module ApplicationTests
class ::OmgController < ActionController::Base
def index
- render :text => env["action_dispatch.show_exceptions"]
+ render text: env["action_dispatch.show_exceptions"]
end
end
@@ -545,7 +483,7 @@ module ApplicationTests
test "config.action_controller.wrap_parameters is set in ActionController::Base" do
app_file 'config/initializers/wrap_parameters.rb', <<-RUBY
- ActionController::Base.wrap_parameters :format => [:json]
+ ActionController::Base.wrap_parameters format: [:json]
RUBY
app_file 'app/models/post.rb', <<-RUBY
@@ -565,7 +503,7 @@ module ApplicationTests
app_file 'app/controllers/posts_controller.rb', <<-RUBY
class PostsController < ApplicationController
def create
- render :text => params[:post].inspect
+ render text: params[:post].inspect
end
end
RUBY
@@ -586,7 +524,7 @@ module ApplicationTests
app_file 'app/controllers/posts_controller.rb', <<-RUBY
class PostsController < ActionController::Base
def create
- render :text => params[:post].permitted? ? "permitted" : "forbidden"
+ render text: params[:post].permitted? ? "permitted" : "forbidden"
end
end
RUBY
@@ -600,7 +538,7 @@ module ApplicationTests
require "#{app_path}/config/environment"
- post "/posts", {:post => {"title" =>"zomg"}}
+ post "/posts", {post: {"title" =>"zomg"}}
assert_equal 'permitted', last_response.body
end
@@ -612,8 +550,8 @@ module ApplicationTests
class ::OmgController < ActionController::Base
def index
respond_to do |format|
- format.html { render :text => "HTML" }
- format.xml { render :text => "XML" }
+ format.html { render text: "HTML" }
+ format.xml { render text: "XML" }
end
end
end
@@ -621,7 +559,7 @@ module ApplicationTests
get "/", {}, "HTTP_ACCEPT" => "application/xml"
assert_equal 'HTML', last_response.body
- get "/", { :format => :xml }, "HTTP_ACCEPT" => "application/xml"
+ get "/", { format: :xml }, "HTTP_ACCEPT" => "application/xml"
assert_equal 'XML', last_response.body
end
@@ -634,6 +572,7 @@ module ApplicationTests
assert_equal app.env_config['action_dispatch.show_exceptions'], app.config.action_dispatch.show_exceptions
assert_equal app.env_config['action_dispatch.logger'], Rails.logger
assert_equal app.env_config['action_dispatch.backtrace_cleaner'], Rails.backtrace_cleaner
+ assert_equal app.env_config['action_dispatch.key_generator'], Rails.application.key_generator
end
test "config.colorize_logging default is true" do
diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb
index b80244f1d2..bc0af499c1 100644
--- a/railties/test/application/generators_test.rb
+++ b/railties/test/application/generators_test.rb
@@ -48,22 +48,22 @@ module ApplicationTests
c.generators.orm = :data_mapper
c.generators.test_framework = :rspec
c.generators.helper = false
- expected = { :rails => { :orm => :data_mapper, :test_framework => :rspec, :helper => false } }
+ expected = { rails: { orm: :data_mapper, test_framework: :rspec, helper: false } }
assert_equal(expected, c.generators.options)
end
end
test "generators set rails aliases" do
with_config do |c|
- c.generators.aliases = { :rails => { :test_framework => "-w" } }
- expected = { :rails => { :test_framework => "-w" } }
+ c.generators.aliases = { rails: { test_framework: "-w" } }
+ expected = { rails: { test_framework: "-w" } }
assert_equal expected, c.generators.aliases
end
end
test "generators aliases, options, templates and fallbacks on initialization" do
add_to_config <<-RUBY
- config.generators.rails :aliases => { :test_framework => "-w" }
+ config.generators.rails aliases: { test_framework: "-w" }
config.generators.orm :data_mapper
config.generators.test_framework :rspec
config.generators.fallbacks[:shoulda] = :test_unit
@@ -76,7 +76,7 @@ module ApplicationTests
assert_equal :rspec, Rails::Generators.options[:rails][:test_framework]
assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework]
- assert_equal Hash[:shoulda => :test_unit], Rails::Generators.fallbacks
+ assert_equal Hash[shoulda: :test_unit], Rails::Generators.fallbacks
assert_equal ["some/where"], Rails::Generators.templates_path
end
@@ -95,31 +95,31 @@ module ApplicationTests
test "generators with hashes for options and aliases" do
with_bare_config do |c|
c.generators do |g|
- g.orm :data_mapper, :migration => false
- g.plugin :aliases => { :generator => "-g" },
- :generator => true
+ g.orm :data_mapper, migration: false
+ g.plugin aliases: { generator: "-g" },
+ generator: true
end
expected = {
- :rails => { :orm => :data_mapper },
- :plugin => { :generator => true },
- :data_mapper => { :migration => false }
+ rails: { orm: :data_mapper },
+ plugin: { generator: true },
+ data_mapper: { migration: false }
}
assert_equal expected, c.generators.options
- assert_equal({ :plugin => { :generator => "-g" } }, c.generators.aliases)
+ assert_equal({ plugin: { generator: "-g" } }, c.generators.aliases)
end
end
test "generators with string and hash for options should generate symbol keys" do
with_bare_config do |c|
c.generators do |g|
- g.orm 'data_mapper', :migration => false
+ g.orm 'data_mapper', migration: false
end
expected = {
- :rails => { :orm => :data_mapper },
- :data_mapper => { :migration => false }
+ rails: { orm: :data_mapper },
+ data_mapper: { migration: false }
}
assert_equal expected, c.generators.options
diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb
index 5268257d62..528bec58ef 100644
--- a/railties/test/application/initializers/frameworks_test.rb
+++ b/railties/test/application/initializers/frameworks_test.rb
@@ -52,14 +52,13 @@ module ApplicationTests
test "uses the default queue for ActionMailer" do
require "#{app_path}/config/environment"
- assert_kind_of ActiveSupport::QueueContainer, ActionMailer::Base.queue
+ assert_kind_of ActiveSupport::Queue, ActionMailer::Base.queue
end
test "allows me to configure queue for ActionMailer" do
app_file "config/environments/development.rb", <<-RUBY
AppTemplate::Application.configure do
- Rails.queue[:mailer] = ActiveSupport::TestQueue.new
- config.action_mailer.queue = Rails.queue[:mailer]
+ config.action_mailer.queue = ActiveSupport::TestQueue.new
end
RUBY
@@ -175,7 +174,7 @@ module ApplicationTests
Dir.chdir("#{app_path}/app") do
require "#{app_path}/config/environment"
- assert_raises(NoMethodError) { [1,2,3].forty_two }
+ assert_raises(NoMethodError) { "hello".exclude? "lo" }
end
end
diff --git a/railties/test/application/initializers/i18n_test.rb b/railties/test/application/initializers/i18n_test.rb
index 02d20bc150..489b7ddb92 100644
--- a/railties/test/application/initializers/i18n_test.rb
+++ b/railties/test/application/initializers/i18n_test.rb
@@ -143,7 +143,7 @@ en:
I18n::Railtie.config.i18n.fallbacks = true
load_app
assert I18n.backend.class.included_modules.include?(I18n::Backend::Fallbacks)
- assert_fallbacks :de => [:de, :en]
+ assert_fallbacks de: [:de, :en]
end
test "config.i18n.fallbacks = true initializes I18n.fallbacks with default settings even when backend changes" do
@@ -151,37 +151,37 @@ en:
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]
+ assert_fallbacks de: [:de, :en]
end
test "config.i18n.fallbacks.defaults = [:'en-US'] initializes fallbacks with en-US as a fallback default" do
I18n::Railtie.config.i18n.fallbacks.defaults = [:'en-US']
load_app
- assert_fallbacks :de => [:de, :'en-US', :en]
+ assert_fallbacks de: [:de, :'en-US', :en]
end
test "config.i18n.fallbacks.map = { :ca => :'es-ES' } initializes fallbacks with a mapping ca => es-ES" do
I18n::Railtie.config.i18n.fallbacks.map = { :ca => :'es-ES' }
load_app
- assert_fallbacks :ca => [:ca, :"es-ES", :es, :en]
+ assert_fallbacks ca: [:ca, :"es-ES", :es, :en]
end
test "[shortcut] config.i18n.fallbacks = [:'en-US'] initializes fallbacks with en-US as a fallback default" do
I18n::Railtie.config.i18n.fallbacks = [:'en-US']
load_app
- assert_fallbacks :de => [:de, :'en-US', :en]
+ assert_fallbacks de: [:de, :'en-US', :en]
end
test "[shortcut] config.i18n.fallbacks = [{ :ca => :'es-ES' }] initializes fallbacks with a mapping de-AT => de-DE" do
I18n::Railtie.config.i18n.fallbacks.map = { :ca => :'es-ES' }
load_app
- assert_fallbacks :ca => [:ca, :"es-ES", :es, :en]
+ assert_fallbacks ca: [:ca, :"es-ES", :es, :en]
end
test "[shortcut] config.i18n.fallbacks = [:'en-US', { :ca => :'es-ES' }] initializes fallbacks with the given arguments" do
I18n::Railtie.config.i18n.fallbacks = [:'en-US', { :ca => :'es-ES' }]
load_app
- assert_fallbacks :ca => [:ca, :"es-ES", :es, :'en-US', :en]
+ assert_fallbacks ca: [:ca, :"es-ES", :es, :'en-US', :en]
end
end
end
diff --git a/railties/test/application/initializers/notifications_test.rb b/railties/test/application/initializers/notifications_test.rb
index d866a63fe0..baae6fd928 100644
--- a/railties/test/application/initializers/notifications_test.rb
+++ b/railties/test/application/initializers/notifications_test.rb
@@ -33,7 +33,7 @@ module ApplicationTests
ActiveRecord::Base.logger = logger
# Mimic Active Record notifications
- instrument "sql.active_record", :name => "SQL", :sql => "SHOW tables"
+ instrument "sql.active_record", name: "SQL", sql: "SHOW tables"
wait
assert_equal 1, logger.logged(:debug).size
diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb
index fcbc3c048c..ad7172c514 100644
--- a/railties/test/application/loading_test.rb
+++ b/railties/test/application/loading_test.rb
@@ -19,14 +19,14 @@ class LoadingTest < ActiveSupport::TestCase
test "constants in app are autoloaded" do
app_file "app/models/post.rb", <<-MODEL
class Post < ActiveRecord::Base
- validates_acceptance_of :title, :accept => "omg"
+ validates_acceptance_of :title, accept: "omg"
end
MODEL
require "#{rails_root}/config/environment"
setup_ar!
- p = Post.create(:title => 'omg')
+ p = Post.create(title: 'omg')
assert_equal 1, Post.count
assert_equal 'omg', p.title
p = Post.first
@@ -36,7 +36,7 @@ class LoadingTest < ActiveSupport::TestCase
test "models without table do not panic on scope definitions when loaded" do
app_file "app/models/user.rb", <<-MODEL
class User < ActiveRecord::Base
- default_scope where(:published => true)
+ default_scope where(published: true)
end
MODEL
@@ -76,8 +76,8 @@ class LoadingTest < ActiveSupport::TestCase
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do
- get '/load', :to => lambda { |env| [200, {}, Post.all] }
- get '/unload', :to => lambda { |env| [200, {}, []] }
+ get '/load', to: lambda { |env| [200, {}, Post.all] }
+ get '/unload', to: lambda { |env| [200, {}, []] }
end
RUBY
@@ -106,7 +106,7 @@ class LoadingTest < ActiveSupport::TestCase
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do
- get '/c', :to => lambda { |env| [200, {"Content-Type" => "text/plain"}, [User.counter.to_s]] }
+ get '/c', to: lambda { |env| [200, {"Content-Type" => "text/plain"}, [User.counter.to_s]] }
end
RUBY
@@ -145,7 +145,7 @@ class LoadingTest < ActiveSupport::TestCase
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do
- get '/c', :to => lambda { |env| [200, {"Content-Type" => "text/plain"}, [User.counter.to_s]] }
+ get '/c', to: lambda { |env| [200, {"Content-Type" => "text/plain"}, [User.counter.to_s]] }
end
RUBY
@@ -181,7 +181,7 @@ class LoadingTest < ActiveSupport::TestCase
app_file 'config/routes.rb', <<-RUBY
$counter = 0
AppTemplate::Application.routes.draw do
- get '/c', :to => lambda { |env| User; [200, {"Content-Type" => "text/plain"}, [$counter.to_s]] }
+ get '/c', to: lambda { |env| User; [200, {"Content-Type" => "text/plain"}, [$counter.to_s]] }
end
RUBY
@@ -212,8 +212,8 @@ class LoadingTest < ActiveSupport::TestCase
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do
- get '/title', :to => lambda { |env| [200, {"Content-Type" => "text/plain"}, [Post.new.title]] }
- get '/body', :to => lambda { |env| [200, {"Content-Type" => "text/plain"}, [Post.new.body]] }
+ get '/title', to: lambda { |env| [200, {"Content-Type" => "text/plain"}, [Post.new.title]] }
+ get '/body', to: lambda { |env| [200, {"Content-Type" => "text/plain"}, [Post.new.body]] }
end
RUBY
@@ -229,7 +229,7 @@ class LoadingTest < ActiveSupport::TestCase
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
- t.string :title, :default => "TITLE"
+ t.string :title, default: "TITLE"
end
end
end
@@ -244,7 +244,7 @@ class LoadingTest < ActiveSupport::TestCase
app_file "db/migrate/2_add_body_to_posts.rb", <<-MIGRATION
class AddBodyToPosts < ActiveRecord::Migration
def change
- add_column :posts, :body, :text, :default => "BODY"
+ add_column :posts, :body, :text, default: "BODY"
end
end
MIGRATION
@@ -297,9 +297,9 @@ class LoadingTest < ActiveSupport::TestCase
protected
def setup_ar!
- ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
+ ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Migration.verbose = false
- ActiveRecord::Schema.define(:version => 1) do
+ ActiveRecord::Schema.define(version: 1) do
create_table :posts do |t|
t.string :title
end
diff --git a/railties/test/application/middleware/cache_test.rb b/railties/test/application/middleware/cache_test.rb
index 19d3f3a397..c99666d7e4 100644
--- a/railties/test/application/middleware/cache_test.rb
+++ b/railties/test/application/middleware/cache_test.rb
@@ -19,17 +19,17 @@ module ApplicationTests
controller :expires, <<-RUBY
class ExpiresController < ApplicationController
def expires_header
- expires_in 10, :public => !params[:private]
- render :text => SecureRandom.hex(16)
+ expires_in 10, public: !params[:private]
+ render text: SecureRandom.hex(16)
end
def expires_etag
- render_conditionally(:etag => "1")
+ render_conditionally(etag: "1")
end
def expires_last_modified
$last_modified ||= Time.now.utc
- render_conditionally(:last_modified => $last_modified)
+ render_conditionally(last_modified: $last_modified)
end
def keeps_if_modified_since
@@ -37,8 +37,8 @@ module ApplicationTests
end
private
def render_conditionally(headers)
- if stale?(headers.merge(:public => !params[:private]))
- render :text => SecureRandom.hex(16)
+ if stale?(headers.merge(public: !params[:private]))
+ render text: SecureRandom.hex(16)
end
end
end
@@ -78,6 +78,8 @@ module ApplicationTests
def test_cache_works_with_expires
simple_controller
+ add_to_config "config.action_dispatch.rack_cache = true"
+
get "/expires/expires_header"
assert_equal "miss, store", last_response.headers["X-Rack-Cache"]
assert_equal "max-age=10, public", last_response.headers["Cache-Control"]
@@ -94,13 +96,15 @@ module ApplicationTests
def test_cache_works_with_expires_private
simple_controller
- get "/expires/expires_header", :private => true
+ add_to_config "config.action_dispatch.rack_cache = true"
+
+ get "/expires/expires_header", private: true
assert_equal "miss", last_response.headers["X-Rack-Cache"]
assert_equal "private, max-age=10", last_response.headers["Cache-Control"]
body = last_response.body
- get "/expires/expires_header", :private => true
+ get "/expires/expires_header", private: true
assert_equal "miss", last_response.headers["X-Rack-Cache"]
assert_not_equal body, last_response.body
end
@@ -108,6 +112,8 @@ module ApplicationTests
def test_cache_works_with_etags
simple_controller
+ add_to_config "config.action_dispatch.rack_cache = true"
+
get "/expires/expires_etag"
assert_equal "miss, store", last_response.headers["X-Rack-Cache"]
assert_equal "public", last_response.headers["Cache-Control"]
@@ -123,14 +129,16 @@ module ApplicationTests
def test_cache_works_with_etags_private
simple_controller
- get "/expires/expires_etag", :private => true
+ add_to_config "config.action_dispatch.rack_cache = true"
+
+ get "/expires/expires_etag", private: true
assert_equal "miss", last_response.headers["X-Rack-Cache"]
assert_equal "must-revalidate, private, max-age=0", last_response.headers["Cache-Control"]
body = last_response.body
etag = last_response.headers["ETag"]
- get "/expires/expires_etag", {:private => true}, "If-None-Match" => etag
+ get "/expires/expires_etag", {private: true}, "If-None-Match" => etag
assert_equal "miss", last_response.headers["X-Rack-Cache"]
assert_not_equal body, last_response.body
end
@@ -138,6 +146,8 @@ module ApplicationTests
def test_cache_works_with_last_modified
simple_controller
+ add_to_config "config.action_dispatch.rack_cache = true"
+
get "/expires/expires_last_modified"
assert_equal "miss, store", last_response.headers["X-Rack-Cache"]
assert_equal "public", last_response.headers["Cache-Control"]
@@ -153,14 +163,16 @@ module ApplicationTests
def test_cache_works_with_last_modified_private
simple_controller
- get "/expires/expires_last_modified", :private => true
+ add_to_config "config.action_dispatch.rack_cache = true"
+
+ get "/expires/expires_last_modified", private: true
assert_equal "miss", last_response.headers["X-Rack-Cache"]
assert_equal "must-revalidate, private, max-age=0", last_response.headers["Cache-Control"]
body = last_response.body
last = last_response.headers["Last-Modified"]
- get "/expires/expires_last_modified", {:private => true}, "If-Modified-Since" => last
+ get "/expires/expires_last_modified", {private: true}, "If-Modified-Since" => last
assert_equal "miss", last_response.headers["X-Rack-Cache"]
assert_not_equal body, last_response.body
end
diff --git a/railties/test/application/middleware/session_test.rb b/railties/test/application/middleware/session_test.rb
index 06dec81d40..5ce41caf61 100644
--- a/railties/test/application/middleware/session_test.rb
+++ b/railties/test/application/middleware/session_test.rb
@@ -36,7 +36,7 @@ module ApplicationTests
flash[:notice] = "notice"
end
- render :nothing => true
+ render nothing: true
end
end
diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb
index 3e096e99f2..c5a0d02fe1 100644
--- a/railties/test/application/middleware_test.rb
+++ b/railties/test/application/middleware_test.rb
@@ -56,8 +56,14 @@ module ApplicationTests
assert !middleware.include?("Rack::Sendfile"), "Rack::Sendfile is not included in the default stack unless you set config.action_dispatch.x_sendfile_header"
end
- test "Rack::Cache is present when action_controller.perform_caching is set" do
- add_to_config "config.action_controller.perform_caching = true"
+ test "Rack::Cache is not included by default" do
+ boot!
+
+ assert !middleware.include?("Rack::Cache"), "Rack::Cache is not included in the default stack unless you set config.action_dispatch.rack_cache"
+ end
+
+ test "Rack::Cache is present when action_dispatch.rack_cache is set" do
+ add_to_config "config.action_dispatch.rack_cache = true"
boot!
@@ -72,10 +78,10 @@ module ApplicationTests
test "ActionDispatch::SSL is configured with options when given" do
add_to_config "config.force_ssl = true"
- add_to_config "config.ssl_options = { :host => 'example.com' }"
+ add_to_config "config.ssl_options = { host: 'example.com' }"
boot!
- assert_equal AppTemplate::Application.middleware.first.args, [{:host => 'example.com'}]
+ assert_equal AppTemplate::Application.middleware.first.args, [{host: 'example.com'}]
end
test "removing Active Record omits its middleware" do
@@ -160,9 +166,9 @@ module ApplicationTests
class ::OmgController < ActionController::Base
def index
if params[:nothing]
- render :text => ""
+ render text: ""
else
- render :text => "OMG"
+ render text: "OMG"
end
end
end
diff --git a/railties/test/application/queue_test.rb b/railties/test/application/queue_test.rb
index e67c6cc371..b0b3cf18e9 100644
--- a/railties/test/application/queue_test.rb
+++ b/railties/test/application/queue_test.rb
@@ -17,16 +17,16 @@ module ApplicationTests
@app_const ||= Class.new(Rails::Application)
end
- test "the queue is a TestQueue in test mode" do
+ test "the queue is a SynchronousQueue in test mode" do
app("test")
- assert_kind_of ActiveSupport::TestQueue, Rails.application.queue[:default]
- assert_kind_of ActiveSupport::TestQueue, Rails.queue[:default]
+ assert_kind_of ActiveSupport::SynchronousQueue, Rails.application.queue
+ assert_kind_of ActiveSupport::SynchronousQueue, Rails.queue
end
test "the queue is a SynchronousQueue in development mode" do
app("development")
- assert_kind_of ActiveSupport::SynchronousQueue, Rails.application.queue[:default]
- assert_kind_of ActiveSupport::SynchronousQueue, Rails.queue[:default]
+ assert_kind_of ActiveSupport::SynchronousQueue, Rails.application.queue
+ assert_kind_of ActiveSupport::SynchronousQueue, Rails.queue
end
class ThreadTrackingJob
@@ -58,54 +58,26 @@ module ApplicationTests
refute job.ran_in_different_thread?, "Expected job to run in the same thread"
end
- test "in test mode, explicitly draining the queue will process it in the same thread" do
+ test "in test mode, an enqueued job will be processed in the same thread" do
app("test")
- Rails.queue.push ThreadTrackingJob.new
- job = Rails.queue.jobs.last
- Rails.queue.drain
+ job = ThreadTrackingJob.new
+ Rails.queue.push job
+ sleep 0.1
assert job.ran?, "Expected job to be run"
refute job.ran_in_different_thread?, "Expected job to run in the same thread"
end
- class IdentifiableJob
- def initialize(id)
- @id = id
- end
-
- def ==(other)
- other.same_id?(@id)
- end
-
- def same_id?(other_id)
- other_id == @id
- end
-
- def run
- end
- end
-
- test "in test mode, the queue can be observed" do
- app("test")
-
- jobs = (1..10).map do |id|
- IdentifiableJob.new(id)
- end
+ test "in production, automatically spawn a queue consumer in a background thread" do
+ add_to_env_config "production", <<-RUBY
+ config.queue = ActiveSupport::Queue.new
+ RUBY
- jobs.each do |job|
- Rails.queue.push job
- end
+ app("production")
- assert_equal jobs, Rails.queue.jobs
- end
-
- test "in test mode, adding an unmarshallable job will raise an exception" do
- app("test")
- anonymous_class_instance = Struct.new(:run).new
- assert_raises TypeError do
- Rails.queue.push anonymous_class_instance
- end
+ assert_nil Rails.application.config.queue_consumer
+ assert_kind_of ActiveSupport::ThreadedQueueConsumer, Rails.application.queue_consumer
end
test "attempting to marshal a queue will raise an exception" do
@@ -115,18 +87,10 @@ module ApplicationTests
end
end
- test "attempting to add a reference to itself to the queue will raise an exception" do
- app("test")
- job = {reference: Rails.queue}
- assert_raises TypeError do
- Rails.queue.push job
- end
- end
-
def setup_custom_queue
add_to_env_config "production", <<-RUBY
require "my_queue"
- config.queue = MyQueue
+ config.queue = MyQueue.new
RUBY
app_file "lib/my_queue.rb", <<-RUBY
@@ -143,7 +107,7 @@ module ApplicationTests
test "a custom queue implementation can be provided" do
setup_custom_queue
- assert_kind_of MyQueue, Rails.queue[:default]
+ assert_kind_of MyQueue, Rails.queue
job = Struct.new(:id, :ran) do
def run
@@ -160,17 +124,16 @@ module ApplicationTests
test "a custom consumer implementation can be provided" do
add_to_env_config "production", <<-RUBY
require "my_queue_consumer"
- config.queue = ActiveSupport::Queue
- config.queue_consumer = MyQueueConsumer
+ config.queue = ActiveSupport::Queue.new
+ config.queue_consumer = MyQueueConsumer.new
RUBY
app_file "lib/my_queue_consumer.rb", <<-RUBY
- class MyQueueConsumer < ActiveSupport::ThreadedQueueConsumer
+ class MyQueueConsumer
attr_reader :started
def start
@started = true
- self
end
end
RUBY
diff --git a/railties/test/application/rake/notes_test.rb b/railties/test/application/rake/notes_test.rb
index 27de75b63b..7a227098ba 100644
--- a/railties/test/application/rake/notes_test.rb
+++ b/railties/test/application/rake/notes_test.rb
@@ -25,6 +25,7 @@ module ApplicationTests
app_file "app/assets/stylesheets/application.css", "// TODO: note in css"
app_file "app/assets/stylesheets/application.css.scss", "// TODO: note in scss"
app_file "app/controllers/application_controller.rb", 1000.times.map { "" }.join("\n") << "# TODO: note in ruby"
+ app_file "lib/tasks/task.rake", "# TODO: note in rake"
boot_rails
require 'rake'
@@ -45,8 +46,9 @@ module ApplicationTests
assert_match(/note in js/, output)
assert_match(/note in css/, output)
assert_match(/note in scss/, output)
+ assert_match(/note in rake/, output)
- assert_equal 8, lines.size
+ assert_equal 9, lines.size
lines.each do |line|
assert_equal 4, line[0].size
diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb
index b05fe3aed5..c5a68a5152 100644
--- a/railties/test/application/rake_test.rb
+++ b/railties/test/application/rake_test.rb
@@ -46,7 +46,7 @@ module ApplicationTests
end
rake_tasks do
- task :do_nothing => :environment do
+ task do_nothing: :environment do
end
end
RUBY
@@ -60,7 +60,7 @@ module ApplicationTests
config.eager_load = true
rake_tasks do
- task :do_nothing => :environment do
+ task do_nothing: :environment do
Hello.new.world
end
end
@@ -86,12 +86,12 @@ module ApplicationTests
def test_rake_test_error_output
Dir.chdir(app_path){ `rake db:migrate` }
- app_file "test/unit/one_unit_test.rb", <<-RUBY
- raise 'unit'
+ app_file "test/models/one_model_test.rb", <<-RUBY
+ raise 'models'
RUBY
- app_file "test/functional/one_functional_test.rb", <<-RUBY
- raise 'functional'
+ app_file "test/controllers/one_controller_test.rb", <<-RUBY
+ raise 'controllers'
RUBY
app_file "test/integration/one_integration_test.rb", <<-RUBY
@@ -100,8 +100,8 @@ module ApplicationTests
silence_stderr do
output = Dir.chdir(app_path) { `rake test 2>&1` }
- assert_match 'unit', output
- assert_match 'functional', output
+ assert_match 'models', output
+ assert_match 'controllers', output
assert_match 'integration', output
end
end
@@ -109,7 +109,7 @@ module ApplicationTests
def test_rake_routes_calls_the_route_inspector
app_file "config/routes.rb", <<-RUBY
AppTemplate::Application.routes.draw do
- get '/cart', :to => 'cart#show'
+ get '/cart', to: 'cart#show'
end
RUBY
assert_equal "cart GET /cart(.:format) cart#show\n", Dir.chdir(app_path){ `rake routes` }
@@ -118,7 +118,7 @@ module ApplicationTests
def test_logger_is_flushed_when_exiting_production_rake_tasks
add_to_config <<-RUBY
rake_tasks do
- task :log_something => :environment do
+ task log_something: :environment do
Rails.logger.error("Sample log message")
end
end
@@ -233,7 +233,7 @@ module ApplicationTests
app_file "lib/tasks/count_user.rake", <<-RUBY
namespace :user do
- task :count => :environment do
+ task count: :environment do
puts User.count
end
end
diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb
index 396b1849d8..ffcdeac7f0 100644
--- a/railties/test/application/routing_test.rb
+++ b/railties/test/application/routing_test.rb
@@ -50,7 +50,7 @@ module ApplicationTests
controller :foo, <<-RUBY
class FooController < ApplicationController
def index
- render :inline => "<%= foo_or_bar? %>"
+ render inline: "<%= foo_or_bar? %>"
end
end
RUBY
@@ -76,7 +76,7 @@ module ApplicationTests
test "mount rack app" do
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do
- mount lambda { |env| [200, {}, [env["PATH_INFO"]]] }, :at => "/blog"
+ mount lambda { |env| [200, {}, [env["PATH_INFO"]]] }, at: "/blog"
# The line below is required because mount sometimes
# fails when a resource route is added.
resource :user
@@ -91,7 +91,7 @@ module ApplicationTests
controller :foo, <<-RUBY
class FooController < ApplicationController
def index
- render :text => "foo"
+ render text: "foo"
end
end
RUBY
@@ -99,7 +99,7 @@ module ApplicationTests
controller :bar, <<-RUBY
class BarController < ActionController::Base
def index
- render :text => "bar"
+ render text: "bar"
end
end
RUBY
@@ -121,7 +121,7 @@ module ApplicationTests
controller 'foo', <<-RUBY
class FooController < ApplicationController
def index
- render :text => "foo"
+ render text: "foo"
end
end
RUBY
@@ -130,7 +130,7 @@ module ApplicationTests
module Admin
class FooController < ApplicationController
def index
- render :text => "admin::foo"
+ render text: "admin::foo"
end
end
end
@@ -138,8 +138,8 @@ module ApplicationTests
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do
- get 'admin/foo', :to => 'admin/foo#index'
- get 'foo', :to => 'foo#index'
+ get 'admin/foo', to: 'admin/foo#index'
+ get 'foo', to: 'foo#index'
end
RUBY
@@ -183,18 +183,18 @@ module ApplicationTests
controller :foo, <<-RUBY
class FooController < ApplicationController
def bar
- render :text => "bar"
+ render text: "bar"
end
def baz
- render :text => "baz"
+ render text: "baz"
end
end
RUBY
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do
- get 'foo', :to => 'foo#bar'
+ get 'foo', to: 'foo#bar'
end
RUBY
@@ -205,7 +205,7 @@ module ApplicationTests
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do
- get 'foo', :to => 'foo#baz'
+ get 'foo', to: 'foo#baz'
end
RUBY
@@ -226,7 +226,7 @@ module ApplicationTests
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do
- get 'foo', :to => ::InitializeRackApp
+ get 'foo', to: ::InitializeRackApp
end
RUBY
@@ -257,7 +257,7 @@ module ApplicationTests
controller 'yazilar', <<-RUBY
class YazilarController < ApplicationController
def index
- render :text => 'yazilar#index'
+ render text: 'yazilar#index'
end
end
RUBY
diff --git a/railties/test/application/url_generation_test.rb b/railties/test/application/url_generation_test.rb
index f7e60749a7..2a48adae5c 100644
--- a/railties/test/application/url_generation_test.rb
+++ b/railties/test/application/url_generation_test.rb
@@ -15,8 +15,9 @@ module ApplicationTests
class MyApp < Rails::Application
config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
- config.session_store :cookie_store, :key => "_myapp_session"
+ config.session_store :cookie_store, key: "_myapp_session"
config.active_support.deprecation = :log
+ config.eager_load = false
end
MyApp.initialize!
@@ -26,12 +27,12 @@ module ApplicationTests
class ::OmgController < ::ApplicationController
def index
- render :text => omg_path
+ render text: omg_path
end
end
MyApp.routes.draw do
- get "/" => "omg#index", :as => :omg
+ get "/" => "omg#index", as: :omg
end
require 'rack/test'
diff --git a/railties/test/commands/console_test.rb b/railties/test/commands/console_test.rb
index 91ede1cb68..e047d4882d 100644
--- a/railties/test/commands/console_test.rb
+++ b/railties/test/commands/console_test.rb
@@ -58,8 +58,8 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
end
def test_console_defaults_to_IRB
- config = mock("config", :console => nil)
- app = mock("app", :config => config)
+ config = mock("config", console: nil)
+ app = mock("app", config: config)
app.expects(:load_console).returns(nil)
assert_equal IRB, Rails::Console.new(app).console
@@ -68,40 +68,40 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
def test_default_environment_with_no_rails_env
with_rails_env nil do
start
- assert_match /\sdevelopment\s/, output
+ assert_match(/\sdevelopment\s/, output)
end
end
def test_default_environment_with_rails_env
with_rails_env 'special-production' do
start
- assert_match /\sspecial-production\s/, output
+ assert_match(/\sspecial-production\s/, output)
end
end
def test_e_option
start ['-e', 'special-production']
- assert_match /\sspecial-production\s/, output
+ assert_match(/\sspecial-production\s/, output)
end
def test_environment_option
start ['--environment=special-production']
- assert_match /\sspecial-production\s/, output
+ 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
+ assert_match(/\sproduction\s/, output)
end
def test_rails_env_is_test_when_first_argument_is_t
start ['t']
- assert_match /\stest\s/, output
+ assert_match(/\stest\s/, output)
end
def test_rails_env_is_development_when_argument_is_d
start ['d']
- assert_match /\sdevelopment\s/, output
+ assert_match(/\sdevelopment\s/, output)
end
private
@@ -115,8 +115,8 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
def app
@app ||= begin
- config = mock("config", :console => FakeConsole)
- app = mock("app", :config => config)
+ config = mock("config", console: FakeConsole)
+ app = mock("app", config: config)
app.stubs(:sandbox=).returns(nil)
app.expects(:load_console)
app
diff --git a/railties/test/fixtures/lib/plugin_builders/spec_builder.rb b/railties/test/fixtures/lib/plugin_builders/spec_builder.rb
index aa18c7ddaa..2721429599 100644
--- a/railties/test/fixtures/lib/plugin_builders/spec_builder.rb
+++ b/railties/test/fixtures/lib/plugin_builders/spec_builder.rb
@@ -4,7 +4,7 @@ class PluginBuilder < Rails::PluginBuilder
append_file "Rakefile", <<-EOF
# spec tasks in rakefile
-task :default => :spec
+task default: :spec
EOF
end
diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb
index bc086c5986..8af92479c3 100644
--- a/railties/test/generators/actions_test.rb
+++ b/railties/test/generators/actions_test.rb
@@ -99,7 +99,7 @@ class ActionsTest < Rails::Generators::TestCase
def test_environment_should_include_data_in_environment_initializer_block_with_env_option
run_generator
autoload_paths = 'config.autoload_paths += %w["#{Rails.root}/app/extras"]'
- action :environment, autoload_paths, :env => 'development'
+ action :environment, autoload_paths, env: 'development'
assert_file "config/environments/development.rb", /Application\.configure do\n #{Regexp.escape(autoload_paths)}/
end
@@ -124,7 +124,7 @@ class ActionsTest < Rails::Generators::TestCase
def test_git_with_hash_should_run_each_command_using_git_scm
generator.expects(:run).times(2)
- action :git, :rm => 'README', :add => '.'
+ action :git, rm: 'README', add: '.'
end
def test_vendor_should_write_data_to_file_in_vendor
@@ -138,8 +138,8 @@ class ActionsTest < Rails::Generators::TestCase
end
def test_rakefile_should_write_date_to_file_in_lib_tasks
- action :rakefile, 'myapp.rake', 'task :run => [:environment]'
- assert_file 'lib/tasks/myapp.rake', 'task :run => [:environment]'
+ action :rakefile, 'myapp.rake', 'task run: [:environment]'
+ assert_file 'lib/tasks/myapp.rake', 'task run: [:environment]'
end
def test_initializer_should_write_date_to_file_in_config_initializers
@@ -148,12 +148,12 @@ class ActionsTest < Rails::Generators::TestCase
end
def test_generate_should_run_script_generate_with_argument_and_options
- generator.expects(:run_ruby_script).once.with('script/rails generate model MyModel', :verbose => false)
+ generator.expects(:run_ruby_script).once.with('script/rails generate model MyModel', verbose: false)
action :generate, 'model', 'MyModel'
end
def test_rake_should_run_rake_command_with_default_env
- generator.expects(:run).once.with("rake log:clear RAILS_ENV=development", :verbose => false)
+ generator.expects(:run).once.with("rake log:clear RAILS_ENV=development", verbose: false)
old_env, ENV['RAILS_ENV'] = ENV["RAILS_ENV"], nil
action :rake, 'log:clear'
ensure
@@ -161,12 +161,12 @@ class ActionsTest < Rails::Generators::TestCase
end
def test_rake_with_env_option_should_run_rake_command_in_env
- generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', :verbose => false)
- action :rake, 'log:clear', :env => 'production'
+ generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', verbose: false)
+ action :rake, 'log:clear', env: 'production'
end
def test_rake_with_rails_env_variable_should_run_rake_command_in_env
- generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', :verbose => false)
+ generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', verbose: false)
old_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "production"
action :rake, 'log:clear'
ensure
@@ -174,29 +174,29 @@ class ActionsTest < Rails::Generators::TestCase
end
def test_env_option_should_win_over_rails_env_variable_when_running_rake
- generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', :verbose => false)
+ generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', verbose: false)
old_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "staging"
- action :rake, 'log:clear', :env => 'production'
+ action :rake, 'log:clear', env: 'production'
ensure
ENV["RAILS_ENV"] = old_env
end
def test_rake_with_sudo_option_should_run_rake_command_with_sudo
- generator.expects(:run).once.with("sudo rake log:clear RAILS_ENV=development", :verbose => false)
+ generator.expects(:run).once.with("sudo rake log:clear RAILS_ENV=development", verbose: false)
old_env, ENV['RAILS_ENV'] = ENV["RAILS_ENV"], nil
- action :rake, 'log:clear', :sudo => true
+ action :rake, 'log:clear', sudo: true
ensure
ENV["RAILS_ENV"] = old_env
end
def test_capify_should_run_the_capify_command
- generator.expects(:run).once.with('capify .', :verbose => false)
+ generator.expects(:run).once.with('capify .', verbose: false)
action :capify!
end
def test_route_should_add_data_to_the_routes_block_in_config_routes
run_generator
- route_command = "route '/login', :controller => 'sessions', :action => 'new'"
+ route_command = "route '/login', controller: 'sessions', action: 'new'"
action :route, route_command
assert_file 'config/routes.rb', /#{Regexp.escape(route_command)}/
end
@@ -208,7 +208,7 @@ class ActionsTest < Rails::Generators::TestCase
end
def test_readme_with_quiet
- generator(default_arguments, :quiet => true)
+ generator(default_arguments, quiet: true)
run_generator
Rails::Generators::AppGenerator.expects(:source_root).times(2).returns(destination_root)
assert_no_match(/Welcome to Rails/, action(:readme, "README.rdoc"))
@@ -223,12 +223,12 @@ class ActionsTest < Rails::Generators::TestCase
end
def test_log_with_quiet
- generator(default_arguments, :quiet => true)
+ generator(default_arguments, quiet: true)
assert_equal("", action(:log, "YES"))
end
def test_log_with_status_with_quiet
- generator(default_arguments, :quiet => true)
+ generator(default_arguments, quiet: true)
assert_equal("", action(:log, :yes, "YES"))
end
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 856a0e163b..62e1f3531e 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -26,10 +26,12 @@ DEFAULT_APP_FILES = %w(
log
script/rails
test/fixtures
- test/functional
+ test/controllers
+ test/models
+ test/helpers
+ test/mailers
test/integration
test/performance
- test/unit
vendor
vendor/assets
tmp/cache
@@ -105,8 +107,8 @@ class AppGeneratorTest < Rails::Generators::TestCase
FileUtils.mv(app_root, app_moved_root)
- generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true },
- :destination_root => app_moved_root, :shell => @shell
+ generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true },
+ destination_root: app_moved_root, shell: @shell
generator.send(:app_const)
quietly { generator.send(:create_config_files) }
assert_file "myapp_moved/config/environment.rb", /Myapp::Application\.initialize!/
@@ -121,7 +123,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
Rails.application.class.stubs(:name).returns("Myapp")
Rails.application.stubs(:is_a?).returns(Rails::Application)
- generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true }, :destination_root => app_root, :shell => @shell
+ generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
generator.send(:app_const)
quietly { generator.send(:create_config_files) }
assert_file "myapp/config/initializers/session_store.rb", /_myapp_session/
@@ -221,7 +223,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
def test_generator_if_skip_sprockets_is_given
run_generator [destination_root, "--skip-sprockets"]
assert_file "config/application.rb" do |content|
- assert_match(/#\s+require\s+["']sprockets\/rails\/railtie["']/, content)
+ assert_match(/#\s+require\s+["']sprockets\/railtie["']/, content)
assert_no_match(/config\.assets\.enabled = true/, content)
end
assert_file "Gemfile" do |content|
@@ -234,7 +236,8 @@ class AppGeneratorTest < Rails::Generators::TestCase
end
assert_file "config/environments/production.rb" do |content|
assert_no_match(/config\.assets\.digest = true/, content)
- assert_no_match(/config\.assets\.compress = true/, content)
+ assert_no_match(/config\.assets\.js_compressor = :uglifier/, content)
+ assert_no_match(/config\.assets\.css_compressor = :sass/, content)
end
assert_file "test/performance/browsing_test.rb"
end
diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb
index c3fa9ebb03..5205deafd9 100644
--- a/railties/test/generators/controller_generator_test.rb
+++ b/railties/test/generators/controller_generator_test.rb
@@ -28,13 +28,13 @@ class ControllerGeneratorTest < Rails::Generators::TestCase
def test_invokes_helper
run_generator
assert_file "app/helpers/account_helper.rb"
- assert_file "test/unit/helpers/account_helper_test.rb"
+ assert_file "test/helpers/account_helper_test.rb"
end
def test_does_not_invoke_helper_if_required
run_generator ["account", "--skip-helper"]
assert_no_file "app/helpers/account_helper.rb"
- assert_no_file "test/unit/helpers/account_helper_test.rb"
+ assert_no_file "test/helpers/account_helper_test.rb"
end
def test_invokes_assets
@@ -45,12 +45,12 @@ class ControllerGeneratorTest < Rails::Generators::TestCase
def test_invokes_default_test_framework
run_generator
- assert_file "test/functional/account_controller_test.rb"
+ assert_file "test/controllers/account_controller_test.rb"
end
def test_does_not_invoke_test_framework_if_required
run_generator ["account", "--no-test-framework"]
- assert_no_file "test/functional/account_controller_test.rb"
+ assert_no_file "test/controllers/account_controller_test.rb"
end
def test_invokes_default_template_engine
diff --git a/railties/test/generators/helper_generator_test.rb b/railties/test/generators/helper_generator_test.rb
index 8da3aa61a4..81d4fcb129 100644
--- a/railties/test/generators/helper_generator_test.rb
+++ b/railties/test/generators/helper_generator_test.rb
@@ -15,7 +15,7 @@ class HelperGeneratorTest < Rails::Generators::TestCase
def test_invokes_default_test_framework
run_generator
- assert_file "test/unit/helpers/admin_helper_test.rb", /class AdminHelperTest < ActionView::TestCase/
+ assert_file "test/helpers/admin_helper_test.rb", /class AdminHelperTest < ActionView::TestCase/
end
def test_logs_if_the_test_framework_cannot_be_found
diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb
index c501780e7f..6b2351fc1a 100644
--- a/railties/test/generators/mailer_generator_test.rb
+++ b/railties/test/generators/mailer_generator_test.rb
@@ -29,7 +29,7 @@ class MailerGeneratorTest < Rails::Generators::TestCase
def test_invokes_default_test_framework
run_generator
- assert_file "test/functional/notifier_test.rb" do |test|
+ assert_file "test/mailers/notifier_test.rb" do |test|
assert_match(/class NotifierTest < ActionMailer::TestCase/, test)
assert_match(/test "foo"/, test)
assert_match(/test "bar"/, test)
diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb
index 436de26826..0c7ff0ebe7 100644
--- a/railties/test/generators/model_generator_test.rb
+++ b/railties/test/generators/model_generator_test.rb
@@ -157,7 +157,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase
assert_match(/create_table :products/, up)
assert_match(/t\.string :name/, up)
assert_match(/t\.integer :supplier_id/, up)
-
+
assert_match(/add_index :products, :name/, up)
assert_match(/add_index :products, :supplier_id/, up)
assert_no_match(/add_index :products, :year/, up)
@@ -181,7 +181,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase
assert_match(/add_index :products, :discount, unique: true/, content)
end
end
-
+
def test_migration_without_timestamps
ActiveRecord::Base.timestamped_migrations = false
run_generator ["account"]
@@ -242,19 +242,19 @@ class ModelGeneratorTest < Rails::Generators::TestCase
def test_migration_is_skipped_on_skip_behavior
run_generator
- output = run_generator ["Account"], :behavior => :skip
+ output = run_generator ["Account"], behavior: :skip
assert_match %r{skip\s+db/migrate/\d+_create_accounts.rb}, output
end
def test_migration_error_is_not_shown_on_revoke
run_generator
- error = capture(:stderr){ run_generator ["Account"], :behavior => :revoke }
+ error = capture(:stderr){ run_generator ["Account"], behavior: :revoke }
assert_no_match(/Another migration is already named create_accounts/, error)
end
def test_migration_is_removed_on_revoke
run_generator
- run_generator ["Account"], :behavior => :revoke
+ run_generator ["Account"], behavior: :revoke
assert_no_migration "db/migrate/create_accounts.rb"
end
@@ -269,7 +269,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase
def test_invokes_default_test_framework
run_generator
- assert_file "test/unit/account_test.rb", /class AccountTest < ActiveSupport::TestCase/
+ assert_file "test/models/account_test.rb", /class AccountTest < ActiveSupport::TestCase/
assert_file "test/fixtures/accounts.yml", /name: MyString/, /age: 1/
end
diff --git a/railties/test/generators/namespaced_generators_test.rb b/railties/test/generators/namespaced_generators_test.rb
index db2b8af217..4b168ae110 100644
--- a/railties/test/generators/namespaced_generators_test.rb
+++ b/railties/test/generators/namespaced_generators_test.rb
@@ -25,7 +25,7 @@ class NamespacedControllerGeneratorTest < NamespacedGeneratorTestCase
/module TestApp/,
/ class AccountController < ApplicationController/
- assert_file "test/functional/test_app/account_controller_test.rb",
+ assert_file "test/controllers/test_app/account_controller_test.rb",
/module TestApp/,
/ class AccountControllerTest/
end
@@ -46,12 +46,12 @@ class NamespacedControllerGeneratorTest < NamespacedGeneratorTestCase
def test_helpr_is_also_namespaced
run_generator
assert_file "app/helpers/test_app/account_helper.rb", /module TestApp/, / module AccountHelper/
- assert_file "test/unit/helpers/test_app/account_helper_test.rb", /module TestApp/, / class AccountHelperTest/
+ assert_file "test/helpers/test_app/account_helper_test.rb", /module TestApp/, / class AccountHelperTest/
end
def test_invokes_default_test_framework
run_generator
- assert_file "test/functional/test_app/account_controller_test.rb"
+ assert_file "test/controllers/test_app/account_controller_test.rb"
end
def test_invokes_default_template_engine
@@ -136,7 +136,7 @@ class NamespacedModelGeneratorTest < NamespacedGeneratorTestCase
def test_invokes_default_test_framework
run_generator
- assert_file "test/unit/test_app/account_test.rb", /module TestApp/, /class AccountTest < ActiveSupport::TestCase/
+ assert_file "test/models/test_app/account_test.rb", /module TestApp/, /class AccountTest < ActiveSupport::TestCase/
assert_file "test/fixtures/test_app/accounts.yml", /name: MyString/, /age: 1/
end
end
@@ -158,7 +158,7 @@ class NamespacedObserverGeneratorTest < NamespacedGeneratorTestCase
def test_invokes_default_test_framework
run_generator
- assert_file "test/unit/test_app/account_observer_test.rb", /module TestApp/, / class AccountObserverTest < ActiveSupport::TestCase/
+ assert_file "test/models/test_app/account_observer_test.rb", /module TestApp/, / class AccountObserverTest < ActiveSupport::TestCase/
end
end
@@ -186,7 +186,7 @@ class NamespacedMailerGeneratorTest < NamespacedGeneratorTestCase
def test_invokes_default_test_framework
run_generator
- assert_file "test/functional/test_app/notifier_test.rb" do |test|
+ assert_file "test/mailers/test_app/notifier_test.rb" do |test|
assert_match(/module TestApp/, test)
assert_match(/class NotifierTest < ActionMailer::TestCase/, test)
assert_match(/test "foo"/, test)
@@ -225,7 +225,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
# Model
assert_file "app/models/test_app/product_line.rb", /module TestApp\n class ProductLine < ActiveRecord::Base/
- assert_file "test/unit/test_app/product_line_test.rb", /module TestApp\n class ProductLineTest < ActiveSupport::TestCase/
+ assert_file "test/models/test_app/product_line_test.rb", /module TestApp\n class ProductLineTest < ActiveSupport::TestCase/
assert_file "test/fixtures/test_app/product_lines.yml"
assert_migration "db/migrate/create_test_app_product_lines.rb"
@@ -240,7 +240,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
/module TestApp/,
/class ProductLinesController < ApplicationController/
- assert_file "test/functional/test_app/product_lines_controller_test.rb",
+ assert_file "test/controllers/test_app/product_lines_controller_test.rb",
/module TestApp\n class ProductLinesControllerTest < ActionController::TestCase/
# Views
@@ -255,7 +255,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
# Helpers
assert_file "app/helpers/test_app/product_lines_helper.rb"
- assert_file "test/unit/helpers/test_app/product_lines_helper_test.rb"
+ assert_file "test/helpers/test_app/product_lines_helper_test.rb"
# Stylesheets
assert_file "app/assets/stylesheets/scaffold.css"
@@ -263,11 +263,11 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
def test_scaffold_on_revoke
run_generator
- run_generator ["product_line"], :behavior => :revoke
+ run_generator ["product_line"], behavior: :revoke
# Model
assert_no_file "app/models/test_app/product_line.rb"
- assert_no_file "test/unit/test_app/product_line_test.rb"
+ assert_no_file "test/models/test_app/product_line_test.rb"
assert_no_file "test/fixtures/test_app/product_lines.yml"
assert_no_migration "db/migrate/create_test_app_product_lines.rb"
@@ -278,7 +278,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
# Controller
assert_no_file "app/controllers/test_app/product_lines_controller.rb"
- assert_no_file "test/functional/test_app/product_lines_controller_test.rb"
+ assert_no_file "test/controllers/test_app/product_lines_controller_test.rb"
# Views
assert_no_file "app/views/test_app/product_lines"
@@ -286,7 +286,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
# Helpers
assert_no_file "app/helpers/test_app/product_lines_helper.rb"
- assert_no_file "test/unit/helpers/test_app/product_lines_helper_test.rb"
+ assert_no_file "test/helpers/test_app/product_lines_helper_test.rb"
# Stylesheets (should not be removed)
assert_file "app/assets/stylesheets/scaffold.css"
@@ -298,13 +298,13 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
# Model
assert_file "app/models/test_app/admin.rb", /module TestApp\n module Admin/
assert_file "app/models/test_app/admin/role.rb", /module TestApp\n class Admin::Role < ActiveRecord::Base/
- assert_file "test/unit/test_app/admin/role_test.rb", /module TestApp\n class Admin::RoleTest < ActiveSupport::TestCase/
+ assert_file "test/models/test_app/admin/role_test.rb", /module TestApp\n class Admin::RoleTest < ActiveSupport::TestCase/
assert_file "test/fixtures/test_app/admin/roles.yml"
assert_migration "db/migrate/create_test_app_admin_roles.rb"
# Route
assert_file "config/routes.rb" do |route|
- assert_match(/namespace :admin do resources :roles end$/, route)
+ assert_match(/^ namespace :admin do\n resources :roles\n end$/, route)
end
# Controller
@@ -312,7 +312,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
assert_match(/module TestApp\n class Admin::RolesController < ApplicationController/, content)
end
- assert_file "test/functional/test_app/admin/roles_controller_test.rb",
+ assert_file "test/controllers/test_app/admin/roles_controller_test.rb",
/module TestApp\n class Admin::RolesControllerTest < ActionController::TestCase/
# Views
@@ -327,7 +327,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
# Helpers
assert_file "app/helpers/test_app/admin/roles_helper.rb"
- assert_file "test/unit/helpers/test_app/admin/roles_helper_test.rb"
+ assert_file "test/helpers/test_app/admin/roles_helper_test.rb"
# Stylesheets
assert_file "app/assets/stylesheets/scaffold.css"
@@ -335,23 +335,23 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
def test_scaffold_with_namespace_on_revoke
run_generator [ "admin/role", "name:string", "description:string" ]
- run_generator [ "admin/role" ], :behavior => :revoke
+ run_generator [ "admin/role" ], behavior: :revoke
# Model
assert_file "app/models/test_app/admin.rb" # ( should not be remove )
assert_no_file "app/models/test_app/admin/role.rb"
- assert_no_file "test/unit/test_app/admin/role_test.rb"
+ assert_no_file "test/models/test_app/admin/role_test.rb"
assert_no_file "test/fixtures/test_app/admin/roles.yml"
assert_no_migration "db/migrate/create_test_app_admin_roles.rb"
# Route
assert_file "config/routes.rb" do |route|
- assert_no_match(/namespace :admin do resources :roles end$/, route)
+ assert_no_match(/^ namespace :admin do\n resources :roles\n end$$/, route)
end
# Controller
assert_no_file "app/controllers/test_app/admin/roles_controller.rb"
- assert_no_file "test/functional/test_app/admin/roles_controller_test.rb"
+ assert_no_file "test/controllers/test_app/admin/roles_controller_test.rb"
# Views
assert_no_file "app/views/test_app/admin/roles"
@@ -359,7 +359,79 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
# Helpers
assert_no_file "app/helpers/test_app/admin/roles_helper.rb"
- assert_no_file "test/unit/helpers/test_app/admin/roles_helper_test.rb"
+ assert_no_file "test/helpers/test_app/admin/roles_helper_test.rb"
+
+ # Stylesheets (should not be removed)
+ assert_file "app/assets/stylesheets/scaffold.css"
+ end
+
+ def test_scaffold_with_nested_namespace_on_invoke
+ run_generator [ "admin/user/special/role", "name:string", "description:string" ]
+
+ # Model
+ assert_file "app/models/test_app/admin/user/special.rb", /module TestApp\n module Admin/
+ assert_file "app/models/test_app/admin/user/special/role.rb", /module TestApp\n class Admin::User::Special::Role < ActiveRecord::Base/
+ assert_file "test/models/test_app/admin/user/special/role_test.rb", /module TestApp\n class Admin::User::Special::RoleTest < ActiveSupport::TestCase/
+ assert_file "test/fixtures/test_app/admin/user/special/roles.yml"
+ assert_migration "db/migrate/create_test_app_admin_user_special_roles.rb"
+
+ # Route
+ assert_file "config/routes.rb" do |route|
+ assert_match(/^ namespace :admin do\n namespace :user do\n namespace :special do\n resources :roles\n end\n end\n end$/, route)
+ end
+
+ # Controller
+ assert_file "app/controllers/test_app/admin/user/special/roles_controller.rb" do |content|
+ assert_match(/module TestApp\n class Admin::User::Special::RolesController < ApplicationController/, content)
+ end
+
+ assert_file "test/controllers/test_app/admin/user/special/roles_controller_test.rb",
+ /module TestApp\n class Admin::User::Special::RolesControllerTest < ActionController::TestCase/
+
+ # Views
+ %w(
+ index
+ edit
+ new
+ show
+ _form
+ ).each { |view| assert_file "app/views/test_app/admin/user/special/roles/#{view}.html.erb" }
+ assert_no_file "app/views/layouts/admin/user/special/roles.html.erb"
+
+ # Helpers
+ assert_file "app/helpers/test_app/admin/user/special/roles_helper.rb"
+ assert_file "test/helpers/test_app/admin/user/special/roles_helper_test.rb"
+
+ # Stylesheets
+ assert_file "app/assets/stylesheets/scaffold.css"
+ end
+
+ def test_scaffold_with_nested_namespace_on_revoke
+ run_generator [ "admin/user/special/role", "name:string", "description:string" ]
+ run_generator [ "admin/user/special/role" ], behavior: :revoke
+
+ # Model
+ assert_file "app/models/test_app/admin/user/special.rb" # ( should not be remove )
+ assert_no_file "app/models/test_app/admin/user/special/role.rb"
+ assert_no_file "test/models/test_app/admin/user/special/role_test.rb"
+ assert_no_file "test/fixtures/test_app/admin/user/special/roles.yml"
+ assert_no_migration "db/migrate/create_test_app_admin_user_special_roles.rb"
+
+ # Route
+ assert_file "config/routes.rb" do |route|
+ assert_no_match(/^ namespace :admin do\n namespace :user do\n namespace :special do\n resources :roles\n end\n end\n end$/, route)
+ end
+
+ # Controller
+ assert_no_file "app/controllers/test_app/admin/user/special/roles_controller.rb"
+ assert_no_file "test/controllers/test_app/admin/user/special/roles_controller_test.rb"
+
+ # Views
+ assert_no_file "app/views/test_app/admin/user/special/roles"
+
+ # Helpers
+ assert_no_file "app/helpers/test_app/admin/user/special/roles_helper.rb"
+ assert_no_file "test/helpers/test_app/admin/user/special/roles_helper_test.rb"
# Stylesheets (should not be removed)
assert_file "app/assets/stylesheets/scaffold.css"
diff --git a/railties/test/generators/observer_generator_test.rb b/railties/test/generators/observer_generator_test.rb
index afcee0a2dc..1231827466 100644
--- a/railties/test/generators/observer_generator_test.rb
+++ b/railties/test/generators/observer_generator_test.rb
@@ -17,7 +17,7 @@ class ObserverGeneratorTest < Rails::Generators::TestCase
def test_invokes_default_test_framework
run_generator
- assert_file "test/unit/account_observer_test.rb", /class AccountObserverTest < ActiveSupport::TestCase/
+ assert_file "test/models/account_observer_test.rb", /class AccountObserverTest < ActiveSupport::TestCase/
end
def test_logs_if_the_test_framework_cannot_be_found
diff --git a/railties/test/generators/orm_test.rb b/railties/test/generators/orm_test.rb
index 9dd3d3e0ec..88ae930554 100644
--- a/railties/test/generators/orm_test.rb
+++ b/railties/test/generators/orm_test.rb
@@ -20,12 +20,12 @@ class OrmTest < Rails::Generators::TestCase
tests Rails::Generators::ScaffoldControllerGenerator
def test_orm_class_returns_custom_generator_if_supported_custom_orm_set
- g = generator ["Foo"], :orm => "ORMWithGenerators"
+ g = generator ["Foo"], orm: "ORMWithGenerators"
assert_equal ORMWithGenerators::Generators::ActiveModel, g.send(:orm_class)
end
def test_orm_class_returns_rails_generator_if_unsupported_custom_orm_set
- g = generator ["Foo"], :orm => "ORMWithoutGenerators"
+ g = generator ["Foo"], orm: "ORMWithoutGenerators"
assert_equal Rails::Generators::ActiveModel, g.send(:orm_class)
end
diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb
index dddbfa64b6..6974db5751 100644
--- a/railties/test/generators/plugin_new_generator_test.rb
+++ b/railties/test/generators/plugin_new_generator_test.rb
@@ -379,7 +379,7 @@ class CustomPluginGeneratorTest < Rails::Generators::TestCase
run_generator([destination_root, "-b", "#{Rails.root}/lib/plugin_builders/spec_builder.rb"])
assert_file 'spec/spec_helper.rb'
assert_file 'spec/dummy'
- assert_file 'Rakefile', /task :default => :spec/
+ assert_file 'Rakefile', /task default: :spec/
assert_file 'Rakefile', /# spec tasks in rakefile/
end
diff --git a/railties/test/generators/resource_generator_test.rb b/railties/test/generators/resource_generator_test.rb
index 73804dae45..3d4e694361 100644
--- a/railties/test/generators/resource_generator_test.rb
+++ b/railties/test/generators/resource_generator_test.rb
@@ -18,7 +18,7 @@ class ResourceGeneratorTest < Rails::Generators::TestCase
%w(
app/models/account.rb
- test/unit/account_test.rb
+ test/models/account_test.rb
test/fixtures/accounts.yml
).each { |path| assert_file path }
@@ -33,10 +33,10 @@ class ResourceGeneratorTest < Rails::Generators::TestCase
def test_resource_controller_with_pluralized_class_name
run_generator
assert_file "app/controllers/accounts_controller.rb", /class AccountsController < ApplicationController/
- assert_file "test/functional/accounts_controller_test.rb", /class AccountsControllerTest < ActionController::TestCase/
+ assert_file "test/controllers/accounts_controller_test.rb", /class AccountsControllerTest < ActionController::TestCase/
assert_file "app/helpers/accounts_helper.rb", /module AccountsHelper/
- assert_file "test/unit/helpers/accounts_helper_test.rb", /class AccountsHelperTest < ActionView::TestCase/
+ assert_file "test/helpers/accounts_helper_test.rb", /class AccountsHelperTest < ActionView::TestCase/
end
def test_resource_controller_with_actions
@@ -62,14 +62,14 @@ class ResourceGeneratorTest < Rails::Generators::TestCase
def test_plural_names_are_singularized
content = run_generator ["accounts".freeze]
assert_file "app/models/account.rb", /class Account < ActiveRecord::Base/
- assert_file "test/unit/account_test.rb", /class AccountTest/
+ assert_file "test/models/account_test.rb", /class AccountTest/
assert_match(/Plural version of the model detected, using singularized version. Override with --force-plural./, content)
end
def test_plural_names_can_be_forced
content = run_generator ["accounts", "--force-plural"]
assert_file "app/models/accounts.rb", /class Accounts < ActiveRecord::Base/
- assert_file "test/unit/accounts_test.rb", /class AccountsTest/
+ assert_file "test/models/accounts_test.rb", /class AccountsTest/
assert_no_match(/Plural version of the model detected/, content)
end
@@ -80,7 +80,7 @@ class ResourceGeneratorTest < Rails::Generators::TestCase
def test_route_is_removed_on_revoke
run_generator
- run_generator ["account"], :behavior => :revoke
+ run_generator ["account"], behavior: :revoke
assert_file "config/routes.rb" do |route|
assert_no_match(/resources :accounts$/, route)
diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb
index aa09343346..38454dfb8b 100644
--- a/railties/test/generators/scaffold_controller_generator_test.rb
+++ b/railties/test/generators/scaffold_controller_generator_test.rb
@@ -57,7 +57,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
def test_helper_are_invoked_with_a_pluralized_name
run_generator
assert_file "app/helpers/users_helper.rb", /module UsersHelper/
- assert_file "test/unit/helpers/users_helper_test.rb", /class UsersHelperTest < ActionView::TestCase/
+ assert_file "test/helpers/users_helper_test.rb", /class UsersHelperTest < ActionView::TestCase/
end
def test_views_are_generated
@@ -75,7 +75,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
def test_functional_tests
run_generator
- assert_file "test/functional/users_controller_test.rb" do |content|
+ assert_file "test/controllers/users_controller_test.rb" do |content|
assert_match(/class UsersControllerTest < ActionController::TestCase/, content)
assert_match(/test "should get index"/, content)
assert_match(/post :create, user: \{ age: @user.age, name: @user.name \}/, content)
@@ -86,7 +86,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
def test_functional_tests_without_attributes
run_generator ["User"]
- assert_file "test/functional/users_controller_test.rb" do |content|
+ assert_file "test/controllers/users_controller_test.rb" do |content|
assert_match(/class UsersControllerTest < ActionController::TestCase/, content)
assert_match(/test "should get index"/, content)
assert_match(/post :create, user: \{ \}/, content)
@@ -97,7 +97,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
def test_skip_helper_if_required
run_generator ["User", "name:string", "age:integer", "--no-helper"]
assert_no_file "app/helpers/users_helper.rb"
- assert_no_file "test/unit/helpers/users_helper_test.rb"
+ assert_no_file "test/helpers/users_helper_test.rb"
end
def test_skip_layout_if_required
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb
index 40c5188042..efe47cdfcb 100644
--- a/railties/test/generators/scaffold_generator_test.rb
+++ b/railties/test/generators/scaffold_generator_test.rb
@@ -12,7 +12,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
# Model
assert_file "app/models/product_line.rb", /class ProductLine < ActiveRecord::Base/
- assert_file "test/unit/product_line_test.rb", /class ProductLineTest < ActiveSupport::TestCase/
+ assert_file "test/models/product_line_test.rb", /class ProductLineTest < ActiveSupport::TestCase/
assert_file "test/fixtures/product_lines.yml"
assert_migration "db/migrate/create_product_lines.rb", /belongs_to :product, index: true/
assert_migration "db/migrate/create_product_lines.rb", /references :user, index: true/
@@ -60,7 +60,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
end
end
- assert_file "test/functional/product_lines_controller_test.rb" do |test|
+ assert_file "test/controllers/product_lines_controller_test.rb" do |test|
assert_match(/class ProductLinesControllerTest < ActionController::TestCase/, test)
assert_match(/post :create, product_line: \{ title: @product_line.title \}/, test)
assert_match(/put :update, id: @product_line, product_line: \{ title: @product_line.title \}/, test)
@@ -78,7 +78,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
# Helpers
assert_file "app/helpers/product_lines_helper.rb"
- assert_file "test/unit/helpers/product_lines_helper_test.rb"
+ assert_file "test/helpers/product_lines_helper_test.rb"
# Assets
assert_file "app/assets/stylesheets/scaffold.css"
@@ -89,7 +89,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
def test_functional_tests_without_attributes
run_generator ["product_line"]
- assert_file "test/functional/product_lines_controller_test.rb" do |content|
+ assert_file "test/controllers/product_lines_controller_test.rb" do |content|
assert_match(/class ProductLinesControllerTest < ActionController::TestCase/, content)
assert_match(/test "should get index"/, content)
assert_match(/post :create, product_line: \{ \}/, content)
@@ -99,11 +99,11 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
def test_scaffold_on_revoke
run_generator
- run_generator ["product_line"], :behavior => :revoke
+ run_generator ["product_line"], behavior: :revoke
# Model
assert_no_file "app/models/product_line.rb"
- assert_no_file "test/unit/product_line_test.rb"
+ assert_no_file "test/models/product_line_test.rb"
assert_no_file "test/fixtures/product_lines.yml"
assert_no_migration "db/migrate/create_product_lines.rb"
@@ -114,7 +114,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
# Controller
assert_no_file "app/controllers/product_lines_controller.rb"
- assert_no_file "test/functional/product_lines_controller_test.rb"
+ assert_no_file "test/controllers/product_lines_controller_test.rb"
# Views
assert_no_file "app/views/product_lines"
@@ -122,7 +122,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
# Helpers
assert_no_file "app/helpers/product_lines_helper.rb"
- assert_no_file "test/unit/helpers/product_lines_helper_test.rb"
+ assert_no_file "test/helpers/product_lines_helper_test.rb"
# Assets
assert_file "app/assets/stylesheets/scaffold.css", /:visited/
@@ -136,13 +136,13 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
# Model
assert_file "app/models/admin.rb", /module Admin/
assert_file "app/models/admin/role.rb", /class Admin::Role < ActiveRecord::Base/
- assert_file "test/unit/admin/role_test.rb", /class Admin::RoleTest < ActiveSupport::TestCase/
+ assert_file "test/models/admin/role_test.rb", /class Admin::RoleTest < ActiveSupport::TestCase/
assert_file "test/fixtures/admin/roles.yml"
assert_migration "db/migrate/create_admin_roles.rb"
# Route
assert_file "config/routes.rb" do |route|
- assert_match(/namespace :admin do resources :roles end$/, route)
+ assert_match(/^ namespace :admin do\n resources :roles\n end$/, route)
end
# Controller
@@ -183,7 +183,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
end
end
- assert_file "test/functional/admin/roles_controller_test.rb",
+ assert_file "test/controllers/admin/roles_controller_test.rb",
/class Admin::RolesControllerTest < ActionController::TestCase/
# Views
@@ -198,7 +198,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
# Helpers
assert_file "app/helpers/admin/roles_helper.rb"
- assert_file "test/unit/helpers/admin/roles_helper_test.rb"
+ assert_file "test/helpers/admin/roles_helper_test.rb"
# Assets
assert_file "app/assets/stylesheets/scaffold.css", /:visited/
@@ -213,7 +213,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
# Model
assert_file "app/models/admin.rb" # ( should not be remove )
assert_no_file "app/models/admin/role.rb"
- assert_no_file "test/unit/admin/role_test.rb"
+ assert_no_file "test/models/admin/role_test.rb"
assert_no_file "test/fixtures/admin/roles.yml"
assert_no_migration "db/migrate/create_admin_roles.rb"
@@ -224,7 +224,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
# Controller
assert_no_file "app/controllers/admin/roles_controller.rb"
- assert_no_file "test/functional/admin/roles_controller_test.rb"
+ assert_no_file "test/controllers/admin/roles_controller_test.rb"
# Views
assert_no_file "app/views/admin/roles"
@@ -232,7 +232,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
# Helpers
assert_no_file "app/helpers/admin/roles_helper.rb"
- assert_no_file "test/unit/helpers/admin/roles_helper_test.rb"
+ assert_no_file "test/helpers/admin/roles_helper_test.rb"
# Assets
assert_file "app/assets/stylesheets/scaffold.css"
diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb
index a4bdfcf438..1e5a4545a1 100644
--- a/railties/test/generators/shared_generator_tests.rb
+++ b/railties/test/generators/shared_generator_tests.rb
@@ -87,7 +87,7 @@ module SharedGeneratorTests
template = %{ say "It works!" }
template.instance_eval "def read; self; end" # Make the string respond to read
- generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template)
+ generator([destination_root], template: path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template)
assert_match(/It works!/, capture(:stdout) { generator.invoke_all })
end
@@ -96,31 +96,31 @@ module SharedGeneratorTests
template = %{ say "It works!" }
template.instance_eval "def read; self; end" # Make the string respond to read
- generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template)
+ generator([destination_root], template: path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template)
assert_match(/It works!/, capture(:stdout) { generator.invoke_all })
end
def test_dev_option
- generator([destination_root], :dev => true).expects(:bundle_command).with('install').once
+ generator([destination_root], dev: true).expects(:bundle_command).with('install').once
quietly { generator.invoke_all }
rails_path = File.expand_path('../../..', Rails.root)
assert_file 'Gemfile', /^gem\s+["']rails["'],\s+path:\s+["']#{Regexp.escape(rails_path)}["']$/
end
def test_edge_option
- generator([destination_root], :edge => true).expects(:bundle_command).with('install').once
+ generator([destination_root], edge: true).expects(:bundle_command).with('install').once
quietly { generator.invoke_all }
assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["']$}
end
def test_skip_gemfile
- generator([destination_root], :skip_gemfile => true).expects(:bundle_command).never
+ generator([destination_root], skip_gemfile: true).expects(:bundle_command).never
quietly { generator.invoke_all }
assert_no_file 'Gemfile'
end
def test_skip_bundle
- generator([destination_root], :skip_bundle => true).expects(:bundle_command).never
+ generator([destination_root], skip_bundle: true).expects(:bundle_command).never
quietly { generator.invoke_all }
# skip_bundle is only about running bundle install, ensure the Gemfile is still
@@ -192,7 +192,7 @@ module SharedCustomGeneratorTests
template = "class #{builder_class}; end"
template.instance_eval "def read; self; end" # Make the string respond to read
- generator([destination_root], :builder => url).expects(:open).with(url, 'Accept' => 'application/x-thor-template').returns(template)
+ generator([destination_root], builder: url).expects(:open).with(url, 'Accept' => 'application/x-thor-template').returns(template)
quietly { generator.invoke_all }
default_files.each{ |path| assert_no_file(path) }
diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb
index 027d8eb9b7..9953aa929b 100644
--- a/railties/test/generators_test.rb
+++ b/railties/test/generators_test.rb
@@ -43,8 +43,8 @@ class GeneratorsTest < Rails::Generators::TestCase
end
def test_invoke_with_config_values
- Rails::Generators::ModelGenerator.expects(:start).with(["Account"], :behavior => :skip)
- Rails::Generators.invoke :model, ["Account"], :behavior => :skip
+ Rails::Generators::ModelGenerator.expects(:start).with(["Account"], behavior: :skip)
+ Rails::Generators.invoke :model, ["Account"], behavior: :skip
end
def test_find_by_namespace
@@ -165,7 +165,7 @@ class GeneratorsTest < Rails::Generators::TestCase
end
def test_developer_options_are_overwriten_by_user_options
- Rails::Generators.options[:with_options] = { :generate => false }
+ Rails::Generators.options[:with_options] = { generate: false }
self.class.class_eval(<<-end_eval, __FILE__, __LINE__ + 1)
class WithOptionsGenerator < Rails::Generators::Base
@@ -186,7 +186,7 @@ class GeneratorsTest < Rails::Generators::TestCase
File.open(template, 'w'){ |f| f.write "empty" }
capture(:stdout) do
- Rails::Generators.invoke :model, ["user"], :destination_root => destination_root
+ Rails::Generators.invoke :model, ["user"], destination_root: destination_root
end
assert_file "app/models/user.rb" do |content|
diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb
index c84c7f204c..16e259be5d 100644
--- a/railties/test/initializable_test.rb
+++ b/railties/test/initializable_test.rb
@@ -43,17 +43,17 @@ module InitializableTests
class Child < Parent
include Rails::Initializable
- initializer :three, :before => :one do
+ initializer :three, before: :one do
$arr << 3
end
- initializer :four, :after => :one, :before => :two do
+ initializer :four, after: :one, before: :two do
$arr << 4
end
end
class Parent
- initializer :five, :before => :one do
+ initializer :five, before: :one do
$arr << 5
end
end
@@ -61,7 +61,7 @@ module InitializableTests
class Instance
include Rails::Initializable
- initializer :one, :group => :assets do
+ initializer :one, group: :assets do
$arr << 1
end
@@ -69,7 +69,7 @@ module InitializableTests
$arr << 2
end
- initializer :three, :group => :all do
+ initializer :three, group: :all do
$arr << 3
end
@@ -90,11 +90,11 @@ module InitializableTests
class MoreInitializers
include Rails::Initializable
- initializer :startup, :before => :last do
+ initializer :startup, before: :last do
$arr << 3
end
- initializer :terminate, :after => :first, :before => :startup do
+ initializer :terminate, after: :first, before: :startup do
$arr << two
end
@@ -134,11 +134,11 @@ module InitializableTests
class PluginB
include Rails::Initializable
- initializer "plugin_b.startup", :after => "plugin_a.startup" do
+ initializer "plugin_b.startup", after: "plugin_a.startup" do
$arr << 2
end
- initializer "plugin_b.terminate", :before => "plugin_a.terminate" do
+ initializer "plugin_b.terminate", before: "plugin_a.terminate" do
$arr << 3
end
end
diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb
index 0f36eb67e5..e59488f97d 100644
--- a/railties/test/isolation/abstract_unit.rb
+++ b/railties/test/isolation/abstract_unit.rb
@@ -113,14 +113,14 @@ module TestHelpers
routes = File.read("#{app_path}/config/routes.rb")
if routes =~ /(\n\s*end\s*)\Z/
File.open("#{app_path}/config/routes.rb", 'w') do |f|
- f.puts $` + "\nmatch ':controller(/:action(/:id))(.:format)', :via => :all\n" + $1
+ f.puts $` + "\nmatch ':controller(/:action(/:id))(.:format)', via: :all\n" + $1
end
end
add_to_config <<-RUBY
config.eager_load = false
config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
- config.session_store :cookie_store, :key => "_myapp_session"
+ config.session_store :cookie_store, key: "_myapp_session"
config.active_support.deprecation = :log
config.action_controller.allow_forgery_protection = false
RUBY
@@ -139,7 +139,7 @@ module TestHelpers
app = Class.new(Rails::Application)
app.config.eager_load = false
app.config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
- app.config.session_store :cookie_store, :key => "_myapp_session"
+ app.config.session_store :cookie_store, key: "_myapp_session"
app.config.active_support.deprecation = :log
yield app if block_given?
@@ -157,7 +157,7 @@ module TestHelpers
controller :foo, <<-RUBY
class FooController < ApplicationController
def index
- render :text => "foo"
+ render text: "foo"
end
end
RUBY
diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb
index 76ff3ec3e4..12f18b9dbf 100644
--- a/railties/test/paths_test.rb
+++ b/railties/test/paths_test.rb
@@ -32,7 +32,7 @@ class PathsTest < ActiveSupport::TestCase
end
test "creating a root level path with options" do
- @root.add "app", :with => "/foo/bar"
+ @root.add "app", with: "/foo/bar"
assert_equal ["/foo/bar"], @root["app"].to_a
end
@@ -52,18 +52,18 @@ class PathsTest < ActiveSupport::TestCase
test "creating a child level path with option" do
@root.add "app"
- @root.add "app/models", :with => "/foo/bar/baz"
+ @root.add "app/models", with: "/foo/bar/baz"
assert_equal ["/foo/bar/baz"], @root["app/models"].to_a
end
test "child level paths are relative from the root" do
@root.add "app"
- @root.add "app/models", :with => "baz"
+ @root.add "app/models", with: "baz"
assert_equal ["/foo/bar/baz"], @root["app/models"].to_a
end
test "adding multiple physical paths as an array" do
- @root.add "app", :with => ["/app", "/app2"]
+ @root.add "app", with: ["/app", "/app2"]
assert_equal ["/app", "/app2"], @root["app"].to_a
end
@@ -92,7 +92,7 @@ class PathsTest < ActiveSupport::TestCase
end
test "it is possible to add a path that should be autoloaded only once" do
- @root.add "app", :with => "/app"
+ @root.add "app", with: "/app"
@root["app"].autoload_once!
assert @root["app"].autoload_once?
assert @root.autoload_once.include?(@root["app"].expanded.first)
@@ -109,13 +109,13 @@ class PathsTest < ActiveSupport::TestCase
end
test "it is possible to add a path without assignment and specify it should be loaded only once" do
- @root.add "app", :with => "/app", :autoload_once => true
+ @root.add "app", with: "/app", autoload_once: true
assert @root["app"].autoload_once?
assert @root.autoload_once.include?("/app")
end
test "it is possible to add multiple paths without assignment and specify it should be loaded only once" do
- @root.add "app", :with => ["/app", "/app2"], :autoload_once => true
+ @root.add "app", with: ["/app", "/app2"], autoload_once: true
assert @root["app"].autoload_once?
assert @root.autoload_once.include?("/app")
assert @root.autoload_once.include?("/app2")
@@ -153,20 +153,20 @@ class PathsTest < ActiveSupport::TestCase
end
test "it is possible to add a path without assignment and mark it as eager" do
- @root.add "app", :with => "/app", :eager_load => true
+ @root.add "app", with: "/app", eager_load: true
assert @root["app"].eager_load?
assert @root.eager_load.include?("/app")
end
test "it is possible to add multiple paths without assignment and mark them as eager" do
- @root.add "app", :with => ["/app", "/app2"], :eager_load => true
+ @root.add "app", with: ["/app", "/app2"], eager_load: true
assert @root["app"].eager_load?
assert @root.eager_load.include?("/app")
assert @root.eager_load.include?("/app2")
end
test "it is possible to create a path without assignment and mark it both as eager and load once" do
- @root.add "app", :with => "/app", :eager_load => true, :autoload_once => true
+ @root.add "app", with: "/app", eager_load: true, autoload_once: true
assert @root["app"].eager_load?
assert @root["app"].autoload_once?
assert @root.eager_load.include?("/app")
@@ -194,12 +194,12 @@ class PathsTest < ActiveSupport::TestCase
end
test "it should be possible to override a path's default glob without assignment" do
- @root.add "app", :with => "/app", :glob => "*.rb"
+ @root.add "app", with: "/app", glob: "*.rb"
assert_equal "*.rb", @root["app"].glob
end
test "it should be possible to replace a path and persist the original paths glob" do
- @root.add "app", :glob => "*.rb"
+ @root.add "app", glob: "*.rb"
@root["app"] = "app2"
assert_equal ["/foo/bar/app2"], @root["app"].to_a
assert_equal "*.rb", @root["app"].glob
@@ -213,7 +213,7 @@ class PathsTest < ActiveSupport::TestCase
end
test "a path can be added to the load path on creation" do
- @root.add "app", :with => "/app", :load_path => true
+ @root.add "app", with: "/app", load_path: true
assert @root["app"].load_path?
assert_equal ["/app"], @root.load_paths
end
@@ -226,7 +226,7 @@ class PathsTest < ActiveSupport::TestCase
end
test "a path can be marked as autoload on creation" do
- @root.add "app", :with => "/app", :autoload => true
+ @root.add "app", with: "/app", autoload: true
assert @root["app"].autoload?
assert_equal ["/app"], @root.autoload_paths
end
diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb
index cfb32b7d35..08fcddd4bf 100644
--- a/railties/test/rails_info_controller_test.rb
+++ b/railties/test/rails_info_controller_test.rb
@@ -21,19 +21,19 @@ class InfoControllerTest < ActionController::TestCase
end
test "info controller does not allow remote requests" do
- @controller.stubs(:local_request? => false)
+ @controller.stubs(local_request?: false)
get :properties
assert_response :forbidden
end
test "info controller renders an error message when request was forbidden" do
- @controller.stubs(:local_request? => false)
+ @controller.stubs(local_request?: false)
get :properties
assert_select 'p'
end
test "info controller allows requests when all requests are considered local" do
- @controller.stubs(:local_request? => true)
+ @controller.stubs(local_request?: true)
get :properties
assert_response :success
end
diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb
index e52b3efdab..fcbe7b6cda 100644
--- a/railties/test/railties/engine_test.rb
+++ b/railties/test/railties/engine_test.rb
@@ -285,8 +285,8 @@ module RailtiesTest
@plugin.write "config/routes.rb", <<-RUBY
Rails.application.routes.draw do
- get 'foo', :to => 'bar#index'
- get 'bar', :to => 'bar#index'
+ get 'foo', to: 'bar#index'
+ get 'bar', to: 'bar#index'
end
RUBY
@@ -366,7 +366,7 @@ YAML
Rails.application.routes.draw do
namespace :admin do
namespace :foo do
- get "bar", :to => "bar#index"
+ get "bar", to: "bar#index"
end
end
end
@@ -375,7 +375,7 @@ YAML
@plugin.write "app/controllers/admin/foo/bar_controller.rb", <<-RUBY
class Admin::Foo::BarController < ApplicationController
def index
- render :text => "Rendered from namespace"
+ render text: "Rendered from namespace"
end
end
RUBY
@@ -487,14 +487,14 @@ YAML
controller "foo", <<-RUBY
class FooController < ActionController::Base
def index
- render :text => params[:username]
+ render text: params[:username]
end
end
RUBY
@plugin.write "config/routes.rb", <<-RUBY
Bukkits::Engine.routes.draw do
- root :to => "foo#index"
+ root to: "foo#index"
end
RUBY
@@ -608,14 +608,14 @@ YAML
app_file "config/routes.rb", <<-RUBY
AppTemplate::Application.routes.draw do
- get "/bar" => "bar#index", :as => "bar"
- mount Bukkits::Engine => "/bukkits", :as => "bukkits"
+ get "/bar" => "bar#index", as: "bar"
+ mount Bukkits::Engine => "/bukkits", as: "bukkits"
end
RUBY
@plugin.write "config/routes.rb", <<-RUBY
Bukkits::Engine.routes.draw do
- get "/foo" => "foo#index", :as => "foo"
+ get "/foo" => "foo#index", as: "foo"
get "/foo/show" => "foo#show"
get "/from_app" => "foo#from_app"
get "/routes_helpers_in_view" => "foo#routes_helpers_in_view"
@@ -643,23 +643,23 @@ YAML
@plugin.write "app/controllers/bukkits/foo_controller.rb", <<-RUBY
class Bukkits::FooController < ActionController::Base
def index
- render :inline => "<%= help_the_engine %>"
+ render inline: "<%= help_the_engine %>"
end
def show
- render :text => foo_path
+ render text: foo_path
end
def from_app
- render :inline => "<%= (self.respond_to?(:bar_path) || self.respond_to?(:something)) %>"
+ render inline: "<%= (self.respond_to?(:bar_path) || self.respond_to?(:something)) %>"
end
def routes_helpers_in_view
- render :inline => "<%= foo_path %>, <%= main_app.bar_path %>"
+ render inline: "<%= foo_path %>, <%= main_app.bar_path %>"
end
def polymorphic_path_without_namespace
- render :text => polymorphic_path(Post.new)
+ render text: polymorphic_path(Post.new)
end
end
RUBY
@@ -726,7 +726,7 @@ YAML
app_file "config/routes.rb", <<-RUBY
AppTemplate::Application.routes.draw do
- mount Bukkits::Engine => "/bukkits", :as => "bukkits"
+ mount Bukkits::Engine => "/bukkits", as: "bukkits"
end
RUBY
@@ -1033,11 +1033,11 @@ YAML
controller "main", <<-RUBY
class MainController < ActionController::Base
def foo
- render :inline => '<%= render :partial => "shared/foo" %>'
+ render inline: '<%= render :partial => "shared/foo" %>'
end
def bar
- render :inline => '<%= render :partial => "shared/bar" %>'
+ render inline: '<%= render :partial => "shared/bar" %>'
end
end
RUBY
@@ -1113,7 +1113,7 @@ YAML
controller "main", <<-RUBY
class MainController < ActionController::Base
def foo
- render :inline => '<%= render :partial => "shared/foo" %>'
+ render inline: '<%= render :partial => "shared/foo" %>'
end
end
RUBY
@@ -1167,7 +1167,7 @@ YAML
fullpath: \#{request.fullpath}
path: \#{request.path}
TEXT
- render :text => text
+ render text: text
end
end
end
@@ -1205,7 +1205,7 @@ YAML
app_file "app/controllers/bar_controller.rb", <<-RUBY
class BarController < ApplicationController
def index
- render :text => bukkits.bukkit_path
+ render text: bukkits.bukkit_path
end
end
RUBY
@@ -1227,7 +1227,7 @@ YAML
@plugin.write "app/controllers/bukkits/bukkit_controller.rb", <<-RUBY
class Bukkits::BukkitController < ActionController::Base
def index
- render :text => main_app.bar_path
+ render text: main_app.bar_path
end
end
RUBY
diff --git a/railties/test/railties/generators_test.rb b/railties/test/railties/generators_test.rb
index c90b795d59..0abb2b7578 100644
--- a/railties/test/railties/generators_test.rb
+++ b/railties/test/railties/generators_test.rb
@@ -46,7 +46,7 @@ module RailtiesTests
f.write <<-GEMFILE.gsub(/^ {12}/, '')
source "http://rubygems.org"
- gem 'rails', :path => '#{RAILS_FRAMEWORK_ROOT}'
+ gem 'rails', path: '#{RAILS_FRAMEWORK_ROOT}'
gem 'sqlite3'
GEMFILE
end
diff --git a/railties/test/railties/mounted_engine_test.rb b/railties/test/railties/mounted_engine_test.rb
index bd13c3aba3..a1c52f01dc 100644
--- a/railties/test/railties/mounted_engine_test.rb
+++ b/railties/test/railties/mounted_engine_test.rb
@@ -42,14 +42,14 @@ module ApplicationTests
@simple_plugin.write "config/routes.rb", <<-RUBY
Weblog::Engine.routes.draw do
- get '/weblog' => "weblogs#index", :as => 'weblogs'
+ get '/weblog' => "weblogs#index", as: 'weblogs'
end
RUBY
@simple_plugin.write "app/controllers/weblogs_controller.rb", <<-RUBY
class WeblogsController < ActionController::Base
def index
- render :text => request.url
+ render text: request.url
end
end
RUBY
@@ -86,9 +86,9 @@ module ApplicationTests
@plugin.write "config/routes.rb", <<-RUBY
Blog::Engine.routes.draw do
resources :posts
- get '/generate_application_route', :to => 'posts#generate_application_route'
- get '/application_route_in_view', :to => 'posts#application_route_in_view'
- get '/engine_polymorphic_path', :to => 'posts#engine_polymorphic_path'
+ get '/generate_application_route', to: 'posts#generate_application_route'
+ get '/application_route_in_view', to: 'posts#application_route_in_view'
+ get '/engine_polymorphic_path', to: 'posts#engine_polymorphic_path'
end
RUBY
@@ -96,22 +96,22 @@ module ApplicationTests
module Blog
class PostsController < ActionController::Base
def index
- render :text => blog.post_path(1)
+ render text: blog.post_path(1)
end
def generate_application_route
- path = main_app.url_for(:controller => "/main",
- :action => "index",
- :only_path => true)
- render :text => path
+ path = main_app.url_for(controller: "/main",
+ action: "index",
+ only_path: true)
+ render text: path
end
def application_route_in_view
- render :inline => "<%= main_app.root_path %>"
+ render inline: "<%= main_app.root_path %>"
end
def engine_polymorphic_path
- render :text => polymorphic_path(Post.new)
+ render text: polymorphic_path(Post.new)
end
end
end
@@ -120,31 +120,31 @@ module ApplicationTests
app_file "app/controllers/application_generating_controller.rb", <<-RUBY
class ApplicationGeneratingController < ActionController::Base
def engine_route
- render :text => blog.posts_path
+ render text: blog.posts_path
end
def engine_route_in_view
- render :inline => "<%= blog.posts_path %>"
+ render inline: "<%= blog.posts_path %>"
end
def weblog_engine_route
- render :text => weblog.weblogs_path
+ render text: weblog.weblogs_path
end
def weblog_engine_route_in_view
- render :inline => "<%= weblog.weblogs_path %>"
+ render inline: "<%= weblog.weblogs_path %>"
end
def url_for_engine_route
- render :text => blog.url_for(:controller => "blog/posts", :action => "index", :user => "john", :only_path => true)
+ render text: blog.url_for(controller: "blog/posts", action: "index", user: "john", only_path: true)
end
def polymorphic_route
- render :text => polymorphic_url([blog, Blog::Post.new])
+ render text: polymorphic_url([blog, Blog::Post.new])
end
def application_polymorphic_path
- render :text => polymorphic_path(Blog::Post.new)
+ render text: polymorphic_path(Blog::Post.new)
end
end
RUBY