diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2017-07-15 21:17:27 +0200 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2017-07-15 21:17:27 +0200 |
commit | aad42dce10a9cc110d67fa03a72ce5b41cbb394a (patch) | |
tree | 7c22623e9f34f2ff7bfa142385010b6a4e5aea85 /railties/test | |
parent | 92fb8621a623afb33a145b1f3736010a3c870086 (diff) | |
parent | b6300f3ecc79bff29cf9bb804a30fd92403feac1 (diff) | |
download | rails-aad42dce10a9cc110d67fa03a72ce5b41cbb394a.tar.gz rails-aad42dce10a9cc110d67fa03a72ce5b41cbb394a.tar.bz2 rails-aad42dce10a9cc110d67fa03a72ce5b41cbb394a.zip |
Merge branch 'master' into unlock-minitest
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/application/configuration_test.rb | 51 | ||||
-rw-r--r-- | railties/test/application/dbconsole_test.rb | 66 | ||||
-rw-r--r-- | railties/test/application/initializers/i18n_test.rb | 2 | ||||
-rw-r--r-- | railties/test/application/rake/tmp_test.rb | 43 | ||||
-rw-r--r-- | railties/test/application/rake_test.rb | 7 | ||||
-rw-r--r-- | railties/test/command/base_test.rb | 2 | ||||
-rw-r--r-- | railties/test/commands/secrets_test.rb | 13 | ||||
-rw-r--r-- | railties/test/generators/actions_test.rb | 7 | ||||
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 46 | ||||
-rw-r--r-- | railties/test/generators/plugin_generator_test.rb | 8 | ||||
-rw-r--r-- | railties/test/generators/scaffold_generator_test.rb | 34 | ||||
-rw-r--r-- | railties/test/generators_test.rb | 2 | ||||
-rw-r--r-- | railties/test/railties/engine_test.rb | 86 | ||||
-rw-r--r-- | railties/test/secrets_test.rb | 52 |
14 files changed, 397 insertions, 22 deletions
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 06767167a9..983ea5c3e6 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -176,13 +176,11 @@ module ApplicationTests test "Rails.application responds to all instance methods" do app "development" - assert_respond_to Rails.application, :routes_reloader assert_equal Rails.application.routes_reloader, AppTemplate::Application.routes_reloader end test "Rails::Application responds to paths" do app "development" - assert_respond_to AppTemplate::Application, :paths assert_equal ["#{app_path}/app/views"], AppTemplate::Application.paths["app/views"].expanded end @@ -1132,6 +1130,8 @@ module ApplicationTests app "development" + ActionController::Base.object_id # force lazy load hooks to run + assert_equal :raise, ActionController::Parameters.action_on_unpermitted_parameters post "/posts", post: { "title" => "zomg" } @@ -1140,6 +1140,9 @@ module ApplicationTests test "config.action_controller.always_permitted_parameters are: controller, action by default" do app "development" + + ActionController::Base.object_id # force lazy load hooks to run + assert_equal %w(controller action), ActionController::Parameters.always_permitted_parameters end @@ -1150,6 +1153,8 @@ module ApplicationTests app "development" + ActionController::Base.object_id # force lazy load hooks to run + assert_equal %w( controller action format ), ActionController::Parameters.always_permitted_parameters end @@ -1172,6 +1177,8 @@ module ApplicationTests app "development" + ActionController::Base.object_id # force lazy load hooks to run + assert_equal :raise, ActionController::Parameters.action_on_unpermitted_parameters post "/posts", post: { "title" => "zomg" }, format: "json" @@ -1181,21 +1188,60 @@ module ApplicationTests test "config.action_controller.action_on_unpermitted_parameters is :log by default on development" do app "development" + ActionController::Base.object_id # force lazy load hooks to run + assert_equal :log, ActionController::Parameters.action_on_unpermitted_parameters end test "config.action_controller.action_on_unpermitted_parameters is :log by default on test" do app "test" + ActionController::Base.object_id # force lazy load hooks to run + assert_equal :log, ActionController::Parameters.action_on_unpermitted_parameters end test "config.action_controller.action_on_unpermitted_parameters is false by default on production" do app "production" + ActionController::Base.object_id # force lazy load hooks to run + assert_equal false, ActionController::Parameters.action_on_unpermitted_parameters end + test "config.action_controller.permit_all_parameters can be configured in an initializer" do + app_file "config/initializers/permit_all_parameters.rb", <<-RUBY + Rails.application.config.action_controller.permit_all_parameters = true + RUBY + + app "development" + + ActionController::Base.object_id # force lazy load hooks to run + assert_equal true, ActionController::Parameters.permit_all_parameters + end + + test "config.action_controller.always_permitted_parameters can be configured in an initializer" do + app_file "config/initializers/always_permitted_parameters.rb", <<-RUBY + Rails.application.config.action_controller.always_permitted_parameters = [] + RUBY + + app "development" + + ActionController::Base.object_id # force lazy load hooks to run + assert_equal [], ActionController::Parameters.always_permitted_parameters + end + + test "config.action_controller.action_on_unpermitted_parameters can be configured in an initializer" do + app_file "config/initializers/action_on_unpermitted_parameters.rb", <<-RUBY + Rails.application.config.action_controller.action_on_unpermitted_parameters = :raise + RUBY + + app "development" + + ActionController::Base.object_id # force lazy load hooks to run + assert_equal :raise, ActionController::Parameters.action_on_unpermitted_parameters + end + test "config.action_dispatch.ignore_accept_header" do make_basic_app do |application| application.config.action_dispatch.ignore_accept_header = true @@ -1220,7 +1266,6 @@ module ApplicationTests test "Rails.application#env_config exists and include some existing parameters" do make_basic_app - assert_respond_to app, :env_config assert_equal app.env_config["action_dispatch.parameter_filter"], app.config.filter_parameters assert_equal app.env_config["action_dispatch.show_exceptions"], app.config.action_dispatch.show_exceptions assert_equal app.env_config["action_dispatch.logger"], Rails.logger diff --git a/railties/test/application/dbconsole_test.rb b/railties/test/application/dbconsole_test.rb new file mode 100644 index 0000000000..7e5e9ea8aa --- /dev/null +++ b/railties/test/application/dbconsole_test.rb @@ -0,0 +1,66 @@ +require "isolation/abstract_unit" +begin + require "pty" +rescue LoadError +end + +module ApplicationTests + class DBConsoleTest < ActiveSupport::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + end + + def teardown + teardown_app + end + + def test_use_value_defined_in_environment_file_in_database_yml + skip "PTY unavailable" unless available_pty? + Dir.chdir(app_path) do + app_file "config/database.yml", <<-YAML + development: + database: <%= Rails.application.config.database %> + adapter: sqlite3 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 + YAML + + app_file "config/environments/development.rb", <<-RUBY + Rails.application.configure do + config.database = "db/development.sqlite3" + end + RUBY + end + + master, slave = PTY.open + spawn_dbconsole(slave) + assert_output("sqlite>", master) + ensure + master.puts ".exit" + end + + private + def spawn_dbconsole(fd) + Process.spawn("#{app_path}/bin/rails dbconsole", in: fd, out: fd, err: fd) + end + + def assert_output(expected, io, timeout = 5) + timeout = Time.now + timeout + + output = "" + until output.include?(expected) || Time.now > timeout + if IO.select([io], [], [], 0.1) + output << io.read(1) + end + end + + assert_includes output, expected, "#{expected.inspect} expected, but got:\n\n#{output}" + end + + def available_pty? + defined?(PTY) && PTY.respond_to?(:open) + end + end +end diff --git a/railties/test/application/initializers/i18n_test.rb b/railties/test/application/initializers/i18n_test.rb index 206e42703b..cee198bd01 100644 --- a/railties/test/application/initializers/i18n_test.rb +++ b/railties/test/application/initializers/i18n_test.rb @@ -245,7 +245,7 @@ fr: end test "[shortcut] config.i18n.fallbacks = [{ :ca => :'es-ES' }] initializes fallbacks with a mapping ca => es-ES" do - I18n::Railtie.config.i18n.fallbacks.map = { ca: :'es-ES' } + I18n::Railtie.config.i18n.fallbacks = [{ ca: :'es-ES' }] load_app assert_fallbacks ca: [:ca, :"es-ES", :es, :en] end diff --git a/railties/test/application/rake/tmp_test.rb b/railties/test/application/rake/tmp_test.rb new file mode 100644 index 0000000000..8423a98f84 --- /dev/null +++ b/railties/test/application/rake/tmp_test.rb @@ -0,0 +1,43 @@ +require "isolation/abstract_unit" + +module ApplicationTests + module RakeTests + class TmpTest < ActiveSupport::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + end + + def teardown + teardown_app + end + + test "tmp:clear clear cache, socket and screenshot files" do + Dir.chdir(app_path) do + FileUtils.mkdir_p("tmp/cache") + FileUtils.touch("tmp/cache/cache_file") + + FileUtils.mkdir_p("tmp/sockets") + FileUtils.touch("tmp/sockets/socket_file") + + FileUtils.mkdir_p("tmp/screenshots") + FileUtils.touch("tmp/screenshots/fail.png") + + `rails tmp:clear` + + assert_not File.exist?("tmp/cache/cache_file") + assert_not File.exist?("tmp/sockets/socket_file") + assert_not File.exist?("tmp/screenshots/fail.png") + end + end + + test "tmp:clear should work if folder missing" do + FileUtils.remove_dir("#{app_path}/tmp") + errormsg = Dir.chdir(app_path) { `bin/rails tmp:clear` } + assert_predicate $?, :success? + assert_empty errormsg + end + end + end +end diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 1b64a0a1ca..5ae6ea925f 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -391,12 +391,5 @@ module ApplicationTests assert_match(/Hello, World!/, output) end - - def test_tmp_clear_should_work_if_folder_missing - FileUtils.remove_dir("#{app_path}/tmp") - errormsg = Dir.chdir(app_path) { `bin/rails tmp:clear` } - assert_predicate $?, :success? - assert_empty errormsg - end end end diff --git a/railties/test/command/base_test.rb b/railties/test/command/base_test.rb index ebfc4d0ba9..bac3285f48 100644 --- a/railties/test/command/base_test.rb +++ b/railties/test/command/base_test.rb @@ -6,6 +6,6 @@ require "rails/commands/secrets/secrets_command" class Rails::Command::BaseTest < ActiveSupport::TestCase test "printing commands" do assert_equal %w(generate), Rails::Command::GenerateCommand.printing_commands - assert_equal %w(secrets:setup secrets:edit), Rails::Command::SecretsCommand.printing_commands + assert_equal %w(secrets:setup secrets:edit secrets:show), Rails::Command::SecretsCommand.printing_commands end end diff --git a/railties/test/commands/secrets_test.rb b/railties/test/commands/secrets_test.rb index be610f3b47..3771919849 100644 --- a/railties/test/commands/secrets_test.rb +++ b/railties/test/commands/secrets_test.rb @@ -27,8 +27,21 @@ class Rails::Command::SecretsCommandTest < ActiveSupport::TestCase end end + test "show secrets" do + run_setup_command + assert_match(/external_api_key: 1466aac22e6a869134be3d09b9e89232fc2c2289/, run_show_command) + end + private def run_edit_command(editor: "cat") Dir.chdir(app_path) { `EDITOR="#{editor}" bin/rails secrets:edit` } end + + def run_show_command + Dir.chdir(app_path) { `bin/rails secrets:show` } + end + + def run_setup_command + Dir.chdir(app_path) { `bin/rails secrets:setup` } + end end diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 360e8e97d7..03b29be907 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -278,9 +278,12 @@ class ActionsTest < Rails::Generators::TestCase end def test_capify_should_run_the_capify_command - assert_called_with(generator, :run, ["capify .", verbose: false]) do - action :capify! + content = capture(:stderr) do + assert_called_with(generator, :run, ["capify .", verbose: false]) do + action :capify! + end end + assert_match(/DEPRECATION WARNING: `capify!` is deprecated/, content) end def test_route_should_add_data_to_the_routes_block_in_config_routes diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 8a8c9a35ce..059c2692be 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -8,32 +8,70 @@ DEFAULT_APP_FILES = %w( Gemfile Rakefile config.ru + app/assets/config/manifest.js + app/assets/images app/assets/javascripts + app/assets/javascripts/application.js + app/assets/javascripts/cable.js + app/assets/javascripts/channels app/assets/stylesheets - app/assets/images + app/assets/stylesheets/application.css + app/channels/application_cable/channel.rb + app/channels/application_cable/connection.rb app/controllers + app/controllers/application_controller.rb app/controllers/concerns app/helpers + app/helpers/application_helper.rb app/mailers + app/mailers/application_mailer.rb app/models + app/models/application_record.rb app/models/concerns app/jobs + app/jobs/application_job.rb app/views/layouts + app/views/layouts/application.html.erb + app/views/layouts/mailer.html.erb + app/views/layouts/mailer.text.erb bin/bundle bin/rails bin/rake bin/setup + bin/update + bin/yarn + config/application.rb + config/boot.rb + config/cable.yml + config/environment.rb config/environments + config/environments/development.rb + config/environments/production.rb + config/environments/test.rb config/initializers + config/initializers/application_controller_renderer.rb + config/initializers/assets.rb + config/initializers/backtrace_silencers.rb + config/initializers/cookies_serializer.rb + config/initializers/filter_parameter_logging.rb + config/initializers/inflections.rb + config/initializers/mime_types.rb + config/initializers/wrap_parameters.rb config/locales - config/cable.yml + config/locales/en.yml config/puma.rb + config/routes.rb + config/secrets.yml config/spring.rb db + db/seeds.rb lib lib/tasks lib/assets log + package.json + public + test/application_system_test_case.rb test/test_helper.rb test/fixtures test/fixtures/files @@ -437,7 +475,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_generator_if_skip_system_test_is_given - run_generator [destination_root, "--skip_system_test"] + run_generator [destination_root, "--skip-system-test"] assert_file "Gemfile" do |content| assert_no_match(/capybara/, content) assert_no_match(/selenium-webdriver/, content) @@ -445,7 +483,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_does_not_generate_system_test_files_if_skip_system_test_is_given - run_generator [destination_root, "--skip_system_test"] + run_generator [destination_root, "--skip-system-test"] Dir.chdir(destination_root) do quietly { `./bin/rails g scaffold User` } diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index af16a2641a..f8512f9157 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -63,11 +63,13 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_no_file "config/routes.rb" assert_no_file "app/assets/config/bukkits_manifest.js" assert_file "test/test_helper.rb" do |content| - assert_match(/require.+test\/dummy\/config\/environment/, content) + assert_match(/require_relative.+test\/dummy\/config\/environment/, content) assert_match(/ActiveRecord::Migrator\.migrations_paths.+test\/dummy\/db\/migrate/, content) assert_match(/Minitest\.backtrace_filter = Minitest::BacktraceFilter\.new/, content) assert_match(/Rails::TestUnitReporter\.executable = 'bin\/test'/, content) end + assert_file "lib/bukkits/railtie.rb", /module Bukkits\n class Railtie < ::Rails::Railtie\n end\nend/ + assert_file "lib/bukkits.rb", /require "bukkits\/railtie"/ assert_file "test/bukkits_test.rb", /assert_kind_of Module, Bukkits/ assert_file "bin/test" assert_no_file "bin/rails" @@ -438,7 +440,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_file "spec/dummy/config/application.rb" assert_no_file "test/dummy" assert_file "test/test_helper.rb" do |content| - assert_match(/require.+spec\/dummy\/config\/environment/, content) + assert_match(/require_relative.+spec\/dummy\/config\/environment/, content) assert_match(/ActiveRecord::Migrator\.migrations_paths.+spec\/dummy\/db\/migrate/, content) end end @@ -449,7 +451,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_file "spec/fake/config/application.rb" assert_no_file "test/dummy" assert_file "test/test_helper.rb" do |content| - assert_match(/require.+spec\/fake\/config\/environment/, content) + assert_match(/require_relative.+spec\/fake\/config\/environment/, content) assert_match(/ActiveRecord::Migrator\.migrations_paths.+spec\/fake\/db\/migrate/, content) end end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index bc76cead18..9926d58d16 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -65,6 +65,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase # System tests assert_file "test/system/product_lines_test.rb" do |test| assert_match(/class ProductLinesTest < ApplicationSystemTestCase/, test) + assert_match(/visit product_lines_url/, test) + assert_match(/fill_in "Title", with: @product_line\.title/, test) + assert_match(/assert_text "Product line was successfully updated"/, test) end # Views @@ -146,6 +149,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_no_match(/assert_redirected_to/, test) end + # System tests + assert_no_file "test/system/product_lines_test.rb" + # Views assert_no_file "app/views/layouts/product_lines.html.erb" @@ -173,6 +179,16 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase end end + def test_system_tests_without_attributes + run_generator ["product_line"] + + assert_file "test/system/product_lines_test.rb" do |content| + assert_match(/class ProductLinesTest < ApplicationSystemTestCase/, content) + assert_match(/test "visiting the index"/, content) + assert_no_match(/fill_in/, content) + end + end + def test_scaffold_on_revoke run_generator run_generator ["product_line"], behavior: :revoke @@ -192,6 +208,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_no_file "app/controllers/product_lines_controller.rb" assert_no_file "test/controllers/product_lines_controller_test.rb" + # System tests + assert_no_file "test/system/product_lines_test.rb" + # Views assert_no_file "app/views/product_lines" assert_no_file "app/views/layouts/product_lines.html.erb" @@ -257,6 +276,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "test/controllers/admin/roles_controller_test.rb", /class Admin::RolesControllerTest < ActionDispatch::IntegrationTest/ + assert_file "test/system/admin/roles_test.rb", + /class Admin::RolesTest < ApplicationSystemTestCase/ + # Views %w(index edit new show _form).each do |view| assert_file "app/views/admin/roles/#{view}.html.erb" @@ -292,6 +314,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_no_file "app/controllers/admin/roles_controller.rb" assert_no_file "test/controllers/admin/roles_controller_test.rb" + # System tests + assert_no_file "test/system/admin/roles_test.rb" + # Views assert_no_file "app/views/admin/roles" assert_no_file "app/views/layouts/admin/roles.html.erb" @@ -478,6 +503,11 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_match(/password_confirmation: 'secret'/, content) end + assert_file "test/system/users_test.rb" do |content| + assert_match(/fill_in "Password", with: 'secret'/, content) + assert_match(/fill_in "Password Confirmation", with: 'secret'/, content) + end + assert_file "test/fixtures/users.yml" do |content| assert_match(/password_digest: <%= BCrypt::Password.create\('secret'\) %>/, content) end @@ -573,6 +603,8 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert File.exist?("app/controllers/bukkits/users_controller.rb") assert File.exist?("test/controllers/bukkits/users_controller_test.rb") + assert File.exist?("test/system/bukkits/users_test.rb") + assert File.exist?("app/views/bukkits/users/index.html.erb") assert File.exist?("app/views/bukkits/users/edit.html.erb") assert File.exist?("app/views/bukkits/users/show.html.erb") @@ -601,6 +633,8 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_not File.exist?("app/controllers/bukkits/users_controller.rb") assert_not File.exist?("test/controllers/bukkits/users_controller_test.rb") + assert_not File.exist?("test/system/bukkits/users_test.rb") + assert_not File.exist?("app/views/bukkits/users/index.html.erb") assert_not File.exist?("app/views/bukkits/users/edit.html.erb") assert_not File.exist?("app/views/bukkits/users/show.html.erb") diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index b784446535..e07627f36d 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -233,7 +233,7 @@ class GeneratorsTest < Rails::Generators::TestCase end def test_usage_with_embedded_ruby - require File.expand_path("fixtures/lib/generators/usage_template/usage_template_generator", __dir__) + require_relative "fixtures/lib/generators/usage_template/usage_template_generator" output = capture(:stdout) { Rails::Generators.invoke :usage_template, ["--help"] } assert_match(/:: 2 ::/, output) end diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index e382a7a873..0379394f31 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -1341,6 +1341,92 @@ YAML assert_equal "/foo/bukkits/bukkit", last_response.body end + test "isolated engine can be mounted under multiple static locations" do + app_file "app/controllers/foos_controller.rb", <<-RUBY + class FoosController < ApplicationController + def through_fruits + render plain: fruit_bukkits.posts_path + end + + def through_vegetables + render plain: vegetable_bukkits.posts_path + end + end + RUBY + + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + scope "/fruits" do + mount Bukkits::Engine => "/bukkits", as: :fruit_bukkits + end + + scope "/vegetables" do + mount Bukkits::Engine => "/bukkits", as: :vegetable_bukkits + end + + get "/through_fruits" => "foos#through_fruits" + get "/through_vegetables" => "foos#through_vegetables" + end + RUBY + + @plugin.write "config/routes.rb", <<-RUBY + Bukkits::Engine.routes.draw do + resources :posts, only: :index + end + RUBY + + boot_rails + + get("/through_fruits") + assert_equal "/fruits/bukkits/posts", last_response.body + + get("/through_vegetables") + assert_equal "/vegetables/bukkits/posts", last_response.body + end + + test "isolated engine can be mounted under multiple dynamic locations" do + app_file "app/controllers/foos_controller.rb", <<-RUBY + class FoosController < ApplicationController + def through_fruits + render plain: fruit_bukkits.posts_path(fruit_id: 1) + end + + def through_vegetables + render plain: vegetable_bukkits.posts_path(vegetable_id: 1) + end + end + RUBY + + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + resources :fruits do + mount Bukkits::Engine => "/bukkits" + end + + resources :vegetables do + mount Bukkits::Engine => "/bukkits" + end + + get "/through_fruits" => "foos#through_fruits" + get "/through_vegetables" => "foos#through_vegetables" + end + RUBY + + @plugin.write "config/routes.rb", <<-RUBY + Bukkits::Engine.routes.draw do + resources :posts, only: :index + end + RUBY + + boot_rails + + get("/through_fruits") + assert_equal "/fruits/1/bukkits/posts", last_response.body + + get("/through_vegetables") + assert_equal "/vegetables/1/bukkits/posts", last_response.body + end + private def app Rails.application diff --git a/railties/test/secrets_test.rb b/railties/test/secrets_test.rb index 36c8ef1fd9..744d831406 100644 --- a/railties/test/secrets_test.rb +++ b/railties/test/secrets_test.rb @@ -111,6 +111,58 @@ class Rails::SecretsTest < ActiveSupport::TestCase end end + test "do not update secrets.yml.enc when secretes do not change" do + run_secrets_generator do + Dir.chdir(app_path) do + Rails::Secrets.read_for_editing do |tmp_path| + File.write(tmp_path, "Empty streets, empty nights. The Downtown Lights.") + end + + FileUtils.cp("config/secrets.yml.enc", "config/secrets.yml.enc.bk") + + Rails::Secrets.read_for_editing do |tmp_path| + File.write(tmp_path, "Empty streets, empty nights. The Downtown Lights.") + end + + assert_equal File.read("config/secrets.yml.enc.bk"), File.read("config/secrets.yml.enc") + end + end + end + + test "can read secrets written in binary" do + run_secrets_generator do + secrets = <<-end_of_secrets + production: + api_key: 00112233445566778899aabbccddeeff… + end_of_secrets + + Rails::Secrets.write(secrets.force_encoding(Encoding::ASCII_8BIT)) + + Rails::Secrets.read_for_editing do |tmp_path| + assert_match(/production:\n\s*api_key: 00112233445566778899aabbccddeeff…\n/, File.read(tmp_path)) + end + + assert_equal "00112233445566778899aabbccddeeff…\n", `bin/rails runner -e production "puts Rails.application.secrets.api_key"` + end + end + + test "can read secrets written in non-binary" do + run_secrets_generator do + secrets = <<-end_of_secrets + production: + api_key: 00112233445566778899aabbccddeeff… + end_of_secrets + + Rails::Secrets.write(secrets) + + Rails::Secrets.read_for_editing do |tmp_path| + assert_equal(secrets.force_encoding(Encoding::ASCII_8BIT), IO.binread(tmp_path)) + end + + assert_equal "00112233445566778899aabbccddeeff…\n", `bin/rails runner -e production "puts Rails.application.secrets.api_key"` + end + end + private def run_secrets_generator Dir.chdir(app_path) do |