diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2016-08-16 04:30:11 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2016-08-16 04:30:11 -0300 |
commit | 55f9b8129a50206513264824abb44088230793c2 (patch) | |
tree | ff2f01cabfc7e74b0bd831c2272a5517e4e81e99 /railties | |
parent | d0bdd74d7f6fae3d69b3681d5bc2d5ef6f55a0f8 (diff) | |
download | rails-55f9b8129a50206513264824abb44088230793c2.tar.gz rails-55f9b8129a50206513264824abb44088230793c2.tar.bz2 rails-55f9b8129a50206513264824abb44088230793c2.zip |
Add three new rubocop rules
Style/SpaceBeforeBlockBraces
Style/SpaceInsideBlockBraces
Style/SpaceInsideHashLiteralBraces
Fix all violations in the repository.
Diffstat (limited to 'railties')
37 files changed, 108 insertions, 108 deletions
diff --git a/railties/lib/rails/code_statistics.rb b/railties/lib/rails/code_statistics.rb index f7e1b5194c..b3d88147a5 100644 --- a/railties/lib/rails/code_statistics.rb +++ b/railties/lib/rails/code_statistics.rb @@ -9,7 +9,7 @@ class CodeStatistics #:nodoc: "Job tests", "Integration tests"] - HEADERS = {lines: " Lines", code_lines: " LOC", classes: "Classes", methods: "Methods"} + HEADERS = { lines: " Lines", code_lines: " LOC", classes: "Classes", methods: "Methods" } def initialize(*pairs) @pairs = pairs @@ -32,7 +32,7 @@ class CodeStatistics #:nodoc: private def calculate_statistics - Hash[@pairs.map{|pair| [pair.first, calculate_directory_statistics(pair.last)]}] + Hash[@pairs.map { |pair| [pair.first, calculate_directory_statistics(pair.last)] }] end def calculate_directory_statistics(directory, pattern = /^(?!\.).*?\.(rb|js|coffee|rake)$/) @@ -70,7 +70,7 @@ class CodeStatistics #:nodoc: end def width_for(label) - [@statistics.values.sum {|s| s.send(label) }.to_s.size, HEADERS[label].length].max + [@statistics.values.sum { |s| s.send(label) }.to_s.size, HEADERS[label].length].max end def print_header diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb index d79a88b025..66b7a14f16 100644 --- a/railties/lib/rails/commands/dbconsole.rb +++ b/railties/lib/rails/commands/dbconsole.rb @@ -152,7 +152,7 @@ module Rails dirs_on_path = ENV["PATH"].to_s.split(File::PATH_SEPARATOR) unless (ext = RbConfig::CONFIG["EXEEXT"]).empty? - commands = commands.map{|cmd| "#{cmd}#{ext}"} + commands = commands.map { |cmd| "#{cmd}#{ext}" } end full_path_command = nil diff --git a/railties/lib/rails/commands/plugin.rb b/railties/lib/rails/commands/plugin.rb index 56413aa7b0..60653a2cee 100644 --- a/railties/lib/rails/commands/plugin.rb +++ b/railties/lib/rails/commands/plugin.rb @@ -3,7 +3,7 @@ if ARGV.first != "new" else ARGV.shift unless ARGV.delete("--no-rc") - customrc = ARGV.index{ |x| x.include?("--rc=") } + customrc = ARGV.index { |x| x.include?("--rc=") } railsrc = if customrc File.expand_path(ARGV.delete_at(customrc).gsub(/--rc=/, "")) else diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 363c65b186..86d66afddb 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -402,7 +402,7 @@ module Rails end unless mod.respond_to?(:railtie_routes_url_helpers) - define_method(:railtie_routes_url_helpers) {|include_path_helpers = true| railtie.routes.url_helpers(include_path_helpers) } + define_method(:railtie_routes_url_helpers) { |include_path_helpers = true| railtie.routes.url_helpers(include_path_helpers) } end end end @@ -590,8 +590,8 @@ module Rails initializer :add_view_paths do views = paths["app/views"].existent unless views.empty? - ActiveSupport.on_load(:action_controller){ prepend_view_path(views) if respond_to?(:prepend_view_path) } - ActiveSupport.on_load(:action_mailer){ prepend_view_path(views) } + ActiveSupport.on_load(:action_controller) { prepend_view_path(views) if respond_to?(:prepend_view_path) } + ActiveSupport.on_load(:action_mailer) { prepend_view_path(views) } end end diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 708c0b11d6..6a112fc710 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -180,9 +180,9 @@ module Rails klass.start(args, config) else options = sorted_groups.flat_map(&:last) - suggestions = options.sort_by {|suggested| levenshtein_distance(namespace.to_s, suggested) }.first(3) + suggestions = options.sort_by { |suggested| levenshtein_distance(namespace.to_s, suggested) }.first(3) msg = "Could not find generator '#{namespace}'. " - msg << "Maybe you meant #{ suggestions.map {|s| "'#{s}'"}.to_sentence(last_word_connector: " or ", locale: :en) }\n" + msg << "Maybe you meant #{ suggestions.map { |s| "'#{s}'" }.to_sentence(last_word_connector: " or ", locale: :en) }\n" msg << "Run `rails generate --help` for more options." puts msg end diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index 5b4cde30c0..c0e34c20e7 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -168,7 +168,7 @@ module Rails names.each do |name| unless class_options.key?(name) defaults = if options[:type] == :boolean - { } + {} elsif [true, false].include?(default_value_for_option(name, options)) { banner: "" } else diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index 6b1e4125cb..c39ea24935 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -51,7 +51,7 @@ module Rails def indent(content, multiplier = 2) spaces = " " * multiplier - content.each_line.map {|line| line.blank? ? line : "#{spaces}#{line}" }.join + content.each_line.map { |line| line.blank? ? line : "#{spaces}#{line}" }.join end def wrap_with_namespace(content) @@ -162,7 +162,7 @@ module Rails end def route_url - @route_url ||= class_path.collect {|dname| "/" + dname }.join + "/" + plural_file_name + @route_url ||= class_path.collect { |dname| "/" + dname }.join + "/" + plural_file_name end def url_helper_prefix diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index a1b1649547..946645ee2d 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -479,7 +479,7 @@ module Rails end def railsrc(argv) - if (customrc = argv.index{ |x| x.include?("--rc=") }) + if (customrc = argv.index { |x| x.include?("--rc=") }) fname = File.expand_path(argv[customrc].gsub(/--rc=/, "")) yield(argv.take(customrc) + argv.drop(customrc + 1), fname) else diff --git a/railties/lib/rails/info_controller.rb b/railties/lib/rails/info_controller.rb index f5aa074703..8b553aea79 100644 --- a/railties/lib/rails/info_controller.rb +++ b/railties/lib/rails/info_controller.rb @@ -21,8 +21,8 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc: path = URI.parser.escape path normalized_path = with_leading_slash path render json: { - exact: match_route {|it| it.match normalized_path }, - fuzzy: match_route {|it| it.spec.to_s.match path } + exact: match_route { |it| it.match normalized_path }, + fuzzy: match_route { |it| it.spec.to_s.match path } } else @routes_inspector = ActionDispatch::Routing::RoutesInspector.new(_routes.routes) @@ -33,9 +33,9 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc: private def match_route - _routes.routes.select {|route| + _routes.routes.select { |route| yield route.path - }.map {|route| route.path.spec.to_s } + }.map { |route| route.path.spec.to_s } end def with_leading_slash(path) diff --git a/railties/lib/rails/mailers_controller.rb b/railties/lib/rails/mailers_controller.rb index 66073899c2..95de998208 100644 --- a/railties/lib/rails/mailers_controller.rb +++ b/railties/lib/rails/mailers_controller.rb @@ -47,8 +47,8 @@ class Rails::MailersController < Rails::ApplicationController # :nodoc: def find_preview candidates = [] - params[:path].to_s.scan(%r{/|$}){ candidates << $` } - preview = candidates.detect{ |candidate| ActionMailer::Preview.exists?(candidate) } + params[:path].to_s.scan(%r{/|$}) { candidates << $` } + preview = candidates.detect { |candidate| ActionMailer::Preview.exists?(candidate) } if preview @preview = ActionMailer::Preview.find(preview) @@ -64,7 +64,7 @@ class Rails::MailersController < Rails::ApplicationController # :nodoc: end end - if formats.any?{ |f| @email.mime_type == f } + if formats.any? { |f| @email.mime_type == f } @email end end diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake index 634b645d40..f5e5b9ae87 100644 --- a/railties/lib/rails/tasks/routes.rake +++ b/railties/lib/rails/tasks/routes.rake @@ -7,7 +7,7 @@ task routes: :environment do all_routes = Rails.application.routes.routes require "action_dispatch/routing/inspector" inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes) - if ARGV.any?{ |argv| argv.start_with? "CONTROLLER" } + if ARGV.any? { |argv| argv.start_with? "CONTROLLER" } puts <<-eow.strip_heredoc Passing `CONTROLLER` to `bin/rails routes` is deprecated and will be removed in Rails 5.1. Please use `bin/rails routes -c controller_name` instead. diff --git a/railties/test/application/asset_debugging_test.rb b/railties/test/application/asset_debugging_test.rb index ccecf2c09e..a732869d62 100644 --- a/railties/test/application/asset_debugging_test.rb +++ b/railties/test/application/asset_debugging_test.rb @@ -42,7 +42,7 @@ 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" - output = Dir.chdir(app_path){ `bin/rails assets:precompile --trace 2>&1` } + output = Dir.chdir(app_path) { `bin/rails assets:precompile --trace 2>&1` } assert $?.success?, output # Load app env diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 94d3bbd165..5dceaae96b 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1043,7 +1043,7 @@ module ApplicationTests app "development" - post "/posts", post: {"title" =>"zomg"} + post "/posts", post: { "title" =>"zomg" } assert_equal "permitted", last_response.body end @@ -1067,7 +1067,7 @@ module ApplicationTests assert_equal :raise, ActionController::Parameters.action_on_unpermitted_parameters - post "/posts", post: {"title" =>"zomg"} + post "/posts", post: { "title" =>"zomg" } assert_match "We're sorry, but something went wrong", last_response.body end @@ -1107,7 +1107,7 @@ module ApplicationTests assert_equal :raise, ActionController::Parameters.action_on_unpermitted_parameters - post "/posts", post: {"title" =>"zomg"}, format: "json" + post "/posts", post: { "title" =>"zomg" }, format: "json" assert_equal 200, last_response.status end diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index 0d7ccb2278..d4008fe677 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -29,7 +29,7 @@ module ApplicationTests end test "allow running plugin new generator inside Rails app directory" do - FileUtils.cd(rails_root){ `ruby bin/rails plugin new vendor/plugins/bukkits` } + FileUtils.cd(rails_root) { `ruby bin/rails plugin new vendor/plugins/bukkits` } assert File.exist?(File.join(rails_root, "vendor/plugins/bukkits/test/dummy/config/application.rb")) end @@ -165,7 +165,7 @@ module ApplicationTests config.api_only = true RUBY - FileUtils.cd(rails_root){ `bin/rails generate mailer notifier foo` } + FileUtils.cd(rails_root) { `bin/rails generate mailer notifier foo` } assert File.exist?(File.join(rails_root, "app/views/notifier_mailer/foo.text.erb")) assert File.exist?(File.join(rails_root, "app/views/notifier_mailer/foo.html.erb")) end diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb index d57384d256..38f96f3ab9 100644 --- a/railties/test/application/loading_test.rb +++ b/railties/test/application/loading_test.rb @@ -298,7 +298,7 @@ class LoadingTest < ActiveSupport::TestCase end MIGRATION - Dir.chdir(app_path) { `rake db:migrate`} + Dir.chdir(app_path) { `rake db:migrate` } require "#{rails_root}/config/environment" get "/title" diff --git a/railties/test/application/middleware/cache_test.rb b/railties/test/application/middleware/cache_test.rb index be44aa774f..cd1371359a 100644 --- a/railties/test/application/middleware/cache_test.rb +++ b/railties/test/application/middleware/cache_test.rb @@ -137,7 +137,7 @@ module ApplicationTests 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 @@ -171,7 +171,7 @@ module ApplicationTests 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_test.rb b/railties/test/application/middleware_test.rb index 3b48ada190..1cc931b29e 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -103,7 +103,7 @@ module ApplicationTests add_to_config "config.ssl_options = { host: 'example.com' }" boot! - assert_equal [{host: "example.com"}], Rails.application.middleware.first.args + assert_equal [{ host: "example.com" }], Rails.application.middleware.first.args end test "removing Active Record omits its middleware" do diff --git a/railties/test/application/rake/migrations_test.rb b/railties/test/application/rake/migrations_test.rb index d608fa1976..76cb302c62 100644 --- a/railties/test/application/rake/migrations_test.rb +++ b/railties/test/application/rake/migrations_test.rb @@ -57,7 +57,7 @@ module ApplicationTests end test "migration status when schema migrations table is not present" do - output = Dir.chdir(app_path){ `bin/rails db:migrate:status 2>&1` } + output = Dir.chdir(app_path) { `bin/rails db:migrate:status 2>&1` } assert_equal "Schema migrations table does not exist yet.\n", output end diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 5bb97a593d..5fd5507453 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -54,7 +54,7 @@ module ApplicationTests Rails.application.initialize! RUBY - assert_match("SuperMiddleware", Dir.chdir(app_path){ `bin/rails middleware` }) + assert_match("SuperMiddleware", Dir.chdir(app_path) { `bin/rails middleware` }) end def test_initializers_are_executed_in_rake_tasks @@ -69,7 +69,7 @@ module ApplicationTests end RUBY - output = Dir.chdir(app_path){ `bin/rails do_nothing` } + output = Dir.chdir(app_path) { `bin/rails do_nothing` } assert_match "Doing something...", output end @@ -128,7 +128,7 @@ module ApplicationTests end RUBY - output = Dir.chdir(app_path){ `bin/rails routes` } + output = Dir.chdir(app_path) { `bin/rails routes` } assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output end @@ -140,13 +140,13 @@ module ApplicationTests end RUBY - output = Dir.chdir(app_path){ `bin/rails routes CONTROLLER=cart` } + output = Dir.chdir(app_path) { `bin/rails routes CONTROLLER=cart` } assert_equal ["Passing `CONTROLLER` to `bin/rails routes` is deprecated and will be removed in Rails 5.1.", "Please use `bin/rails routes -c controller_name` instead.", "Prefix Verb URI Pattern Controller#Action", " cart GET /cart(.:format) cart#show\n"].join("\n"), output - output = Dir.chdir(app_path){ `bin/rails routes -c cart` } + output = Dir.chdir(app_path) { `bin/rails routes -c cart` } assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output end @@ -167,10 +167,10 @@ module ApplicationTests " PUT /admin/post(.:format) admin/posts#update", " DELETE /admin/post(.:format) admin/posts#destroy\n"].join("\n") - output = Dir.chdir(app_path){ `bin/rails routes -c Admin::PostController` } + output = Dir.chdir(app_path) { `bin/rails routes -c Admin::PostController` } assert_equal expected_output, output - output = Dir.chdir(app_path){ `bin/rails routes -c PostController` } + output = Dir.chdir(app_path) { `bin/rails routes -c PostController` } assert_equal expected_output, output end @@ -183,13 +183,13 @@ module ApplicationTests end RUBY - output = Dir.chdir(app_path){ `bin/rails routes -g show` } + output = Dir.chdir(app_path) { `bin/rails routes -g show` } assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output - output = Dir.chdir(app_path){ `bin/rails routes -g POST` } + output = Dir.chdir(app_path) { `bin/rails routes -g POST` } assert_equal "Prefix Verb URI Pattern Controller#Action\n POST /cart(.:format) cart#create\n", output - output = Dir.chdir(app_path){ `bin/rails routes -g basketballs` } + output = Dir.chdir(app_path) { `bin/rails routes -g basketballs` } assert_equal " Prefix Verb URI Pattern Controller#Action\n" \ "basketballs GET /basketballs(.:format) basketball#index\n", output end @@ -202,13 +202,13 @@ module ApplicationTests end RUBY - output = Dir.chdir(app_path){ `bin/rails routes -c cart` } + output = Dir.chdir(app_path) { `bin/rails routes -c cart` } assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output - output = Dir.chdir(app_path){ `bin/rails routes -c Cart` } + output = Dir.chdir(app_path) { `bin/rails routes -c Cart` } assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output - output = Dir.chdir(app_path){ `bin/rails routes -c CartController` } + output = Dir.chdir(app_path) { `bin/rails routes -c CartController` } assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output end @@ -218,7 +218,7 @@ module ApplicationTests end RUBY - assert_equal <<-MESSAGE.strip_heredoc, Dir.chdir(app_path){ `bin/rails routes` } + assert_equal <<-MESSAGE.strip_heredoc, Dir.chdir(app_path) { `bin/rails routes` } You don't have any routes defined! Please add some routes in config/routes.rb. @@ -234,7 +234,7 @@ module ApplicationTests end RUBY - output = Dir.chdir(app_path){ `bin/rake --rakefile Rakefile routes` } + output = Dir.chdir(app_path) { `bin/rake --rakefile Rakefile routes` } assert_equal "Prefix Verb URI Pattern Controller#Action\n cart GET /cart(.:format) cart#show\n", output end @@ -247,7 +247,7 @@ module ApplicationTests end RUBY - output = Dir.chdir(app_path){ `bin/rails log_something RAILS_ENV=production && cat log/production.log` } + output = Dir.chdir(app_path) { `bin/rails log_something RAILS_ENV=production && cat log/production.log` } assert_match "Sample log message", output end diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index c70af162ae..c86759de5a 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -263,7 +263,7 @@ module ApplicationTests assert_equal "WIN", last_response.body end - {"development" => "baz", "production" => "bar"}.each do |mode, expected| + { "development" => "baz", "production" => "bar" }.each do |mode, expected| test "reloads routes when configuration is changed in #{mode}" do controller :foo, <<-RUBY class FooController < ApplicationController diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb index 545460e933..286e7c16c1 100644 --- a/railties/test/commands/dbconsole_test.rb +++ b/railties/test/commands/dbconsole_test.rb @@ -9,7 +9,7 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase def teardown Rails::DBConsole.send(:remove_const, "APP_PATH") - %w[PGUSER PGHOST PGPORT PGPASSWORD DATABASE_URL].each{|key| ENV.delete(key)} + %w[PGUSER PGHOST PGPORT PGPASSWORD DATABASE_URL].each { |key| ENV.delete(key) } end def test_config_with_db_config_only @@ -123,7 +123,7 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase end def test_mysql_include_password - start({adapter: "mysql2", database: "db", username: "user", password: "qwerty"}, ["-p"]) + start({ adapter: "mysql2", database: "db", username: "user", password: "qwerty" }, ["-p"]) assert !aborted assert_equal [%w[mysql mysql5], "--user=user", "--password=qwerty", "db"], dbconsole.find_cmd_and_exec_args end @@ -145,7 +145,7 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase end def test_postgresql_include_password - start({adapter: "postgresql", database: "db", username: "user", password: "q1w2e3"}, ["-p"]) + start({ adapter: "postgresql", database: "db", username: "user", password: "q1w2e3" }, ["-p"]) assert !aborted assert_equal ["psql", "db"], dbconsole.find_cmd_and_exec_args assert_equal "user", ENV["PGUSER"] @@ -159,13 +159,13 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase end def test_sqlite3_mode - start({adapter: "sqlite3", database: "db.sqlite3"}, ["--mode", "html"]) + start({ adapter: "sqlite3", database: "db.sqlite3" }, ["--mode", "html"]) assert !aborted assert_equal ["sqlite3", "-html", Rails.root.join("db.sqlite3").to_s], dbconsole.find_cmd_and_exec_args end def test_sqlite3_header - start({adapter: "sqlite3", database: "db.sqlite3"}, ["--header"]) + start({ adapter: "sqlite3", database: "db.sqlite3" }, ["--header"]) assert_equal ["sqlite3", "-header", Rails.root.join("db.sqlite3").to_s], dbconsole.find_cmd_and_exec_args end @@ -190,7 +190,7 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase end def test_oracle_include_password - start({adapter: "oracle", database: "db", username: "user", password: "secret"}, ["-p"]) + start({ adapter: "oracle", database: "db", username: "user", password: "secret" }, ["-p"]) assert !aborted assert_equal ["sqlplus", "user/secret@db"], dbconsole.find_cmd_and_exec_args end diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 9d0d0dc59d..0a26897a4d 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -34,7 +34,7 @@ class ActionsTest < Rails::Generators::TestCase end def test_create_file_should_write_block_contents_to_file_path - action(:create_file, "lib/test_file.rb"){ "heres block data" } + action(:create_file, "lib/test_file.rb") { "heres block data" } assert_file "lib/test_file.rb", "heres block data" end @@ -78,7 +78,7 @@ class ActionsTest < Rails::Generators::TestCase def test_gem_should_insert_on_separate_lines run_generator - File.open("Gemfile", "a") {|f| f.write("# Some content...") } + File.open("Gemfile", "a") { |f| f.write("# Some content...") } action :gem, "rspec" action :gem, "rspec-rails" @@ -372,6 +372,6 @@ F protected def action(*args, &block) - capture(:stdout){ generator.send(*args, &block) } + capture(:stdout) { generator.send(*args, &block) } end end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 3b149d6cf9..77e484184c 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -77,7 +77,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_invalid_application_name_raises_an_error - content = capture(:stderr){ run_generator [File.join(destination_root, "43-things")] } + content = capture(:stderr) { run_generator [File.join(destination_root, "43-things")] } assert_equal "Invalid application name 43-things. Please give a name which does not start with numbers.\n", content end diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index dd19c5e166..9b986a636a 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -19,7 +19,7 @@ class ControllerGeneratorTest < Rails::Generators::TestCase def test_check_class_collision Object.send :const_set, :ObjectController, Class.new - content = capture(:stderr){ run_generator ["object"] } + content = capture(:stderr) { run_generator ["object"] } assert_match(/The name 'ObjectController' is either already used in your application or reserved/, content) ensure Object.send :remove_const, :ObjectController diff --git a/railties/test/generators/generator_generator_test.rb b/railties/test/generators/generator_generator_test.rb index d68cdc29b0..5ff8bb0357 100644 --- a/railties/test/generators/generator_generator_test.rb +++ b/railties/test/generators/generator_generator_test.rb @@ -12,7 +12,7 @@ class GeneratorGeneratorTest < Rails::Generators::TestCase lib/generators/awesome lib/generators/awesome/USAGE lib/generators/awesome/templates - ).each{ |path| assert_file path } + ).each { |path| assert_file path } assert_file "lib/generators/awesome/awesome_generator.rb", /class AwesomeGenerator < Rails::Generators::NamedBase/ @@ -28,7 +28,7 @@ class GeneratorGeneratorTest < Rails::Generators::TestCase lib/generators/rails/awesome lib/generators/rails/awesome/USAGE lib/generators/rails/awesome/templates - ).each{ |path| assert_file path } + ).each { |path| assert_file path } assert_file "lib/generators/rails/awesome/awesome_generator.rb", /class Rails::AwesomeGenerator < Rails::Generators::NamedBase/ @@ -44,7 +44,7 @@ class GeneratorGeneratorTest < Rails::Generators::TestCase lib/generators/ lib/generators/USAGE lib/generators/templates - ).each{ |path| assert_file path } + ).each { |path| assert_file path } assert_file "lib/generators/awesome_generator.rb", /class AwesomeGenerator < Rails::Generators::NamedBase/ @@ -60,7 +60,7 @@ class GeneratorGeneratorTest < Rails::Generators::TestCase lib/generators/rails lib/generators/rails/USAGE lib/generators/rails/templates - ).each{ |path| assert_file path } + ).each { |path| assert_file path } assert_file "lib/generators/rails/awesome_generator.rb", /class Rails::AwesomeGenerator < Rails::Generators::NamedBase/ diff --git a/railties/test/generators/helper_generator_test.rb b/railties/test/generators/helper_generator_test.rb index e64cb4cbe0..d9e6e0a85a 100644 --- a/railties/test/generators/helper_generator_test.rb +++ b/railties/test/generators/helper_generator_test.rb @@ -14,7 +14,7 @@ class HelperGeneratorTest < Rails::Generators::TestCase end def test_check_class_collision - content = capture(:stderr){ run_generator ["object"] } + content = capture(:stderr) { run_generator ["object"] } assert_match(/The name 'ObjectHelper' is either already used in your application or reserved/, content) end diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb index 1edaa1b37f..7d69d7470d 100644 --- a/railties/test/generators/mailer_generator_test.rb +++ b/railties/test/generators/mailer_generator_test.rb @@ -30,7 +30,7 @@ class MailerGeneratorTest < Rails::Generators::TestCase def test_check_class_collision Object.send :const_set, :NotifierMailer, Class.new - content = capture(:stderr){ run_generator } + content = capture(:stderr) { run_generator } assert_match(/The name 'NotifierMailer' is either already used in your application or reserved/, content) ensure Object.send :remove_const, :NotifierMailer @@ -59,7 +59,7 @@ class MailerGeneratorTest < Rails::Generators::TestCase def test_check_test_class_collision Object.send :const_set, :NotifierMailerTest, Class.new - content = capture(:stderr){ run_generator } + content = capture(:stderr) { run_generator } assert_match(/The name 'NotifierMailerTest' is either already used in your application or reserved/, content) ensure Object.send :remove_const, :NotifierMailerTest @@ -67,7 +67,7 @@ class MailerGeneratorTest < Rails::Generators::TestCase def test_check_preview_class_collision Object.send :const_set, :NotifierMailerPreview, Class.new - content = capture(:stderr){ run_generator } + content = capture(:stderr) { run_generator } assert_match(/The name 'NotifierMailerPreview' is either already used in your application or reserved/, content) ensure Object.send :remove_const, :NotifierMailerPreview diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index 6451aa75c9..701d3ceaf2 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -275,7 +275,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase 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 @@ -300,7 +300,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase assert_file "test/fixtures/accounts.yml", /name: MyString/, /age: 1/ assert_generated_fixture("test/fixtures/accounts.yml", - "one"=>{"name"=>"MyString", "age"=>1}, "two"=>{"name"=>"MyString", "age"=>1}) + "one"=>{ "name"=>"MyString", "age"=>1 }, "two"=>{ "name"=>"MyString", "age"=>1 }) end def test_fixtures_use_the_references_ids @@ -308,7 +308,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase assert_file "test/fixtures/line_items.yml", /product: one\n cart: one/ assert_generated_fixture("test/fixtures/line_items.yml", - "one"=>{"product"=>"one", "cart"=>"one"}, "two"=>{"product"=>"two", "cart"=>"two"}) + "one"=>{ "product"=>"one", "cart"=>"one" }, "two"=>{ "product"=>"two", "cart"=>"two" }) end def test_fixtures_use_the_references_ids_and_type @@ -316,15 +316,15 @@ class ModelGeneratorTest < Rails::Generators::TestCase assert_file "test/fixtures/line_items.yml", /product: one\n product_type: Product\n cart: one/ assert_generated_fixture("test/fixtures/line_items.yml", - "one"=>{"product"=>"one", "product_type"=>"Product", "cart"=>"one"}, - "two"=>{"product"=>"two", "product_type"=>"Product", "cart"=>"two"}) + "one"=>{ "product"=>"one", "product_type"=>"Product", "cart"=>"one" }, + "two"=>{ "product"=>"two", "product_type"=>"Product", "cart"=>"two" }) end def test_fixtures_respect_reserved_yml_keywords run_generator ["LineItem", "no:integer", "Off:boolean", "ON:boolean"] assert_generated_fixture("test/fixtures/line_items.yml", - "one"=>{"no"=>1, "Off"=>false, "ON"=>false}, "two"=>{"no"=>1, "Off"=>false, "ON"=>false}) + "one"=>{ "no"=>1, "Off"=>false, "ON"=>false }, "two"=>{ "no"=>1, "Off"=>false, "ON"=>false }) end def test_fixture_is_skipped @@ -343,13 +343,13 @@ class ModelGeneratorTest < Rails::Generators::TestCase ActiveRecord::Base.pluralize_table_names = false run_generator assert_generated_fixture("test/fixtures/account.yml", - "one"=>{"name"=>"MyString", "age"=>1}, "two"=>{"name"=>"MyString", "age"=>1}) + "one"=>{ "name"=>"MyString", "age"=>1 }, "two"=>{ "name"=>"MyString", "age"=>1 }) ensure ActiveRecord::Base.pluralize_table_names = original_pluralize_table_name end def test_check_class_collision - content = capture(:stderr){ run_generator ["object"] } + content = capture(:stderr) { run_generator ["object"] } assert_match(/The name 'Object' is either already used in your application or reserved/, content) end diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index f5b1532e5f..0d8e6f8907 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -27,19 +27,19 @@ class PluginGeneratorTest < Rails::Generators::TestCase include SharedGeneratorTests def test_invalid_plugin_name_raises_an_error - content = capture(:stderr){ run_generator [File.join(destination_root, "my_plugin-31fr-extension")] } + content = capture(:stderr) { run_generator [File.join(destination_root, "my_plugin-31fr-extension")] } assert_equal "Invalid plugin name my_plugin-31fr-extension. Please give a name which does not contain a namespace starting with numeric characters.\n", content - content = capture(:stderr){ run_generator [File.join(destination_root, "things4.3")] } + content = capture(:stderr) { run_generator [File.join(destination_root, "things4.3")] } assert_equal "Invalid plugin name things4.3. Please give a name which uses only alphabetic, numeric, \"_\" or \"-\" characters.\n", content - content = capture(:stderr){ run_generator [File.join(destination_root, "43things")] } + content = capture(:stderr) { run_generator [File.join(destination_root, "43things")] } assert_equal "Invalid plugin name 43things. Please give a name which does not start with numbers.\n", content - content = capture(:stderr){ run_generator [File.join(destination_root, "plugin")] } + content = capture(:stderr) { run_generator [File.join(destination_root, "plugin")] } assert_equal "Invalid plugin name plugin. Please give a name which does not match one of the reserved rails words: application, destroy, plugin, runner, test\n", content - content = capture(:stderr){ run_generator [File.join(destination_root, "Digest")] } + content = capture(:stderr) { run_generator [File.join(destination_root, "Digest")] } assert_equal "Invalid plugin name Digest, constant Digest is already in use. Please choose another plugin name.\n", content end @@ -710,7 +710,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase protected def action(*args, &block) - silence(:stdout){ generator.send(*args, &block) } + silence(:stdout) { generator.send(*args, &block) } end def default_files diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index 766162b625..27b2fc8955 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -28,11 +28,11 @@ module SharedGeneratorTests def test_plugin_new_generate_pretend run_generator ["testapp", "--pretend"] - default_files.each{ |path| assert_no_file File.join("testapp",path) } + default_files.each { |path| assert_no_file File.join("testapp",path) } end def test_invalid_database_option_raises_an_error - content = capture(:stderr){ run_generator([destination_root, "-d", "unknown"]) } + content = capture(:stderr) { run_generator([destination_root, "-d", "unknown"]) } assert_match(/Invalid value for \-\-database option/, content) end @@ -44,14 +44,14 @@ module SharedGeneratorTests def test_name_collision_raises_an_error reserved_words = %w[application destroy plugin runner test] reserved_words.each do |reserved| - content = capture(:stderr){ run_generator [File.join(destination_root, reserved)] } + content = capture(:stderr) { run_generator [File.join(destination_root, reserved)] } assert_match(/Invalid \w+ name #{reserved}. Please give a name which does not match one of the reserved rails words: application, destroy, plugin, runner, test\n/, content) end end def test_name_raises_an_error_if_name_already_used_constant %w{ String Hash Class Module Set Symbol }.each do |ruby_class| - content = capture(:stderr){ run_generator [File.join(destination_root, ruby_class)] } + content = capture(:stderr) { run_generator [File.join(destination_root, ruby_class)] } assert_match(/Invalid \w+ name #{ruby_class}, constant #{ruby_class} is already in use. Please choose another \w+ name.\n/, content) end end @@ -68,7 +68,7 @@ module SharedGeneratorTests def test_template_raises_an_error_with_invalid_path quietly do - content = capture(:stderr){ run_generator([destination_root, "-m", "non/existent/path"]) } + content = capture(:stderr) { run_generator([destination_root, "-m", "non/existent/path"]) } assert_match(/The template \[.*\] could not be loaded/, content) assert_match(/non\/existent\/path/, content) diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 83c1d6811c..3c22881080 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -23,32 +23,32 @@ class GeneratorsTest < Rails::Generators::TestCase def test_invoke_when_generator_is_not_found name = :unknown - output = capture(:stdout){ Rails::Generators.invoke name } + output = capture(:stdout) { Rails::Generators.invoke name } assert_match "Could not find generator '#{name}'", output assert_match "`rails generate --help`", output end def test_generator_suggestions name = :migrationz - output = capture(:stdout){ Rails::Generators.invoke name } + output = capture(:stdout) { Rails::Generators.invoke name } assert_match "Maybe you meant 'migration'", output end def test_generator_multiple_suggestions name = :tas - output = capture(:stdout){ Rails::Generators.invoke name } + output = capture(:stdout) { Rails::Generators.invoke name } assert_match "Maybe you meant 'task', 'job' or", output end def test_help_when_a_generator_with_required_arguments_is_invoked_without_arguments - output = capture(:stdout){ Rails::Generators.invoke :model, [] } + output = capture(:stdout) { Rails::Generators.invoke :model, [] } assert_match(/Description:/, output) end def test_should_give_higher_preference_to_rails_generators assert File.exist?(File.join(@path, "generators", "model_generator.rb")) assert_called_with(Rails::Generators::ModelGenerator, :start, [["Account"], {}]) do - warnings = capture(:stderr){ Rails::Generators.invoke :model, ["Account"] } + warnings = capture(:stderr) { Rails::Generators.invoke :model, ["Account"] } assert warnings.empty? end end @@ -115,7 +115,7 @@ class GeneratorsTest < Rails::Generators::TestCase end def test_rails_generators_help_with_builtin_information - output = capture(:stdout){ Rails::Generators.help } + output = capture(:stdout) { Rails::Generators.help } assert_match(/Rails:/, output) assert_match(/^ model$/, output) assert_match(/^ scaffold_controller$/, output) @@ -123,19 +123,19 @@ class GeneratorsTest < Rails::Generators::TestCase end def test_rails_generators_help_does_not_include_app_nor_plugin_new - output = capture(:stdout){ Rails::Generators.help } + output = capture(:stdout) { Rails::Generators.help } assert_no_match(/app/, output) assert_no_match(/[^:]plugin/, output) end def test_rails_generators_with_others_information - output = capture(:stdout){ Rails::Generators.help } + output = capture(:stdout) { Rails::Generators.help } assert_match(/Fixjour:/, output) assert_match(/^ fixjour$/, output) end def test_rails_generators_does_not_show_active_record_hooks - output = capture(:stdout){ Rails::Generators.help } + output = capture(:stdout) { Rails::Generators.help } assert_match(/ActiveRecord:/, output) assert_match(/^ active_record:fixjour$/, output) end @@ -214,7 +214,7 @@ class GeneratorsTest < Rails::Generators::TestCase # Create template mkdir_p(File.dirname(template)) - File.open(template, "w"){ |f| f.write "empty" } + File.open(template, "w") { |f| f.write "empty" } capture(:stdout) do Rails::Generators.invoke :model, ["user"], destination_root: destination_root diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index fb3818b92c..b9b11504dc 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -66,7 +66,7 @@ module TestHelpers def extract_body(response) "".tap do |body| - response[2].each {|chunk| body << chunk } + response[2].each { |chunk| body << chunk } end end @@ -214,7 +214,7 @@ module TestHelpers def write(file, string) path = "#{@path}/#{file}" FileUtils.mkdir_p(File.dirname(path)) - File.open(path, "w") {|f| f.puts string } + File.open(path, "w") { |f| f.puts string } end def delete(file) @@ -308,7 +308,7 @@ module TestHelpers remove_from_config "config.active_record.*" end - $:.reject! {|path| path =~ %r'/(#{to_remove.join('|')})/' } + $:.reject! { |path| path =~ %r'/(#{to_remove.join('|')})/' } end end end diff --git a/railties/test/path_generation_test.rb b/railties/test/path_generation_test.rb index 4d2dba0e2b..579e50ac95 100644 --- a/railties/test/path_generation_test.rb +++ b/railties/test/path_generation_test.rb @@ -38,7 +38,7 @@ class PathGenerationTest < ActiveSupport::TestCase host = uri_or_host.host unless path path ||= uri_or_host.path - params = {"PATH_INFO" => path, + params = { "PATH_INFO" => path, "REQUEST_METHOD" => method, "HTTP_HOST" => host } diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index 5e96f9f32f..a4f6922cb4 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -139,7 +139,7 @@ class PathsTest < ActiveSupport::TestCase @root["app"] = "/app" @root["app"].autoload_once! @root["app"].autoload_once! - assert_equal 1, @root.autoload_once.select {|p| p == @root["app"].expanded.first }.size + assert_equal 1, @root.autoload_once.select { |p| p == @root["app"].expanded.first }.size end end @@ -203,7 +203,7 @@ class PathsTest < ActiveSupport::TestCase @root["app"] = "/app" @root["app"].eager_load! @root["app"].eager_load! - assert_equal 1, @root.eager_load.select {|p| p == @root["app"].expanded.first }.size + assert_equal 1, @root.eager_load.select { |p| p == @root["app"].expanded.first }.size end end diff --git a/railties/test/rack_logger_test.rb b/railties/test/rack_logger_test.rb index e14eff41ce..7dd91a2465 100644 --- a/railties/test/rack_logger_test.rb +++ b/railties/test/rack_logger_test.rb @@ -47,7 +47,7 @@ module Rails end def test_notification - logger = TestLogger.new { } + logger = TestLogger.new {} assert_difference("subscriber.starts.length") do assert_difference("subscriber.finishes.length") do diff --git a/railties/test/rails_info_test.rb b/railties/test/rails_info_test.rb index 3c893fb3e0..fc4175719e 100644 --- a/railties/test/rails_info_test.rb +++ b/railties/test/rails_info_test.rb @@ -17,7 +17,7 @@ class InfoTest < ActiveSupport::TestCase def test_property_with_block_swallows_exceptions_and_ignores_property assert_nothing_raised do Rails::Info.module_eval do - property("Bogus") {raise} + property("Bogus") { raise } end end assert !property_defined?("Bogus") @@ -32,7 +32,7 @@ class InfoTest < ActiveSupport::TestCase def test_property_with_block Rails::Info.module_eval do - property("Goodbye") {"World"} + property("Goodbye") { "World" } end assert_property "Goodbye", "World" end diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 84867dcdec..0c8896a715 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -98,7 +98,7 @@ module RailtiesTest assert_no_match(/2_create_users/, output.join("\n")) - bukkits_migration_order = output.index(output.detect{|o| /NOTE: Migration 3_create_sessions.rb from bukkits has been skipped/ =~ o }) + bukkits_migration_order = output.index(output.detect { |o| /NOTE: Migration 3_create_sessions.rb from bukkits has been skipped/ =~ o }) assert_not_nil bukkits_migration_order, "Expected migration to be skipped" migrations_count = Dir["#{app_path}/db/migrate/*.rb"].length |