From 1b7263143a91f87faabde3a5d10c74308876f640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gomes=20J=C3=BAnior?= Date: Fri, 21 Oct 2016 10:32:49 -0200 Subject: don't create db directory when skip active_record --- railties/test/generators/app_generator_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 8f7fa1155f..830e49a1b5 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -356,6 +356,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_generator_if_skip_active_record_is_given run_generator [destination_root, "--skip-active-record"] + assert_no_directory "db/" assert_no_file "config/database.yml" assert_no_file "app/models/application_record.rb" assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/ -- cgit v1.2.3 From 797f1dd63c68eb44c1af358d377cfef271e685c5 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 21 Oct 2016 11:27:26 -0700 Subject: Prevent the test framework from being loaded in production mode The test framework should not be autoloaded in production mode. Before this commit, the testing railtie would extend AS::TestCase. This caused AS::TestCase to be preloaded regardless of the environment in which we were running. This commit just moves the code that adds line filtering support in to the test command where we actually execute the test runner. That allows us to maintain the line runner feature but only load the minimal amount of code we need. --- railties/test/application/runner_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb index 77e7a2cca5..8769703f66 100644 --- a/railties/test/application/runner_test.rb +++ b/railties/test/application/runner_test.rb @@ -43,6 +43,15 @@ module ApplicationTests assert_match "42", Dir.chdir(app_path) { `bin/rails runner "bin/count_users.rb"` } end + def test_no_minitest_loaded_in_production_mode + app_file "bin/print_features.rb", <<-SCRIPT + p $LOADED_FEATURES.grep(/minitest/) + SCRIPT + assert_match "[]", Dir.chdir(app_path) { + `RAILS_ENV=production bin/rails runner "bin/print_features.rb"` + } + end + def test_should_set_dollar_0_to_file app_file "bin/dollar0.rb", <<-SCRIPT puts $0 -- cgit v1.2.3 From 5b54a904101c48aac9467df1f060b83c67bee832 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Tue, 25 Oct 2016 07:58:05 +0900 Subject: remove assets config from `new_framework_defaults` if `--skip-sprockets` is true If `sprockets` is not loaded, `Rails.application.config.assets` is not defined. --- railties/test/generators/app_generator_test.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 830e49a1b5..9299b9ebea 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -412,6 +412,9 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_no_match(/config\.assets\.js_compressor = :uglifier/, content) assert_no_match(/config\.assets\.css_compressor = :sass/, content) end + assert_file "config/initializers/new_framework_defaults.rb" do |content| + assert_no_match(/unknown_asset_fallback/, content) + end end def test_generator_if_skip_action_cable_is_given -- cgit v1.2.3 From fe1f4b2ad56f010a4e9b93d547d63a15953d9dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 29 Oct 2016 01:05:58 -0200 Subject: Add more rubocop rules about whitespaces --- railties/test/app_loader_test.rb | 2 +- railties/test/application/assets_test.rb | 4 ++-- railties/test/application/configuration_test.rb | 6 +++--- .../test/application/initializers/frameworks_test.rb | 2 +- railties/test/application/initializers/hooks_test.rb | 4 ++-- railties/test/application/test_runner_test.rb | 12 ++++++------ railties/test/code_statistics_calculator_test.rb | 2 +- railties/test/commands/dbconsole_test.rb | 18 +++++++++--------- railties/test/generators/generator_test.rb | 2 +- railties/test/generators/model_generator_test.rb | 16 ++++++++-------- railties/test/generators/plugin_test_runner_test.rb | 2 +- railties/test/generators/shared_generator_tests.rb | 2 +- railties/test/isolation/abstract_unit.rb | 2 +- railties/test/path_generation_test.rb | 2 +- railties/test/railties/engine_test.rb | 4 ++-- railties/test/railties/generators_test.rb | 2 +- 16 files changed, 41 insertions(+), 41 deletions(-) (limited to 'railties/test') diff --git a/railties/test/app_loader_test.rb b/railties/test/app_loader_test.rb index 7fd5c72c1c..85f5502b4d 100644 --- a/railties/test/app_loader_test.rb +++ b/railties/test/app_loader_test.rb @@ -17,7 +17,7 @@ class AppLoaderTest < ActiveSupport::TestCase end end - def write(filename, contents=nil) + def write(filename, contents = nil) FileUtils.mkdir_p(File.dirname(filename)) File.write(filename, contents) end diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 741ae543e0..edd43503bf 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -475,9 +475,9 @@ module ApplicationTests class ::PostsController < ActionController::Base; end - get "/posts", {}, "HTTPS"=>"off" + get "/posts", {}, "HTTPS" => "off" assert_match('src="http://example.com/assets/application.self.js', last_response.body) - get "/posts", {}, "HTTPS"=>"on" + get "/posts", {}, "HTTPS" => "on" assert_match('src="https://example.com/assets/application.self.js', last_response.body) end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index b0f5b30174..be84cd5027 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/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index b2cd339c1a..32bce7d372 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -185,7 +185,7 @@ module ApplicationTests test "if there's no config.active_support.bare, all of ActiveSupport is required" do use_frameworks [] require "#{app_path}/config/environment" - assert_nothing_raised { [1,2,3].sample } + assert_nothing_raised { [1, 2, 3].sample } end test "config.active_support.bare does not require all of ActiveSupport" do diff --git a/railties/test/application/initializers/hooks_test.rb b/railties/test/application/initializers/hooks_test.rb index 0309d02730..36926c50ff 100644 --- a/railties/test/application/initializers/hooks_test.rb +++ b/railties/test/application/initializers/hooks_test.rb @@ -31,7 +31,7 @@ module ApplicationTests RUBY require "#{app_path}/config/environment" - assert_equal [1,2,3], $initialization_callbacks + assert_equal [1, 2, 3], $initialization_callbacks end test "hooks block works correctly with eager_load" do @@ -46,7 +46,7 @@ module ApplicationTests RUBY require "#{app_path}/config/environment" - assert_equal [1,2,3,4], $initialization_callbacks + assert_equal [1, 2, 3, 4], $initialization_callbacks end test "after_initialize runs after frameworks have been initialized" do diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index b442891769..0939587960 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -495,7 +495,7 @@ module ApplicationTests create_test_file :models, "post", pass: false # This specifically verifies TEST for backwards compatibility with rake test # as bin/rails test already supports running tests from a single file more cleanly. - output = Dir.chdir(app_path) { `bin/rake test TEST=test/models/post_test.rb` } + output = Dir.chdir(app_path) { `bin/rake test TEST=test/models/post_test.rb` } assert_match "PostTest", output, "passing TEST= should run selected test" assert_no_match "AccountTest", output, "passing TEST= should only run selected test" @@ -504,7 +504,7 @@ module ApplicationTests def test_pass_rake_options create_test_file :models, "account" - output = Dir.chdir(app_path) { `bin/rake --rakefile Rakefile --trace=stdout test` } + output = Dir.chdir(app_path) { `bin/rake --rakefile Rakefile --trace=stdout test` } assert_match "1 runs, 1 assertions", output assert_match "Execute test", output @@ -512,26 +512,26 @@ module ApplicationTests def test_rails_db_create_all_restores_db_connection create_test_file :models, "account" - output = Dir.chdir(app_path) { `bin/rails db:create:all db:migrate && echo ".tables" | rails dbconsole` } + output = Dir.chdir(app_path) { `bin/rails db:create:all db:migrate && echo ".tables" | rails dbconsole` } assert_match "ar_internal_metadata", output, "tables should be dumped" end def test_rails_db_create_all_restores_db_connection_after_drop create_test_file :models, "account" Dir.chdir(app_path) { `bin/rails db:create:all` } # create all to avoid warnings - output = Dir.chdir(app_path) { `bin/rails db:drop:all db:create:all db:migrate && echo ".tables" | rails dbconsole` } + output = Dir.chdir(app_path) { `bin/rails db:drop:all db:create:all db:migrate && echo ".tables" | rails dbconsole` } assert_match "ar_internal_metadata", output, "tables should be dumped" end def test_rake_passes_TESTOPTS_to_minitest create_test_file :models, "account" - output = Dir.chdir(app_path) { `bin/rake test TESTOPTS=-v` } + output = Dir.chdir(app_path) { `bin/rake test TESTOPTS=-v` } assert_match "AccountTest#test_truth", output, "passing TEST= should run selected test" end def test_rake_passes_multiple_TESTOPTS_to_minitest create_test_file :models, "account" - output = Dir.chdir(app_path) { `bin/rake test TESTOPTS='-v --seed=1234'` } + output = Dir.chdir(app_path) { `bin/rake test TESTOPTS='-v --seed=1234'` } assert_match "AccountTest#test_truth", output, "passing TEST= should run selected test" assert_match "seed=1234", output, "passing TEST= should run selected test" end diff --git a/railties/test/code_statistics_calculator_test.rb b/railties/test/code_statistics_calculator_test.rb index 2dba3c6e96..8a2f0294d0 100644 --- a/railties/test/code_statistics_calculator_test.rb +++ b/railties/test/code_statistics_calculator_test.rb @@ -52,7 +52,7 @@ class CodeStatisticsCalculatorTest < ActiveSupport::TestCase assert_equal 3, @code_statistics_calculator.classes assert_equal 4, @code_statistics_calculator.methods - code_statistics_calculator_2 = CodeStatisticsCalculator.new(2, 3, 4, 5) + code_statistics_calculator_2 = CodeStatisticsCalculator.new(2, 3, 4, 5) @code_statistics_calculator.add(code_statistics_calculator_2) assert_equal 3, @code_statistics_calculator.lines diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb index 2ddb269eae..0f8c5dbb79 100644 --- a/railties/test/commands/dbconsole_test.rb +++ b/railties/test/commands/dbconsole_test.rb @@ -15,15 +15,15 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase def test_config_with_db_config_only config_sample = { - "test"=> { - "adapter"=> "sqlite3", - "host"=> "localhost", - "port"=> "9000", - "database"=> "foo_test", - "user"=> "foo", - "password"=> "bar", - "pool"=> "5", - "timeout"=> "3000" + "test" => { + "adapter" => "sqlite3", + "host" => "localhost", + "port" => "9000", + "database" => "foo_test", + "user" => "foo", + "password" => "bar", + "pool" => "5", + "timeout" => "3000" } } app_db_config(config_sample) do diff --git a/railties/test/generators/generator_test.rb b/railties/test/generators/generator_test.rb index c4e4747468..904bade658 100644 --- a/railties/test/generators/generator_test.rb +++ b/railties/test/generators/generator_test.rb @@ -20,7 +20,7 @@ module Rails end def test_construction - klass = make_builder_class + klass = make_builder_class assert klass.start(["new", "blah"]) end diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index 701d3ceaf2..2b9f3ed7f2 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -212,10 +212,10 @@ class ModelGeneratorTest < Rails::Generators::TestCase def test_migration_without_timestamps ActiveRecord::Base.timestamped_migrations = false run_generator ["account"] - assert_file "db/migrate/001_create_accounts.rb", /class CreateAccounts < ActiveRecord::Migration\[[0-9.]+\]/ + assert_file "db/migrate/001_create_accounts.rb", /class CreateAccounts < ActiveRecord::Migration\[[0-9.]+\]/ run_generator ["project"] - assert_file "db/migrate/002_create_projects.rb", /class CreateProjects < ActiveRecord::Migration\[[0-9.]+\]/ + assert_file "db/migrate/002_create_projects.rb", /class CreateProjects < ActiveRecord::Migration\[[0-9.]+\]/ ensure ActiveRecord::Base.timestamped_migrations = true 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,7 +343,7 @@ 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 diff --git a/railties/test/generators/plugin_test_runner_test.rb b/railties/test/generators/plugin_test_runner_test.rb index 7a10a2afa9..0bdf3b2726 100644 --- a/railties/test/generators/plugin_test_runner_test.rb +++ b/railties/test/generators/plugin_test_runner_test.rb @@ -88,7 +88,7 @@ class PluginTestRunnerTest < ActiveSupport::TestCase def test_executed_only_once create_test_file "foo" - result = run_test_command("test/foo_test.rb") + result = run_test_command("test/foo_test.rb") assert_equal 1, result.scan(/1 runs, 1 assertions, 0 failures/).length end diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index 27b2fc8955..08b0e34fe2 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -28,7 +28,7 @@ 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 diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 6880cf306a..aa0a06faf1 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -104,7 +104,7 @@ module TestHelpers # Build an application by invoking the generator and going through the whole stack. def build_app(options = {}) @prev_rails_env = ENV["RAILS_ENV"] - ENV["RAILS_ENV"] = "development" + ENV["RAILS_ENV"] = "development" ENV["SECRET_KEY_BASE"] ||= SecureRandom.hex(16) FileUtils.rm_rf(app_path) diff --git a/railties/test/path_generation_test.rb b/railties/test/path_generation_test.rb index 579e50ac95..c0b03d0c15 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/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 397037a394..70a6cd90b2 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -133,7 +133,7 @@ module RailtiesTest boot_rails Dir.chdir(app_path) do - output = `bundle exec rake railties:install:migrations`.split("\n") + output = `bundle exec rake railties:install:migrations`.split("\n") assert_match(/Copied migration \d+_create_users.bukkits.rb from bukkits/, output.first) assert_match(/Copied migration \d+_create_blogs.blog_engine.rb from blog_engine/, output.last) @@ -169,7 +169,7 @@ module RailtiesTest boot_rails Dir.chdir(app_path) do - output = `bundle exec rake railties:install:migrations`.split("\n") + output = `bundle exec rake railties:install:migrations`.split("\n") assert_match(/Copied migration \d+_create_users.core_engine.rb from core_engine/, output.first) assert_match(/Copied migration \d+_create_keys.api_engine.rb from api_engine/, output.last) diff --git a/railties/test/railties/generators_test.rb b/railties/test/railties/generators_test.rb index 732898d0c0..5c691b9ec4 100644 --- a/railties/test/railties/generators_test.rb +++ b/railties/test/railties/generators_test.rb @@ -29,7 +29,7 @@ module RailtiesTests `#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/exe/rails #{cmd}` end - def build_engine(is_mountable=false) + def build_engine(is_mountable = false) FileUtils.rm_rf(engine_path) FileUtils.mkdir_p(engine_path) -- cgit v1.2.3 From de08be6af68373f6387854960ac967611d69ec9f Mon Sep 17 00:00:00 2001 From: Bouke van der Bijl Date: Tue, 1 Nov 2016 14:29:29 -0400 Subject: Don't put db:migrate and db:setup in binfiles if activerecord is excluded --- railties/test/generators/app_generator_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 9299b9ebea..6c6c5613ab 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -363,6 +363,12 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "test/test_helper.rb" do |helper_content| assert_no_match(/fixtures :all/, helper_content) end + assert_file "bin/setup" do |setup_content| + assert_no_match(/db:setup/, setup_content) + end + assert_file "bin/update" do |update_content| + assert_no_match(/db:migrate/, update_content) + end assert_file "config/initializers/new_framework_defaults.rb" do |initializer_content| assert_no_match(/belongs_to_required_by_default/, initializer_content) -- cgit v1.2.3 From d2e84fa919156d5faba750e023087f12ac4ff4bb Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Sat, 12 Nov 2016 15:10:59 -0500 Subject: Add test for #25248 --- railties/test/generators/app_generator_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 6c6c5613ab..3ec99193e3 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -488,6 +488,16 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_coffeescript_is_skipped_if_required + run_generator [destination_root, "--skip-coffee"] + + assert_file "Gemfile" do |content| + assert_no_match(/coffee-rails/, content) + assert_match(/jquery-rails/, content) + assert_match(/uglifier/, content) + end + end + def test_inclusion_of_jbuilder run_generator assert_gem "jbuilder" -- cgit v1.2.3 From 592c06d7cb158df07bf87246c23af24b72d13c97 Mon Sep 17 00:00:00 2001 From: Tsukuru Tanimichi Date: Mon, 14 Nov 2016 18:09:26 +0900 Subject: Add `:skip_sprockets` to `Rails::PluginBuilder::PASSTHROUGH_OPTIONS` `rails plugin new` with `--full` and `--skip-sprockets` options generates a dummy application that throws `NoMethodError`. ``` % rails plugin new my_engine -S --full --skip-gemspec % cd my_engine % bin/rails test rails aborted! NoMethodError: undefined method `assets' for # ``` --- railties/test/generators/plugin_generator_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index 15079f2735..0fdc30ac43 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -100,6 +100,14 @@ class PluginGeneratorTest < Rails::Generators::TestCase end end + def test_generating_adds_dummy_app_in_full_mode_without_sprockets + run_generator [destination_root, "-S", "--full"] + + assert_file "test/dummy/config/environments/production.rb" do |contents| + assert_no_match(/config\.assets/, contents) + end + end + def test_generating_adds_dummy_app_rake_tasks_without_unit_test_files run_generator [destination_root, "-T", "--mountable", "--dummy-path", "my_dummy_app"] assert_file "Rakefile", /APP_RAKEFILE/ -- cgit v1.2.3 From c79848e1e7c16d36a4af87c317422e17e04cde39 Mon Sep 17 00:00:00 2001 From: Erick Reyna Date: Thu, 17 Nov 2016 16:32:49 -0600 Subject: Fix incorrect output from rails routes when using singular resources issue #26606 Rails routes (even rake routes in previous versions) output showed incorrect routes when an application use resource :controller, implying that edit_controller_path match with controller#show. The order of the output has changed to correct this. View #26606 for more information. Added a test case, change unit test in rake to expect the new output. Since the output of resource :controller is changing, the string spected of the railties/test/application/rake_test.rb test_rails_routes_with_controller_environment had to be modified. --- .../test/application/rake/single_resource_test.rb | 33 ++++++++++++++++++++++ railties/test/application/rake_test.rb | 6 ++-- 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 railties/test/application/rake/single_resource_test.rb (limited to 'railties/test') diff --git a/railties/test/application/rake/single_resource_test.rb b/railties/test/application/rake/single_resource_test.rb new file mode 100644 index 0000000000..d23516d3b1 --- /dev/null +++ b/railties/test/application/rake/single_resource_test.rb @@ -0,0 +1,33 @@ +require "isolation/abstract_unit" +require "active_support/core_ext/string/strip" + +class RakeTest < ActiveSupport::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + end + + def teardown + teardown_app + end + + def test_singular_resource_output_in_rake_routes + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + resource :post + end + RUBY + expected_output = [" Prefix Verb URI Pattern Controller#Action", + " new_post GET /post/new(.:format) posts#new", + "edit_post GET /post/edit(.:format) posts#edit", + " post GET /post(.:format) posts#show", + " PATCH /post(.:format) posts#update", + " PUT /post(.:format) posts#update", + " DELETE /post(.:format) posts#destroy", + " POST /post(.:format) posts#create\n"].join("\n") + + output = Dir.chdir(app_path) { `bin/rails routes -c PostController` } + assert_equal expected_output, output + end +end diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 5fd5507453..1288d43231 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -159,13 +159,13 @@ module ApplicationTests end RUBY expected_output = [" Prefix Verb URI Pattern Controller#Action", - " admin_post POST /admin/post(.:format) admin/posts#create", " new_admin_post GET /admin/post/new(.:format) admin/posts#new", "edit_admin_post GET /admin/post/edit(.:format) admin/posts#edit", - " GET /admin/post(.:format) admin/posts#show", + " admin_post GET /admin/post(.:format) admin/posts#show", " PATCH /admin/post(.:format) admin/posts#update", " PUT /admin/post(.:format) admin/posts#update", - " DELETE /admin/post(.:format) admin/posts#destroy\n"].join("\n") + " DELETE /admin/post(.:format) admin/posts#destroy", + " POST /admin/post(.:format) admin/posts#create\n"].join("\n") output = Dir.chdir(app_path) { `bin/rails routes -c Admin::PostController` } assert_equal expected_output, output -- cgit v1.2.3 From b945c9ad62a0c14fffda8f08d6cf3fdc1141e3a9 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sat, 19 Nov 2016 16:24:28 +0530 Subject: Add missing test for singular resource output in rake routes - This test was present in https://github.com/rails/rails/pull/27089 but not present on master, may be removed in merge commit? - There was discussion about moving this to `application/rake_test` so may be this happened in merge commit. - https://github.com/rails/rails/pull/27089#discussion_r88731157 --- railties/test/application/rake_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 1288d43231..cd09270df1 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -174,6 +174,26 @@ module ApplicationTests assert_equal expected_output, output end + def test_singular_resource_output_in_rake_routes + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + resource :post + end + RUBY + + expected_output = [" Prefix Verb URI Pattern Controller#Action", + " new_post GET /post/new(.:format) posts#new", + "edit_post GET /post/edit(.:format) posts#edit", + " post GET /post(.:format) posts#show", + " PATCH /post(.:format) posts#update", + " PUT /post(.:format) posts#update", + " DELETE /post(.:format) posts#destroy", + " POST /post(.:format) posts#create\n"].join("\n") + + output = Dir.chdir(app_path) { `bin/rails routes -c PostController` } + assert_equal expected_output, output + end + def test_rails_routes_with_global_search_key app_file "config/routes.rb", <<-RUBY Rails.application.routes.draw do -- cgit v1.2.3 From 5aea0952e7cb445e614652e3cd9aba71a836eed0 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sun, 20 Nov 2016 16:02:39 +0100 Subject: Pass `rails runner` args onto file again. When making the new command insfrastructure I had missed that `bin/rails runner some_file.rb some args` would pass the extra args onto the file in `ARGV`. Now fixed by allowing the command to take extra args again, and make sure to remove the file name from `ARGV`. --- railties/test/application/runner_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb index 8769703f66..7d058f6ee6 100644 --- a/railties/test/application/runner_test.rb +++ b/railties/test/application/runner_test.rb @@ -68,6 +68,14 @@ module ApplicationTests assert_match "bin/program_name.rb", Dir.chdir(app_path) { `bin/rails runner "bin/program_name.rb"` } end + def test_passes_extra_args_to_file + app_file "bin/program_name.rb", <<-SCRIPT + p ARGV + SCRIPT + + assert_match %w( a b ).to_s, Dir.chdir(app_path) { `bin/rails runner "bin/program_name.rb" a b` } + end + def test_with_hook add_to_config <<-RUBY runner do |app| -- cgit v1.2.3 From 7102c6ce8984c82e0ea84b039f288f72c79dcf18 Mon Sep 17 00:00:00 2001 From: Isaac Sloan Date: Fri, 28 Oct 2016 21:53:29 -0600 Subject: deep symbolize keys on secrets.yml --- railties/test/application/configuration_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index be84cd5027..7e3bd26212 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -636,6 +636,20 @@ module ApplicationTests end end + test "that nested keys are symbolized the same as parents for hashes more than one level deep" do + app_file "config/secrets.yml", <<-YAML + development: + smtp_settings: + address: "smtp.example.com" + user_name: "postmaster@example.com" + password: "697361616320736c6f616e2028656c6f7265737429" + YAML + + app "development" + + assert_equal "697361616320736c6f616e2028656c6f7265737429", app.secrets.smtp_settings[:password] + end + test "protect from forgery is the default in a new app" do make_basic_app -- cgit v1.2.3 From a865e3b2620197641e6ae519647ad81098182dec Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sat, 19 Nov 2016 18:16:28 -0500 Subject: Don't add jQuery by default in new apps and use rails-ujs as UJS adapter instead --- railties/test/generators/api_app_generator_test.rb | 2 +- railties/test/generators/app_generator_test.rb | 20 ++++++++------------ railties/test/generators/plugin_generator_test.rb | 1 - 3 files changed, 9 insertions(+), 14 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb index bbb814ef4e..cefad48f52 100644 --- a/railties/test/generators/api_app_generator_test.rb +++ b/railties/test/generators/api_app_generator_test.rb @@ -35,7 +35,7 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile" do |content| assert_no_match(/gem 'coffee-rails'/, content) - assert_no_match(/gem 'jquery-rails'/, content) + assert_no_match(/gem 'rails-ujs'/, content) assert_no_match(/gem 'sass-rails'/, content) assert_no_match(/gem 'web-console'/, content) assert_match(/# gem 'jbuilder'/, content) diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 3ec99193e3..2d01da7f46 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -405,7 +405,6 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_match(/#\s+require\s+["']sprockets\/railtie["']/, content) end assert_file "Gemfile" do |content| - assert_no_match(/jquery-rails/, content) assert_no_match(/sass-rails/, content) assert_no_match(/uglifier/, content) assert_no_match(/coffee-rails/, content) @@ -448,22 +447,20 @@ class AppGeneratorTest < Rails::Generators::TestCase end end - def test_jquery_is_the_default_javascript_library + def test_rails_ujs_is_the_default_ujs_library run_generator assert_file "app/assets/javascripts/application.js" do |contents| - assert_match %r{^//= require jquery}, contents - assert_match %r{^//= require jquery_ujs}, contents + assert_match %r{^//= require rails-ujs}, contents end - assert_gem "jquery-rails" + assert_gem "rails-ujs" end - def test_other_javascript_libraries - run_generator [destination_root, "-j", "prototype"] + def test_inclusion_of_javascript_libraries_if_required + run_generator [destination_root, "-j", "jquery"] assert_file "app/assets/javascripts/application.js" do |contents| - assert_match %r{^//= require prototype}, contents - assert_match %r{^//= require prototype_ujs}, contents + assert_match %r{^//= require jquery}, contents end - assert_gem "prototype-rails" + assert_gem "jquery-rails" end def test_javascript_is_skipped_if_required @@ -479,8 +476,8 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile" do |content| assert_no_match(/coffee-rails/, content) - assert_no_match(/jquery-rails/, content) assert_no_match(/uglifier/, content) + assert_no_match(/rails-ujs/, content) end assert_file "config/environments/production.rb" do |content| @@ -493,7 +490,6 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile" do |content| assert_no_match(/coffee-rails/, content) - assert_match(/jquery-rails/, content) assert_match(/uglifier/, content) end end diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index 0fdc30ac43..a0018dc782 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -507,7 +507,6 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_no_match("gemspec", contents) assert_match(/gem 'rails'/, contents) assert_match_sqlite3(contents) - assert_no_match(/# gem "jquery-rails"/, contents) end end -- cgit v1.2.3 From da1453e6bad5551dd85f9692b921e1ff770d0319 Mon Sep 17 00:00:00 2001 From: Taishi Kasuga Date: Thu, 24 Nov 2016 14:17:13 +0900 Subject: Remove aggressive unit test with mock. And add integration level test. --- railties/test/application/configuration_test.rb | 19 +++++++++++++++++++ railties/test/isolation/abstract_unit.rb | 1 - 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 7e3bd26212..c409f1ea79 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1532,5 +1532,24 @@ module ApplicationTests assert_equal :default, Rails.configuration.debug_exception_response_format end + + test "controller force_ssl declaration can be used even if session_store is disabled" do + make_basic_app do |application| + application.config.session_store :disabled + end + + class ::OmgController < ActionController::Base + force_ssl + + def index + render plain: "Yay! You're on Rails!" + end + end + + get "/" + + assert_equal 301, last_response.status + assert_equal "https://example.org/", last_response.location + end end end diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index aa0a06faf1..1902eac862 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -162,7 +162,6 @@ module TestHelpers require "rails" require "action_controller/railtie" require "action_view/railtie" - require "action_dispatch/middleware/flash" @app = Class.new(Rails::Application) @app.config.eager_load = false -- cgit v1.2.3 From f0a55a7c6a7797a2a1f0359357c895ab5512e3f5 Mon Sep 17 00:00:00 2001 From: Fumiaki MATSUSHIMA Date: Thu, 24 Nov 2016 18:03:46 +0900 Subject: [ci skip] `MiniTest` -> `Minitest` MiniTest was renamed to Minitest. Already renamed on https://github.com/rails/rails/pull/13366 But slipped into on https://github.com/rails/rails/pull/18413/files#diff-6bb90a693835b0e92910b796c8b0ef59R27 --- railties/test/code_statistics_calculator_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/code_statistics_calculator_test.rb b/railties/test/code_statistics_calculator_test.rb index 8a2f0294d0..1bd4225f34 100644 --- a/railties/test/code_statistics_calculator_test.rb +++ b/railties/test/code_statistics_calculator_test.rb @@ -24,7 +24,7 @@ class CodeStatisticsCalculatorTest < ActiveSupport::TestCase end end - test "count number of methods in MiniTest file" do + test "count number of methods in Minitest file" do code = <<-RUBY class FooTest < ActionController::TestCase test 'expectation' do -- cgit v1.2.3 From 93b7816eefc2ac4cfe6cd10002598d84bf3df097 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 26 Nov 2016 10:55:11 +0900 Subject: use correct variable in BacktraceCleaner test `@target_dir` variable was changed to local variable in 8e1714b. --- railties/test/backtrace_cleaner_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb index 17201d6f77..f71e56f323 100644 --- a/railties/test/backtrace_cleaner_test.rb +++ b/railties/test/backtrace_cleaner_test.rb @@ -15,7 +15,7 @@ class BacktraceCleanerTest < ActiveSupport::TestCase test "should format installed gems not in Gem.default_dir correctly" do target_dir = Gem.path.detect { |p| p != Gem.default_dir } # skip this test if default_dir is the only directory on Gem.path - if @target_dir + if target_dir backtrace = [ "#{target_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ] result = @cleaner.clean(backtrace, :all) assert_equal "nosuchgem (1.2.3) lib/foo.rb", result[0] -- cgit v1.2.3 From 4c00c6ed230e6fdc6199dfba43f6da1e741a02aa Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Sun, 13 Nov 2016 22:18:14 -0500 Subject: Use YAML to serialize schema cache --- railties/test/application/rake_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index cd09270df1..d80a45a83f 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -387,14 +387,14 @@ module ApplicationTests bin/rails generate model product name:string; bin/rails db:migrate db:schema:cache:dump` end - assert File.exist?(File.join(app_path, "db", "schema_cache.dump")) + assert File.exist?(File.join(app_path, "db", "schema_cache.yml")) end def test_rake_clear_schema_cache Dir.chdir(app_path) do `bin/rails db:schema:cache:dump db:schema:cache:clear` end - assert !File.exist?(File.join(app_path, "db", "schema_cache.dump")) + assert !File.exist?(File.join(app_path, "db", "schema_cache.yml")) end def test_copy_templates -- cgit v1.2.3 From 89822e86d8da3771f5a72c2d33888af76aec9d6e Mon Sep 17 00:00:00 2001 From: Liceth Ovalles Date: Sun, 20 Nov 2016 16:35:37 -0500 Subject: Add package.json for Yarn if --yarn option is added --- railties/test/generators/app_generator_test.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 2d01da7f46..f673058de8 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -494,6 +494,11 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_generator_if_yarn_option_is_given + run_generator([destination_root, "--yarn"]) + assert_file "package.json", /dependencies/ + end + def test_inclusion_of_jbuilder run_generator assert_gem "jbuilder" @@ -614,6 +619,10 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_generates_with_bundler end + def test_generation_runs_yarn_install_with_yarn_option + assert_generates_with_yarn yarn: true + end + def test_dev_option assert_generates_with_bundler dev: true rails_path = File.expand_path("../../..", Rails.root) @@ -839,4 +848,18 @@ class AppGeneratorTest < Rails::Generators::TestCase quietly { generator.invoke_all } end end + + def assert_generates_with_yarn(options = {}) + generator([destination_root], options) + + command_check = -> command do + @install_called ||= 0 + @install_called += 1 + assert_equal 1, @install_called, "install expected to be called once, but was called #{@install_called} times" + end + + generator.stub :yarn_command, command_check do + quietly { generator.invoke_all } + end + end end -- cgit v1.2.3 From e6730c7ffbf51c985611d9281e3d080880eb3366 Mon Sep 17 00:00:00 2001 From: Liceth Ovalles Date: Sun, 20 Nov 2016 16:37:06 -0500 Subject: Add node_modules path to assets load paths when --yarn option is used --- railties/test/generators/app_generator_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index f673058de8..d7b682c5a9 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -497,6 +497,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_generator_if_yarn_option_is_given run_generator([destination_root, "--yarn"]) assert_file "package.json", /dependencies/ + assert_file "config/initializers/assets.rb", /node_modules/ end def test_inclusion_of_jbuilder -- cgit v1.2.3 From ffb81ad6e3326332556e8eab867fe1a27a989bf5 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Tue, 29 Nov 2016 09:48:19 -0500 Subject: rails-ujs is now shipped with Action View --- railties/test/generators/api_app_generator_test.rb | 1 - railties/test/generators/app_generator_test.rb | 2 -- 2 files changed, 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb index cefad48f52..7069a07bbe 100644 --- a/railties/test/generators/api_app_generator_test.rb +++ b/railties/test/generators/api_app_generator_test.rb @@ -35,7 +35,6 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile" do |content| assert_no_match(/gem 'coffee-rails'/, content) - assert_no_match(/gem 'rails-ujs'/, content) assert_no_match(/gem 'sass-rails'/, content) assert_no_match(/gem 'web-console'/, content) assert_match(/# gem 'jbuilder'/, content) diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 2d01da7f46..d2818eeaf1 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -452,7 +452,6 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "app/assets/javascripts/application.js" do |contents| assert_match %r{^//= require rails-ujs}, contents end - assert_gem "rails-ujs" end def test_inclusion_of_javascript_libraries_if_required @@ -477,7 +476,6 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile" do |content| assert_no_match(/coffee-rails/, content) assert_no_match(/uglifier/, content) - assert_no_match(/rails-ujs/, content) end assert_file "config/environments/production.rb" do |content| -- cgit v1.2.3 From 3dac36bd8e26363bb10f4d2a7b21efa75d200e26 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 1 Dec 2016 18:51:43 +0100 Subject: Yarn: Move node_modules, package.json, and yarn.lock file to vendor (#27245) Move node_modules, package.json, and yarn.lock file to vendor --- railties/test/generators/app_generator_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 0f73c43e0c..15a923676d 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -494,7 +494,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_generator_if_yarn_option_is_given run_generator([destination_root, "--yarn"]) - assert_file "package.json", /dependencies/ + assert_file "vendor/package.json", /dependencies/ assert_file "config/initializers/assets.rb", /node_modules/ end -- cgit v1.2.3 From 0d20530e5edfd7d00fbc2a38ef5f87eca6ccc924 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 8 Dec 2016 10:33:23 -0800 Subject: Make Yarn the default, drop default vendor/asset directories (#27300) --- railties/test/generators/api_app_generator_test.rb | 1 - railties/test/generators/app_generator_test.rb | 35 +++++++--------------- 2 files changed, 11 insertions(+), 25 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb index 7069a07bbe..dc2872e45e 100644 --- a/railties/test/generators/api_app_generator_test.rb +++ b/railties/test/generators/api_app_generator_test.rb @@ -108,7 +108,6 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase config/initializers/assets.rb config/initializers/cookies_serializer.rb lib/assets - vendor/assets test/helpers tmp/cache/assets public/404.html diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 15a923676d..d7c9ae5266 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -43,9 +43,6 @@ DEFAULT_APP_FILES = %w( test/mailers test/integration vendor - vendor/assets - vendor/assets/stylesheets - vendor/assets/javascripts tmp tmp/cache tmp/cache/assets @@ -466,7 +463,6 @@ class AppGeneratorTest < Rails::Generators::TestCase run_generator [destination_root, "--skip-javascript"] assert_no_file "app/assets/javascripts" - assert_no_file "vendor/assets/javascripts" assert_file "app/views/layouts/application.html.erb" do |contents| assert_match(/stylesheet_link_tag\s+'application', media: 'all' %>/, contents) @@ -492,12 +488,21 @@ class AppGeneratorTest < Rails::Generators::TestCase end end - def test_generator_if_yarn_option_is_given - run_generator([destination_root, "--yarn"]) + def test_generator_for_yarn + run_generator([destination_root]) assert_file "vendor/package.json", /dependencies/ assert_file "config/initializers/assets.rb", /node_modules/ end + def test_generator_for_yarn_skipped + run_generator([destination_root]) + assert_no_file "vendor/package.json" + + assert_file "config/environments/production.rb" do |content| + assert_no_match(/node_modules/, content) + end + end + def test_inclusion_of_jbuilder run_generator assert_gem "jbuilder" @@ -618,10 +623,6 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_generates_with_bundler end - def test_generation_runs_yarn_install_with_yarn_option - assert_generates_with_yarn yarn: true - end - def test_dev_option assert_generates_with_bundler dev: true rails_path = File.expand_path("../../..", Rails.root) @@ -847,18 +848,4 @@ class AppGeneratorTest < Rails::Generators::TestCase quietly { generator.invoke_all } end end - - def assert_generates_with_yarn(options = {}) - generator([destination_root], options) - - command_check = -> command do - @install_called ||= 0 - @install_called += 1 - assert_equal 1, @install_called, "install expected to be called once, but was called #{@install_called} times" - end - - generator.stub :yarn_command, command_check do - quietly { generator.invoke_all } - end - end end -- cgit v1.2.3 From fbd33b911acd5a4487f37dc1df2aad439c090bfa Mon Sep 17 00:00:00 2001 From: Yuji Yaginuma Date: Fri, 9 Dec 2016 12:07:40 +0900 Subject: specify `skip_yarn` option in API-only Application (#27309) --- railties/test/generators/api_app_generator_test.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb index dc2872e45e..c54d9cc599 100644 --- a/railties/test/generators/api_app_generator_test.rb +++ b/railties/test/generators/api_app_generator_test.rb @@ -105,6 +105,7 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase %w(app/assets app/helpers app/views/layouts/application.html.erb + bin/yarn config/initializers/assets.rb config/initializers/cookies_serializer.rb lib/assets @@ -115,6 +116,8 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase public/500.html public/apple-touch-icon-precomposed.png public/apple-touch-icon.png - public/favicon.ico) + public/favicon.icon + vendor/package.json + ) end end -- cgit v1.2.3 From 23f99ed7eb602c05952e53bc14afb9e692f7053d Mon Sep 17 00:00:00 2001 From: Yuji Yaginuma Date: Fri, 9 Dec 2016 12:08:13 +0900 Subject: fix broken tests (#27308) Follow up to 0d20530e5edfd7d00fbc2a38ef5f87eca6ccc924 --- railties/test/generators/app_generator_test.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index d7c9ae5266..9285a9f091 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -495,10 +495,10 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_generator_for_yarn_skipped - run_generator([destination_root]) + run_generator([destination_root, "--skip-yarn"]) assert_no_file "vendor/package.json" - assert_file "config/environments/production.rb" do |content| + assert_file "config/initializers/assets.rb" do |content| assert_no_match(/node_modules/, content) end end @@ -741,7 +741,6 @@ class AppGeneratorTest < Rails::Generators::TestCase test/helpers test/integration tmp - vendor/assets/stylesheets ) folders_with_keep.each do |folder| assert_file("#{folder}/.keep") -- cgit v1.2.3 From fa69b2c03582f5817572050a4373e365d9071b5d Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Fri, 16 Dec 2016 20:10:21 -0500 Subject: `ARGV.shift` before calling Rails generators Gems like rspec-rails depend on `ARGV` being shifted, and `scaffold` (for example) not being the first item in `ARGV`. This should allow rspec-rails to be passing on Rails master. --- railties/test/application/generators_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index 0153f94504..d75577c5f6 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -169,5 +169,20 @@ module ApplicationTests 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 + + test "ARGV is mutated as expected" do + require "#{app_path}/config/environment" + Rails::Command.const_set("APP_PATH", "rails/all") + + FileUtils.cd(rails_root) do + ARGV = ["mailer", "notifier", "foo"] + Rails::Command.const_set("ARGV", ARGV) + Rails::Command.invoke :generate, ARGV + + assert_equal ["notifier", "foo"], ARGV + end + + Rails::Command.send(:remove_const, "APP_PATH") + end end end -- cgit v1.2.3 From c79c40ed82186fc5000cf5beea697b286422bcdb Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Mon, 19 Dec 2016 21:24:12 -0500 Subject: Limit length of secret being passed Very similar to PR #25758, see more in depth reasoning there. --- railties/test/application/middleware/session_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/middleware/session_test.rb b/railties/test/application/middleware/session_test.rb index 0e4acfdcec..959a629ede 100644 --- a/railties/test/application/middleware/session_test.rb +++ b/railties/test/application/middleware/session_test.rb @@ -173,7 +173,7 @@ module ApplicationTests secret = app.key_generator.generate_key("encrypted cookie") sign_secret = app.key_generator.generate_key("signed encrypted cookie") - encryptor = ActiveSupport::MessageEncryptor.new(secret, sign_secret) + encryptor = ActiveSupport::MessageEncryptor.new(secret[0, ActiveSupport::MessageEncryptor.key_len], sign_secret) get "/foo/read_raw_cookie" assert_equal 1, encryptor.decrypt_and_verify(last_response.body)["foo"] @@ -222,7 +222,7 @@ module ApplicationTests secret = app.key_generator.generate_key("encrypted cookie") sign_secret = app.key_generator.generate_key("signed encrypted cookie") - encryptor = ActiveSupport::MessageEncryptor.new(secret, sign_secret) + encryptor = ActiveSupport::MessageEncryptor.new(secret[0, ActiveSupport::MessageEncryptor.key_len], sign_secret) get "/foo/read_raw_cookie" assert_equal 1, encryptor.decrypt_and_verify(last_response.body)["foo"] @@ -281,7 +281,7 @@ module ApplicationTests secret = app.key_generator.generate_key("encrypted cookie") sign_secret = app.key_generator.generate_key("signed encrypted cookie") - encryptor = ActiveSupport::MessageEncryptor.new(secret, sign_secret) + encryptor = ActiveSupport::MessageEncryptor.new(secret[0, ActiveSupport::MessageEncryptor.key_len], sign_secret) get "/foo/read_raw_cookie" assert_equal 2, encryptor.decrypt_and_verify(last_response.body)["foo"] -- cgit v1.2.3 From baa8c5ad0fb3f860388eeec4421ccb8afa0096a8 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Thu, 22 Dec 2016 11:01:15 +0900 Subject: quiet generators log in test This quiet the following log. ``` create app/mailers/notifier_mailer.rb invoke erb create app/views/notifier_mailer identical app/views/layouts/mailer.text.erb identical app/views/layouts/mailer.html.erb create app/views/notifier_mailer/foo.text.erb create app/views/notifier_mailer/foo.html.erb invoke test_unit create test/mailers/notifier_mailer_test.rb create test/mailers/previews/notifier_mailer_preview.rb ``` --- railties/test/application/generators_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index d75577c5f6..d2ce14f594 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -177,7 +177,7 @@ module ApplicationTests FileUtils.cd(rails_root) do ARGV = ["mailer", "notifier", "foo"] Rails::Command.const_set("ARGV", ARGV) - Rails::Command.invoke :generate, ARGV + quietly { Rails::Command.invoke :generate, ARGV } assert_equal ["notifier", "foo"], ARGV end -- cgit v1.2.3 From 10fb7211bb4e7df5b796da489df8b056b95178d4 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 23 Dec 2016 23:45:39 +0900 Subject: Privatize unneededly protected methods in Railties tests --- railties/test/application/loading_test.rb | 2 +- railties/test/generators/actions_test.rb | 2 +- railties/test/generators/app_generator_test.rb | 2 +- railties/test/generators/named_base_test.rb | 2 +- railties/test/generators/plugin_generator_test.rb | 2 +- railties/test/rails_info_test.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb index 38f96f3ab9..c75a25bc6f 100644 --- a/railties/test/application/loading_test.rb +++ b/railties/test/application/loading_test.rb @@ -357,7 +357,7 @@ class LoadingTest < ActiveSupport::TestCase assert Rails.application.initialized? end - protected + private def setup_ar! ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 0a26897a4d..360e8e97d7 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -369,7 +369,7 @@ F assert_equal("", action(:log, :yes, "YES")) end - protected + private def action(*args, &block) capture(:stdout) { generator.send(*args, &block) } diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 9285a9f091..079ee3765c 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -788,7 +788,7 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_equal 3, @sequence_step end - protected + private def stub_rails_application(root) Rails.application.config.root = root diff --git a/railties/test/generators/named_base_test.rb b/railties/test/generators/named_base_test.rb index 0258b3b9d7..3015b5363b 100644 --- a/railties/test/generators/named_base_test.rb +++ b/railties/test/generators/named_base_test.rb @@ -131,7 +131,7 @@ class NamedBaseTest < Rails::Generators::TestCase assert_name g, "admin.foos", :controller_i18n_scope end - protected + private def assert_name(generator, value, method) assert_equal value, generator.send(method) diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index a0018dc782..9921a80342 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -714,7 +714,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase end end - protected + private def action(*args, &block) silence(:stdout) { generator.send(*args, &block) } diff --git a/railties/test/rails_info_test.rb b/railties/test/rails_info_test.rb index 59e79de41a..9f4c5bb025 100644 --- a/railties/test/rails_info_test.rb +++ b/railties/test/rails_info_test.rb @@ -54,7 +54,7 @@ class InfoTest < ActiveSupport::TestCase end end - protected + private def properties Rails::Info.properties end -- cgit v1.2.3 From e8ba0c0f21e2660b90f872fa4595156ca6190c77 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sun, 25 Dec 2016 02:29:52 +0900 Subject: "Use assert_nil if expecting nil. This will fail in minitest 6." --- railties/test/application/assets_test.rb | 2 +- railties/test/application/configuration/custom_test.rb | 2 +- railties/test/application/configuration_test.rb | 6 +++--- railties/test/application/middleware_test.rb | 4 ++-- railties/test/commands/server_test.rb | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index edd43503bf..f38cacd6da 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -384,7 +384,7 @@ module ApplicationTests get "/assets/demo.js" assert_match "alert()", last_response.body - assert_equal nil, last_response.headers["Set-Cookie"] + assert_nil last_response.headers["Set-Cookie"] end test "files in any assets/ directories are not added to Sprockets" do diff --git a/railties/test/application/configuration/custom_test.rb b/railties/test/application/configuration/custom_test.rb index 13fc98f0d6..3c675eec71 100644 --- a/railties/test/application/configuration/custom_test.rb +++ b/railties/test/application/configuration/custom_test.rb @@ -28,7 +28,7 @@ module ApplicationTests assert_equal 3, x.payment_processing.retries assert_equal true, x.super_debugger assert_equal false, x.hyper_debugger - assert_equal nil, x.nil_debugger + assert_nil x.nil_debugger assert_nil x.i_do_not_exist.zomg end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index c409f1ea79..31c3b5cf52 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -614,7 +614,7 @@ module ApplicationTests app "development" assert_equal "b3c631c314c0bbca50c1b2843150fe33", app.config.secret_token - assert_equal nil, app.secrets.secret_key_base + assert_nil app.secrets.secret_key_base assert_equal app.key_generator.class, ActiveSupport::LegacyKeyGenerator end @@ -630,7 +630,7 @@ module ApplicationTests app "development" assert_equal "", app.config.secret_token - assert_equal nil, app.secrets.secret_key_base + assert_nil app.secrets.secret_key_base assert_raise ArgumentError, /\AA secret is required/ do app.key_generator end @@ -1204,7 +1204,7 @@ module ApplicationTests application.config.session_store :disabled end - assert_equal nil, app.config.session_store + assert_nil app.config.session_store end test "default session store initializer sets session store to cookie store" do diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 9baf7360a5..be41dcb299 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -246,7 +246,7 @@ module ApplicationTests get "/", {}, "HTTP_IF_NONE_MATCH" => etag assert_equal 304, last_response.status assert_equal "", last_response.body - assert_equal nil, last_response.headers["Content-Type"] + assert_nil last_response.headers["Content-Type"] assert_equal "max-age=0, private, must-revalidate", last_response.headers["Cache-Control"] assert_equal etag, last_response.headers["Etag"] @@ -255,7 +255,7 @@ module ApplicationTests assert_equal "", last_response.body assert_equal "text/plain; charset=utf-8", last_response.headers["Content-Type"] assert_equal "no-cache", last_response.headers["Cache-Control"] - assert_equal nil, last_response.headers["Etag"] + assert_nil last_response.headers["Etag"] end test "ORIGINAL_FULLPATH is passed to env" do diff --git a/railties/test/commands/server_test.rb b/railties/test/commands/server_test.rb index 391886bf33..2e8076ed2b 100644 --- a/railties/test/commands/server_test.rb +++ b/railties/test/commands/server_test.rb @@ -63,7 +63,7 @@ class Rails::ServerTest < ActiveSupport::TestCase args = [] options = Rails::Server::Options.new.parse!(args) merged_options = Rails::Server.new.default_options.merge(options) - assert_equal nil, merged_options[:caching] + assert_nil merged_options[:caching] end def test_caching_with_option -- cgit v1.2.3 From f27edc84dfe714869a1702206c5c6e57a0810cfc Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Sun, 25 Dec 2016 16:44:39 +1030 Subject: Correct indent-accounting in controller route generation Fixes #27447 [Matthew Draper & Yuuji Yaginuma] --- railties/test/generators/controller_generator_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index 9b986a636a..af86a0136f 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -65,7 +65,7 @@ class ControllerGeneratorTest < Rails::Generators::TestCase def test_add_routes run_generator - assert_file "config/routes.rb", /get 'account\/foo'/, /get 'account\/bar'/ + assert_file "config/routes.rb", /^ get 'account\/foo'/, /^ get 'account\/bar'/ end def test_skip_routes -- cgit v1.2.3 From a46b2f8911c5730c8c56d487b65f7c5627d334ee Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 26 Dec 2016 11:04:41 +0900 Subject: assert_equal takes expectation first --- railties/test/railties/engine_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 70a6cd90b2..52d691b73b 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -890,7 +890,7 @@ YAML boot_rails - assert_equal AppTemplate.railtie_namespace, AppTemplate::Engine + assert_equal AppTemplate::Engine, AppTemplate.railtie_namespace end test "properly reload routes" do -- cgit v1.2.3