aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.codeclimate.yml1
-rw-r--r--.rubocop.yml1
-rw-r--r--Gemfile4
-rw-r--r--Gemfile.lock9
-rw-r--r--README.md2
-rw-r--r--actioncable/README.md2
-rw-r--r--actioncable/lib/action_cable/remote_connections.rb3
-rw-r--r--actioncable/lib/action_cable/server/base.rb2
-rw-r--r--actionmailer/README.rdoc2
-rw-r--r--actionmailer/lib/action_mailer/base.rb6
-rw-r--r--actionmailer/lib/action_mailer/message_delivery.rb2
-rw-r--r--actionmailer/lib/action_mailer/preview.rb8
-rw-r--r--actionmailer/lib/action_mailer/rescuable.rb2
-rw-r--r--actionmailer/test/asset_host_test.rb4
-rw-r--r--actionmailer/test/base_test.rb4
-rw-r--r--actionmailer/test/url_test.rb2
-rw-r--r--actionpack/CHANGELOG.md6
-rw-r--r--actionpack/README.rdoc2
-rw-r--r--actionpack/lib/action_controller/metal/conditional_get.rb2
-rw-r--r--actionpack/lib/action_controller/metal/data_streaming.rb6
-rw-r--r--actionpack/lib/action_controller/metal/redirecting.rb4
-rw-r--r--actionpack/lib/action_controller/metal/request_forgery_protection.rb2
-rw-r--r--actionpack/lib/action_controller/metal/rescue.rb6
-rw-r--r--actionpack/lib/action_dispatch/http/cache.rb2
-rw-r--r--actionpack/lib/action_dispatch/http/mime_types.rb4
-rw-r--r--actionpack/lib/action_dispatch/http/request.rb16
-rw-r--r--actionpack/lib/action_dispatch/journey/router/utils.rb2
-rw-r--r--actionpack/lib/action_dispatch/middleware/cookies.rb18
-rw-r--r--actionpack/lib/action_dispatch/middleware/debug_locks.rb14
-rw-r--r--actionpack/lib/action_dispatch/middleware/public_exceptions.rb8
-rw-r--r--actionpack/lib/action_dispatch/middleware/remote_ip.rb4
-rw-r--r--actionpack/lib/action_dispatch/middleware/session/cookie_store.rb6
-rw-r--r--actionpack/lib/action_dispatch/middleware/ssl.rb2
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb4
-rw-r--r--actionpack/lib/action_dispatch/routing/redirection.rb6
-rw-r--r--actionpack/lib/action_dispatch/routing/url_for.rb2
-rw-r--r--actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb20
-rw-r--r--actionpack/lib/action_dispatch/testing/test_request.rb2
-rw-r--r--actionpack/test/dispatch/cookies_test.rb32
-rw-r--r--actionpack/test/dispatch/debug_locks_test.rb38
-rw-r--r--actionpack/test/dispatch/session/cookie_store_test.rb9
-rw-r--r--actionpack/test/dispatch/system_testing/screenshot_helper_test.rb43
-rw-r--r--actionview/CHANGELOG.md6
-rw-r--r--actionview/README.rdoc2
-rw-r--r--actionview/lib/action_view/helpers/active_model_helper.rb2
-rw-r--r--actionview/lib/action_view/helpers/asset_tag_helper.rb28
-rw-r--r--actionview/lib/action_view/helpers/asset_url_helper.rb10
-rw-r--r--actionview/lib/action_view/helpers/atom_feed_helper.rb2
-rw-r--r--actionview/lib/action_view/helpers/cache_helper.rb10
-rw-r--r--actionview/lib/action_view/helpers/capture_helper.rb14
-rw-r--r--actionview/lib/action_view/helpers/controller_helper.rb2
-rw-r--r--actionview/lib/action_view/helpers/csrf_helper.rb2
-rw-r--r--actionview/lib/action_view/helpers/date_helper.rb2
-rw-r--r--actionview/lib/action_view/helpers/debug_helper.rb2
-rw-r--r--actionview/lib/action_view/helpers/form_helper.rb32
-rw-r--r--actionview/lib/action_view/helpers/form_options_helper.rb2
-rw-r--r--actionview/lib/action_view/helpers/form_tag_helper.rb16
-rw-r--r--actionview/lib/action_view/helpers/javascript_helper.rb2
-rw-r--r--actionview/lib/action_view/helpers/record_tag_helper.rb2
-rw-r--r--actionview/lib/action_view/helpers/rendering_helper.rb2
-rw-r--r--actionview/lib/action_view/helpers/sanitize_helper.rb2
-rw-r--r--actionview/lib/action_view/helpers/tags.rb2
-rw-r--r--actionview/lib/action_view/helpers/translation_helper.rb2
-rw-r--r--actionview/lib/action_view/renderer/partial_renderer.rb20
-rw-r--r--actionview/lib/action_view/template/handlers.rb2
-rw-r--r--actionview/lib/action_view/template/html.rb2
-rw-r--r--actionview/lib/action_view/template/resolver.rb6
-rw-r--r--actionview/lib/action_view/template/text.rb2
-rw-r--r--actionview/lib/action_view/template/types.rb2
-rw-r--r--actionview/test/template/asset_tag_helper_test.rb52
-rw-r--r--actionview/test/template/form_tag_helper_test.rb2
-rw-r--r--actionview/test/tmp/.keep (renamed from actionview/test/tmp/.gitkeep)0
-rw-r--r--actionview/test/ujs/public/vendor/qunit.js2
-rw-r--r--activejob/README.md2
-rw-r--r--activejob/lib/active_job/enqueuing.rb2
-rw-r--r--activejob/lib/active_job/queue_adapters/async_adapter.rb2
-rw-r--r--activemodel/README.rdoc2
-rw-r--r--activemodel/lib/active_model/callbacks.rb4
-rw-r--r--activerecord/CHANGELOG.md13
-rw-r--r--activerecord/README.rdoc4
-rw-r--r--activerecord/lib/active_record/associations/belongs_to_association.rb2
-rw-r--r--activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb2
-rw-r--r--activerecord/lib/active_record/associations/has_many_association.rb2
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb2
-rw-r--r--activerecord/lib/active_record/associations/has_one_association.rb2
-rw-r--r--activerecord/lib/active_record/associations/has_one_through_association.rb2
-rw-r--r--activerecord/lib/active_record/associations/join_dependency.rb6
-rw-r--r--activerecord/lib/active_record/associations/through_association.rb2
-rw-r--r--activerecord/lib/active_record/attribute_methods/dirty.rb22
-rw-r--r--activerecord/lib/active_record/attribute_methods/read.rb2
-rw-r--r--activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb2
-rw-r--r--activerecord/lib/active_record/attribute_methods/write.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/quoting.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb82
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb6
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_adapter.rb1
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb14
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb46
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb8
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb19
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb8
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb40
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb3
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb8
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb11
-rw-r--r--activerecord/lib/active_record/core.rb2
-rw-r--r--activerecord/lib/active_record/define_callbacks.rb6
-rw-r--r--activerecord/lib/active_record/errors.rb5
-rw-r--r--activerecord/lib/active_record/fixtures.rb2
-rw-r--r--activerecord/lib/active_record/inheritance.rb2
-rw-r--r--activerecord/lib/active_record/locking/pessimistic.rb2
-rw-r--r--activerecord/lib/active_record/no_touching.rb2
-rw-r--r--activerecord/lib/active_record/persistence.rb4
-rw-r--r--activerecord/lib/active_record/reflection.rb18
-rw-r--r--activerecord/lib/active_record/relation.rb16
-rw-r--r--activerecord/lib/active_record/relation/delegation.rb12
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb11
-rw-r--r--activerecord/lib/active_record/schema.rb2
-rw-r--r--activerecord/lib/active_record/schema_dumper.rb11
-rw-r--r--activerecord/lib/active_record/tasks/postgresql_database_tasks.rb2
-rw-r--r--activerecord/lib/active_record/tasks/sqlite_database_tasks.rb2
-rw-r--r--activerecord/lib/active_record/transactions.rb2
-rw-r--r--activerecord/lib/active_record/validations/uniqueness.rb2
-rw-r--r--activerecord/test/cases/adapter_test.rb4
-rw-r--r--activerecord/test/cases/adapters/mysql2/sp_test.rb2
-rw-r--r--activerecord/test/cases/adapters/mysql2/table_options_test.rb8
-rw-r--r--activerecord/test/cases/adapters/mysql2/transaction_test.rb6
-rw-r--r--activerecord/test/cases/adapters/mysql2/unsigned_type_test.rb2
-rw-r--r--activerecord/test/cases/adapters/postgresql/connection_test.rb7
-rw-r--r--activerecord/test/cases/associations/eager_test.rb6
-rw-r--r--activerecord/test/cases/associations/has_one_associations_test.rb2
-rw-r--r--activerecord/test/cases/associations/inverse_associations_test.rb39
-rw-r--r--activerecord/test/cases/associations_test.rb12
-rw-r--r--activerecord/test/cases/autosave_association_test.rb21
-rw-r--r--activerecord/test/cases/comment_test.rb2
-rw-r--r--activerecord/test/cases/enum_test.rb2
-rw-r--r--activerecord/test/cases/migration_test.rb4
-rw-r--r--activerecord/test/cases/primary_keys_test.rb6
-rw-r--r--activerecord/test/cases/relation/delegation_test.rb11
-rw-r--r--activerecord/test/cases/relation/or_test.rb2
-rw-r--r--activerecord/test/cases/schema_dumper_test.rb13
-rw-r--r--activerecord/test/cases/tasks/postgresql_rake_test.rb10
-rw-r--r--activerecord/test/cases/tasks/sqlite_rake_test.rb25
-rw-r--r--activerecord/test/migrations/empty/.keep (renamed from activerecord/test/migrations/empty/.gitkeep)0
-rw-r--r--activerecord/test/models/comment.rb3
-rw-r--r--activestorage/app/controllers/active_storage/disk_controller.rb4
-rw-r--r--activestorage/app/jobs/active_storage/purge_job.rb6
-rw-r--r--activestorage/app/models/active_storage/attachment.rb10
-rw-r--r--activestorage/app/models/active_storage/blob.rb6
-rw-r--r--activestorage/app/models/active_storage/filename.rb38
-rw-r--r--activestorage/app/models/active_storage/filename/parameters.rb36
-rw-r--r--activestorage/app/models/active_storage/variant.rb2
-rw-r--r--activestorage/app/models/active_storage/variation.rb2
-rwxr-xr-xactivestorage/bin/test5
-rw-r--r--activestorage/db/migrate/20170806125915_create_active_storage_tables.rb6
-rw-r--r--activestorage/lib/active_storage/attached.rb6
-rw-r--r--activestorage/lib/active_storage/attached/macros.rb4
-rw-r--r--activestorage/lib/active_storage/attached/one.rb22
-rw-r--r--activestorage/lib/active_storage/service.rb2
-rw-r--r--activestorage/lib/active_storage/service/azure_storage_service.rb12
-rw-r--r--activestorage/lib/active_storage/service/disk_service.rb6
-rw-r--r--activestorage/lib/active_storage/service/gcs_service.rb4
-rw-r--r--activestorage/lib/active_storage/service/s3_service.rb4
-rw-r--r--activestorage/test/controllers/disk_controller_test.rb4
-rw-r--r--activestorage/test/database/create_users_migration.rb2
-rw-r--r--activestorage/test/models/attachments_test.rb25
-rw-r--r--activestorage/test/models/blob_test.rb2
-rw-r--r--activestorage/test/models/filename/parameters_test.rb32
-rw-r--r--activestorage/test/models/filename_test.rb18
-rw-r--r--activestorage/test/service/azure_storage_service_test.rb4
-rw-r--r--activestorage/test/service/disk_service_test.rb4
-rw-r--r--activestorage/test/service/gcs_service_test.rb2
-rw-r--r--activestorage/test/service/s3_service_test.rb2
-rw-r--r--activestorage/test/template/image_tag_test.rb6
-rw-r--r--activesupport/README.rdoc2
-rw-r--r--activesupport/lib/active_support/cache/mem_cache_store.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/digest/uuid.rb2
-rw-r--r--activesupport/lib/active_support/dependencies.rb2
-rw-r--r--activesupport/lib/active_support/duration.rb2
-rw-r--r--activesupport/lib/active_support/duration/iso8601_parser.rb2
-rw-r--r--activesupport/lib/active_support/message_encryptor.rb4
-rw-r--r--activesupport/lib/active_support/xml_mini/jdom.rb2
-rw-r--r--guides/source/2_3_release_notes.md2
-rw-r--r--guides/source/3_0_release_notes.md2
-rw-r--r--guides/source/3_1_release_notes.md2
-rw-r--r--guides/source/3_2_release_notes.md4
-rw-r--r--guides/source/4_0_release_notes.md4
-rw-r--r--guides/source/5_0_release_notes.md10
-rw-r--r--guides/source/action_controller_overview.md2
-rw-r--r--guides/source/action_mailer_basics.md7
-rw-r--r--guides/source/action_view_overview.md4
-rw-r--r--guides/source/active_job_basics.md2
-rw-r--r--guides/source/active_record_basics.md2
-rw-r--r--guides/source/active_record_migrations.md2
-rw-r--r--guides/source/active_record_querying.md4
-rw-r--r--guides/source/active_support_core_extensions.md12
-rw-r--r--guides/source/api_app.md8
-rw-r--r--guides/source/api_documentation_guidelines.md6
-rw-r--r--guides/source/asset_pipeline.md8
-rw-r--r--guides/source/association_basics.md23
-rw-r--r--guides/source/autoloading_and_reloading_constants.md11
-rw-r--r--guides/source/caching_with_rails.md30
-rw-r--r--guides/source/command_line.md11
-rw-r--r--guides/source/configuring.md2
-rw-r--r--guides/source/contributing_to_ruby_on_rails.md18
-rw-r--r--guides/source/debugging_rails_applications.md30
-rw-r--r--guides/source/development_dependencies_install.md6
-rw-r--r--guides/source/generators.md12
-rw-r--r--guides/source/getting_started.md143
-rw-r--r--guides/source/i18n.md26
-rw-r--r--guides/source/initialization.md17
-rw-r--r--guides/source/kindle/toc.html.erb2
-rw-r--r--guides/source/layout.html.erb2
-rw-r--r--guides/source/plugins.md4
-rw-r--r--guides/source/rails_on_rack.md4
-rw-r--r--guides/source/security.md8
-rw-r--r--guides/source/testing.md6
-rw-r--r--guides/source/upgrading_ruby_on_rails.md4
-rw-r--r--guides/source/working_with_javascript_in_rails.md14
-rw-r--r--railties/RDOC_MAIN.rdoc104
-rw-r--r--railties/README.rdoc3
-rw-r--r--railties/lib/rails/api/generator.rb9
-rw-r--r--railties/lib/rails/api/task.rb1
-rw-r--r--railties/lib/rails/application/configuration.rb2
-rw-r--r--railties/lib/rails/command/actions.rb6
-rw-r--r--railties/lib/rails/command/base.rb4
-rw-r--r--railties/lib/rails/commands/dbconsole/dbconsole_command.rb2
-rw-r--r--railties/lib/rails/commands/server/server_command.rb8
-rw-r--r--railties/lib/rails/dev_caching.rb1
-rw-r--r--railties/lib/rails/generators/rails/app/templates/Rakefile2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/app/channels/application_cable/channel.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/app/channels/application_cable/connection.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/app/helpers/application_helper.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/app/models/application_record.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/application.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/boot.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/cable.yml2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environment.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/initializers/cors.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/initializers/mime_types.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/puma.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/routes.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/spring.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/test/test_helper.rb2
-rw-r--r--railties/lib/rails/generators/rails/controller/templates/controller.rb2
-rw-r--r--railties/lib/rails/generators/rails/helper/templates/helper.rb2
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/README.md2
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/Rakefile2
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/config/routes.rb2
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb2
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb2
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb2
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb2
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/lib/tasks/%namespaced_name%_tasks.rake2
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/rails/application.rb2
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/rails/boot.rb2
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/rails/routes.rb2
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb2
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb2
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb3
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/test/test_helper.rb2
-rw-r--r--railties/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb2
-rw-r--r--railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb2
-rw-r--r--railties/lib/rails/generators/rails/task/templates/task.rb2
-rw-r--r--railties/lib/rails/secrets.rb2
-rw-r--r--railties/lib/rails/source_annotation_extractor.rb2
-rw-r--r--railties/lib/rails/tasks/restart.rake1
-rw-r--r--railties/lib/rails/test_unit/line_filtering.rb1
-rw-r--r--railties/test/application/rake/dev_test.rb12
-rw-r--r--railties/test/application/rake/restart_test.rb9
-rw-r--r--railties/test/application/server_test.rb28
-rw-r--r--railties/test/commands/dbconsole_test.rb6
-rw-r--r--railties/test/commands/server_test.rb2
-rw-r--r--railties/test/generators/actions_test.rb2
-rw-r--r--railties/test/generators/encrypted_secrets_generator_test.rb4
-rw-r--r--railties/test/secrets_test.rb4
288 files changed, 1311 insertions, 908 deletions
diff --git a/.codeclimate.yml b/.codeclimate.yml
index 17fcaa4360..63d3562e9b 100644
--- a/.codeclimate.yml
+++ b/.codeclimate.yml
@@ -1,6 +1,7 @@
engines:
rubocop:
enabled: true
+ channel: rubocop-0-49
ratings:
paths:
diff --git a/.rubocop.yml b/.rubocop.yml
index c1101d849b..f3ed8bc841 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -88,6 +88,7 @@ Style/FrozenStringLiteralComment:
- 'actionview/test/**/*.ruby'
- 'actionpack/test/**/*.builder'
- 'actionpack/test/**/*.ruby'
+ - 'activestorage/db/migrate/**/*.rb'
# Use `foo {}` not `foo{}`.
Layout/SpaceBeforeBlockBraces:
diff --git a/Gemfile b/Gemfile
index 412cc627b9..ece09d0731 100644
--- a/Gemfile
+++ b/Gemfile
@@ -37,8 +37,12 @@ gem "json", ">= 2.0.0"
gem "rubocop", ">= 0.47", require: false
+# https://github.com/guard/rb-inotify/pull/79
gem "rb-inotify", github: "matthewd/rb-inotify", branch: "close-handling", require: false
+# https://github.com/puma/puma/pull/1345
+gem "stopgap_13632", platforms: :mri if %w(2.2.7 2.3.4 2.4.1).include? RUBY_VERSION
+
group :doc do
gem "sdoc", github: "robin850/sdoc", branch: "upgrade"
gem "redcarpet", "~> 3.2.3", platforms: :ruby
diff --git a/Gemfile.lock b/Gemfile.lock
index 516b4155c1..9da1aef756 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -127,9 +127,10 @@ GEM
aws-sdk-resources (2.10.27)
aws-sdk-core (= 2.10.27)
aws-sigv4 (1.0.1)
- azure-core (0.1.10)
+ azure-core (0.1.11)
faraday (~> 0.9)
faraday_middleware (~> 0.10)
+ nokogiri (~> 1.6)
azure-storage (0.12.3.preview)
azure-core (~> 0.1)
faraday (~> 0.9)
@@ -217,7 +218,7 @@ GEM
eventmachine (1.2.5-x64-mingw32)
eventmachine (1.2.5-x86-mingw32)
execjs (2.7.0)
- faraday (0.13.0)
+ faraday (0.13.1)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.12.2)
faraday (>= 0.7.4, < 1.0)
@@ -437,6 +438,7 @@ GEM
sqlite3 (1.3.13-x64-mingw32)
sqlite3 (1.3.13-x86-mingw32)
stackprof (0.2.10)
+ stopgap_13632 (1.0.1)
sucker_punch (2.0.2)
concurrent-ruby (~> 1.0.0)
thin (1.7.2)
@@ -534,6 +536,7 @@ DEPENDENCIES
sprockets-export
sqlite3 (~> 1.3.6)
stackprof
+ stopgap_13632
sucker_punch
turbolinks (~> 5)
tzinfo-data
@@ -543,4 +546,4 @@ DEPENDENCIES
websocket-client-simple!
BUNDLED WITH
- 1.15.3
+ 1.15.4
diff --git a/README.md b/README.md
index ee0ee2019d..030dd405cb 100644
--- a/README.md
+++ b/README.md
@@ -94,4 +94,4 @@ Everyone interacting in Rails and its sub-projects' codebases, issue trackers, c
## License
-Ruby on Rails is released under the [MIT License](http://www.opensource.org/licenses/MIT).
+Ruby on Rails is released under the [MIT License](https://opensource.org/licenses/MIT).
diff --git a/actioncable/README.md b/actioncable/README.md
index 9667403673..a060e8938e 100644
--- a/actioncable/README.md
+++ b/actioncable/README.md
@@ -549,7 +549,7 @@ Source code can be downloaded as part of the Rails project on GitHub
Action Cable is released under the MIT license:
-* http://www.opensource.org/licenses/MIT
+* https://opensource.org/licenses/MIT
## Support
diff --git a/actioncable/lib/action_cable/remote_connections.rb b/actioncable/lib/action_cable/remote_connections.rb
index a92b5e90b4..a07a517092 100644
--- a/actioncable/lib/action_cable/remote_connections.rb
+++ b/actioncable/lib/action_cable/remote_connections.rb
@@ -51,9 +51,10 @@ module ActionCable
server.connection_identifiers
end
- private
+ protected
attr_reader :server
+ private
def set_identifier_instance_vars(ids)
raise InvalidIdentifiersError unless valid_identifiers?(ids)
ids.each { |k, v| instance_variable_set("@#{k}", v) }
diff --git a/actioncable/lib/action_cable/server/base.rb b/actioncable/lib/action_cable/server/base.rb
index 6c6f6c2936..1ee03f6dfc 100644
--- a/actioncable/lib/action_cable/server/base.rb
+++ b/actioncable/lib/action_cable/server/base.rb
@@ -30,7 +30,7 @@ module ActionCable
config.connection_class.call.new(self, env).process
end
- # Disconnect all the connections identified by `identifiers` on this server or any others via RemoteConnections.
+ # Disconnect all the connections identified by +identifiers+ on this server or any others via RemoteConnections.
def disconnect(identifiers)
remote_connections.where(identifiers).disconnect
end
diff --git a/actionmailer/README.rdoc b/actionmailer/README.rdoc
index 397ebe4201..9993d3777d 100644
--- a/actionmailer/README.rdoc
+++ b/actionmailer/README.rdoc
@@ -157,7 +157,7 @@ Source code can be downloaded as part of the Rails project on GitHub
Action Mailer is released under the MIT license:
-* http://www.opensource.org/licenses/MIT
+* https://opensource.org/licenses/MIT
== Support
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index a54eb52dcb..1c1e1a9a3b 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -59,7 +59,7 @@ module ActionMailer
# The hash passed to the mail method allows you to specify any header that a <tt>Mail::Message</tt>
# will accept (any valid email header including optional fields).
#
- # The mail method, if not passed a block, will inspect your views and send all the views with
+ # The +mail+ method, if not passed a block, will inspect your views and send all the views with
# the same name as the method, so the above action would send the +welcome.text.erb+ view
# file as well as the +welcome.html.erb+ view file in a +multipart/alternative+ email.
#
@@ -138,7 +138,7 @@ module ActionMailer
# You can also define a <tt>default_url_options</tt> method on individual mailers to override these
# default settings per-mailer.
#
- # By default when <tt>config.force_ssl</tt> is true, URLs generated for hosts will use the HTTPS protocol.
+ # By default when <tt>config.force_ssl</tt> is +true+, URLs generated for hosts will use the HTTPS protocol.
#
# = Sending mail
#
@@ -316,7 +316,7 @@ module ActionMailer
#
# = Callbacks
#
- # You can specify callbacks using before_action and after_action for configuring your messages.
+ # You can specify callbacks using <tt>before_action</tt> and <tt>after_action</tt> for configuring your messages.
# This may be useful, for example, when you want to add default inline attachments for all
# messages sent out by a certain mailer class:
#
diff --git a/actionmailer/lib/action_mailer/message_delivery.rb b/actionmailer/lib/action_mailer/message_delivery.rb
index fe7265834f..a2ea45dc7b 100644
--- a/actionmailer/lib/action_mailer/message_delivery.rb
+++ b/actionmailer/lib/action_mailer/message_delivery.rb
@@ -4,7 +4,7 @@ require "delegate"
module ActionMailer
# The <tt>ActionMailer::MessageDelivery</tt> class is used by
- # <tt>ActionMailer::Base</tt> when creating a new mailer.
+ # ActionMailer::Base when creating a new mailer.
# <tt>MessageDelivery</tt> is a wrapper (+Delegator+ subclass) around a lazy
# created <tt>Mail::Message</tt>. You can get direct access to the
# <tt>Mail::Message</tt>, deliver the email or schedule the email to be sent
diff --git a/actionmailer/lib/action_mailer/preview.rb b/actionmailer/lib/action_mailer/preview.rb
index 4a8d3659ec..730ac89c94 100644
--- a/actionmailer/lib/action_mailer/preview.rb
+++ b/actionmailer/lib/action_mailer/preview.rb
@@ -17,7 +17,7 @@ module ActionMailer
#
# config.action_mailer.show_previews = true
#
- # Defaults to true for development environment
+ # Defaults to +true+ for development environment
#
mattr_accessor :show_previews, instance_writer: false
@@ -33,7 +33,7 @@ module ActionMailer
# Register an Interceptor which will be called before mail is previewed.
# Either a class or a string can be passed in as the Interceptor. If a
- # string is passed in it will be <tt>constantize</tt>d.
+ # string is passed in it will be constantized.
def register_preview_interceptor(interceptor)
preview_interceptor = \
case interceptor
@@ -81,12 +81,12 @@ module ActionMailer
public_instance_methods(false).map(&:to_s).sort
end
- # Returns true if the email exists.
+ # Returns +true+ if the email exists.
def email_exists?(email)
emails.include?(email)
end
- # Returns true if the preview exists.
+ # Returns +true+ if the preview exists.
def exists?(preview)
all.any? { |p| p.preview_name == preview }
end
diff --git a/actionmailer/lib/action_mailer/rescuable.rb b/actionmailer/lib/action_mailer/rescuable.rb
index 28950eb834..5b567eb500 100644
--- a/actionmailer/lib/action_mailer/rescuable.rb
+++ b/actionmailer/lib/action_mailer/rescuable.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module ActionMailer #:nodoc:
- # Provides `rescue_from` for mailers. Wraps mailer action processing,
+ # Provides +rescue_from+ for mailers. Wraps mailer action processing,
# mail job processing, and mail delivery.
module Rescuable
extend ActiveSupport::Concern
diff --git a/actionmailer/test/asset_host_test.rb b/actionmailer/test/asset_host_test.rb
index 2a14248488..9cd8cae88c 100644
--- a/actionmailer/test/asset_host_test.rb
+++ b/actionmailer/test/asset_host_test.rb
@@ -24,7 +24,7 @@ class AssetHostTest < ActionMailer::TestCase
def test_asset_host_as_string
mail = AssetHostMailer.email_with_asset
- assert_dom_equal '<img alt="Somelogo" src="http://www.example.com/images/somelogo.png" />', mail.body.to_s.strip
+ assert_dom_equal '<img src="http://www.example.com/images/somelogo.png" />', mail.body.to_s.strip
end
def test_asset_host_as_one_argument_proc
@@ -34,6 +34,6 @@ class AssetHostTest < ActionMailer::TestCase
end
}
mail = AssetHostMailer.email_with_asset
- assert_dom_equal '<img alt="Somelogo" src="http://images.example.com/images/somelogo.png" />', mail.body.to_s.strip
+ assert_dom_equal '<img src="http://images.example.com/images/somelogo.png" />', mail.body.to_s.strip
end
end
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb
index d029329497..0da969c349 100644
--- a/actionmailer/test/base_test.rb
+++ b/actionmailer/test/base_test.rb
@@ -578,7 +578,7 @@ class BaseTest < ActiveSupport::TestCase
mail = AssetMailer.welcome
- assert_dom_equal(%{<img alt="Dummy" src="http://global.com/images/dummy.png" />}, mail.body.to_s.strip)
+ assert_dom_equal(%{<img src="http://global.com/images/dummy.png" />}, mail.body.to_s.strip)
end
test "assets tags should use a Mailer's asset_host settings when available" do
@@ -592,7 +592,7 @@ class BaseTest < ActiveSupport::TestCase
mail = TempAssetMailer.welcome
- assert_dom_equal(%{<img alt="Dummy" src="http://local.com/images/dummy.png" />}, mail.body.to_s.strip)
+ assert_dom_equal(%{<img src="http://local.com/images/dummy.png" />}, mail.body.to_s.strip)
end
test "the view is not rendered when mail was never called" do
diff --git a/actionmailer/test/url_test.rb b/actionmailer/test/url_test.rb
index 0bd3371878..82035689ad 100644
--- a/actionmailer/test/url_test.rb
+++ b/actionmailer/test/url_test.rb
@@ -121,7 +121,7 @@ class ActionMailerUrlTest < ActionMailer::TestCase
expected = new_mail
expected.to = @recipient
expected.subject = "[Signed up] Welcome #{@recipient}"
- expected.body = "Hello there,\n\nMr. #{@recipient}. Please see our greeting at http://example.com/welcome/greeting http://www.basecamphq.com/welcome\n\n<img alt=\"Somelogo\" src=\"/images/somelogo.png\" />"
+ expected.body = "Hello there,\n\nMr. #{@recipient}. Please see our greeting at http://example.com/welcome/greeting http://www.basecamphq.com/welcome\n\n<img src=\"/images/somelogo.png\" />"
expected.from = "system@loudthinking.com"
expected.date = Time.local(2004, 12, 12)
expected.content_type = "text/html"
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 938b24a6b9..b56a1c5d4b 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,3 +1,9 @@
+* Make `take_failed_screenshot` work within engine.
+
+ Fixes #30405.
+
+ *Yuji Yaginuma*
+
* Deprecate `ActionDispatch::TestResponse` response aliases
`#success?`, `#missing?` & `#error?` are not supported by the actual
diff --git a/actionpack/README.rdoc b/actionpack/README.rdoc
index 0720c66cb9..93b2a0932a 100644
--- a/actionpack/README.rdoc
+++ b/actionpack/README.rdoc
@@ -39,7 +39,7 @@ Source code can be downloaded as part of the Rails project on GitHub
Action Pack is released under the MIT license:
-* http://www.opensource.org/licenses/MIT
+* https://opensource.org/licenses/MIT
== Support
diff --git a/actionpack/lib/action_controller/metal/conditional_get.rb b/actionpack/lib/action_controller/metal/conditional_get.rb
index 0d9a0c8c56..06b6a95ff8 100644
--- a/actionpack/lib/action_controller/metal/conditional_get.rb
+++ b/actionpack/lib/action_controller/metal/conditional_get.rb
@@ -228,7 +228,7 @@ module ActionController
# expires_in 3.hours, public: true, must_revalidate: true
#
# This method will overwrite an existing Cache-Control header.
- # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for more possibilities.
+ # See https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for more possibilities.
#
# The method will also ensure an HTTP Date header for client compatibility.
def expires_in(seconds, options = {})
diff --git a/actionpack/lib/action_controller/metal/data_streaming.rb b/actionpack/lib/action_controller/metal/data_streaming.rb
index 30234ee304..882f6f3d0a 100644
--- a/actionpack/lib/action_controller/metal/data_streaming.rb
+++ b/actionpack/lib/action_controller/metal/data_streaming.rb
@@ -56,14 +56,14 @@ module ActionController #:nodoc:
#
# Read about the other Content-* HTTP headers if you'd like to
# provide the user with more information (such as Content-Description) in
- # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11.
+ # https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11.
#
# Also be aware that the document may be cached by proxies and browsers.
# The Pragma and Cache-Control headers declare how the file may be cached
# by intermediaries. They default to require clients to validate with
# the server before releasing cached responses. See
- # http://www.mnot.net/cache_docs/ for an overview of web caching and
- # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
+ # https://www.mnot.net/cache_docs/ for an overview of web caching and
+ # https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
# for the Cache-Control header spec.
def send_file(path, options = {}) #:doc:
raise MissingFile, "Cannot read file #{path}" unless File.file?(path) && File.readable?(path)
diff --git a/actionpack/lib/action_controller/metal/redirecting.rb b/actionpack/lib/action_controller/metal/redirecting.rb
index 2db2c78622..5cd8568d8d 100644
--- a/actionpack/lib/action_controller/metal/redirecting.rb
+++ b/actionpack/lib/action_controller/metal/redirecting.rb
@@ -31,7 +31,7 @@ module ActionController
# redirect_to post_url(@post), status: 301
# redirect_to action: 'atom', status: 302
#
- # The status code can either be a standard {HTTP Status code}[http://www.iana.org/assignments/http-status-codes] as an
+ # The status code can either be a standard {HTTP Status code}[https://www.iana.org/assignments/http-status-codes] as an
# integer, or a symbol representing the downcased, underscored and symbolized description.
# Note that the status code must be a 3xx HTTP code, or redirection will not occur.
#
@@ -95,7 +95,7 @@ module ActionController
# The scheme name consist of a letter followed by any combination of
# letters, digits, and the plus ("+"), period ("."), or hyphen ("-")
# characters; and is terminated by a colon (":").
- # See http://tools.ietf.org/html/rfc3986#section-3.1
+ # See https://tools.ietf.org/html/rfc3986#section-3.1
# The protocol relative scheme starts with a double slash "//".
when /\A([a-z][a-z\d\-+\.]*:|\/\/).*/i
options
diff --git a/actionpack/lib/action_controller/metal/request_forgery_protection.rb b/actionpack/lib/action_controller/metal/request_forgery_protection.rb
index d397c62461..813a7e00d4 100644
--- a/actionpack/lib/action_controller/metal/request_forgery_protection.rb
+++ b/actionpack/lib/action_controller/metal/request_forgery_protection.rb
@@ -22,7 +22,7 @@ module ActionController #:nodoc:
# Since HTML and JavaScript requests are typically made from the browser, we
# need to ensure to verify request authenticity for the web browser. We can
# use session-oriented authentication for these types of requests, by using
- # the `protect_from_forgery` method in our controllers.
+ # the <tt>protect_from_forgery</tt> method in our controllers.
#
# GET requests are not protected since they don't have side effects like writing
# to the database and don't leak sensitive information. JavaScript requests are
diff --git a/actionpack/lib/action_controller/metal/rescue.rb b/actionpack/lib/action_controller/metal/rescue.rb
index 843c99f57b..44f7fb7a07 100644
--- a/actionpack/lib/action_controller/metal/rescue.rb
+++ b/actionpack/lib/action_controller/metal/rescue.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module ActionController #:nodoc:
- # This module is responsible for providing `rescue_from` helpers
+ # This module is responsible for providing +rescue_from+ helpers
# to controllers and configuring when detailed exceptions must be
# shown.
module Rescue
@@ -10,8 +10,8 @@ module ActionController #:nodoc:
# Override this method if you want to customize when detailed
# exceptions must be shown. This method is only called when
- # consider_all_requests_local is false. By default, it returns
- # false, but someone may set it to `request.local?` so local
+ # +consider_all_requests_local+ is +false+. By default, it returns
+ # +false+, but someone may set it to <tt>request.local?</tt> so local
# requests in production still show the detailed exception pages.
def show_detailed_exceptions?
false
diff --git a/actionpack/lib/action_dispatch/http/cache.rb b/actionpack/lib/action_dispatch/http/cache.rb
index 2cc609406a..8073685b78 100644
--- a/actionpack/lib/action_dispatch/http/cache.rb
+++ b/actionpack/lib/action_dispatch/http/cache.rb
@@ -97,7 +97,7 @@ module ActionDispatch
# support strong ETags and will ignore weak ETags entirely.
#
# Weak ETags are what we almost always need, so they're the default.
- # Check out `#strong_etag=` to provide a strong ETag validator.
+ # Check out #strong_etag= to provide a strong ETag validator.
def etag=(weak_validators)
self.weak_etag = weak_validators
end
diff --git a/actionpack/lib/action_dispatch/http/mime_types.rb b/actionpack/lib/action_dispatch/http/mime_types.rb
index 5d866e5d71..f8e6fca36d 100644
--- a/actionpack/lib/action_dispatch/http/mime_types.rb
+++ b/actionpack/lib/action_dispatch/http/mime_types.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
# Build list of Mime types for HTTP responses
-# http://www.iana.org/assignments/media-types/
+# https://www.iana.org/assignments/media-types/
Mime::Type.register "text/html", :html, %w( application/xhtml+xml ), %w( xhtml )
Mime::Type.register "text/plain", :text, [], %w(txt)
@@ -28,7 +28,7 @@ Mime::Type.register "application/x-yaml", :yaml, %w( text/yaml ), %w(yml yaml)
Mime::Type.register "multipart/form-data", :multipart_form
Mime::Type.register "application/x-www-form-urlencoded", :url_encoded_form
-# http://www.ietf.org/rfc/rfc4627.txt
+# https://www.ietf.org/rfc/rfc4627.txt
# http://www.json.org/JSONRequest.html
Mime::Type.register "application/json", :json, %w( text/x-json application/jsonrequest )
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb
index 0b38ab7afb..dee7be184a 100644
--- a/actionpack/lib/action_dispatch/http/request.rb
+++ b/actionpack/lib/action_dispatch/http/request.rb
@@ -98,14 +98,14 @@ module ActionDispatch
end
# List of HTTP request methods from the following RFCs:
- # Hypertext Transfer Protocol -- HTTP/1.1 (http://www.ietf.org/rfc/rfc2616.txt)
- # HTTP Extensions for Distributed Authoring -- WEBDAV (http://www.ietf.org/rfc/rfc2518.txt)
- # Versioning Extensions to WebDAV (http://www.ietf.org/rfc/rfc3253.txt)
- # Ordered Collections Protocol (WebDAV) (http://www.ietf.org/rfc/rfc3648.txt)
- # Web Distributed Authoring and Versioning (WebDAV) Access Control Protocol (http://www.ietf.org/rfc/rfc3744.txt)
- # Web Distributed Authoring and Versioning (WebDAV) SEARCH (http://www.ietf.org/rfc/rfc5323.txt)
- # Calendar Extensions to WebDAV (http://www.ietf.org/rfc/rfc4791.txt)
- # PATCH Method for HTTP (http://www.ietf.org/rfc/rfc5789.txt)
+ # Hypertext Transfer Protocol -- HTTP/1.1 (https://www.ietf.org/rfc/rfc2616.txt)
+ # HTTP Extensions for Distributed Authoring -- WEBDAV (https://www.ietf.org/rfc/rfc2518.txt)
+ # Versioning Extensions to WebDAV (https://www.ietf.org/rfc/rfc3253.txt)
+ # Ordered Collections Protocol (WebDAV) (https://www.ietf.org/rfc/rfc3648.txt)
+ # Web Distributed Authoring and Versioning (WebDAV) Access Control Protocol (https://www.ietf.org/rfc/rfc3744.txt)
+ # Web Distributed Authoring and Versioning (WebDAV) SEARCH (https://www.ietf.org/rfc/rfc5323.txt)
+ # Calendar Extensions to WebDAV (https://www.ietf.org/rfc/rfc4791.txt)
+ # PATCH Method for HTTP (https://www.ietf.org/rfc/rfc5789.txt)
RFC2616 = %w(OPTIONS GET HEAD POST PUT DELETE TRACE CONNECT)
RFC2518 = %w(PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK)
RFC3253 = %w(VERSION-CONTROL REPORT CHECKOUT CHECKIN UNCHECKOUT MKWORKSPACE UPDATE LABEL MERGE BASELINE-CONTROL MKACTIVITY)
diff --git a/actionpack/lib/action_dispatch/journey/router/utils.rb b/actionpack/lib/action_dispatch/journey/router/utils.rb
index 35df7f1aae..df3f79a407 100644
--- a/actionpack/lib/action_dispatch/journey/router/utils.rb
+++ b/actionpack/lib/action_dispatch/journey/router/utils.rb
@@ -27,7 +27,7 @@ module ActionDispatch
end
# URI path and fragment escaping
- # http://tools.ietf.org/html/rfc3986
+ # https://tools.ietf.org/html/rfc3986
class UriEncoder # :nodoc:
ENCODE = "%%%02X".freeze
US_ASCII = Encoding::US_ASCII
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb
index 5a55ee13ee..c0913715ac 100644
--- a/actionpack/lib/action_dispatch/middleware/cookies.rb
+++ b/actionpack/lib/action_dispatch/middleware/cookies.rb
@@ -360,7 +360,11 @@ module ActionDispatch
@cookies.map { |k, v| "#{escape(k)}=#{escape(v)}" }.join "; "
end
- def handle_options(options) #:nodoc:
+ def handle_options(options) # :nodoc:
+ if options[:expires].respond_to?(:from_now)
+ options[:expires] = options[:expires].from_now
+ end
+
options[:path] ||= "/"
if options[:domain] == :all || options[:domain] == "all"
@@ -488,6 +492,14 @@ module ActionDispatch
def request; @parent_jar.request; end
private
+ def expiry_options(options)
+ if options[:expires].respond_to?(:from_now)
+ { expires_in: options[:expires] }
+ else
+ { expires_at: options[:expires] }
+ end
+ end
+
def parse(name, data); data; end
def commit(options); end
end
@@ -569,7 +581,7 @@ module ActionDispatch
end
def commit(options)
- options[:value] = @verifier.generate(serialize(options[:value]))
+ options[:value] = @verifier.generate(serialize(options[:value]), expiry_options(options))
raise CookieOverflow if options[:value].bytesize > MAX_COOKIE_SIZE
end
@@ -609,7 +621,7 @@ module ActionDispatch
end
def commit(options)
- options[:value] = @encryptor.encrypt_and_sign(serialize(options[:value]))
+ options[:value] = @encryptor.encrypt_and_sign(serialize(options[:value]), expiry_options(options))
raise CookieOverflow if options[:value].bytesize > MAX_COOKIE_SIZE
end
diff --git a/actionpack/lib/action_dispatch/middleware/debug_locks.rb b/actionpack/lib/action_dispatch/middleware/debug_locks.rb
index c61a941010..03760438f7 100644
--- a/actionpack/lib/action_dispatch/middleware/debug_locks.rb
+++ b/actionpack/lib/action_dispatch/middleware/debug_locks.rb
@@ -43,7 +43,7 @@ module ActionDispatch
private
def render_details(req)
- threads = ActiveSupport::Dependencies.interlock.raw_state do |threads|
+ threads = ActiveSupport::Dependencies.interlock.raw_state do |raw_threads|
# The Interlock itself comes to a complete halt as long as this block
# is executing. That gives us a more consistent picture of everything,
# but creates a pretty strong Observer Effect.
@@ -53,29 +53,29 @@ module ActionDispatch
# strictly diagnostic tool (to be used when something has gone wrong),
# and not for any sort of general monitoring.
- threads.each.with_index do |(thread, info), idx|
+ raw_threads.each.with_index do |(thread, info), idx|
info[:index] = idx
info[:backtrace] = thread.backtrace
end
- threads
+ raw_threads
end
str = threads.map do |thread, info|
if info[:exclusive]
- lock_state = "Exclusive"
+ lock_state = "Exclusive".dup
elsif info[:sharing] > 0
- lock_state = "Sharing"
+ lock_state = "Sharing".dup
lock_state << " x#{info[:sharing]}" if info[:sharing] > 1
else
- lock_state = "No lock"
+ lock_state = "No lock".dup
end
if info[:waiting]
lock_state << " (yielded share)"
end
- msg = "Thread #{info[:index]} [0x#{thread.__id__.to_s(16)} #{thread.status || 'dead'}] #{lock_state}\n"
+ msg = "Thread #{info[:index]} [0x#{thread.__id__.to_s(16)} #{thread.status || 'dead'}] #{lock_state}\n".dup
if info[:sleeper]
msg << " Waiting in #{info[:sleeper]}"
diff --git a/actionpack/lib/action_dispatch/middleware/public_exceptions.rb b/actionpack/lib/action_dispatch/middleware/public_exceptions.rb
index 02be97b4cc..3feb3a19f3 100644
--- a/actionpack/lib/action_dispatch/middleware/public_exceptions.rb
+++ b/actionpack/lib/action_dispatch/middleware/public_exceptions.rb
@@ -2,12 +2,12 @@
module ActionDispatch
# When called, this middleware renders an error page. By default if an HTML
- # response is expected it will render static error pages from the `/public`
+ # response is expected it will render static error pages from the <tt>/public</tt>
# directory. For example when this middleware receives a 500 response it will
- # render the template found in `/public/500.html`.
+ # render the template found in <tt>/public/500.html</tt>.
# If an internationalized locale is set, this middleware will attempt to render
- # the template in `/public/500.<locale>.html`. If an internationalized template
- # is not found it will fall back on `/public/500.html`.
+ # the template in <tt>/public/500.<locale>.html</tt>. If an internationalized template
+ # is not found it will fall back on <tt>/public/500.html</tt>.
#
# When a request with a content type other than HTML is made, this middleware
# will attempt to convert error information into the appropriate response type.
diff --git a/actionpack/lib/action_dispatch/middleware/remote_ip.rb b/actionpack/lib/action_dispatch/middleware/remote_ip.rb
index 7ccb99c7f0..35158f9062 100644
--- a/actionpack/lib/action_dispatch/middleware/remote_ip.rb
+++ b/actionpack/lib/action_dispatch/middleware/remote_ip.rb
@@ -12,7 +12,7 @@ module ActionDispatch
# by @gingerlime. A more detailed explanation of the algorithm is given
# at GetIp#calculate_ip.
#
- # Some Rack servers concatenate repeated headers, like {HTTP RFC 2616}[http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2]
+ # Some Rack servers concatenate repeated headers, like {HTTP RFC 2616}[https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2]
# requires. Some Rack servers simply drop preceding headers, and only report
# the value that was {given in the last header}[http://andre.arko.net/2011/12/26/repeated-headers-and-ruby-web-servers].
# If you are behind multiple proxy servers (like NGINX to HAProxy to Unicorn)
@@ -31,7 +31,7 @@ module ActionDispatch
# The default trusted IPs list simply includes IP addresses that are
# guaranteed by the IP specification to be private addresses. Those will
# not be the ultimate client IP in production, and so are discarded. See
- # http://en.wikipedia.org/wiki/Private_network for details.
+ # https://en.wikipedia.org/wiki/Private_network for details.
TRUSTED_PROXIES = [
"127.0.0.1", # localhost IPv4
"::1", # localhost IPv6
diff --git a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
index 65e93984e3..a12cb00d36 100644
--- a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
@@ -29,16 +29,16 @@ module ActionDispatch
# be encrypted, and signed cookies generated by Rails 3 will be
# transparently read and encrypted to provide a smooth upgrade path.
#
- # Configure your session store in config/initializers/session_store.rb:
+ # Configure your session store in <tt>config/initializers/session_store.rb</tt>:
#
# Rails.application.config.session_store :cookie_store, key: '_your_app_session'
#
- # Configure your secret key in config/secrets.yml:
+ # Configure your secret key in <tt>config/secrets.yml</tt>:
#
# development:
# secret_key_base: 'secret key'
#
- # To generate a secret key for an existing application, run `rails secret`.
+ # To generate a secret key for an existing application, run <tt>rails secret</tt>.
#
# If you are upgrading an existing Rails 3 app, you should leave your
# existing secret_token in place and simply add the new secret_key_base.
diff --git a/actionpack/lib/action_dispatch/middleware/ssl.rb b/actionpack/lib/action_dispatch/middleware/ssl.rb
index fb2bfbb41e..45290b6ac3 100644
--- a/actionpack/lib/action_dispatch/middleware/ssl.rb
+++ b/actionpack/lib/action_dispatch/middleware/ssl.rb
@@ -94,7 +94,7 @@ module ActionDispatch
end
end
- # http://tools.ietf.org/html/rfc6797#section-6.1
+ # https://tools.ietf.org/html/rfc6797#section-6.1
def build_hsts_header(hsts)
value = "max-age=#{hsts[:expires].to_i}".dup
value << "; includeSubDomains" if hsts[:subdomains]
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 28809d7e67..2b43ade081 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -473,7 +473,7 @@ module ActionDispatch
# <tt>params[<:param>]</tt>.
# In your router:
#
- # resources :user, param: :name
+ # resources :users, param: :name
#
# You can override <tt>ActiveRecord::Base#to_param</tt> of a related
# model to construct a URL:
@@ -1851,7 +1851,7 @@ module ActionDispatch
path_types.fetch(String, []).each do |_path|
route_options = options.dup
if _path && option_path
- raise ArgumentError, "Ambiguous route definition. Both :path and the route path where specified as strings."
+ raise ArgumentError, "Ambiguous route definition. Both :path and the route path were specified as strings."
end
to = get_to_from_path(_path, to, route_options[:action])
decomposed_match(_path, controller, route_options, _path, to, via, formatted, anchor, options_constraints)
diff --git a/actionpack/lib/action_dispatch/routing/redirection.rb b/actionpack/lib/action_dispatch/routing/redirection.rb
index a04f06de1b..2e2bc87b57 100644
--- a/actionpack/lib/action_dispatch/routing/redirection.rb
+++ b/actionpack/lib/action_dispatch/routing/redirection.rb
@@ -142,7 +142,7 @@ module ActionDispatch
# get "/stories" => redirect("/posts")
#
# This will redirect the user, while ignoring certain parts of the request, including query string, etc.
- # `/stories`, `/stories?foo=bar`, etc all redirect to `/posts`.
+ # <tt>/stories</tt>, <tt>/stories?foo=bar</tt>, etc all redirect to <tt>/posts</tt>.
#
# You can also use interpolation in the supplied redirect argument:
#
@@ -175,8 +175,8 @@ module ActionDispatch
# get '/stories', to: redirect(path: '/posts')
#
# This will redirect the user, while changing only the specified parts of the request,
- # for example the `path` option in the last example.
- # `/stories`, `/stories?foo=bar`, redirect to `/posts` and `/posts?foo=bar` respectively.
+ # for example the +path+ option in the last example.
+ # <tt>/stories</tt>, <tt>/stories?foo=bar</tt>, redirect to <tt>/posts</tt> and <tt>/posts?foo=bar</tt> respectively.
#
# Finally, an object which responds to call can be supplied to redirect, allowing you to reuse
# common redirect routes. The call method must accept two arguments, params and request, and return
diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb
index 6f3db258ab..3ae533dd37 100644
--- a/actionpack/lib/action_dispatch/routing/url_for.rb
+++ b/actionpack/lib/action_dispatch/routing/url_for.rb
@@ -109,7 +109,7 @@ module ActionDispatch
end
# Hook overridden in controller to add request information
- # with `default_url_options`. Application logic should not
+ # with +default_url_options+. Application logic should not
# go into url_options.
def url_options
default_url_options
diff --git a/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb b/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb
index 4eef15b6c2..6c337cdc31 100644
--- a/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb
+++ b/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb
@@ -16,12 +16,12 @@ module ActionDispatch
# You can set the +RAILS_SYSTEM_TESTING_SCREENSHOT+ environment variable to
# control the output. Possible values are:
# * [+inline+ (default)] display the screenshot in the terminal using the
- # iTerm image protocol (http://iterm2.com/documentation-images.html).
+ # iTerm image protocol (https://iterm2.com/documentation-images.html).
# * [+simple+] only display the screenshot path.
# This is the default value if the +CI+ environment variables
# is defined.
# * [+artifact+] display the screenshot in the terminal, using the terminal
- # artifact format (http://buildkite.github.io/terminal/inline-images/).
+ # artifact format (https://buildkite.github.io/terminal/inline-images/).
def take_screenshot
save_image
puts display_image
@@ -44,11 +44,15 @@ module ActionDispatch
end
def image_path
- "tmp/screenshots/#{image_name}.png"
+ @image_path ||= absolute_image_path.relative_path_from(Pathname.pwd).to_s
+ end
+
+ def absolute_image_path
+ Rails.root.join("tmp/screenshots/#{image_name}.png")
end
def save_image
- page.save_screenshot(Rails.root.join(image_path))
+ page.save_screenshot(absolute_image_path)
end
def output_type
@@ -65,14 +69,14 @@ module ActionDispatch
end
def display_image
- message = "[Screenshot]: #{image_path}\n"
+ message = "[Screenshot]: #{image_path}\n".dup
case output_type
when "artifact"
- message << "\e]1338;url=artifact://#{image_path}\a\n"
+ message << "\e]1338;url=artifact://#{absolute_image_path}\a\n"
when "inline"
- name = inline_base64(File.basename(image_path))
- image = inline_base64(File.read(image_path))
+ name = inline_base64(File.basename(absolute_image_path))
+ image = inline_base64(File.read(absolute_image_path))
message << "\e]1337;File=name=#{name};height=400px;inline=1:#{image}\a\n"
end
diff --git a/actionpack/lib/action_dispatch/testing/test_request.rb b/actionpack/lib/action_dispatch/testing/test_request.rb
index 0a4dec1364..6c5b7af50e 100644
--- a/actionpack/lib/action_dispatch/testing/test_request.rb
+++ b/actionpack/lib/action_dispatch/testing/test_request.rb
@@ -11,7 +11,7 @@ module ActionDispatch
"HTTP_USER_AGENT" => "Rails Testing",
)
- # Create a new test request with default `env` values.
+ # Create a new test request with default +env+ values.
def self.create(env = {})
env = Rails.application.env_config.merge(env) if defined?(Rails.application) && Rails.application
env["rack.request.cookie_hash"] ||= {}.with_indifferent_access
diff --git a/actionpack/test/dispatch/cookies_test.rb b/actionpack/test/dispatch/cookies_test.rb
index a551fb00a8..cb225c0f62 100644
--- a/actionpack/test/dispatch/cookies_test.rb
+++ b/actionpack/test/dispatch/cookies_test.rb
@@ -278,6 +278,11 @@ class CookiesTest < ActionController::TestCase
def encrypted_cookie
cookies.encrypted["foo"]
end
+
+ def cookie_expires_in_two_hours
+ cookies[:user_name] = { value: "assain", expires: 2.hours }
+ head :ok
+ end
end
tests TestController
@@ -1235,6 +1240,33 @@ class CookiesTest < ActionController::TestCase
assert_equal "bar", @controller.encrypted_cookie
end
+ def test_signed_cookie_with_expires_set_relatively
+ cookies.signed[:user_name] = { value: "assain", expires: 2.hours }
+
+ travel 1.hour
+ assert_equal "assain", cookies.signed[:user_name]
+
+ travel 2.hours
+ assert_nil cookies.signed[:user_name]
+ end
+
+ def test_encrypted_cookie_with_expires_set_relatively
+ cookies.encrypted[:user_name] = { value: "assain", expires: 2.hours }
+
+ travel 1.hour
+ assert_equal "assain", cookies.encrypted[:user_name]
+
+ travel 2.hours
+ assert_nil cookies.encrypted[:user_name]
+ end
+
+ def test_vanilla_cookie_with_expires_set_relatively
+ travel_to Time.utc(2017, 8, 15) do
+ get :cookie_expires_in_two_hours
+ assert_cookie_header "user_name=assain; path=/; expires=Tue, 15 Aug 2017 02:00:00 -0000"
+ end
+ end
+
private
def assert_cookie_header(expected)
header = @response.headers["Set-Cookie"]
diff --git a/actionpack/test/dispatch/debug_locks_test.rb b/actionpack/test/dispatch/debug_locks_test.rb
new file mode 100644
index 0000000000..d69614bd79
--- /dev/null
+++ b/actionpack/test/dispatch/debug_locks_test.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+require "abstract_unit"
+
+class DebugLocksTest < ActionDispatch::IntegrationTest
+ setup do
+ build_app
+ end
+
+ def test_render_threads_status
+ thread_ready = Concurrent::CountDownLatch.new
+ test_terminated = Concurrent::CountDownLatch.new
+
+ thread = Thread.new do
+ ActiveSupport::Dependencies.interlock.running do
+ thread_ready.count_down
+ test_terminated.wait
+ end
+ end
+
+ thread_ready.wait
+
+ get "/rails/locks"
+
+ test_terminated.count_down
+
+ assert_match(/Thread.*?Sharing/, @response.body)
+ ensure
+ thread.join
+ end
+
+ private
+ def build_app
+ @app = self.class.build_app do |middleware|
+ middleware.use ActionDispatch::DebugLocks
+ end
+ end
+end
diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb
index 26a63c9f7d..6517cf4c99 100644
--- a/actionpack/test/dispatch/session/cookie_store_test.rb
+++ b/actionpack/test/dispatch/session/cookie_store_test.rb
@@ -26,6 +26,11 @@ class CookieStoreTest < ActionDispatch::IntegrationTest
render plain: Rack::Utils.escape(Verifier.generate(session.to_hash))
end
+ def set_session_value_expires_in_five_hours
+ session[:foo] = "bar"
+ render plain: Rack::Utils.escape(Verifier.generate(session.to_hash, expires_in: 5.hours))
+ end
+
def get_session_value
render plain: "foo: #{session[:foo].inspect}"
end
@@ -283,7 +288,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest
cookies[SessionKey] = SignedBar
- get "/set_session_value"
+ get "/set_session_value_expires_in_five_hours"
assert_response :success
cookie_body = response.body
@@ -299,7 +304,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest
get "/no_session_access"
assert_response :success
- assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly",
+ assert_equal "_myapp_session=#{cookies[SessionKey]}; path=/; expires=#{expected_expiry}; HttpOnly",
headers["Set-Cookie"]
end
end
diff --git a/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb b/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb
index c8711f22d8..2afda31cf5 100644
--- a/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb
+++ b/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb
@@ -8,26 +8,57 @@ class ScreenshotHelperTest < ActiveSupport::TestCase
test "image path is saved in tmp directory" do
new_test = DrivenBySeleniumWithChrome.new("x")
- assert_equal "tmp/screenshots/x.png", new_test.send(:image_path)
+ Rails.stub :root, Pathname.getwd do
+ assert_equal "tmp/screenshots/x.png", new_test.send(:image_path)
+ end
end
test "image path includes failures text if test did not pass" do
new_test = DrivenBySeleniumWithChrome.new("x")
- new_test.stub :passed?, false do
- assert_equal "tmp/screenshots/failures_x.png", new_test.send(:image_path)
+ Rails.stub :root, Pathname.getwd do
+ new_test.stub :passed?, false do
+ assert_equal "tmp/screenshots/failures_x.png", new_test.send(:image_path)
+ end
end
end
test "image path does not include failures text if test skipped" do
new_test = DrivenBySeleniumWithChrome.new("x")
- new_test.stub :passed?, false do
- new_test.stub :skipped?, true do
- assert_equal "tmp/screenshots/x.png", new_test.send(:image_path)
+ Rails.stub :root, Pathname.getwd do
+ new_test.stub :passed?, false do
+ new_test.stub :skipped?, true do
+ assert_equal "tmp/screenshots/x.png", new_test.send(:image_path)
+ end
end
end
end
+
+ test "display_image return artifact format when specify RAILS_SYSTEM_TESTING_SCREENSHOT environment" do
+ begin
+ original_output_type = ENV["RAILS_SYSTEM_TESTING_SCREENSHOT"]
+ ENV["RAILS_SYSTEM_TESTING_SCREENSHOT"] = "artifact"
+
+ new_test = DrivenBySeleniumWithChrome.new("x")
+
+ Rails.stub :root, Pathname.getwd do
+ new_test.stub :passed?, false do
+ assert_match %r|url=artifact://.+?tmp/screenshots/failures_x\.png|, new_test.send(:display_image)
+ end
+ end
+ ensure
+ ENV["RAILS_SYSTEM_TESTING_SCREENSHOT"] = original_output_type
+ end
+ end
+
+ test "image path returns the relative path from current directory" do
+ new_test = DrivenBySeleniumWithChrome.new("x")
+
+ Rails.stub :root, Pathname.getwd.join("..") do
+ assert_equal "../tmp/screenshots/x.png", new_test.send(:image_path)
+ end
+ end
end
class RackTestScreenshotsTest < DrivenByRackTest
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md
index 5bc93fcb5b..b22686d1d8 100644
--- a/actionview/CHANGELOG.md
+++ b/actionview/CHANGELOG.md
@@ -1,3 +1,9 @@
+* Remove default `alt` text generation.
+
+ Fixes #30096
+
+ *Cameron Cundiff*
+
* Add `srcset` option to `image_tag` helper.
*Roberto Miranda*
diff --git a/actionview/README.rdoc b/actionview/README.rdoc
index 7a3e5e31d0..d5029599b7 100644
--- a/actionview/README.rdoc
+++ b/actionview/README.rdoc
@@ -20,7 +20,7 @@ Source code can be downloaded as part of the Rails project on GitHub
Action View is released under the MIT license:
-* http://www.opensource.org/licenses/MIT
+* https://opensource.org/licenses/MIT
== Support
diff --git a/actionview/lib/action_view/helpers/active_model_helper.rb b/actionview/lib/action_view/helpers/active_model_helper.rb
index 46b514012c..f1ef715710 100644
--- a/actionview/lib/action_view/helpers/active_model_helper.rb
+++ b/actionview/lib/action_view/helpers/active_model_helper.rb
@@ -5,7 +5,7 @@ require "active_support/core_ext/enumerable"
module ActionView
# = Active Model Helpers
- module Helpers
+ module Helpers #:nodoc:
module ActiveModelHelper
end
diff --git a/actionview/lib/action_view/helpers/asset_tag_helper.rb b/actionview/lib/action_view/helpers/asset_tag_helper.rb
index 82b0fcbf2e..bc2713d13e 100644
--- a/actionview/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionview/lib/action_view/helpers/asset_tag_helper.rb
@@ -13,7 +13,7 @@ module ActionView
# the assets exist before linking to them:
#
# image_tag("rails.png")
- # # => <img alt="Rails" src="/assets/rails.png" />
+ # # => <img src="/assets/rails.png" />
# stylesheet_link_tag("application")
# # => <link href="/assets/application.css?body=1" media="screen" rel="stylesheet" />
module AssetTagHelper
@@ -207,8 +207,6 @@ module ActionView
# You can add HTML attributes using the +options+. The +options+ supports
# additional keys for convenience and conformance:
#
- # * <tt>:alt</tt> - If no alt text is given, the file name part of the
- # +source+ is used (capitalized and without the extension)
# * <tt>:size</tt> - Supplied as "{Width}x{Height}" or "{Number}", so "30x45" becomes
# width="30" and height="45", and "50" becomes width="50" and height="50".
# <tt>:size</tt> will be ignored if the value is not in the correct format.
@@ -220,17 +218,17 @@ module ActionView
# Assets (images that are part of your app):
#
# image_tag("icon")
- # # => <img alt="Icon" src="/assets/icon" />
+ # # => <img src="/assets/icon" />
# image_tag("icon.png")
- # # => <img alt="Icon" src="/assets/icon.png" />
+ # # => <img src="/assets/icon.png" />
# image_tag("icon.png", size: "16x10", alt: "Edit Entry")
# # => <img src="/assets/icon.png" width="16" height="10" alt="Edit Entry" />
# image_tag("/icons/icon.gif", size: "16")
- # # => <img src="/icons/icon.gif" width="16" height="16" alt="Icon" />
+ # # => <img src="/icons/icon.gif" width="16" height="16" />
# image_tag("/icons/icon.gif", height: '32', width: '32')
- # # => <img alt="Icon" height="32" src="/icons/icon.gif" width="32" />
+ # # => <img height="32" src="/icons/icon.gif" width="32" />
# image_tag("/icons/icon.gif", class: "menu_icon")
- # # => <img alt="Icon" class="menu_icon" src="/icons/icon.gif" />
+ # # => <img class="menu_icon" src="/icons/icon.gif" />
# image_tag("/icons/icon.gif", data: { title: 'Rails Application' })
# # => <img data-title="Rails Application" src="/icons/icon.gif" />
# image_tag("icon.png", srcset: { "icon_2x.png" => "2x", "icon_4x.png" => "4x" })
@@ -241,21 +239,17 @@ module ActionView
# Active Storage (images that are uploaded by the users of your app):
#
# image_tag(user.avatar)
- # # => <img src="/rails/active_storage/blobs/.../tiger.jpg" alt="Tiger" />
+ # # => <img src="/rails/active_storage/blobs/.../tiger.jpg" />
# image_tag(user.avatar.variant(resize: "100x100"))
- # # => <img src="/rails/active_storage/variants/.../tiger.jpg" alt="Tiger" />
+ # # => <img src="/rails/active_storage/variants/.../tiger.jpg" />
# image_tag(user.avatar.variant(resize: "100x100"), size: '100')
- # # => <img width="100" height="100" src="/rails/active_storage/variants/.../tiger.jpg" alt="Tiger" />
+ # # => <img width="100" height="100" src="/rails/active_storage/variants/.../tiger.jpg" />
def image_tag(source, options = {})
options = options.symbolize_keys
check_for_image_tag_errors(options)
skip_pipeline = options.delete(:skip_pipeline)
- src = options[:src] = resolve_image_source(source, skip_pipeline)
-
- unless src.start_with?("cid:") || src.start_with?("data:") || src.blank?
- options[:alt] = options.fetch(:alt) { image_alt(src) }
- end
+ options[:src] = resolve_image_source(source, skip_pipeline)
if options[:srcset] && !options[:srcset].is_a?(String)
options[:srcset] = options[:srcset].map do |src_path, size|
@@ -286,6 +280,8 @@ module ActionView
# image_alt('underscored_file_name.png')
# # => Underscored file name
def image_alt(src)
+ ActiveSupport::Deprecation.warn("image_alt is deprecated and will be removed from Rails 6.0. You must explicitly set alt text on images.")
+
File.basename(src, ".*".freeze).sub(/-[[:xdigit:]]{32,64}\z/, "".freeze).tr("-_".freeze, " ".freeze).capitalize
end
diff --git a/actionview/lib/action_view/helpers/asset_url_helper.rb b/actionview/lib/action_view/helpers/asset_url_helper.rb
index 4c131aa27a..a4dcfc9a6c 100644
--- a/actionview/lib/action_view/helpers/asset_url_helper.rb
+++ b/actionview/lib/action_view/helpers/asset_url_helper.rb
@@ -4,7 +4,7 @@ require "zlib"
module ActionView
# = Action View Asset URL Helpers
- module Helpers
+ module Helpers #:nodoc:
# This module provides methods for generating asset paths and
# urls.
#
@@ -29,7 +29,7 @@ module ActionView
# Helpers take that into account:
#
# image_tag("rails.png")
- # # => <img alt="Rails" src="http://assets.example.com/assets/rails.png" />
+ # # => <img src="http://assets.example.com/assets/rails.png" />
# stylesheet_link_tag("application")
# # => <link href="http://assets.example.com/assets/application.css" media="screen" rel="stylesheet" />
#
@@ -42,7 +42,7 @@ module ActionView
# "assets0.example.com", ..., "assets3.example.com".
#
# image_tag("rails.png")
- # # => <img alt="Rails" src="http://assets0.example.com/assets/rails.png" />
+ # # => <img src="http://assets0.example.com/assets/rails.png" />
# stylesheet_link_tag("application")
# # => <link href="http://assets2.example.com/assets/application.css" media="screen" rel="stylesheet" />
#
@@ -68,7 +68,7 @@ module ActionView
# "http://assets#{Digest::MD5.hexdigest(source).to_i(16) % 2 + 1}.example.com"
# }
# image_tag("rails.png")
- # # => <img alt="Rails" src="http://assets1.example.com/assets/rails.png" />
+ # # => <img src="http://assets1.example.com/assets/rails.png" />
# stylesheet_link_tag("application")
# # => <link href="http://assets2.example.com/assets/application.css" media="screen" rel="stylesheet" />
#
@@ -87,7 +87,7 @@ module ActionView
# end
# }
# image_tag("rails.png")
- # # => <img alt="Rails" src="http://assets.example.com/assets/rails.png" />
+ # # => <img src="http://assets.example.com/assets/rails.png" />
# stylesheet_link_tag("application")
# # => <link href="http://stylesheets.example.com/assets/application.css" media="screen" rel="stylesheet" />
#
diff --git a/actionview/lib/action_view/helpers/atom_feed_helper.rb b/actionview/lib/action_view/helpers/atom_feed_helper.rb
index 34245b5df5..e6b9878271 100644
--- a/actionview/lib/action_view/helpers/atom_feed_helper.rb
+++ b/actionview/lib/action_view/helpers/atom_feed_helper.rb
@@ -4,7 +4,7 @@ require "set"
module ActionView
# = Action View Atom Feed Helpers
- module Helpers
+ module Helpers #:nodoc:
module AtomFeedHelper
# Adds easy defaults to writing Atom feeds with the Builder template engine (this does not work on ERB or any other
# template languages).
diff --git a/actionview/lib/action_view/helpers/cache_helper.rb b/actionview/lib/action_view/helpers/cache_helper.rb
index cd213ad6a2..3cbb1ed1a7 100644
--- a/actionview/lib/action_view/helpers/cache_helper.rb
+++ b/actionview/lib/action_view/helpers/cache_helper.rb
@@ -2,7 +2,7 @@
module ActionView
# = Action View Cache Helper
- module Helpers
+ module Helpers #:nodoc:
module CacheHelper
# This helper exposes a method for caching fragments of a view
# rather than an entire action or page. This technique is useful
@@ -111,9 +111,9 @@ module ActionView
# <%= render_categorizable_events @person.events %>
#
# This marks every template in the directory as a dependency. To find those
- # templates, the wildcard path must be absolutely defined from app/views or paths
+ # templates, the wildcard path must be absolutely defined from <tt>app/views</tt> or paths
# otherwise added with +prepend_view_path+ or +append_view_path+.
- # This way the wildcard for `app/views/recordings/events` would be `recordings/events/*` etc.
+ # This way the wildcard for <tt>app/views/recordings/events</tt> would be <tt>recordings/events/*</tt> etc.
#
# The pattern used to match explicit dependencies is <tt>/# Template Dependency: (\S+)/</tt>,
# so it's important that you type it out just so.
@@ -133,14 +133,14 @@ module ActionView
#
# === Collection Caching
#
- # When rendering a collection of objects that each use the same partial, a `cached`
+ # When rendering a collection of objects that each use the same partial, a <tt>:cached</tt>
# option can be passed.
#
# For collections rendered such:
#
# <%= render partial: 'projects/project', collection: @projects, cached: true %>
#
- # The `cached: true` will make Action View's rendering read several templates
+ # The <tt>cached: true</tt> will make Action View's rendering read several templates
# from cache at once instead of one call per template.
#
# Templates in the collection not already cached are written to cache.
diff --git a/actionview/lib/action_view/helpers/capture_helper.rb b/actionview/lib/action_view/helpers/capture_helper.rb
index 690ce6a0ee..92f7ddb70d 100644
--- a/actionview/lib/action_view/helpers/capture_helper.rb
+++ b/actionview/lib/action_view/helpers/capture_helper.rb
@@ -4,12 +4,12 @@ require "active_support/core_ext/string/output_safety"
module ActionView
# = Action View Capture Helper
- module Helpers
+ module Helpers #:nodoc:
# CaptureHelper exposes methods to let you extract generated markup which
# can be used in other parts of a template or layout file.
#
# It provides a method to capture blocks into variables through capture and
- # a way to capture a block of markup for use in a layout through content_for.
+ # a way to capture a block of markup for use in a layout through {content_for}[rdoc-ref:ActionView::Helpers::CaptureHelper#content_for].
module CaptureHelper
# The capture method extracts part of a template as a String object.
# You can then use this object anywhere in your templates, layout, or helpers.
@@ -44,7 +44,7 @@ module ActionView
end
end
- # Calling content_for stores a block of markup in an identifier for later use.
+ # Calling <tt>content_for</tt> stores a block of markup in an identifier for later use.
# In order to access this stored content in other templates, helper modules
# or the layout, you would pass the identifier as an argument to <tt>content_for</tt>.
#
@@ -110,7 +110,7 @@ module ActionView
# That will place +script+ tags for your default set of JavaScript files on the page;
# this technique is useful if you'll only be using these scripts in a few views.
#
- # Note that content_for concatenates (default) the blocks it is given for a particular
+ # Note that <tt>content_for</tt> concatenates (default) the blocks it is given for a particular
# identifier in order. For example:
#
# <% content_for :navigation do %>
@@ -127,7 +127,7 @@ module ActionView
#
# <ul><%= content_for :navigation %></ul>
#
- # If the flush parameter is true content_for replaces the blocks it is given. For example:
+ # If the flush parameter is +true+ <tt>content_for</tt> replaces the blocks it is given. For example:
#
# <% content_for :navigation do %>
# <li><%= link_to 'Home', action: 'index' %></li>
@@ -147,7 +147,7 @@ module ActionView
#
# <% content_for :script, javascript_include_tag(:defaults) %>
#
- # WARNING: content_for is ignored in caches. So you shouldn't use it for elements that will be fragment cached.
+ # WARNING: <tt>content_for</tt> is ignored in caches. So you shouldn't use it for elements that will be fragment cached.
def content_for(name, content = nil, options = {}, &block)
if content || block_given?
if block_given?
@@ -174,7 +174,7 @@ module ActionView
result unless content
end
- # content_for? checks whether any content has been captured yet using `content_for`.
+ # <tt>content_for?</tt> checks whether any content has been captured yet using <tt>content_for</tt>.
# Useful to render parts of your layout differently based on what is in your views.
#
# <%# This is the layout %>
diff --git a/actionview/lib/action_view/helpers/controller_helper.rb b/actionview/lib/action_view/helpers/controller_helper.rb
index 00d8b9665d..79cf86c7d1 100644
--- a/actionview/lib/action_view/helpers/controller_helper.rb
+++ b/actionview/lib/action_view/helpers/controller_helper.rb
@@ -3,7 +3,7 @@
require "active_support/core_ext/module/attr_internal"
module ActionView
- module Helpers
+ module Helpers #:nodoc:
# This module keeps all methods and behavior in ActionView
# that simply delegates to the controller.
module ControllerHelper #:nodoc:
diff --git a/actionview/lib/action_view/helpers/csrf_helper.rb b/actionview/lib/action_view/helpers/csrf_helper.rb
index d1b83f87d3..69c59844a6 100644
--- a/actionview/lib/action_view/helpers/csrf_helper.rb
+++ b/actionview/lib/action_view/helpers/csrf_helper.rb
@@ -2,7 +2,7 @@
module ActionView
# = Action View CSRF Helper
- module Helpers
+ module Helpers #:nodoc:
module CsrfHelper
# Returns meta tags "csrf-param" and "csrf-token" with the name of the cross-site
# request forgery protection parameter and token, respectively.
diff --git a/actionview/lib/action_view/helpers/date_helper.rb b/actionview/lib/action_view/helpers/date_helper.rb
index 339d582f76..642bd0fec6 100644
--- a/actionview/lib/action_view/helpers/date_helper.rb
+++ b/actionview/lib/action_view/helpers/date_helper.rb
@@ -9,7 +9,7 @@ require "active_support/core_ext/object/acts_like"
require "active_support/core_ext/object/with_options"
module ActionView
- module Helpers
+ module Helpers #:nodoc:
# = Action View Date Helpers
#
# The Date Helper primarily creates select/option tags for different kinds of dates and times or date and time
diff --git a/actionview/lib/action_view/helpers/debug_helper.rb b/actionview/lib/action_view/helpers/debug_helper.rb
index 232d688077..52dff1f750 100644
--- a/actionview/lib/action_view/helpers/debug_helper.rb
+++ b/actionview/lib/action_view/helpers/debug_helper.rb
@@ -4,7 +4,7 @@ module ActionView
# = Action View Debug Helper
#
# Provides a set of methods for making it easier to debug Rails objects.
- module Helpers
+ module Helpers #:nodoc:
module DebugHelper
include TagHelper
diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb
index e5a2f7e520..6702c65ccb 100644
--- a/actionview/lib/action_view/helpers/form_helper.rb
+++ b/actionview/lib/action_view/helpers/form_helper.rb
@@ -14,7 +14,7 @@ require "active_support/core_ext/string/inflections"
module ActionView
# = Action View Form Helpers
- module Helpers
+ module Helpers #:nodoc:
# Form helpers are designed to make working with resources much easier
# compared to using vanilla HTML.
#
@@ -543,6 +543,36 @@ module ActionView
# and adds an authenticity token needed for cross site request forgery
# protection.
#
+ # === Resource-oriented style
+ #
+ # In many of the examples just shown, the +:model+ passed to +form_with+
+ # is a _resource_. It corresponds to a set of RESTful routes, most likely
+ # defined via +resources+ in <tt>config/routes.rb</tt>.
+ #
+ # So when passing such a model record, Rails infers the URL and method.
+ #
+ # <%= form_with model: @post do |form| %>
+ # ...
+ # <% end %>
+ #
+ # is then equivalent to something like:
+ #
+ # <%= form_with scope: :post, url: post_path(@post), method: :patch do |form| %>
+ # ...
+ # <% end %>
+ #
+ # And for a new record
+ #
+ # <%= form_with model: Post.new do |form| %>
+ # ...
+ # <% end %>
+ #
+ # is equivalent to something like:
+ #
+ # <%= form_with scope: :post, url: posts_path do |form| %>
+ # ...
+ # <% end %>
+ #
# ==== +form_with+ options
#
# * <tt>:url</tt> - The URL the form submits to. Akin to values passed to
diff --git a/actionview/lib/action_view/helpers/form_options_helper.rb b/actionview/lib/action_view/helpers/form_options_helper.rb
index 0f1a452652..1517abfad0 100644
--- a/actionview/lib/action_view/helpers/form_options_helper.rb
+++ b/actionview/lib/action_view/helpers/form_options_helper.rb
@@ -9,7 +9,7 @@ require "active_support/core_ext/array/wrap"
module ActionView
# = Action View Form Option Helpers
- module Helpers
+ module Helpers #:nodoc:
# Provides a number of methods for turning different kinds of containers into a set of option tags.
#
# The <tt>collection_select</tt>, <tt>select</tt> and <tt>time_zone_select</tt> methods take an <tt>options</tt> parameter, a hash:
diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb
index 2519ff2837..31a1f8be8c 100644
--- a/actionview/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionview/lib/action_view/helpers/form_tag_helper.rb
@@ -7,7 +7,7 @@ require "active_support/core_ext/module/attribute_accessors"
module ActionView
# = Action View Form Tag Helpers
- module Helpers
+ module Helpers #:nodoc:
# Provides a number of methods for creating form tags that don't rely on an Active Record object assigned to the template like
# FormHelper does. Instead, you provide the names and values manually.
#
@@ -456,7 +456,7 @@ module ActionView
# submit tag but it isn't supported in legacy browsers. However,
# the button tag does allow for richer labels such as images and emphasis,
# so this helper will also accept a block. By default, it will create
- # a button tag with type `submit`, if type is not given.
+ # a button tag with type <tt>submit</tt>, if type is not given.
#
# ==== Options
# * <tt>:data</tt> - This option can be used to add custom data attributes.
@@ -534,22 +534,22 @@ module ActionView
#
# ==== Examples
# image_submit_tag("login.png")
- # # => <input alt="Login" src="/assets/login.png" type="image" />
+ # # => <input src="/assets/login.png" type="image" />
#
# image_submit_tag("purchase.png", disabled: true)
- # # => <input alt="Purchase" disabled="disabled" src="/assets/purchase.png" type="image" />
+ # # => <input disabled="disabled" src="/assets/purchase.png" type="image" />
#
# image_submit_tag("search.png", class: 'search_button', alt: 'Find')
- # # => <input alt="Find" class="search_button" src="/assets/search.png" type="image" />
+ # # => <input class="search_button" src="/assets/search.png" type="image" />
#
# image_submit_tag("agree.png", disabled: true, class: "agree_disagree_button")
- # # => <input alt="Agree" class="agree_disagree_button" disabled="disabled" src="/assets/agree.png" type="image" />
+ # # => <input class="agree_disagree_button" disabled="disabled" src="/assets/agree.png" type="image" />
#
# image_submit_tag("save.png", data: { confirm: "Are you sure?" })
- # # => <input alt="Save" src="/assets/save.png" data-confirm="Are you sure?" type="image" />
+ # # => <input src="/assets/save.png" data-confirm="Are you sure?" type="image" />
def image_submit_tag(source, options = {})
options = options.stringify_keys
- tag :input, { "alt" => image_alt(source), "type" => "image", "src" => path_to_image(source) }.update(options)
+ tag :input, { "type" => "image", "src" => path_to_image(source) }.update(options)
end
# Creates a field set for grouping HTML form elements.
diff --git a/actionview/lib/action_view/helpers/javascript_helper.rb b/actionview/lib/action_view/helpers/javascript_helper.rb
index cce7c1dcfd..11eefe0ee0 100644
--- a/actionview/lib/action_view/helpers/javascript_helper.rb
+++ b/actionview/lib/action_view/helpers/javascript_helper.rb
@@ -3,7 +3,7 @@
require_relative "tag_helper"
module ActionView
- module Helpers
+ module Helpers #:nodoc:
module JavaScriptHelper
JS_ESCAPE_MAP = {
'\\' => '\\\\',
diff --git a/actionview/lib/action_view/helpers/record_tag_helper.rb b/actionview/lib/action_view/helpers/record_tag_helper.rb
index 4303de4209..a6953ee905 100644
--- a/actionview/lib/action_view/helpers/record_tag_helper.rb
+++ b/actionview/lib/action_view/helpers/record_tag_helper.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module ActionView
- module Helpers
+ module Helpers #:nodoc:
module RecordTagHelper
def div_for(*) # :nodoc:
raise NoMethodError, "The `div_for` method has been removed from " \
diff --git a/actionview/lib/action_view/helpers/rendering_helper.rb b/actionview/lib/action_view/helpers/rendering_helper.rb
index 2702fa28b2..8e505ab054 100644
--- a/actionview/lib/action_view/helpers/rendering_helper.rb
+++ b/actionview/lib/action_view/helpers/rendering_helper.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module ActionView
- module Helpers
+ module Helpers #:nodoc:
# = Action View Rendering
#
# Implements methods that allow rendering from a view context.
diff --git a/actionview/lib/action_view/helpers/sanitize_helper.rb b/actionview/lib/action_view/helpers/sanitize_helper.rb
index 713b2fbb45..275a2dffb4 100644
--- a/actionview/lib/action_view/helpers/sanitize_helper.rb
+++ b/actionview/lib/action_view/helpers/sanitize_helper.rb
@@ -5,7 +5,7 @@ require "rails-html-sanitizer"
module ActionView
# = Action View Sanitize Helpers
- module Helpers
+ module Helpers #:nodoc:
# The SanitizeHelper module provides a set of methods for scrubbing text of undesired HTML elements.
# These helper methods extend Action View making them callable within your template files.
module SanitizeHelper
diff --git a/actionview/lib/action_view/helpers/tags.rb b/actionview/lib/action_view/helpers/tags.rb
index 2552ebba4e..566668b958 100644
--- a/actionview/lib/action_view/helpers/tags.rb
+++ b/actionview/lib/action_view/helpers/tags.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module ActionView
- module Helpers
+ module Helpers #:nodoc:
module Tags #:nodoc:
extend ActiveSupport::Autoload
diff --git a/actionview/lib/action_view/helpers/translation_helper.rb b/actionview/lib/action_view/helpers/translation_helper.rb
index 75c1161de1..e663892592 100644
--- a/actionview/lib/action_view/helpers/translation_helper.rb
+++ b/actionview/lib/action_view/helpers/translation_helper.rb
@@ -6,7 +6,7 @@ require "i18n/exceptions"
module ActionView
# = Action View Translation Helpers
- module Helpers
+ module Helpers #:nodoc:
module TranslationHelper
extend ActiveSupport::Concern
diff --git a/actionview/lib/action_view/renderer/partial_renderer.rb b/actionview/lib/action_view/renderer/partial_renderer.rb
index f2edcb750c..beb0a18b65 100644
--- a/actionview/lib/action_view/renderer/partial_renderer.rb
+++ b/actionview/lib/action_view/renderer/partial_renderer.rb
@@ -52,12 +52,12 @@ module ActionView
# <%= render partial: "ad", locals: { ad: ad } %>
# <% end %>
#
- # This would first render "advertiser/_account.html.erb" with @buyer passed in as the local variable +account+, then
- # render "advertiser/_ad.html.erb" and pass the local variable +ad+ to the template for display.
+ # This would first render <tt>advertiser/_account.html.erb</tt> with <tt>@buyer</tt> passed in as the local variable +account+, then
+ # render <tt>advertiser/_ad.html.erb</tt> and pass the local variable +ad+ to the template for display.
#
# == The :as and :object options
#
- # By default <tt>ActionView::PartialRenderer</tt> doesn't have any local variables.
+ # By default ActionView::PartialRenderer doesn't have any local variables.
# The <tt>:object</tt> option can be used to pass an object to the partial. For instance:
#
# <%= render partial: "account", object: @buyer %>
@@ -85,7 +85,7 @@ module ActionView
#
# <%= render partial: "ad", collection: @advertisements %>
#
- # This will render "advertiser/_ad.html.erb" and pass the local variable +ad+ to the template for display. An
+ # This will render <tt>advertiser/_ad.html.erb</tt> and pass the local variable +ad+ to the template for display. An
# iteration object will automatically be made available to the template with a name of the form
# +partial_name_iteration+. The iteration object has knowledge about which index the current object has in
# the collection and the total size of the collection. The iteration object also has two convenience methods,
@@ -100,7 +100,7 @@ module ActionView
#
# <%= render partial: "ad", collection: @advertisements, spacer_template: "ad_divider" %>
#
- # If the given <tt>:collection</tt> is +nil+ or empty, <tt>render</tt> will return nil. This will allow you
+ # If the given <tt>:collection</tt> is +nil+ or empty, <tt>render</tt> will return +nil+. This will allow you
# to specify a text which will be displayed instead by using this form:
#
# <%= render(partial: "ad", collection: @advertisements) || "There's no ad to be displayed" %>
@@ -114,18 +114,18 @@ module ActionView
#
# <%= render partial: "advertisement/ad", locals: { ad: @advertisement } %>
#
- # This will render the partial "advertisement/_ad.html.erb" regardless of which controller this is being called from.
+ # This will render the partial <tt>advertisement/_ad.html.erb</tt> regardless of which controller this is being called from.
#
- # == \Rendering objects that respond to `to_partial_path`
+ # == \Rendering objects that respond to +to_partial_path+
#
# Instead of explicitly naming the location of a partial, you can also let PartialRenderer do the work
- # and pick the proper path by checking `to_partial_path` method.
+ # and pick the proper path by checking +to_partial_path+ method.
#
# # @account.to_partial_path returns 'accounts/account', so it can be used to replace:
# # <%= render partial: "accounts/account", locals: { account: @account} %>
# <%= render partial: @account %>
#
- # # @posts is an array of Post instances, so every post record returns 'posts/post' on `to_partial_path`,
+ # # @posts is an array of Post instances, so every post record returns 'posts/post' on +to_partial_path+,
# # that's why we can replace:
# # <%= render partial: "posts/post", collection: @posts %>
# <%= render partial: @posts %>
@@ -145,7 +145,7 @@ module ActionView
# # <%= render partial: "accounts/account", locals: { account: @account} %>
# <%= render @account %>
#
- # # @posts is an array of Post instances, so every post record returns 'posts/post' on `to_partial_path`,
+ # # @posts is an array of Post instances, so every post record returns 'posts/post' on +to_partial_path+,
# # that's why we can replace:
# # <%= render partial: "posts/post", collection: @posts %>
# <%= render @posts %>
diff --git a/actionview/lib/action_view/template/handlers.rb b/actionview/lib/action_view/template/handlers.rb
index b3df0aa606..7ec76dcc3f 100644
--- a/actionview/lib/action_view/template/handlers.rb
+++ b/actionview/lib/action_view/template/handlers.rb
@@ -2,7 +2,7 @@
module ActionView #:nodoc:
# = Action View Template Handlers
- class Template
+ class Template #:nodoc:
module Handlers #:nodoc:
autoload :Raw, "action_view/template/handlers/raw"
autoload :ERB, "action_view/template/handlers/erb"
diff --git a/actionview/lib/action_view/template/html.rb b/actionview/lib/action_view/template/html.rb
index 540597efa1..a262c6d9ad 100644
--- a/actionview/lib/action_view/template/html.rb
+++ b/actionview/lib/action_view/template/html.rb
@@ -2,7 +2,7 @@
module ActionView #:nodoc:
# = Action View HTML Template
- class Template
+ class Template #:nodoc:
class HTML #:nodoc:
attr_accessor :type
diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb
index 708dee3164..a58d375293 100644
--- a/actionview/lib/action_view/template/resolver.rb
+++ b/actionview/lib/action_view/template/resolver.rb
@@ -310,13 +310,13 @@ module ActionView
# ==== Examples
#
# Default pattern, loads views the same way as previous versions of rails, eg. when you're
- # looking for `users/new` it will produce query glob: `users/new{.{en},}{.{html,js},}{.{erb,haml},}`
+ # looking for <tt>users/new</tt> it will produce query glob: <tt>users/new{.{en},}{.{html,js},}{.{erb,haml},}</tt>
#
# FileSystemResolver.new("/path/to/views", ":prefix/:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}")
#
# This one allows you to keep files with different formats in separate subdirectories,
- # eg. `users/new.html` will be loaded from `users/html/new.erb` or `users/new.html.erb`,
- # `users/new.js` from `users/js/new.erb` or `users/new.js.erb`, etc.
+ # eg. <tt>users/new.html</tt> will be loaded from <tt>users/html/new.erb</tt> or <tt>users/new.html.erb</tt>,
+ # <tt>users/new.js</tt> from <tt>users/js/new.erb</tt> or <tt>users/new.js.erb</tt>, etc.
#
# FileSystemResolver.new("/path/to/views", ":prefix/{:formats/,}:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}")
#
diff --git a/actionview/lib/action_view/template/text.rb b/actionview/lib/action_view/template/text.rb
index f070005881..f8d6c2811f 100644
--- a/actionview/lib/action_view/template/text.rb
+++ b/actionview/lib/action_view/template/text.rb
@@ -2,7 +2,7 @@
module ActionView #:nodoc:
# = Action View Text Template
- class Template
+ class Template #:nodoc:
class Text #:nodoc:
attr_accessor :type
diff --git a/actionview/lib/action_view/template/types.rb b/actionview/lib/action_view/template/types.rb
index f0f37c9722..67b7a62de6 100644
--- a/actionview/lib/action_view/template/types.rb
+++ b/actionview/lib/action_view/template/types.rb
@@ -3,7 +3,7 @@
require "active_support/core_ext/module/attribute_accessors"
module ActionView
- class Template
+ class Template #:nodoc:
class Types
class Type
SET = Struct.new(:symbols).new([ :html, :text, :js, :css, :xml, :json ])
diff --git a/actionview/test/template/asset_tag_helper_test.rb b/actionview/test/template/asset_tag_helper_test.rb
index 5b8e50cc5e..6645839f0e 100644
--- a/actionview/test/template/asset_tag_helper_test.rb
+++ b/actionview/test/template/asset_tag_helper_test.rb
@@ -183,26 +183,26 @@ class AssetTagHelperTest < ActionView::TestCase
}
ImageLinkToTag = {
- %(image_tag("xml.png")) => %(<img alt="Xml" src="/images/xml.png" />),
+ %(image_tag("xml.png")) => %(<img src="/images/xml.png" />),
%(image_tag("rss.gif", :alt => "rss syndication")) => %(<img alt="rss syndication" src="/images/rss.gif" />),
- %(image_tag("gold.png", :size => "20")) => %(<img alt="Gold" height="20" src="/images/gold.png" width="20" />),
- %(image_tag("gold.png", :size => 20)) => %(<img alt="Gold" height="20" src="/images/gold.png" width="20" />),
- %(image_tag("gold.png", :size => "45x70")) => %(<img alt="Gold" height="70" src="/images/gold.png" width="45" />),
- %(image_tag("gold.png", "size" => "45x70")) => %(<img alt="Gold" height="70" src="/images/gold.png" width="45" />),
- %(image_tag("error.png", "size" => "45 x 70")) => %(<img alt="Error" src="/images/error.png" />),
- %(image_tag("error.png", "size" => "x")) => %(<img alt="Error" src="/images/error.png" />),
- %(image_tag("google.com.png")) => %(<img alt="Google.com" src="/images/google.com.png" />),
- %(image_tag("slash..png")) => %(<img alt="Slash." src="/images/slash..png" />),
- %(image_tag(".pdf.png")) => %(<img alt=".pdf" src="/images/.pdf.png" />),
- %(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />),
- %(image_tag("//www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="//www.rubyonrails.com/images/rails.png" />),
+ %(image_tag("gold.png", :size => "20")) => %(<img height="20" src="/images/gold.png" width="20" />),
+ %(image_tag("gold.png", :size => 20)) => %(<img height="20" src="/images/gold.png" width="20" />),
+ %(image_tag("gold.png", :size => "45x70")) => %(<img height="70" src="/images/gold.png" width="45" />),
+ %(image_tag("gold.png", "size" => "45x70")) => %(<img height="70" src="/images/gold.png" width="45" />),
+ %(image_tag("error.png", "size" => "45 x 70")) => %(<img src="/images/error.png" />),
+ %(image_tag("error.png", "size" => "x")) => %(<img src="/images/error.png" />),
+ %(image_tag("google.com.png")) => %(<img src="/images/google.com.png" />),
+ %(image_tag("slash..png")) => %(<img src="/images/slash..png" />),
+ %(image_tag(".pdf.png")) => %(<img src="/images/.pdf.png" />),
+ %(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(<img src="http://www.rubyonrails.com/images/rails.png" />),
+ %(image_tag("//www.rubyonrails.com/images/rails.png")) => %(<img src="//www.rubyonrails.com/images/rails.png" />),
%(image_tag("mouse.png", :alt => nil)) => %(<img src="/images/mouse.png" />),
%(image_tag("data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==", :alt => nil)) => %(<img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" />),
%(image_tag("")) => %(<img src="" />),
- %(image_tag("gold.png", data: { title: 'Rails Application' })) => %(<img data-title="Rails Application" src="/images/gold.png" alt="Gold" />),
- %(image_tag("rss.gif", srcset: "/assets/pic_640.jpg 640w, /assets/pic_1024.jpg 1024w")) => %(<img srcset="/assets/pic_640.jpg 640w, /assets/pic_1024.jpg 1024w" src="/images/rss.gif" alt="Rss" />),
- %(image_tag("rss.gif", srcset: { "pic_640.jpg" => "640w", "pic_1024.jpg" => "1024w" })) => %(<img srcset="/images/pic_640.jpg 640w, /images/pic_1024.jpg 1024w" src="/images/rss.gif" alt="Rss" />),
- %(image_tag("rss.gif", srcset: [["pic_640.jpg", "640w"], ["pic_1024.jpg", "1024w"]])) => %(<img srcset="/images/pic_640.jpg 640w, /images/pic_1024.jpg 1024w" src="/images/rss.gif" alt="Rss" />)
+ %(image_tag("gold.png", data: { title: 'Rails Application' })) => %(<img data-title="Rails Application" src="/images/gold.png" />),
+ %(image_tag("rss.gif", srcset: "/assets/pic_640.jpg 640w, /assets/pic_1024.jpg 1024w")) => %(<img srcset="/assets/pic_640.jpg 640w, /assets/pic_1024.jpg 1024w" src="/images/rss.gif" />),
+ %(image_tag("rss.gif", srcset: { "pic_640.jpg" => "640w", "pic_1024.jpg" => "1024w" })) => %(<img srcset="/images/pic_640.jpg 640w, /images/pic_1024.jpg 1024w" src="/images/rss.gif" />),
+ %(image_tag("rss.gif", srcset: [["pic_640.jpg", "640w"], ["pic_1024.jpg", "1024w"]])) => %(<img srcset="/images/pic_640.jpg 640w, /images/pic_1024.jpg 1024w" src="/images/rss.gif" />)
}
FaviconLinkToTag = {
@@ -463,11 +463,21 @@ class AssetTagHelperTest < ActionView::TestCase
def test_image_alt
[nil, "/", "/foo/bar/", "foo/bar/"].each do |prefix|
- assert_equal "Rails", image_alt("#{prefix}rails.png")
- assert_equal "Rails", image_alt("#{prefix}rails-9c0a079bdd7701d7e729bd956823d153.png")
- assert_equal "Rails", image_alt("#{prefix}rails-f56ef62bc41b040664e801a38f068082a75d506d9048307e8096737463503d0b.png")
- assert_equal "Long file name with hyphens", image_alt("#{prefix}long-file-name-with-hyphens.png")
- assert_equal "Long file name with underscores", image_alt("#{prefix}long_file_name_with_underscores.png")
+ assert_deprecated do
+ assert_equal "Rails", image_alt("#{prefix}rails.png")
+ end
+ assert_deprecated do
+ assert_equal "Rails", image_alt("#{prefix}rails-9c0a079bdd7701d7e729bd956823d153.png")
+ end
+ assert_deprecated do
+ assert_equal "Rails", image_alt("#{prefix}rails-f56ef62bc41b040664e801a38f068082a75d506d9048307e8096737463503d0b.png")
+ end
+ assert_deprecated do
+ assert_equal "Long file name with hyphens", image_alt("#{prefix}long-file-name-with-hyphens.png")
+ end
+ assert_deprecated do
+ assert_equal "Long file name with underscores", image_alt("#{prefix}long_file_name_with_underscores.png")
+ end
end
end
diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb
index 48c567008d..5e328ebf53 100644
--- a/actionview/test/template/form_tag_helper_test.rb
+++ b/actionview/test/template/form_tag_helper_test.rb
@@ -641,7 +641,7 @@ class FormTagHelperTest < ActionView::TestCase
def test_image_submit_tag_with_confirmation
assert_dom_equal(
- %(<input alt="Save" type="image" src="/images/save.gif" data-confirm="Are you sure?" />),
+ %(<input type="image" src="/images/save.gif" data-confirm="Are you sure?" />),
image_submit_tag("save.gif", data: { confirm: "Are you sure?" })
)
end
diff --git a/actionview/test/tmp/.gitkeep b/actionview/test/tmp/.keep
index e69de29bb2..e69de29bb2 100644
--- a/actionview/test/tmp/.gitkeep
+++ b/actionview/test/tmp/.keep
diff --git a/actionview/test/ujs/public/vendor/qunit.js b/actionview/test/ujs/public/vendor/qunit.js
index 0e279fde17..50a9e6455d 100644
--- a/actionview/test/ujs/public/vendor/qunit.js
+++ b/actionview/test/ujs/public/vendor/qunit.js
@@ -42,7 +42,7 @@ var QUnit,
* with IE 7 (and prior) where Error.prototype.toString is
* not properly implemented
*
- * Based on http://es5.github.com/#x15.11.4.4
+ * Based on https://es5.github.io/#x15.11.4.4
*
* @param {String|Error} error
* @return {String} error message
diff --git a/activejob/README.md b/activejob/README.md
index 8becac7753..8a9a23929b 100644
--- a/activejob/README.md
+++ b/activejob/README.md
@@ -108,7 +108,7 @@ Source code can be downloaded as part of the Rails project on GitHub
Active Job is released under the MIT license:
-* http://www.opensource.org/licenses/MIT
+* https://opensource.org/licenses/MIT
## Support
diff --git a/activejob/lib/active_job/enqueuing.rb b/activejob/lib/active_job/enqueuing.rb
index ad32d3065b..c0d016853c 100644
--- a/activejob/lib/active_job/enqueuing.rb
+++ b/activejob/lib/active_job/enqueuing.rb
@@ -10,7 +10,7 @@ module ActiveJob
# Includes the +perform_later+ method for job initialization.
module ClassMethods
# Push a job onto the queue. The arguments must be legal JSON types
- # (string, int, float, nil, true, false, hash or array) or
+ # (+string+, +int+, +float+, +nil+, +true+, +false+, +hash+ or +array+) or
# GlobalID::Identification instances. Arbitrary Ruby objects
# are not supported.
#
diff --git a/activejob/lib/active_job/queue_adapters/async_adapter.rb b/activejob/lib/active_job/queue_adapters/async_adapter.rb
index eec9ae08bb..ebf6f384e3 100644
--- a/activejob/lib/active_job/queue_adapters/async_adapter.rb
+++ b/activejob/lib/active_job/queue_adapters/async_adapter.rb
@@ -31,7 +31,7 @@ module ActiveJob
# jobs. Since jobs share a single thread pool, long-running jobs will block
# short-lived jobs. Fine for dev/test; bad for production.
class AsyncAdapter
- # See {Concurrent::ThreadPoolExecutor}[http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ThreadPoolExecutor.html] for executor options.
+ # See {Concurrent::ThreadPoolExecutor}[https://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ThreadPoolExecutor.html] for executor options.
def initialize(**executor_options)
@scheduler = Scheduler.new(**executor_options)
end
diff --git a/activemodel/README.rdoc b/activemodel/README.rdoc
index 77f5761993..772df0f8f6 100644
--- a/activemodel/README.rdoc
+++ b/activemodel/README.rdoc
@@ -246,7 +246,7 @@ Source code can be downloaded as part of the Rails project on GitHub
Active Model is released under the MIT license:
-* http://www.opensource.org/licenses/MIT
+* https://opensource.org/licenses/MIT
== Support
diff --git a/activemodel/lib/active_model/callbacks.rb b/activemodel/lib/active_model/callbacks.rb
index 5768eec7f5..8fa9680cb1 100644
--- a/activemodel/lib/active_model/callbacks.rb
+++ b/activemodel/lib/active_model/callbacks.rb
@@ -103,8 +103,8 @@ module ActiveModel
# end
# end
#
- # NOTE: +method_name+ passed to `define_model_callbacks` must not end with
- # `!`, `?` or `=`.
+ # NOTE: +method_name+ passed to define_model_callbacks must not end with
+ # <tt>!</tt>, <tt>?</tt> or <tt>=</tt>.
def define_model_callbacks(*callbacks)
options = callbacks.extract_options!
options = {
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index b39d28ca31..b421fedc96 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,16 @@
+* Add new error class `TransactionTimeout` for MySQL adapter which will be raised
+ when lock wait time expires.
+
+ *Gabriel Courtemanche*
+
+* Remove deprecated `#migration_keys`.
+
+ *Ryuta Kamizono*
+
+* Automatically guess the inverse associations for STI.
+
+ *Yuichiro Kaneko*
+
* Ensure `sum` honors `distinct` on `has_many :through` associations
Fixes #16791.
diff --git a/activerecord/README.rdoc b/activerecord/README.rdoc
index cfbee4d6f7..ae53ecd177 100644
--- a/activerecord/README.rdoc
+++ b/activerecord/README.rdoc
@@ -162,7 +162,7 @@ This would also define the following accessors: <tt>Product#name</tt> and
== Philosophy
Active Record is an implementation of the object-relational mapping (ORM)
-pattern[http://www.martinfowler.com/eaaCatalog/activeRecord.html] by the same
+pattern[https://www.martinfowler.com/eaaCatalog/activeRecord.html] by the same
name described by Martin Fowler:
"An object that wraps a row in a database table or view,
@@ -199,7 +199,7 @@ Source code can be downloaded as part of the Rails project on GitHub:
Active Record is released under the MIT license:
-* http://www.opensource.org/licenses/MIT
+* https://opensource.org/licenses/MIT
== Support
diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb
index 7a9f5f7937..ba54cd8f49 100644
--- a/activerecord/lib/active_record/associations/belongs_to_association.rb
+++ b/activerecord/lib/active_record/associations/belongs_to_association.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
module ActiveRecord
- # = Active Record Belongs To Association
module Associations
+ # = Active Record Belongs To Association
class BelongsToAssociation < SingularAssociation #:nodoc:
def handle_dependency
target.send(options[:dependent]) if load_target
diff --git a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
index 13b4a084ea..4ce3474bd5 100644
--- a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
+++ b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
module ActiveRecord
- # = Active Record Belongs To Polymorphic Association
module Associations
+ # = Active Record Belongs To Polymorphic Association
class BelongsToPolymorphicAssociation < BelongsToAssociation #:nodoc:
def klass
type = owner[reflection.foreign_type]
diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb
index 88fe33eef2..07c7f28d2d 100644
--- a/activerecord/lib/active_record/associations/has_many_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_association.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
module ActiveRecord
- # = Active Record Has Many Association
module Associations
+ # = Active Record Has Many Association
# This is the proxy that handles a has many association.
#
# If the association has a <tt>:through</tt> option further specialization
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb
index 89ce00f98e..adbf52b87c 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
module ActiveRecord
- # = Active Record Has Many Through Association
module Associations
+ # = Active Record Has Many Through Association
class HasManyThroughAssociation < HasManyAssociation #:nodoc:
include ThroughAssociation
diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb
index 9a88c1af70..7953b89f61 100644
--- a/activerecord/lib/active_record/associations/has_one_association.rb
+++ b/activerecord/lib/active_record/associations/has_one_association.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
module ActiveRecord
- # = Active Record Has One Association
module Associations
+ # = Active Record Has One Association
class HasOneAssociation < SingularAssociation #:nodoc:
include ForeignAssociation
diff --git a/activerecord/lib/active_record/associations/has_one_through_association.rb b/activerecord/lib/active_record/associations/has_one_through_association.rb
index eb54977aa0..36746f9115 100644
--- a/activerecord/lib/active_record/associations/has_one_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_one_through_association.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
module ActiveRecord
- # = Active Record Has One Through Association
module Associations
+ # = Active Record Has One Through Association
class HasOneThroughAssociation < HasOneAssociation #:nodoc:
include ThroughAssociation
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb
index dc029c08bd..ac37c3c015 100644
--- a/activerecord/lib/active_record/associations/join_dependency.rb
+++ b/activerecord/lib/active_record/associations/join_dependency.rb
@@ -119,7 +119,7 @@ module ActiveRecord
end
def aliases
- Aliases.new join_root.each_with_index.map { |join_part, i|
+ @aliases ||= Aliases.new join_root.each_with_index.map { |join_part, i|
columns = join_part.column_names.each_with_index.map { |column_name, j|
Aliases::Column.new column_name, "t#{i}_r#{j}"
}
@@ -127,7 +127,7 @@ module ActiveRecord
}
end
- def instantiate(result_set, aliases)
+ def instantiate(result_set, &block)
primary_key = aliases.column_alias(join_root, join_root.primary_key)
seen = Hash.new { |i, object_id|
@@ -150,7 +150,7 @@ module ActiveRecord
message_bus.instrument("instantiation.active_record", payload) do
result_set.each { |row_hash|
parent_key = primary_key ? row_hash[primary_key] : row_hash
- parent = parents[parent_key] ||= join_root.instantiate(row_hash, column_aliases)
+ parent = parents[parent_key] ||= join_root.instantiate(row_hash, column_aliases, &block)
construct(parent, join_root, row_hash, result_set, seen, model_cache, aliases)
}
end
diff --git a/activerecord/lib/active_record/associations/through_association.rb b/activerecord/lib/active_record/associations/through_association.rb
index cba565448f..bce2a95ce1 100644
--- a/activerecord/lib/active_record/associations/through_association.rb
+++ b/activerecord/lib/active_record/associations/through_association.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
module ActiveRecord
- # = Active Record Through Association
module Associations
+ # = Active Record Through Association
module ThroughAssociation #:nodoc:
delegate :source_reflection, :through_reflection, to: :reflection
diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb
index c622df132e..4f957ac3ca 100644
--- a/activerecord/lib/active_record/attribute_methods/dirty.rb
+++ b/activerecord/lib/active_record/attribute_methods/dirty.rb
@@ -94,7 +94,7 @@ module ActiveRecord
end
# Did this attribute change when we last saved? This method can be invoked
- # as `saved_change_to_name?` instead of `saved_change_to_attribute?("name")`.
+ # as +saved_change_to_name?+ instead of <tt>saved_change_to_attribute?("name")</tt>.
# Behaves similarly to +attribute_changed?+. This method is useful in
# after callbacks to determine if the call to save changed a certain
# attribute.
@@ -117,8 +117,8 @@ module ActiveRecord
# Behaves similarly to +attribute_change+. This method is useful in after
# callbacks, to see the change in an attribute that just occurred
#
- # This method can be invoked as `saved_change_to_name` in instead of
- # `saved_change_to_attribute("name")`
+ # This method can be invoked as +saved_change_to_name+ in instead of
+ # <tt>saved_change_to_attribute("name")</tt>
def saved_change_to_attribute(attr_name)
mutations_before_last_save.change_to_attribute(attr_name)
end
@@ -131,7 +131,7 @@ module ActiveRecord
mutations_before_last_save.original_value(attr_name)
end
- # Did the last call to `save` have any changes to change?
+ # Did the last call to +save+ have any changes to change?
def saved_changes?
mutations_before_last_save.any_changes?
end
@@ -141,37 +141,37 @@ module ActiveRecord
mutations_before_last_save.changes
end
- # Alias for `attribute_changed?`
+ # Alias for +attribute_changed?+
def will_save_change_to_attribute?(attr_name, **options)
mutations_from_database.changed?(attr_name, **options)
end
- # Alias for `attribute_change`
+ # Alias for +attribute_change+
def attribute_change_to_be_saved(attr_name)
mutations_from_database.change_to_attribute(attr_name)
end
- # Alias for `attribute_was`
+ # Alias for +attribute_was+
def attribute_in_database(attr_name)
mutations_from_database.original_value(attr_name)
end
- # Alias for `changed?`
+ # Alias for +changed?+
def has_changes_to_save?
mutations_from_database.any_changes?
end
- # Alias for `changes`
+ # Alias for +changes+
def changes_to_save
mutations_from_database.changes
end
- # Alias for `changed`
+ # Alias for +changed+
def changed_attribute_names_to_save
changes_to_save.keys
end
- # Alias for `changed_attributes`
+ # Alias for +changed_attributes+
def attributes_in_database
changes_to_save.transform_values(&:first)
end
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb
index 615b2fa701..b070235684 100644
--- a/activerecord/lib/active_record/attribute_methods/read.rb
+++ b/activerecord/lib/active_record/attribute_methods/read.rb
@@ -5,7 +5,7 @@ module ActiveRecord
module Read
extend ActiveSupport::Concern
- module ClassMethods
+ module ClassMethods # :nodoc:
private
# We want to generate the methods via module_eval rather than
diff --git a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
index f12a9f915c..d2b7817b45 100644
--- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
+++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
@@ -62,7 +62,7 @@ module ActiveRecord
class_attribute :time_zone_aware_types, instance_writer: false, default: [ :datetime, :time ]
end
- module ClassMethods
+ module ClassMethods # :nodoc:
private
def inherited(subclass)
diff --git a/activerecord/lib/active_record/attribute_methods/write.rb b/activerecord/lib/active_record/attribute_methods/write.rb
index 62c5ce059b..37891ce2ef 100644
--- a/activerecord/lib/active_record/attribute_methods/write.rb
+++ b/activerecord/lib/active_record/attribute_methods/write.rb
@@ -9,7 +9,7 @@ module ActiveRecord
attribute_method_suffix "="
end
- module ClassMethods
+ module ClassMethods # :nodoc:
private
def define_method_attribute=(name)
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
index 4078345abf..36048bee03 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
@@ -181,7 +181,7 @@ module ActiveRecord
#
# In order to get around this problem, #transaction will emulate the effect
# of nested transactions, by using savepoints:
- # http://dev.mysql.com/doc/refman/5.7/en/savepoint.html
+ # https://dev.mysql.com/doc/refman/5.7/en/savepoint.html
# Savepoints are supported by MySQL and PostgreSQL. SQLite3 version >= '3.6.8'
# supports savepoints.
#
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
index 7b83bc319c..9ad04c3216 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
@@ -7,7 +7,7 @@ module ActiveRecord
module ConnectionAdapters # :nodoc:
module Quoting
# Quotes the column value to help prevent
- # {SQL injection attacks}[http://en.wikipedia.org/wiki/SQL_injection].
+ # {SQL injection attacks}[https://en.wikipedia.org/wiki/SQL_injection].
def quote(value)
value = id_value_for_database(value) if value.is_a?(Base)
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb
index 9be26254b2..1926603474 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb
@@ -1,65 +1,40 @@
# frozen_string_literal: true
+require "active_support/core_ext/hash/compact"
+
module ActiveRecord
module ConnectionAdapters # :nodoc:
- # The goal of this module is to move Adapter specific column
- # definitions to the Adapter instead of having it in the schema
- # dumper itself. This code represents the normal case.
- # We can then redefine how certain data types may be handled in the schema dumper on the
- # Adapter level by over-writing this code inside the database specific adapters
- module ColumnDumper
- def column_spec(column)
- [schema_type_with_virtual(column), prepare_column_options(column)]
- end
-
- def column_spec_for_primary_key(column)
- return {} if default_primary_key?(column)
- spec = { id: schema_type(column).inspect }
- spec.merge!(prepare_column_options(column).except!(:null))
- spec[:default] ||= "nil" if explicit_primary_key_default?(column)
- spec
+ class SchemaDumper < SchemaDumper # :nodoc:
+ def self.create(connection, options)
+ new(connection, options)
end
- # This can be overridden on an Adapter level basis to support other
- # extended datatypes (Example: Adding an array option in the
- # PostgreSQL::ColumnDumper)
- def prepare_column_options(column)
- spec = {}
-
- if limit = schema_limit(column)
- spec[:limit] = limit
- end
-
- if precision = schema_precision(column)
- spec[:precision] = precision
+ private
+ def column_spec(column)
+ [schema_type_with_virtual(column), prepare_column_options(column)]
end
- if scale = schema_scale(column)
- spec[:scale] = scale
+ def column_spec_for_primary_key(column)
+ return {} if default_primary_key?(column)
+ spec = { id: schema_type(column).inspect }
+ spec.merge!(prepare_column_options(column).except!(:null))
+ spec[:default] ||= "nil" if explicit_primary_key_default?(column)
+ spec
end
- default = schema_default(column) if column.has_default?
- spec[:default] = default unless default.nil?
-
- spec[:null] = "false" unless column.null
-
- if collation = schema_collation(column)
- spec[:collation] = collation
+ def prepare_column_options(column)
+ spec = {}
+ spec[:limit] = schema_limit(column)
+ spec[:precision] = schema_precision(column)
+ spec[:scale] = schema_scale(column)
+ spec[:default] = schema_default(column)
+ spec[:null] = "false" unless column.null
+ spec[:collation] = schema_collation(column)
+ spec[:comment] = column.comment.inspect if column.comment.present?
+ spec.compact!
+ spec
end
- spec[:comment] = column.comment.inspect if column.comment.present?
-
- spec
- end
-
- # Lists the valid migration options
- def migration_keys # :nodoc:
- column_options_keys
- end
- deprecate :migration_keys
-
- private
-
def default_primary_key?(column)
schema_type(column) == :bigint
end
@@ -69,7 +44,7 @@ module ActiveRecord
end
def schema_type_with_virtual(column)
- if supports_virtual_columns? && column.virtual?
+ if @connection.supports_virtual_columns? && column.virtual?
:virtual
else
schema_type(column)
@@ -86,7 +61,7 @@ module ActiveRecord
def schema_limit(column)
limit = column.limit unless column.bigint?
- limit.inspect if limit && limit != native_database_types[column.type][:limit]
+ limit.inspect if limit && limit != @connection.native_database_types[column.type][:limit]
end
def schema_precision(column)
@@ -98,7 +73,8 @@ module ActiveRecord
end
def schema_default(column)
- type = lookup_cast_type_from_column(column)
+ return unless column.has_default?
+ type = @connection.lookup_cast_type_from_column(column)
default = type.deserialize(column.default)
if default.nil?
schema_expression(column)
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index 3c9b25e411..f57c7a5d4d 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -406,6 +406,8 @@ module ActiveRecord
#
# Defaults to false.
#
+ # Only supported on the MySQL adapter, ignored elsewhere.
+ #
# ====== Add a column
#
# change_table(:suppliers) do |t|
@@ -1174,6 +1176,10 @@ module ActiveRecord
raise NotImplementedError, "#{self.class} does not support changing column comments"
end
+ def create_schema_dumper(options) # :nodoc:
+ SchemaDumper.create(self, options)
+ end
+
private
def column_options_keys
[:limit, :precision, :scale, :default, :null, :collation, :comment]
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index 7645cf7825..47881e3305 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -72,7 +72,6 @@ module ActiveRecord
include Quoting, DatabaseStatements, SchemaStatements
include DatabaseLimits
include QueryCache
- include ColumnDumper
include Savepoints
SIMPLE_INT = /\A\d+\z/
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
index 5915f0db2d..7cd086084a 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -17,13 +17,8 @@ module ActiveRecord
module ConnectionAdapters
class AbstractMysqlAdapter < AbstractAdapter
include MySQL::Quoting
- include MySQL::ColumnDumper
include MySQL::SchemaStatements
- def update_table_definition(table_name, base) # :nodoc:
- MySQL::Table.new(table_name, base)
- end
-
##
# :singleton-method:
# By default, the Mysql2Adapter will consider all columns of type <tt>tinyint(1)</tt>
@@ -38,7 +33,7 @@ module ActiveRecord
string: { name: "varchar", limit: 255 },
text: { name: "text", limit: 65535 },
integer: { name: "int", limit: 4 },
- float: { name: "float" },
+ float: { name: "float", limit: 24 },
decimal: { name: "decimal" },
datetime: { name: "datetime" },
timestamp: { name: "timestamp" },
@@ -634,6 +629,7 @@ module ActiveRecord
ER_LOCK_DEADLOCK = 1213
ER_CANNOT_ADD_FOREIGN = 1215
ER_CANNOT_CREATE_TABLE = 1005
+ ER_LOCK_WAIT_TIMEOUT = 1205
def translate_exception(exception, message)
case error_number(exception)
@@ -657,6 +653,8 @@ module ActiveRecord
NotNullViolation.new(message)
when ER_LOCK_DEADLOCK
Deadlocked.new(message)
+ when ER_LOCK_WAIT_TIMEOUT
+ TransactionTimeout.new(message)
else
super
end
@@ -760,7 +758,7 @@ module ActiveRecord
defaults = [":default", :default].to_set
# Make MySQL reject illegal values rather than truncating or blanking them, see
- # http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_strict_all_tables
+ # https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_strict_all_tables
# If the user has provided another value for sql_mode, don't replace it.
if sql_mode = variables.delete("sql_mode")
sql_mode = quote(sql_mode)
@@ -777,7 +775,7 @@ module ActiveRecord
sql_mode_assignment = "@@SESSION.sql_mode = #{sql_mode}, " if sql_mode
# NAMES does not have an equals sign, see
- # http://dev.mysql.com/doc/refman/5.7/en/set-statement.html#id944430
+ # https://dev.mysql.com/doc/refman/5.7/en/set-names.html
# (trailing comma because variable_assignments will always have content)
if @config[:encoding]
encoding = "NAMES #{@config[:encoding]}".dup
diff --git a/activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb b/activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb
index 5a35823c72..75377693c6 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb
@@ -30,7 +30,7 @@ module ActiveRecord
# By default, TIMESTAMP columns are NOT NULL, cannot contain NULL values,
# and assigning NULL assigns the current timestamp. To permit a TIMESTAMP
# column to contain NULL, explicitly declare it with the NULL attribute.
- # See http://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html
+ # See https://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html
if /\Atimestamp\b/.match?(options[:column].sql_type) && !options[:primary_key]
sql << " NULL" unless options[:null] == false || options_include_default?(options)
end
diff --git a/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb b/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb
index fbe3596dda..95eb77aea4 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb
@@ -3,25 +3,20 @@
module ActiveRecord
module ConnectionAdapters
module MySQL
- module ColumnDumper # :nodoc:
- def prepare_column_options(column)
- spec = super
- spec[:unsigned] = "true" if column.unsigned?
-
- if supports_virtual_columns? && column.virtual?
- spec[:as] = extract_expression_for_virtual_column(column)
- spec[:stored] = "true" if /\b(?:STORED|PERSISTENT)\b/.match?(column.extra)
- spec = { type: schema_type(column).inspect }.merge!(spec)
- end
-
- spec
- end
+ class SchemaDumper < ConnectionAdapters::SchemaDumper # :nodoc:
+ private
+ def prepare_column_options(column)
+ spec = super
+ spec[:unsigned] = "true" if column.unsigned?
- def migration_keys
- super + [:unsigned]
- end
+ if @connection.supports_virtual_columns? && column.virtual?
+ spec[:as] = extract_expression_for_virtual_column(column)
+ spec[:stored] = "true" if /\b(?:STORED|PERSISTENT)\b/.match?(column.extra)
+ spec = { type: schema_type(column).inspect }.merge!(spec)
+ end
- private
+ spec
+ end
def default_primary_key?(column)
super && column.auto_increment? && !column.unsigned?
@@ -49,24 +44,27 @@ module ActiveRecord
def schema_collation(column)
if column.collation && table_name = column.table_name
@table_collation_cache ||= {}
- @table_collation_cache[table_name] ||= exec_query("SHOW TABLE STATUS LIKE #{quote(table_name)}", "SCHEMA").first["Collation"]
+ @table_collation_cache[table_name] ||=
+ @connection.exec_query("SHOW TABLE STATUS LIKE #{@connection.quote(table_name)}", "SCHEMA").first["Collation"]
column.collation.inspect if column.collation != @table_collation_cache[table_name]
end
end
def extract_expression_for_virtual_column(column)
- if mariadb? && version < "10.2.5"
- create_table_info = create_table_info(column.table_name)
- if %r/#{quote_column_name(column.name)} #{Regexp.quote(column.sql_type)}(?: COLLATE \w+)? AS \((?<expression>.+?)\) #{column.extra}/ =~ create_table_info
+ if @connection.mariadb? && @connection.version < "10.2.5"
+ create_table_info = @connection.send(:create_table_info, column.table_name)
+ column_name = @connection.quote_column_name(column.name)
+ if %r/#{column_name} #{Regexp.quote(column.sql_type)}(?: COLLATE \w+)? AS \((?<expression>.+?)\) #{column.extra}/ =~ create_table_info
$~[:expression].inspect
end
else
- scope = quoted_scope(column.table_name)
+ scope = @connection.send(:quoted_scope, column.table_name)
+ column_name = @connection.quote(column.name)
sql = "SELECT generation_expression FROM information_schema.columns" \
" WHERE table_schema = #{scope[:schema]}" \
" AND table_name = #{scope[:name]}" \
- " AND column_name = #{quote(column.name)}"
- query_value(sql, "SCHEMA").inspect
+ " AND column_name = #{column_name}"
+ @connection.query_value(sql, "SCHEMA").inspect
end
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb
index 1d87d60ba9..759493e3bd 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb
@@ -62,6 +62,14 @@ module ActiveRecord
end
end
+ def update_table_definition(table_name, base)
+ MySQL::Table.new(table_name, base)
+ end
+
+ def create_schema_dumper(options)
+ MySQL::SchemaDumper.create(self, options)
+ end
+
private
CHARSETS_OF_4BYTES_MAXLEN = ["utf8mb4", "utf16", "utf16le", "utf32"]
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb
index 12c6603081..c0dbb166b7 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb
@@ -3,20 +3,13 @@
module ActiveRecord
module ConnectionAdapters
module PostgreSQL
- module ColumnDumper # :nodoc:
- # Adds +:array+ option to the default set
- def prepare_column_options(column)
- spec = super
- spec[:array] = "true" if column.array?
- spec
- end
-
- # Adds +:array+ as a valid migration key
- def migration_keys
- super + [:array]
- end
-
+ class SchemaDumper < ConnectionAdapters::SchemaDumper # :nodoc:
private
+ def prepare_column_options(column)
+ spec = super
+ spec[:array] = "true" if column.array?
+ spec
+ end
def default_primary_key?(column)
schema_type(column) == :bigserial
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
index 780e642f21..9e2f61e6ce 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -586,6 +586,14 @@ module ActiveRecord
[super, *order_columns].join(", ")
end
+ def update_table_definition(table_name, base) # :nodoc:
+ PostgreSQL::Table.new(table_name, base)
+ end
+
+ def create_schema_dumper(options) # :nodoc:
+ PostgreSQL::SchemaDumper.create(self, options)
+ end
+
private
def schema_creation
PostgreSQL::SchemaCreation.new(self)
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 3b4439fc46..4d37a292d6 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -76,7 +76,7 @@ module ActiveRecord
primary_key: "bigserial primary key",
string: { name: "character varying" },
text: { name: "text" },
- integer: { name: "integer" },
+ integer: { name: "integer", limit: 4 },
float: { name: "float" },
decimal: { name: "decimal" },
datetime: { name: "timestamp" },
@@ -121,7 +121,6 @@ module ActiveRecord
include PostgreSQL::ReferentialIntegrity
include PostgreSQL::SchemaStatements
include PostgreSQL::DatabaseStatements
- include PostgreSQL::ColumnDumper
def supports_index_sort_order?
true
@@ -368,10 +367,6 @@ module ActiveRecord
@use_insert_returning
end
- def update_table_definition(table_name, base) #:nodoc:
- PostgreSQL::Table.new(table_name, base)
- end
-
def column_name_for_operation(operation, node) # :nodoc:
OPERATION_ALIASES.fetch(operation) { operation.downcase }
end
@@ -439,9 +434,9 @@ module ActiveRecord
end
def initialize_type_map(m = type_map)
- register_class_with_limit m, "int2", Type::Integer
- register_class_with_limit m, "int4", Type::Integer
- register_class_with_limit m, "int8", Type::Integer
+ m.register_type "int2", Type::Integer.new(limit: 2)
+ m.register_type "int4", Type::Integer.new(limit: 4)
+ m.register_type "int8", Type::Integer.new(limit: 8)
m.register_type "oid", OID::Oid.new
m.register_type "float4", Type::Float.new
m.alias_type "float8", "float4"
@@ -508,17 +503,6 @@ module ActiveRecord
load_additional_types
end
- def extract_limit(sql_type)
- case sql_type
- when /^bigint/i, /^int8/i
- 8
- when /^smallint/i
- 2
- else
- super
- end
- end
-
# Extracts the value from a PostgreSQL column default definition.
def extract_value_from_default(default)
case default
@@ -638,7 +622,7 @@ module ActiveRecord
# ActiveRecord::PreparedStatementCacheExpired
#
# Check here for more details:
- # http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/utils/cache/plancache.c#l573
+ # https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/utils/cache/plancache.c#l573
CACHED_PLAN_HEURISTIC = "cached plan must not change result type".freeze
def is_cached_plan_failure?(e)
pgerror = e.cause
@@ -703,18 +687,20 @@ module ActiveRecord
# Use standard-conforming strings so we don't have to do the E'...' dance.
set_standard_conforming_strings
+ variables = @config.fetch(:variables, {}).stringify_keys
+
# If using Active Record's time zone support configure the connection to return
# TIMESTAMP WITH ZONE types in UTC.
- # (SET TIME ZONE does not use an equals sign like other SET variables)
- if ActiveRecord::Base.default_timezone == :utc
- execute("SET time zone 'UTC'", "SCHEMA")
- elsif @local_tz
- execute("SET time zone '#{@local_tz}'", "SCHEMA")
+ unless variables["timezone"]
+ if ActiveRecord::Base.default_timezone == :utc
+ variables["timezone"] = "UTC"
+ elsif @local_tz
+ variables["timezone"] = @local_tz
+ end
end
# SET statements from :variables config hash
# https://www.postgresql.org/docs/current/static/sql-set.html
- variables = @config[:variables] || {}
variables.map do |k, v|
if v == ":default" || v == :default
# Sets the value to the global or compile default
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb b/activerecord/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb
index ab057c73f1..621678ec65 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb
@@ -3,9 +3,8 @@
module ActiveRecord
module ConnectionAdapters
module SQLite3
- module ColumnDumper # :nodoc:
+ class SchemaDumper < ConnectionAdapters::SchemaDumper # :nodoc:
private
-
def default_primary_key?(column)
schema_type(column) == :integer
end
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb
index c155e7f1ac..a512702b7b 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb
@@ -39,6 +39,14 @@ module ActiveRecord
end
end
+ def update_table_definition(table_name, base)
+ SQLite3::Table.new(table_name, base)
+ end
+
+ def create_schema_dumper(options)
+ SQLite3::SchemaDumper.create(self, options)
+ end
+
private
def schema_creation
SQLite3::SchemaCreation.new(self)
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
index 10e80179ac..6fdd666486 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
@@ -57,7 +57,6 @@ module ActiveRecord
ADAPTER_NAME = "SQLite".freeze
include SQLite3::Quoting
- include SQLite3::ColumnDumper
include SQLite3::SchemaStatements
NATIVE_DATABASE_TYPES = {
@@ -77,7 +76,7 @@ module ActiveRecord
##
# :singleton-method:
# Indicates whether boolean values are stored in sqlite3 databases as 1
- # and 0 or 't' and 'f'. Leaving `ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer`
+ # and 0 or 't' and 'f'. Leaving <tt>ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer</tt>
# set to false is deprecated. SQLite databases have used 't' and 'f' to
# serialize boolean values and must have old data converted to 1 and 0
# (its native boolean serialization) before setting this flag to true.
@@ -86,7 +85,7 @@ module ActiveRecord
# ExampleModel.where("boolean_column = 't'").update_all(boolean_column: 1)
# ExampleModel.where("boolean_column = 'f'").update_all(boolean_column: 0)
# for all models and all boolean columns, after which the flag must be set
- # to true by adding the following to your application.rb file:
+ # to true by adding the following to your <tt>application.rb</tt> file:
#
# Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
class_attribute :represent_boolean_as_integer, default: false
@@ -99,10 +98,6 @@ module ActiveRecord
end
end
- def update_table_definition(table_name, base) # :nodoc:
- SQLite3::Table.new(table_name, base)
- end
-
def initialize(connection, logger, connection_options, config)
super(connection, logger, config)
@@ -291,7 +286,7 @@ module ActiveRecord
rename_table_indexes(table_name, new_name)
end
- # See: http://www.sqlite.org/lang_altertable.html
+ # See: https://www.sqlite.org/lang_altertable.html
# SQLite has an additional restriction on the ALTER TABLE statement
def valid_alter_table_type?(type)
type.to_sym != :primary_key
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index a84e62ab11..945c4eca78 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -529,7 +529,7 @@ module ActiveRecord
#
# So we can avoid the +method_missing+ hit by explicitly defining +#to_ary+ as +nil+ here.
#
- # See also http://tenderlovemaking.com/2011/06/28/til-its-ok-to-return-nil-from-to_ary.html
+ # See also https://tenderlovemaking.com/2011/06/28/til-its-ok-to-return-nil-from-to_ary.html
def to_ary
nil
end
diff --git a/activerecord/lib/active_record/define_callbacks.rb b/activerecord/lib/active_record/define_callbacks.rb
index 2c8783dcc9..87ecd7cec5 100644
--- a/activerecord/lib/active_record/define_callbacks.rb
+++ b/activerecord/lib/active_record/define_callbacks.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
module ActiveRecord
- # This module exists because `ActiveRecord::AttributeMethods::Dirty` needs to
- # define callbacks, but continue to have its version of `save` be the super
- # method of `ActiveRecord::Callbacks`. This will be removed when the removal
+ # This module exists because ActiveRecord::AttributeMethods::Dirty needs to
+ # define callbacks, but continue to have its version of +save+ be the super
+ # method of ActiveRecord::Callbacks. This will be removed when the removal
# of deprecated code removes this need.
module DefineCallbacks
extend ActiveSupport::Concern
diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb
index e790760292..9ef3316393 100644
--- a/activerecord/lib/active_record/errors.rb
+++ b/activerecord/lib/active_record/errors.rb
@@ -334,4 +334,9 @@ module ActiveRecord
# +reverse_order+ to automatically reverse.
class IrreversibleOrderError < ActiveRecordError
end
+
+ # TransactionTimeout will be raised when lock wait timeout expires.
+ # Wait time value is set by innodb_lock_wait_timeout.
+ class TransactionTimeout < StatementInvalid
+ end
end
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index 4940e122f4..12169fffa9 100644
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -147,7 +147,7 @@ module ActiveRecord
# unwanted inter-test dependencies. Methods used by multiple fixtures should be defined in a module
# that is included in ActiveRecord::FixtureSet.context_class.
#
- # - define a helper method in `test_helper.rb`
+ # - define a helper method in <tt>test_helper.rb</tt>
# module FixtureFileHelpers
# def file_sha(path)
# Digest::SHA2.hexdigest(File.read(Rails.root.join('test/fixtures', path)))
diff --git a/activerecord/lib/active_record/inheritance.rb b/activerecord/lib/active_record/inheritance.rb
index e3deaafeec..0715c11473 100644
--- a/activerecord/lib/active_record/inheritance.rb
+++ b/activerecord/lib/active_record/inheritance.rb
@@ -32,7 +32,7 @@ module ActiveRecord
# for differentiating between them or reloading the right type with find.
#
# Note, all the attributes for all the cases are kept in the same table. Read more:
- # http://www.martinfowler.com/eaaCatalog/singleTableInheritance.html
+ # https://www.martinfowler.com/eaaCatalog/singleTableInheritance.html
#
module Inheritance
extend ActiveSupport::Concern
diff --git a/activerecord/lib/active_record/locking/pessimistic.rb b/activerecord/lib/active_record/locking/pessimistic.rb
index e939a24ad5..72bccd4906 100644
--- a/activerecord/lib/active_record/locking/pessimistic.rb
+++ b/activerecord/lib/active_record/locking/pessimistic.rb
@@ -53,7 +53,7 @@ module ActiveRecord
# end
#
# Database-specific information on row locking:
- # MySQL: http://dev.mysql.com/doc/refman/5.7/en/innodb-locking-reads.html
+ # MySQL: https://dev.mysql.com/doc/refman/5.7/en/innodb-locking-reads.html
# PostgreSQL: https://www.postgresql.org/docs/current/interactive/sql-select.html#SQL-FOR-UPDATE-SHARE
module Pessimistic
# Obtain a row lock on this record. Reloads the record to obtain the requested
diff --git a/activerecord/lib/active_record/no_touching.rb b/activerecord/lib/active_record/no_touching.rb
index c573deb63a..754c891884 100644
--- a/activerecord/lib/active_record/no_touching.rb
+++ b/activerecord/lib/active_record/no_touching.rb
@@ -6,7 +6,7 @@ module ActiveRecord
extend ActiveSupport::Concern
module ClassMethods
- # Lets you selectively disable calls to `touch` for the
+ # Lets you selectively disable calls to +touch+ for the
# duration of a block.
#
# ==== Examples
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 1297e0cde7..fbbf9082cc 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -353,7 +353,7 @@ module ActiveRecord
# Wrapper around #increment that writes the update to the database.
# Only +attribute+ is updated; the record itself is not saved.
# This means that any other modified attributes will still be dirty.
- # Validations and callbacks are skipped. Supports the `touch` option from
+ # Validations and callbacks are skipped. Supports the +touch+ option from
# +update_counters+, see that for more.
# Returns +self+.
def increment!(attribute, by = 1, touch: nil)
@@ -374,7 +374,7 @@ module ActiveRecord
# Wrapper around #decrement that writes the update to the database.
# Only +attribute+ is updated; the record itself is not saved.
# This means that any other modified attributes will still be dirty.
- # Validations and callbacks are skipped. Supports the `touch` option from
+ # Validations and callbacks are skipped. Supports the +touch+ option from
# +update_counters+, see that for more.
# Returns +self+.
def decrement!(attribute, by = 1, touch: nil)
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index b847933b2e..00ff20f4d7 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -657,7 +657,7 @@ module ActiveRecord
# from calling +klass+, +reflection+ will already be set to false.
def valid_inverse_reflection?(reflection)
reflection &&
- klass.name == reflection.active_record.name &&
+ klass <= reflection.active_record &&
can_find_inverse_of_automatically?(reflection)
end
@@ -1036,20 +1036,12 @@ module ActiveRecord
def scopes
scopes = @previous_reflection.scopes
- if @previous_reflection.options[:source_type]
- scopes + [@previous_reflection.source_type_scope]
- else
- scopes
- end
+ scopes << @previous_reflection.source_type_scope
end
def join_scopes(table, predicate_builder) # :nodoc:
scopes = @previous_reflection.join_scopes(table, predicate_builder) + super
- if @previous_reflection.options[:source_type]
- scopes + [@previous_reflection.source_type_scope]
- else
- scopes
- end
+ scopes << @previous_reflection.source_type_scope
end
def klass
@@ -1100,10 +1092,6 @@ module ActiveRecord
@reflection.constraints
end
- def alias_candidate(name)
- "#{plural_name}_#{name}_join"
- end
-
def alias_name
Arel::Table.new(table_name, type_caster: klass.type_caster)
end
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index d319978930..012bc838b1 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -566,7 +566,7 @@ module ActiveRecord
relation = self
if eager_loading?
- find_with_associations { |rel| relation = rel }
+ find_with_associations { |rel, _| relation = rel }
end
conn = klass.connection
@@ -660,7 +660,19 @@ module ActiveRecord
def exec_queries(&block)
skip_query_cache_if_necessary do
- @records = eager_loading? ? find_with_associations.freeze : @klass.find_by_sql(arel, &block).freeze
+ @records =
+ if eager_loading?
+ find_with_associations do |relation, join_dependency|
+ if ActiveRecord::NullRelation === relation
+ []
+ else
+ rows = connection.select_all(relation.arel, "SQL")
+ join_dependency.instantiate(rows, &block)
+ end.freeze
+ end
+ else
+ klass.find_by_sql(arel, &block).freeze
+ end
preload = preload_values
preload += includes_values unless eager_loading?
diff --git a/activerecord/lib/active_record/relation/delegation.rb b/activerecord/lib/active_record/relation/delegation.rb
index 4793f2a49b..c5354bf4e9 100644
--- a/activerecord/lib/active_record/relation/delegation.rb
+++ b/activerecord/lib/active_record/relation/delegation.rb
@@ -39,9 +39,9 @@ module ActiveRecord
# for each different klass, and the delegations are compiled into that subclass only.
delegate :to_xml, :encode_with, :length, :each, :uniq, :to_ary, :join,
- :[], :&, :|, :+, :-, :sample, :reverse, :compact, :in_groups, :in_groups_of,
+ :[], :&, :|, :+, :-, :sample, :reverse, :rotate, :compact, :in_groups, :in_groups_of,
:to_sentence, :to_formatted_s, :as_json,
- :shuffle, :split, :index, to: :records
+ :shuffle, :split, :slice, :index, :rindex, to: :records
delegate :table_name, :quoted_table_name, :primary_key, :quoted_primary_key,
:connection, :columns_hash, to: :klass
@@ -75,13 +75,6 @@ module ActiveRecord
end
end
end
-
- def delegate(method, opts = {})
- @delegation_mutex.synchronize do
- return if method_defined?(method)
- super
- end
- end
end
private
@@ -93,7 +86,6 @@ module ActiveRecord
elsif arel.respond_to?(method)
ActiveSupport::Deprecation.warn \
"Delegating #{method} to arel is deprecated and will be removed in Rails 6.0."
- self.class.delegate method, to: :arel
arel.public_send(method, *args, &block)
else
super
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 5da9573052..2aed941916 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -372,16 +372,7 @@ module ActiveRecord
relation = select aliases.columns
relation = apply_join_dependency(relation, join_dependency)
- if block_given?
- yield relation
- else
- if ActiveRecord::NullRelation === relation
- []
- else
- rows = skip_query_cache_if_necessary { connection.select_all(relation.arel, "SQL") }
- join_dependency.instantiate(rows, aliases)
- end
- end
+ yield relation, join_dependency
end
def construct_relation_for_exists(relation, conditions)
diff --git a/activerecord/lib/active_record/schema.rb b/activerecord/lib/active_record/schema.rb
index f166c27fd9..1e121f2a09 100644
--- a/activerecord/lib/active_record/schema.rb
+++ b/activerecord/lib/active_record/schema.rb
@@ -39,7 +39,7 @@ module ActiveRecord
# The +info+ hash is optional, and if given is used to define metadata
# about the current schema (currently, only the schema's version):
#
- # ActiveRecord::Schema.define(version: 20380119000001) do
+ # ActiveRecord::Schema.define(version: 2038_01_19_000001) do
# ...
# end
def self.define(info = {}, &block)
diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb
index fd644225ca..8d0311fabd 100644
--- a/activerecord/lib/active_record/schema_dumper.rb
+++ b/activerecord/lib/active_record/schema_dumper.rb
@@ -19,7 +19,7 @@ module ActiveRecord
class << self
def dump(connection = ActiveRecord::Base.connection, stream = STDOUT, config = ActiveRecord::Base)
- new(connection, generate_options(config)).dump(stream)
+ connection.create_schema_dumper(generate_options(config)).dump(stream)
stream
end
@@ -123,7 +123,7 @@ HEADER
when String
tbl.print ", primary_key: #{pk.inspect}" unless pk == "id"
pkcol = columns.detect { |c| c.name == pk }
- pkcolspec = @connection.column_spec_for_primary_key(pkcol)
+ pkcolspec = column_spec_for_primary_key(pkcol)
if pkcolspec.present?
tbl.print ", #{format_colspec(pkcolspec)}"
end
@@ -132,20 +132,19 @@ HEADER
else
tbl.print ", id: false"
end
- tbl.print ", force: :cascade"
table_options = @connection.table_options(table)
if table_options.present?
tbl.print ", #{format_options(table_options)}"
end
- tbl.puts " do |t|"
+ tbl.puts ", force: :cascade do |t|"
# then dump all non-primary key columns
columns.each do |column|
raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" unless @connection.valid_type?(column.type)
next if column.name == pk
- type, colspec = @connection.column_spec(column)
+ type, colspec = column_spec(column)
tbl.print " t.#{type} #{column.name.inspect}"
tbl.print ", #{format_colspec(colspec)}" if colspec.present?
tbl.puts
@@ -163,8 +162,6 @@ HEADER
stream.puts "# #{e.message}"
stream.puts
end
-
- stream
end
# Keep it for indexing materialized views
diff --git a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb
index 5681ccdd23..647e066137 100644
--- a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb
@@ -117,7 +117,7 @@ module ActiveRecord
end
def run_cmd_error(cmd, args, action)
- msg = "failed to execute:\n"
+ msg = "failed to execute:\n".dup
msg << "#{cmd} #{args.join(' ')}\n\n"
msg << "Please check the output above for any errors and make sure that `#{cmd}` is installed in your PATH and has proper permissions.\n\n"
msg
diff --git a/activerecord/lib/active_record/tasks/sqlite_database_tasks.rb b/activerecord/lib/active_record/tasks/sqlite_database_tasks.rb
index abdd6db64a..dfe599c4dd 100644
--- a/activerecord/lib/active_record/tasks/sqlite_database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/sqlite_database_tasks.rb
@@ -73,7 +73,7 @@ module ActiveRecord
end
def run_cmd_error(cmd, args)
- msg = "failed to execute:\n"
+ msg = "failed to execute:\n".dup
msg << "#{cmd} #{args.join(' ')}\n\n"
msg << "Please check the output above for any errors and make sure that `#{cmd}` is installed in your PATH and has proper permissions.\n\n"
msg
diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb
index 603dee8c0d..6761f2da25 100644
--- a/activerecord/lib/active_record/transactions.rb
+++ b/activerecord/lib/active_record/transactions.rb
@@ -170,7 +170,7 @@ module ActiveRecord
# writing, the only database that we're aware of that supports true nested
# transactions, is MS-SQL. Because of this, Active Record emulates nested
# transactions by using savepoints on MySQL and PostgreSQL. See
- # http://dev.mysql.com/doc/refman/5.7/en/savepoint.html
+ # https://dev.mysql.com/doc/refman/5.7/en/savepoint.html
# for more information about savepoints.
#
# === \Callbacks
diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb
index baeb653c61..f4ad58c087 100644
--- a/activerecord/lib/active_record/validations/uniqueness.rb
+++ b/activerecord/lib/active_record/validations/uniqueness.rb
@@ -219,7 +219,7 @@ module ActiveRecord
# can catch it and restart the transaction (e.g. by telling the user
# that the title already exists, and asking them to re-enter the title).
# This technique is also known as
- # {optimistic concurrency control}[http://en.wikipedia.org/wiki/Optimistic_concurrency_control].
+ # {optimistic concurrency control}[https://en.wikipedia.org/wiki/Optimistic_concurrency_control].
#
# The bundled ActiveRecord::ConnectionAdapters distinguish unique index
# constraint errors from other types of database errors by throwing an
diff --git a/activerecord/test/cases/adapter_test.rb b/activerecord/test/cases/adapter_test.rb
index d7551cd658..9aaa2852d0 100644
--- a/activerecord/test/cases/adapter_test.rb
+++ b/activerecord/test/cases/adapter_test.rb
@@ -288,11 +288,11 @@ module ActiveRecord
def test_log_invalid_encoding
error = assert_raises RuntimeError do
@connection.send :log, "SELECT 'ы' FROM DUAL" do
- raise "ы".force_encoding(Encoding::ASCII_8BIT)
+ raise "ы".dup.force_encoding(Encoding::ASCII_8BIT)
end
end
- assert_not_nil error.message
+ assert_equal "ы", error.message
end
end
end
diff --git a/activerecord/test/cases/adapters/mysql2/sp_test.rb b/activerecord/test/cases/adapters/mysql2/sp_test.rb
index 47cedc5edf..7b6dce71e9 100644
--- a/activerecord/test/cases/adapters/mysql2/sp_test.rb
+++ b/activerecord/test/cases/adapters/mysql2/sp_test.rb
@@ -17,7 +17,7 @@ class Mysql2StoredProcedureTest < ActiveRecord::Mysql2TestCase
# Test that MySQL allows multiple results for stored procedures
#
# In MySQL 5.6, CLIENT_MULTI_RESULTS is enabled by default.
- # http://dev.mysql.com/doc/refman/5.6/en/call.html
+ # https://dev.mysql.com/doc/refman/5.6/en/call.html
def test_multi_results
rows = @connection.select_rows("CALL ten();")
assert_equal 10, rows[0][0].to_i, "ten() did not return 10 as expected: #{rows.inspect}"
diff --git a/activerecord/test/cases/adapters/mysql2/table_options_test.rb b/activerecord/test/cases/adapters/mysql2/table_options_test.rb
index 6183d66b63..9f6bd38a8c 100644
--- a/activerecord/test/cases/adapters/mysql2/table_options_test.rb
+++ b/activerecord/test/cases/adapters/mysql2/table_options_test.rb
@@ -17,28 +17,28 @@ class Mysql2TableOptionsTest < ActiveRecord::Mysql2TestCase
test "table options with ENGINE" do
@connection.create_table "mysql_table_options", force: true, options: "ENGINE=MyISAM"
output = dump_table_schema("mysql_table_options")
- options = %r{create_table "mysql_table_options", force: :cascade, options: "(?<options>.*)"}.match(output)[:options]
+ options = %r{create_table "mysql_table_options", options: "(?<options>.*)"}.match(output)[:options]
assert_match %r{ENGINE=MyISAM}, options
end
test "table options with ROW_FORMAT" do
@connection.create_table "mysql_table_options", force: true, options: "ROW_FORMAT=REDUNDANT"
output = dump_table_schema("mysql_table_options")
- options = %r{create_table "mysql_table_options", force: :cascade, options: "(?<options>.*)"}.match(output)[:options]
+ options = %r{create_table "mysql_table_options", options: "(?<options>.*)"}.match(output)[:options]
assert_match %r{ROW_FORMAT=REDUNDANT}, options
end
test "table options with CHARSET" do
@connection.create_table "mysql_table_options", force: true, options: "CHARSET=utf8mb4"
output = dump_table_schema("mysql_table_options")
- options = %r{create_table "mysql_table_options", force: :cascade, options: "(?<options>.*)"}.match(output)[:options]
+ options = %r{create_table "mysql_table_options", options: "(?<options>.*)"}.match(output)[:options]
assert_match %r{CHARSET=utf8mb4}, options
end
test "table options with COLLATE" do
@connection.create_table "mysql_table_options", force: true, options: "COLLATE=utf8mb4_bin"
output = dump_table_schema("mysql_table_options")
- options = %r{create_table "mysql_table_options", force: :cascade, options: "(?<options>.*)"}.match(output)[:options]
+ options = %r{create_table "mysql_table_options", options: "(?<options>.*)"}.match(output)[:options]
assert_match %r{COLLATE=utf8mb4_bin}, options
end
end
diff --git a/activerecord/test/cases/adapters/mysql2/transaction_test.rb b/activerecord/test/cases/adapters/mysql2/transaction_test.rb
index e603baab69..25d9f69a89 100644
--- a/activerecord/test/cases/adapters/mysql2/transaction_test.rb
+++ b/activerecord/test/cases/adapters/mysql2/transaction_test.rb
@@ -59,5 +59,11 @@ module ActiveRecord
end
end
end
+
+ test "raises TransactionTimeout when mysql raises ER_LOCK_WAIT_TIMEOUT" do
+ assert_raises(ActiveRecord::TransactionTimeout) do
+ ActiveRecord::Base.connection.execute("SIGNAL SQLSTATE 'HY000' SET MESSAGE_TEXT = 'Testing error', MYSQL_ERRNO = 1205;")
+ end
+ end
end
end
diff --git a/activerecord/test/cases/adapters/mysql2/unsigned_type_test.rb b/activerecord/test/cases/adapters/mysql2/unsigned_type_test.rb
index d0a09f6481..b01f5d7f5a 100644
--- a/activerecord/test/cases/adapters/mysql2/unsigned_type_test.rb
+++ b/activerecord/test/cases/adapters/mysql2/unsigned_type_test.rb
@@ -62,7 +62,7 @@ class Mysql2UnsignedTypeTest < ActiveRecord::Mysql2TestCase
schema = dump_table_schema "unsigned_types"
assert_match %r{t\.integer\s+"unsigned_integer",\s+unsigned: true$}, schema
assert_match %r{t\.bigint\s+"unsigned_bigint",\s+unsigned: true$}, schema
- assert_match %r{t\.float\s+"unsigned_float",\s+limit: 24,\s+unsigned: true$}, schema
+ assert_match %r{t\.float\s+"unsigned_float",\s+unsigned: true$}, schema
assert_match %r{t\.decimal\s+"unsigned_decimal",\s+precision: 10,\s+scale: 2,\s+unsigned: true$}, schema
end
end
diff --git a/activerecord/test/cases/adapters/postgresql/connection_test.rb b/activerecord/test/cases/adapters/postgresql/connection_test.rb
index 24875c6678..2bb217a8b1 100644
--- a/activerecord/test/cases/adapters/postgresql/connection_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/connection_test.rb
@@ -220,6 +220,13 @@ module ActiveRecord
end
end
+ def test_set_session_timezone
+ run_without_connection do |orig_connection|
+ ActiveRecord::Base.establish_connection(orig_connection.deep_merge(variables: { timezone: "America/New_York" }))
+ assert_equal "America/New_York", ActiveRecord::Base.connection.query_value("SHOW TIME ZONE")
+ end
+ end
+
def test_get_and_release_advisory_lock
lock_id = 5295901941911233559
list_advisory_locks = <<-SQL
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index 1f5f9eddb5..44bf7f7d2f 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -40,6 +40,12 @@ class EagerAssociationTest < ActiveRecord::TestCase
assert_nil member.favourite_club
end
+ def test_should_work_inverse_of_with_eager_load
+ author = authors(:david)
+ assert_same author, author.posts.first.author
+ assert_same author, author.posts.eager_load(:comments).first.author
+ end
+
def test_loading_with_one_association
posts = Post.all.merge!(includes: :comments).to_a
post = posts.find { |p| p.id == 1 }
diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb
index fdb98d84e0..2a9ebd19ed 100644
--- a/activerecord/test/cases/associations/has_one_associations_test.rb
+++ b/activerecord/test/cases/associations/has_one_associations_test.rb
@@ -15,7 +15,7 @@ require "models/post"
class HasOneAssociationsTest < ActiveRecord::TestCase
self.use_transactional_tests = false unless supports_savepoints?
- fixtures :accounts, :companies, :developers, :projects, :developers_projects, :ships, :pirates, :authors
+ fixtures :accounts, :companies, :developers, :projects, :developers_projects, :ships, :pirates, :authors, :author_addresses
def setup
Account.destroyed_account_ids.clear
diff --git a/activerecord/test/cases/associations/inverse_associations_test.rb b/activerecord/test/cases/associations/inverse_associations_test.rb
index 536077fb92..e13cf93dcf 100644
--- a/activerecord/test/cases/associations/inverse_associations_test.rb
+++ b/activerecord/test/cases/associations/inverse_associations_test.rb
@@ -18,6 +18,8 @@ require "models/admin/user"
require "models/developer"
require "models/company"
require "models/project"
+require "models/author"
+require "models/post"
class AutomaticInverseFindingTests < ActiveRecord::TestCase
fixtures :ratings, :comments, :cars
@@ -60,6 +62,20 @@ class AutomaticInverseFindingTests < ActiveRecord::TestCase
assert_equal rating_reflection, comment_reflection.inverse_of, "The Comment reflection's inverse should be the Rating reflection"
end
+ def test_has_many_and_belongs_to_should_find_inverse_automatically_for_sti
+ author_reflection = Author.reflect_on_association(:posts)
+ author_child_reflection = Author.reflect_on_association(:special_posts)
+ post_reflection = Post.reflect_on_association(:author)
+
+ assert_respond_to author_reflection, :has_inverse?
+ assert author_reflection.has_inverse?, "The Author reflection should have an inverse"
+ assert_equal post_reflection, author_reflection.inverse_of, "The Author reflection's inverse should be the Post reflection"
+
+ assert_respond_to author_child_reflection, :has_inverse?
+ assert author_child_reflection.has_inverse?, "The Author reflection should have an inverse"
+ assert_equal post_reflection, author_child_reflection.inverse_of, "The Author reflection's inverse should be the Post reflection"
+ end
+
def test_has_one_and_belongs_to_automatic_inverse_shares_objects
car = Car.first
bulb = Bulb.create!(car: car)
@@ -267,7 +283,7 @@ class InverseHasOneTests < ActiveRecord::TestCase
end
class InverseHasManyTests < ActiveRecord::TestCase
- fixtures :men, :interests
+ fixtures :men, :interests, :posts, :authors, :author_addresses
def test_parent_instance_should_be_shared_with_every_child_on_find
m = men(:gordon)
@@ -281,6 +297,27 @@ class InverseHasManyTests < ActiveRecord::TestCase
end
end
+ def test_parent_instance_should_be_shared_with_every_child_on_find_for_sti
+ a = authors(:david)
+ ps = a.posts
+ ps.each do |p|
+ assert_equal a.name, p.author.name, "Name of man should be the same before changes to parent instance"
+ a.name = "Bongo"
+ assert_equal a.name, p.author.name, "Name of man should be the same after changes to parent instance"
+ p.author.name = "Mungo"
+ assert_equal a.name, p.author.name, "Name of man should be the same after changes to child-owned instance"
+ end
+
+ sps = a.special_posts
+ sps.each do |sp|
+ assert_equal a.name, sp.author.name, "Name of man should be the same before changes to parent instance"
+ a.name = "Bongo"
+ assert_equal a.name, sp.author.name, "Name of man should be the same after changes to parent instance"
+ sp.author.name = "Mungo"
+ assert_equal a.name, sp.author.name, "Name of man should be the same after changes to child-owned instance"
+ end
+ end
+
def test_parent_instance_should_be_shared_with_eager_loaded_children
m = Man.all.merge!(where: { name: "Gordon" }, includes: :interests).first
is = m.interests
diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb
index 9d1999bcb1..de04221ea6 100644
--- a/activerecord/test/cases/associations_test.rb
+++ b/activerecord/test/cases/associations_test.rb
@@ -247,16 +247,16 @@ class AssociationProxyTest < ActiveRecord::TestCase
test "first! works on loaded associations" do
david = authors(:david)
- assert_equal david.posts.first, david.posts.reload.first!
- assert david.posts.loaded?
- assert_no_queries { david.posts.first! }
+ assert_equal david.first_posts.first, david.first_posts.reload.first!
+ assert david.first_posts.loaded?
+ assert_no_queries { david.first_posts.first! }
end
def test_pluck_uses_loaded_target
david = authors(:david)
- assert_equal david.posts.pluck(:title), david.posts.load.pluck(:title)
- assert david.posts.loaded?
- assert_no_queries { david.posts.pluck(:title) }
+ assert_equal david.first_posts.pluck(:title), david.first_posts.load.pluck(:title)
+ assert david.first_posts.loaded?
+ assert_no_queries { david.first_posts.pluck(:title) }
end
def test_reset_unloads_target
diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb
index ae492f1c1c..4d8368fd8a 100644
--- a/activerecord/test/cases/autosave_association_test.rb
+++ b/activerecord/test/cases/autosave_association_test.rb
@@ -5,6 +5,7 @@ require "models/bird"
require "models/post"
require "models/comment"
require "models/company"
+require "models/contract"
require "models/customer"
require "models/developer"
require "models/computer"
@@ -12,9 +13,7 @@ require "models/invoice"
require "models/line_item"
require "models/order"
require "models/parrot"
-require "models/person"
require "models/pirate"
-require "models/reader"
require "models/ship"
require "models/ship_part"
require "models/tag"
@@ -496,7 +495,7 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociationWithAcceptsNestedAttrib
end
class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCase
- fixtures :companies, :people
+ fixtures :companies, :developers
def test_invalid_adding
firm = Firm.find(1)
@@ -591,12 +590,12 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCa
end
def test_assign_ids_for_through_a_belongs_to
- post = Post.new(title: "Assigning IDs works!", body: "You heard it here first, folks!")
- post.person_ids = [people(:david).id, people(:michael).id]
- post.save
- post.reload
- assert_equal 2, post.people.length
- assert_includes post.people, people(:david)
+ firm = Firm.new("name" => "Apple")
+ firm.developer_ids = [developers(:david).id, developers(:jamis).id]
+ firm.save
+ firm.reload
+ assert_equal 2, firm.developers.length
+ assert_includes firm.developers, developers(:david)
end
def test_build_before_save
@@ -1724,6 +1723,10 @@ class TestAutosaveAssociationOnAHasManyAssociationWithInverse < ActiveRecord::Te
end
end
+ def setup
+ Comment.delete_all
+ end
+
def test_after_save_callback_with_autosave
post = Post.new(title: "Test", body: "...")
comment = post.comments.build(body: "...")
diff --git a/activerecord/test/cases/comment_test.rb b/activerecord/test/cases/comment_test.rb
index f2ec5d6518..1bcafd4b55 100644
--- a/activerecord/test/cases/comment_test.rb
+++ b/activerecord/test/cases/comment_test.rb
@@ -111,7 +111,7 @@ if ActiveRecord::Base.connection.supports_comments?
# And check that these changes are reflected in dump
output = dump_table_schema "commenteds"
- assert_match %r[create_table "commenteds",.+\s+comment: "A table with comment"], output
+ assert_match %r[create_table "commenteds",.*\s+comment: "A table with comment"], output
assert_match %r[t\.string\s+"name",\s+comment: "Comment should help clarify the column purpose"], output
assert_match %r[t\.string\s+"obvious"\n], output
assert_match %r[t\.string\s+"content",\s+comment: "Whoa, content describes itself!"], output
diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb
index 68a1190d68..78cb89ccc5 100644
--- a/activerecord/test/cases/enum_test.rb
+++ b/activerecord/test/cases/enum_test.rb
@@ -5,7 +5,7 @@ require "models/author"
require "models/book"
class EnumTest < ActiveRecord::TestCase
- fixtures :books, :authors
+ fixtures :books, :authors, :author_addresses
setup do
@book = books(:awdr)
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb
index 0fa43583ac..07afa89779 100644
--- a/activerecord/test/cases/migration_test.rb
+++ b/activerecord/test/cases/migration_test.rb
@@ -1112,10 +1112,6 @@ class CopyMigrationsTest < ActiveRecord::TestCase
assert_deprecated { ActiveRecord::Base.connection.initialize_internal_metadata_table }
end
- def test_deprecate_migration_keys
- assert_deprecated { ActiveRecord::Base.connection.migration_keys }
- end
-
def test_deprecate_supports_migrations
assert_deprecated { ActiveRecord::Base.connection.supports_migrations? }
end
diff --git a/activerecord/test/cases/primary_keys_test.rb b/activerecord/test/cases/primary_keys_test.rb
index df83fe0ea1..e0888f5fe9 100644
--- a/activerecord/test/cases/primary_keys_test.rb
+++ b/activerecord/test/cases/primary_keys_test.rb
@@ -434,7 +434,7 @@ if current_adapter?(:PostgreSQLAdapter, :Mysql2Adapter)
test "schema dump primary key with serial/integer" do
@connection.create_table(:widgets, id: @pk_type, force: true)
schema = dump_table_schema "widgets"
- assert_match %r{create_table "widgets", id: :#{@pk_type}, force: :cascade}, schema
+ assert_match %r{create_table "widgets", id: :#{@pk_type}, }, schema
end
if current_adapter?(:Mysql2Adapter)
@@ -447,7 +447,7 @@ if current_adapter?(:PostgreSQLAdapter, :Mysql2Adapter)
assert column.unsigned?
schema = dump_table_schema "widgets"
- assert_match %r{create_table "widgets", id: :integer, unsigned: true, force: :cascade}, schema
+ assert_match %r{create_table "widgets", id: :integer, unsigned: true, }, schema
end
test "bigint primary key with unsigned" do
@@ -459,7 +459,7 @@ if current_adapter?(:PostgreSQLAdapter, :Mysql2Adapter)
assert column.unsigned?
schema = dump_table_schema "widgets"
- assert_match %r{create_table "widgets", id: :bigint, unsigned: true, force: :cascade}, schema
+ assert_match %r{create_table "widgets", id: :bigint, unsigned: true, }, schema
end
end
end
diff --git a/activerecord/test/cases/relation/delegation_test.rb b/activerecord/test/cases/relation/delegation_test.rb
index 3089aee959..2696d1bb00 100644
--- a/activerecord/test/cases/relation/delegation_test.rb
+++ b/activerecord/test/cases/relation/delegation_test.rb
@@ -10,8 +10,8 @@ module ActiveRecord
:+, :-, :|, :&, :[], :shuffle,
:all?, :collect, :compact, :detect, :each, :each_cons, :each_with_index,
:exclude?, :find_all, :flat_map, :group_by, :include?, :length,
- :map, :none?, :one?, :partition, :reject, :reverse,
- :sample, :second, :sort, :sort_by, :third,
+ :map, :none?, :one?, :partition, :reject, :reverse, :rotate,
+ :sample, :second, :sort, :sort_by, :slice, :third, :index, :rindex,
:to_ary, :to_set, :to_xml, :to_yaml, :join,
:in_groups, :in_groups_of, :to_sentence, :to_formatted_s, :as_json
]
@@ -32,6 +32,7 @@ module ActiveRecord
def test_deprecate_arel_delegation
AREL_METHODS.each do |method|
assert_deprecated { target.public_send(method) }
+ assert_deprecated { target.public_send(method) }
end
end
end
@@ -40,10 +41,8 @@ module ActiveRecord
include DelegationWhitelistTests
include DeprecatedArelDelegationTests
- fixtures :posts
-
def target
- Post.first.comments
+ Post.new.comments
end
end
@@ -51,8 +50,6 @@ module ActiveRecord
include DelegationWhitelistTests
include DeprecatedArelDelegationTests
- fixtures :comments
-
def target
Comment.all
end
diff --git a/activerecord/test/cases/relation/or_test.rb b/activerecord/test/cases/relation/or_test.rb
index b01801b41f..955e9fc9ce 100644
--- a/activerecord/test/cases/relation/or_test.rb
+++ b/activerecord/test/cases/relation/or_test.rb
@@ -8,7 +8,7 @@ require "models/post"
module ActiveRecord
class OrTest < ActiveRecord::TestCase
fixtures :posts
- fixtures :authors
+ fixtures :authors, :author_addresses
def test_or_with_relation
expected = Post.where("id = 1 or id = 2").to_a
diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb
index eb9b257da9..799a65c61e 100644
--- a/activerecord/test/cases/schema_dumper_test.rb
+++ b/activerecord/test/cases/schema_dumper_test.rb
@@ -66,7 +66,7 @@ class SchemaDumperTest < ActiveRecord::TestCase
def test_schema_dump_uses_force_cascade_on_create_table
output = dump_table_schema "authors"
- assert_match %r{create_table "authors", force: :cascade}, output
+ assert_match %r{create_table "authors",.* force: :cascade}, output
end
def test_schema_dump_excludes_sqlite_sequence
@@ -207,20 +207,25 @@ class SchemaDumperTest < ActiveRecord::TestCase
end
def test_schema_dump_should_use_false_as_default
- output = standard_dump
+ output = dump_table_schema "booleans"
assert_match %r{t\.boolean\s+"has_fun",.+default: false}, output
end
def test_schema_dump_does_not_include_limit_for_text_field
- output = standard_dump
+ output = dump_table_schema "admin_users"
assert_match %r{t\.text\s+"params"$}, output
end
def test_schema_dump_does_not_include_limit_for_binary_field
- output = standard_dump
+ output = dump_table_schema "binaries"
assert_match %r{t\.binary\s+"data"$}, output
end
+ def test_schema_dump_does_not_include_limit_for_float_field
+ output = dump_table_schema "numeric_data"
+ assert_match %r{t\.float\s+"temperature"$}, output
+ end
+
if current_adapter?(:Mysql2Adapter)
def test_schema_dump_includes_length_for_mysql_binary_fields
output = standard_dump
diff --git a/activerecord/test/cases/tasks/postgresql_rake_test.rb b/activerecord/test/cases/tasks/postgresql_rake_test.rb
index 693503250b..6302e84884 100644
--- a/activerecord/test/cases/tasks/postgresql_rake_test.rb
+++ b/activerecord/test/cases/tasks/postgresql_rake_test.rb
@@ -295,6 +295,16 @@ if current_adapter?(:PostgreSQLAdapter)
end
end
+ def test_structure_dump_execution_fails
+ filename = "awesome-file.sql"
+ Kernel.expects(:system).with("pg_dump", "-s", "-x", "-O", "-f", filename, "my-app-db").returns(nil)
+
+ e = assert_raise(RuntimeError) do
+ ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, filename)
+ end
+ assert_match("failed to execute:", e.message)
+ end
+
private
def with_dump_schemas(value, &block)
old_dump_schemas = ActiveRecord::Base.dump_schemas
diff --git a/activerecord/test/cases/tasks/sqlite_rake_test.rb b/activerecord/test/cases/tasks/sqlite_rake_test.rb
index 8ac4878c37..d7e3caa2ff 100644
--- a/activerecord/test/cases/tasks/sqlite_rake_test.rb
+++ b/activerecord/test/cases/tasks/sqlite_rake_test.rb
@@ -215,6 +215,31 @@ if current_adapter?(:SQLite3Adapter)
FileUtils.rm_f(filename)
FileUtils.rm_f(dbfile)
end
+
+ def test_structure_dump_execution_fails
+ dbfile = @database
+ filename = "awesome-file.sql"
+ Kernel.expects(:system).with("sqlite3", "--noop", "db_create.sqlite3", ".schema", out: "awesome-file.sql").returns(nil)
+
+ e = assert_raise(RuntimeError) do
+ with_structure_dump_flags(["--noop"]) do
+ quietly { ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, filename, "/rails/root") }
+ end
+ end
+ assert_match("failed to execute:", e.message)
+ ensure
+ FileUtils.rm_f(filename)
+ FileUtils.rm_f(dbfile)
+ end
+
+ private
+ def with_structure_dump_flags(flags)
+ old = ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags
+ ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = flags
+ yield
+ ensure
+ ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = old
+ end
end
class SqliteStructureLoadTest < ActiveRecord::TestCase
diff --git a/activerecord/test/migrations/empty/.gitkeep b/activerecord/test/migrations/empty/.keep
index e69de29bb2..e69de29bb2 100644
--- a/activerecord/test/migrations/empty/.gitkeep
+++ b/activerecord/test/migrations/empty/.keep
diff --git a/activerecord/test/models/comment.rb b/activerecord/test/models/comment.rb
index 61c54a77a7..740aa593ac 100644
--- a/activerecord/test/models/comment.rb
+++ b/activerecord/test/models/comment.rb
@@ -1,5 +1,8 @@
# frozen_string_literal: true
+# `counter_cache` requires association class before `attr_readonly`.
+class Post < ActiveRecord::Base; end
+
class Comment < ActiveRecord::Base
scope :limit_by, lambda { |l| limit(l) }
scope :containing_the_letter_e, -> { where("comments.body LIKE '%e%'") }
diff --git a/activestorage/app/controllers/active_storage/disk_controller.rb b/activestorage/app/controllers/active_storage/disk_controller.rb
index b10d4e2cac..41e6d61bff 100644
--- a/activestorage/app/controllers/active_storage/disk_controller.rb
+++ b/activestorage/app/controllers/active_storage/disk_controller.rb
@@ -8,7 +8,7 @@ class ActiveStorage::DiskController < ActionController::Base
def show
if key = decode_verified_key
send_data disk_service.download(key),
- filename: params[:filename], disposition: disposition_param, content_type: params[:content_type]
+ disposition: disposition_param, content_type: params[:content_type]
else
head :not_found
end
@@ -39,7 +39,7 @@ class ActiveStorage::DiskController < ActionController::Base
end
def disposition_param
- params[:disposition].presence_in(%w( inline attachment )) || "inline"
+ params[:disposition].presence || "inline"
end
diff --git a/activestorage/app/jobs/active_storage/purge_job.rb b/activestorage/app/jobs/active_storage/purge_job.rb
index 369c07929d..990ab27c9f 100644
--- a/activestorage/app/jobs/active_storage/purge_job.rb
+++ b/activestorage/app/jobs/active_storage/purge_job.rb
@@ -1,11 +1,11 @@
# frozen_string_literal: true
-# Provides delayed purging of attachments or blobs using their +purge_later+ method.
+# Provides delayed purging of ActiveStorage::Blob records via ActiveStorage::Blob#purge_later.
class ActiveStorage::PurgeJob < ActiveJob::Base
# FIXME: Limit this to a custom ActiveStorage error
retry_on StandardError
- def perform(attachment_or_blob)
- attachment_or_blob.purge
+ def perform(blob)
+ blob.purge
end
end
diff --git a/activestorage/app/models/active_storage/attachment.rb b/activestorage/app/models/active_storage/attachment.rb
index ad43845e4e..2a1c20b7db 100644
--- a/activestorage/app/models/active_storage/attachment.rb
+++ b/activestorage/app/models/active_storage/attachment.rb
@@ -14,17 +14,15 @@ class ActiveStorage::Attachment < ActiveRecord::Base
delegate_missing_to :blob
- # Purging an attachment will purge the blob (delete the file on the service, then destroy the record)
- # and then destroy the attachment itself.
+ # Synchronously purges the blob (deletes it from the configured service) and destroys the attachment.
def purge
blob.purge
destroy
end
- # Purging an attachment means purging the blob, which means talking to the service, which means
- # talking over the Internet. Whenever you're doing that, it's a good idea to put that work in a job,
- # so it doesn't hold up other operations. That's what +purge_later+ provides.
+ # Destroys the attachment and asynchronously purges the blob (deletes it from the configured service).
def purge_later
- ActiveStorage::PurgeJob.perform_later(self)
+ blob.purge_later
+ destroy
end
end
diff --git a/activestorage/app/models/active_storage/blob.rb b/activestorage/app/models/active_storage/blob.rb
index 9f2ed1e5ac..e6cf08ce83 100644
--- a/activestorage/app/models/active_storage/blob.rb
+++ b/activestorage/app/models/active_storage/blob.rb
@@ -3,8 +3,8 @@
# A blob is a record that contains the metadata about a file and a key for where that file resides on the service.
# Blobs can be created in two ways:
#
-# 1) Subsequent to the file being uploaded server-side to the service via <tt>create_after_upload!</tt>.
-# 2) Ahead of the file being directly uploaded client-side to the service via <tt>create_before_direct_upload!</tt>.
+# 1. Subsequent to the file being uploaded server-side to the service via <tt>create_after_upload!</tt>.
+# 2. Ahead of the file being directly uploaded client-side to the service via <tt>create_before_direct_upload!</tt>.
#
# The first option doesn't require any client-side JavaScript integration, and can be used by any other back-end
# service that deals with files. The second option is faster, since you're not using your own server as a staging
@@ -127,7 +127,7 @@ class ActiveStorage::Blob < ActiveRecord::Base
# Hiding the +service_url+ behind a redirect also gives you the power to change services without updating all URLs. And
# it allows permanent URLs that redirect to the +service_url+ to be cached in the view.
def service_url(expires_in: 5.minutes, disposition: :inline)
- service.url key, expires_in: expires_in, disposition: disposition, filename: filename, content_type: content_type
+ service.url key, expires_in: expires_in, disposition: "#{disposition}; #{filename.parameters}", filename: filename, content_type: content_type
end
# Returns a URL that can be used to directly upload a file for this blob on the service. This URL is intended to be
diff --git a/activestorage/app/models/active_storage/filename.rb b/activestorage/app/models/active_storage/filename.rb
index 6a9889addf..dead6b6d33 100644
--- a/activestorage/app/models/active_storage/filename.rb
+++ b/activestorage/app/models/active_storage/filename.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
# Encapsulates a string representing a filename to provide convenience access to parts of it and a sanitized version.
-# This is what's returned by `ActiveStorage::Blob#filename`. A Filename instance is comparable so it can be used for sorting.
+# This is what's returned by ActiveStorage::Blob#filename. A Filename instance is comparable so it can be used for sorting.
class ActiveStorage::Filename
include Comparable
@@ -9,29 +9,43 @@ class ActiveStorage::Filename
@filename = filename
end
- # Filename.new("racecar.jpg").extname # => ".jpg"
- def extname
- File.extname(@filename)
+ # Returns the basename of the filename.
+ #
+ # ActiveStorage::Filename.new("racecar.jpg").base # => "racecar"
+ def base
+ File.basename @filename, extension_with_delimiter
end
- # Filename.new("racecar.jpg").extension # => "jpg"
- def extension
- extname.from(1)
+ # Returns the extension with delimiter of the filename.
+ #
+ # ActiveStorage::Filename.new("racecar.jpg").extension_with_delimiter # => ".jpg"
+ def extension_with_delimiter
+ File.extname @filename
end
- # Filename.new("racecar.jpg").base # => "racecar"
- def base
- File.basename(@filename, extname)
+ # Returns the extension without delimiter of the filename.
+ #
+ # ActiveStorage::Filename.new("racecar.jpg").extension_without_delimiter # => "jpg"
+ def extension_without_delimiter
+ extension_with_delimiter.from(1).to_s
end
- # Filename.new("foo:bar.jpg").sanitized # => "foo-bar.jpg"
- # Filename.new("foo/bar.jpg").sanitized # => "foo-bar.jpg"
+ alias_method :extension, :extension_without_delimiter
+
+ # Returns the sanitized filename.
+ #
+ # ActiveStorage::Filename.new("foo:bar.jpg").sanitized # => "foo-bar.jpg"
+ # ActiveStorage::Filename.new("foo/bar.jpg").sanitized # => "foo-bar.jpg"
#
# ...and any other character unsafe for URLs or storage is converted or stripped.
def sanitized
@filename.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "�").strip.tr("\u{202E}%$|:;/\t\r\n\\", "-")
end
+ def parameters
+ Parameters.new self
+ end
+
# Returns the sanitized version of the filename.
def to_s
sanitized.to_s
diff --git a/activestorage/app/models/active_storage/filename/parameters.rb b/activestorage/app/models/active_storage/filename/parameters.rb
new file mode 100644
index 0000000000..58ce198d38
--- /dev/null
+++ b/activestorage/app/models/active_storage/filename/parameters.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+class ActiveStorage::Filename::Parameters
+ attr_reader :filename
+
+ def initialize(filename)
+ @filename = filename
+ end
+
+ def combined
+ "#{ascii}; #{utf8}"
+ end
+
+ TRADITIONAL_ESCAPED_CHAR = /[^ A-Za-z0-9!#$+.^_`|~-]/
+
+ def ascii
+ 'filename="' + percent_escape(I18n.transliterate(filename.sanitized), TRADITIONAL_ESCAPED_CHAR) + '"'
+ end
+
+ RFC_5987_ESCAPED_CHAR = /[^A-Za-z0-9!#$&+.^_`|~-]/
+
+ def utf8
+ "filename*=UTF-8''" + percent_escape(filename.sanitized, RFC_5987_ESCAPED_CHAR)
+ end
+
+ def to_s
+ combined
+ end
+
+ private
+ def percent_escape(string, pattern)
+ string.gsub(pattern) do |char|
+ char.bytes.map { |byte| "%%%02X" % byte }.join
+ end
+ end
+end
diff --git a/activestorage/app/models/active_storage/variant.rb b/activestorage/app/models/active_storage/variant.rb
index 40648a27f7..02bf32b352 100644
--- a/activestorage/app/models/active_storage/variant.rb
+++ b/activestorage/app/models/active_storage/variant.rb
@@ -4,7 +4,7 @@
# These variants are used to create thumbnails, fixed-size avatars, or any other derivative image from the
# original.
#
-# Variants rely on {MiniMagick}(https://github.com/minimagick/minimagick) for the actual transformations
+# Variants rely on {MiniMagick}[https://github.com/minimagick/minimagick] for the actual transformations
# of the file, so you must add <tt>gem "mini_magick"</tt> to your Gemfile if you wish to use variants.
#
# Note that to create a variant it's necessary to download the entire blob file from the service and load it
diff --git a/activestorage/app/models/active_storage/variation.rb b/activestorage/app/models/active_storage/variation.rb
index f657d90db4..bf269e2a8f 100644
--- a/activestorage/app/models/active_storage/variation.rb
+++ b/activestorage/app/models/active_storage/variation.rb
@@ -3,7 +3,7 @@
require "active_support/core_ext/object/inclusion"
# A set of transformations that can be applied to a blob to create a variant. This class is exposed via
-# the `ActiveStorage::Blob#variant` method and should rarely be used directly.
+# the ActiveStorage::Blob#variant method and should rarely be used directly.
#
# In case you do need to use this directly, it's instantiated using a hash of transformations where
# the key is the command and the value is the arguments. Example:
diff --git a/activestorage/bin/test b/activestorage/bin/test
new file mode 100755
index 0000000000..c53377cc97
--- /dev/null
+++ b/activestorage/bin/test
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+COMPONENT_ROOT = File.expand_path("..", __dir__)
+require_relative "../../tools/test"
diff --git a/activestorage/db/migrate/20170806125915_create_active_storage_tables.rb b/activestorage/db/migrate/20170806125915_create_active_storage_tables.rb
index d333b6bf9c..9e31e3966a 100644
--- a/activestorage/db/migrate/20170806125915_create_active_storage_tables.rb
+++ b/activestorage/db/migrate/20170806125915_create_active_storage_tables.rb
@@ -1,13 +1,11 @@
-# frozen_string_literal: true
-
-class CreateActiveStorageTables < ActiveRecord::Migration[5.1]
+class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
def change
create_table :active_storage_blobs do |t|
t.string :key, null: false
t.string :filename, null: false
t.string :content_type
t.text :metadata
- t.integer :byte_size, null: false
+ t.bigint :byte_size, null: false
t.string :checksum, null: false
t.datetime :created_at, null: false
diff --git a/activestorage/lib/active_storage/attached.rb b/activestorage/lib/active_storage/attached.rb
index 9c4b6d5d1d..c08fd56652 100644
--- a/activestorage/lib/active_storage/attached.rb
+++ b/activestorage/lib/active_storage/attached.rb
@@ -8,10 +8,10 @@ module ActiveStorage
# Abstract base class for the concrete ActiveStorage::Attached::One and ActiveStorage::Attached::Many
# classes that both provide proxy access to the blob association for a record.
class Attached
- attr_reader :name, :record
+ attr_reader :name, :record, :dependent
- def initialize(name, record)
- @name, @record = name, record
+ def initialize(name, record, dependent:)
+ @name, @record, @dependent = name, record, dependent
end
private
diff --git a/activestorage/lib/active_storage/attached/macros.rb b/activestorage/lib/active_storage/attached/macros.rb
index f3879ee2e3..35a081adc4 100644
--- a/activestorage/lib/active_storage/attached/macros.rb
+++ b/activestorage/lib/active_storage/attached/macros.rb
@@ -26,7 +26,7 @@ module ActiveStorage
def has_one_attached(name, dependent: :purge_later)
class_eval <<-CODE, __FILE__, __LINE__ + 1
def #{name}
- @active_storage_attached_#{name} ||= ActiveStorage::Attached::One.new("#{name}", self)
+ @active_storage_attached_#{name} ||= ActiveStorage::Attached::One.new("#{name}", self, dependent: #{dependent == :purge_later ? ":purge_later" : "false"})
end
CODE
@@ -65,7 +65,7 @@ module ActiveStorage
def has_many_attached(name, dependent: :purge_later)
class_eval <<-CODE, __FILE__, __LINE__ + 1
def #{name}
- @active_storage_attached_#{name} ||= ActiveStorage::Attached::Many.new("#{name}", self)
+ @active_storage_attached_#{name} ||= ActiveStorage::Attached::Many.new("#{name}", self, dependent: #{dependent == :purge_later ? ":purge_later" : "false"})
end
CODE
diff --git a/activestorage/lib/active_storage/attached/one.rb b/activestorage/lib/active_storage/attached/one.rb
index 2e5831348e..ac90f32d95 100644
--- a/activestorage/lib/active_storage/attached/one.rb
+++ b/activestorage/lib/active_storage/attached/one.rb
@@ -21,11 +21,14 @@ module ActiveStorage
# person.avatar.attach(io: File.open("~/face.jpg"), filename: "face.jpg", content_type: "image/jpg")
# person.avatar.attach(avatar_blob) # ActiveStorage::Blob object
def attach(attachable)
- write_attachment \
- ActiveStorage::Attachment.create!(record: record, name: name, blob: create_blob_from(attachable))
+ if attached? && dependent == :purge_later
+ replace attachable
+ else
+ write_attachment create_attachment_from(attachable)
+ end
end
- # Returns true if an attachment has been made.
+ # Returns +true+ if an attachment has been made.
#
# class User < ActiveRecord::Base
# has_one_attached :avatar
@@ -53,6 +56,19 @@ module ActiveStorage
end
private
+ def replace(attachable)
+ blob.tap do
+ transaction do
+ destroy
+ write_attachment create_attachment_from(attachable)
+ end
+ end.purge_later
+ end
+
+ def create_attachment_from(attachable)
+ ActiveStorage::Attachment.create!(record: record, name: name, blob: create_blob_from(attachable))
+ end
+
def write_attachment(attachment)
record.public_send("#{name}_attachment=", attachment)
end
diff --git a/activestorage/lib/active_storage/service.rb b/activestorage/lib/active_storage/service.rb
index ce736b8728..b80fdea1ab 100644
--- a/activestorage/lib/active_storage/service.rb
+++ b/activestorage/lib/active_storage/service.rb
@@ -77,7 +77,7 @@ module ActiveStorage
raise NotImplementedError
end
- # Return true if a file exists at the +key+.
+ # Return +true+ if a file exists at the +key+.
def exist?(key)
raise NotImplementedError
end
diff --git a/activestorage/lib/active_storage/service/azure_storage_service.rb b/activestorage/lib/active_storage/service/azure_storage_service.rb
index d0ee2273c5..895cc9c2f1 100644
--- a/activestorage/lib/active_storage/service/azure_storage_service.rb
+++ b/activestorage/lib/active_storage/service/azure_storage_service.rb
@@ -59,12 +59,16 @@ module ActiveStorage
end
end
- def url(key, expires_in:, disposition:, filename:, content_type:)
+ def url(key, expires_in:, filename:, disposition:, content_type:)
instrument :url, key do |payload|
base_url = url_for(key)
- generated_url = signer.signed_uri(URI(base_url), false, permissions: "r",
- expiry: format_expiry(expires_in), content_type: content_type,
- content_disposition: "#{disposition}; filename=\"#{filename}\"").to_s
+ generated_url = signer.signed_uri(
+ URI(base_url), false,
+ permissions: "r",
+ expiry: format_expiry(expires_in),
+ content_disposition: disposition,
+ content_type: content_type
+ ).to_s
payload[:url] = generated_url
diff --git a/activestorage/lib/active_storage/service/disk_service.rb b/activestorage/lib/active_storage/service/disk_service.rb
index 1d121dcb6c..f600753a08 100644
--- a/activestorage/lib/active_storage/service/disk_service.rb
+++ b/activestorage/lib/active_storage/service/disk_service.rb
@@ -56,7 +56,7 @@ module ActiveStorage
end
end
- def url(key, expires_in:, disposition:, filename:, content_type:)
+ def url(key, expires_in:, filename:, disposition:, content_type:)
instrument :url, key do |payload|
verified_key_with_expiration = ActiveStorage.verifier.generate(key, expires_in: expires_in, purpose: :blob_key)
@@ -64,9 +64,9 @@ module ActiveStorage
if defined?(Rails.application)
Rails.application.routes.url_helpers.rails_disk_service_path \
verified_key_with_expiration,
- disposition: disposition, filename: filename, content_type: content_type
+ filename: filename, disposition: disposition, content_type: content_type
else
- "/rails/active_storage/disk/#{verified_key_with_expiration}/#{filename}?disposition=#{disposition}&content_type=#{content_type}"
+ "/rails/active_storage/disk/#{verified_key_with_expiration}/#{filename}?content_type=#{content_type}&disposition=#{disposition}"
end
payload[:url] = generated_url
diff --git a/activestorage/lib/active_storage/service/gcs_service.rb b/activestorage/lib/active_storage/service/gcs_service.rb
index e656f2c69f..ebf24a36d7 100644
--- a/activestorage/lib/active_storage/service/gcs_service.rb
+++ b/activestorage/lib/active_storage/service/gcs_service.rb
@@ -47,10 +47,10 @@ module ActiveStorage
end
end
- def url(key, expires_in:, disposition:, filename:, content_type:)
+ def url(key, expires_in:, filename:, content_type:, disposition:)
instrument :url, key do |payload|
generated_url = file_for(key).signed_url expires: expires_in, query: {
- "response-content-disposition" => "#{disposition}; filename=\"#{filename}\"",
+ "response-content-disposition" => disposition,
"response-content-type" => content_type
}
diff --git a/activestorage/lib/active_storage/service/s3_service.rb b/activestorage/lib/active_storage/service/s3_service.rb
index bef2ecbea9..e5d1e56e05 100644
--- a/activestorage/lib/active_storage/service/s3_service.rb
+++ b/activestorage/lib/active_storage/service/s3_service.rb
@@ -52,10 +52,10 @@ module ActiveStorage
end
end
- def url(key, expires_in:, disposition:, filename:, content_type:)
+ def url(key, expires_in:, filename:, disposition:, content_type:)
instrument :url, key do |payload|
generated_url = object_for(key).presigned_url :get, expires_in: expires_in,
- response_content_disposition: "#{disposition}; filename=\"#{filename}\"",
+ response_content_disposition: disposition,
response_content_type: content_type
payload[:url] = generated_url
diff --git a/activestorage/test/controllers/disk_controller_test.rb b/activestorage/test/controllers/disk_controller_test.rb
index 53a086f214..940dbf5918 100644
--- a/activestorage/test/controllers/disk_controller_test.rb
+++ b/activestorage/test/controllers/disk_controller_test.rb
@@ -8,7 +8,7 @@ class ActiveStorage::DiskControllerTest < ActionDispatch::IntegrationTest
blob = create_blob
get blob.service_url
- assert_equal "inline; filename=\"#{blob.filename.base}\"", @response.headers["Content-Disposition"]
+ assert_equal "inline; filename=\"hello.txt\"; filename*=UTF-8''hello.txt", @response.headers["Content-Disposition"]
assert_equal "text/plain", @response.headers["Content-Type"]
end
@@ -16,7 +16,7 @@ class ActiveStorage::DiskControllerTest < ActionDispatch::IntegrationTest
blob = create_blob
get blob.service_url(disposition: :attachment)
- assert_equal "attachment; filename=\"#{blob.filename.base}\"", @response.headers["Content-Disposition"]
+ assert_equal "attachment; filename=\"hello.txt\"; filename*=UTF-8''hello.txt", @response.headers["Content-Disposition"]
assert_equal "text/plain", @response.headers["Content-Type"]
end
diff --git a/activestorage/test/database/create_users_migration.rb b/activestorage/test/database/create_users_migration.rb
index 317daa87b5..fdba87cacf 100644
--- a/activestorage/test/database/create_users_migration.rb
+++ b/activestorage/test/database/create_users_migration.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-class ActiveStorageCreateUsers < ActiveRecord::Migration[5.1]
+class ActiveStorageCreateUsers < ActiveRecord::Migration[5.2]
def change
create_table :users do |t|
t.string :name
diff --git a/activestorage/test/models/attachments_test.rb b/activestorage/test/models/attachments_test.rb
index 7cfd8683db..ac346c0087 100644
--- a/activestorage/test/models/attachments_test.rb
+++ b/activestorage/test/models/attachments_test.rb
@@ -31,6 +31,31 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase
assert_equal "racecar.jpg", @user.avatar.filename.to_s
end
+ test "replace attached blob" do
+ @user.avatar.attach create_blob(filename: "funky.jpg")
+
+ perform_enqueued_jobs do
+ assert_no_difference -> { ActiveStorage::Blob.count } do
+ @user.avatar.attach create_blob(filename: "town.jpg")
+ end
+ end
+
+ assert_equal "town.jpg", @user.avatar.filename.to_s
+ end
+
+ test "replace attached blob unsuccessfully" do
+ @user.avatar.attach create_blob(filename: "funky.jpg")
+
+ perform_enqueued_jobs do
+ assert_raises do
+ @user.avatar.attach nil
+ end
+ end
+
+ assert_equal "funky.jpg", @user.reload.avatar.filename.to_s
+ assert ActiveStorage::Blob.service.exist?(@user.avatar.key)
+ end
+
test "access underlying associations of new blob" do
@user.avatar.attach create_blob(filename: "funky.jpg")
assert_equal @user, @user.avatar_attachment.record
diff --git a/activestorage/test/models/blob_test.rb b/activestorage/test/models/blob_test.rb
index 99f2fb20b0..6e815997ba 100644
--- a/activestorage/test/models/blob_test.rb
+++ b/activestorage/test/models/blob_test.rb
@@ -50,7 +50,7 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase
private
def expected_url_for(blob, disposition: :inline)
- query_string = { content_type: blob.content_type, disposition: disposition }.to_param
+ query_string = { content_type: blob.content_type, disposition: "#{disposition}; #{blob.filename.parameters}" }.to_param
"/rails/active_storage/disk/#{ActiveStorage.verifier.generate(blob.key, expires_in: 5.minutes, purpose: :blob_key)}/#{blob.filename}?#{query_string}"
end
end
diff --git a/activestorage/test/models/filename/parameters_test.rb b/activestorage/test/models/filename/parameters_test.rb
new file mode 100644
index 0000000000..431be00639
--- /dev/null
+++ b/activestorage/test/models/filename/parameters_test.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+require "test_helper"
+
+class ActiveStorage::Filename::ParametersTest < ActiveSupport::TestCase
+ test "parameterizing a Latin filename" do
+ filename = ActiveStorage::Filename.new("racecar.jpg")
+
+ assert_equal %(filename="racecar.jpg"), filename.parameters.ascii
+ assert_equal "filename*=UTF-8''racecar.jpg", filename.parameters.utf8
+ assert_equal "#{filename.parameters.ascii}; #{filename.parameters.utf8}", filename.parameters.combined
+ assert_equal filename.parameters.combined, filename.parameters.to_s
+ end
+
+ test "parameterizing a Latin filename with accented characters" do
+ filename = ActiveStorage::Filename.new("råcëçâr.jpg")
+
+ assert_equal %(filename="racecar.jpg"), filename.parameters.ascii
+ assert_equal "filename*=UTF-8''r%C3%A5c%C3%AB%C3%A7%C3%A2r.jpg", filename.parameters.utf8
+ assert_equal "#{filename.parameters.ascii}; #{filename.parameters.utf8}", filename.parameters.combined
+ assert_equal filename.parameters.combined, filename.parameters.to_s
+ end
+
+ test "parameterizing a non-Latin filename" do
+ filename = ActiveStorage::Filename.new("автомобиль.jpg")
+
+ assert_equal %(filename="%3F%3F%3F%3F%3F%3F%3F%3F%3F%3F.jpg"), filename.parameters.ascii
+ assert_equal "filename*=UTF-8''%D0%B0%D0%B2%D1%82%D0%BE%D0%BC%D0%BE%D0%B1%D0%B8%D0%BB%D1%8C.jpg", filename.parameters.utf8
+ assert_equal "#{filename.parameters.ascii}; #{filename.parameters.utf8}", filename.parameters.combined
+ assert_equal filename.parameters.combined, filename.parameters.to_s
+ end
+end
diff --git a/activestorage/test/models/filename_test.rb b/activestorage/test/models/filename_test.rb
index f1e4a467ba..88405e41c0 100644
--- a/activestorage/test/models/filename_test.rb
+++ b/activestorage/test/models/filename_test.rb
@@ -3,6 +3,24 @@
require "test_helper"
class ActiveStorage::FilenameTest < ActiveSupport::TestCase
+ test "base" do
+ assert_equal "racecar", ActiveStorage::Filename.new("racecar.jpg").base
+ assert_equal "race.car", ActiveStorage::Filename.new("race.car.jpg").base
+ assert_equal "racecar", ActiveStorage::Filename.new("racecar").base
+ end
+
+ test "extension with delimiter" do
+ assert_equal ".jpg", ActiveStorage::Filename.new("racecar.jpg").extension_with_delimiter
+ assert_equal ".jpg", ActiveStorage::Filename.new("race.car.jpg").extension_with_delimiter
+ assert_equal "", ActiveStorage::Filename.new("racecar").extension_with_delimiter
+ end
+
+ test "extension without delimiter" do
+ assert_equal "jpg", ActiveStorage::Filename.new("racecar.jpg").extension_without_delimiter
+ assert_equal "jpg", ActiveStorage::Filename.new("race.car.jpg").extension_without_delimiter
+ assert_equal "", ActiveStorage::Filename.new("racecar").extension_without_delimiter
+ end
+
test "sanitize" do
"%$|:;/\t\r\n\\".each_char do |character|
filename = ActiveStorage::Filename.new("foo#{character}bar.pdf")
diff --git a/activestorage/test/service/azure_storage_service_test.rb b/activestorage/test/service/azure_storage_service_test.rb
index dac154cf11..4729bdfbc5 100644
--- a/activestorage/test/service/azure_storage_service_test.rb
+++ b/activestorage/test/service/azure_storage_service_test.rb
@@ -11,9 +11,9 @@ if SERVICE_CONFIGURATIONS[:azure]
test "signed URL generation" do
url = @service.url(FIXTURE_KEY, expires_in: 5.minutes,
- disposition: :inline, filename: "avatar.png", content_type: "image/png")
+ disposition: "inline; filename=\"avatar.png\"", filename: "avatar.png", content_type: "image/png")
- assert_match(/(\S+)&rsct=image%2Fpng&rscd=inline%3B\+filename%3D%22avatar.png/, url)
+ assert_match(/(\S+)&rscd=inline%3B\+filename%3D%22avatar.png%22&rsct=image%2Fpng/, url)
assert_match SERVICE_CONFIGURATIONS[:azure][:container], url
end
end
diff --git a/activestorage/test/service/disk_service_test.rb b/activestorage/test/service/disk_service_test.rb
index 835a3a2971..e07d1d88bc 100644
--- a/activestorage/test/service/disk_service_test.rb
+++ b/activestorage/test/service/disk_service_test.rb
@@ -8,7 +8,7 @@ class ActiveStorage::Service::DiskServiceTest < ActiveSupport::TestCase
include ActiveStorage::Service::SharedServiceTests
test "url generation" do
- assert_match(/rails\/active_storage\/disk\/.*\/avatar\.png\?.+disposition=inline/,
- @service.url(FIXTURE_KEY, expires_in: 5.minutes, disposition: :inline, filename: "avatar.png", content_type: "image/png"))
+ assert_match(/rails\/active_storage\/disk\/.*\/avatar\.png\?content_type=image%2Fpng&disposition=inline/,
+ @service.url(FIXTURE_KEY, expires_in: 5.minutes, disposition: "inline; filename=\"avatar.png\"", filename: "avatar.png", content_type: "image/png"))
end
end
diff --git a/activestorage/test/service/gcs_service_test.rb b/activestorage/test/service/gcs_service_test.rb
index 5f53f61baf..f664cee90b 100644
--- a/activestorage/test/service/gcs_service_test.rb
+++ b/activestorage/test/service/gcs_service_test.rb
@@ -37,7 +37,7 @@ if SERVICE_CONFIGURATIONS[:gcs]
"&response-content-disposition=inline%3B+filename%3D%22test.txt%22" +
"&response-content-type=text%2Fplain"
- assert_equal url, @service.url(FIXTURE_KEY, expires_in: 2.minutes, disposition: :inline, filename: "test.txt", content_type: "text/plain")
+ assert_equal url, @service.url(FIXTURE_KEY, expires_in: 2.minutes, disposition: "inline; filename=\"test.txt\"", filename: "test.txt", content_type: "text/plain")
end
end
end
diff --git a/activestorage/test/service/s3_service_test.rb b/activestorage/test/service/s3_service_test.rb
index 98f520741d..c07d6396b1 100644
--- a/activestorage/test/service/s3_service_test.rb
+++ b/activestorage/test/service/s3_service_test.rb
@@ -33,7 +33,7 @@ if SERVICE_CONFIGURATIONS[:s3] && SERVICE_CONFIGURATIONS[:s3][:access_key_id].pr
test "signed URL generation" do
url = @service.url(FIXTURE_KEY, expires_in: 5.minutes,
- disposition: :inline, filename: "avatar.png", content_type: "image/png")
+ disposition: "inline; filename=\"avatar.png\"", filename: "avatar.png", content_type: "image/png")
assert_match(/s3\.(\S+)?amazonaws.com.*response-content-disposition=inline.*avatar\.png.*response-content-type=image%2Fpng/, url)
assert_match SERVICE_CONFIGURATIONS[:s3][:bucket], url
diff --git a/activestorage/test/template/image_tag_test.rb b/activestorage/test/template/image_tag_test.rb
index 46dd97b3e9..dedc58452e 100644
--- a/activestorage/test/template/image_tag_test.rb
+++ b/activestorage/test/template/image_tag_test.rb
@@ -11,17 +11,17 @@ class ActiveStorage::ImageTagTest < ActionView::TestCase
end
test "blob" do
- assert_dom_equal %(<img alt="Racecar" src="#{polymorphic_url @blob}" />), image_tag(@blob)
+ assert_dom_equal %(<img src="#{polymorphic_url @blob}" />), image_tag(@blob)
end
test "variant" do
variant = @blob.variant(resize: "100x100")
- assert_dom_equal %(<img alt="Racecar" src="#{polymorphic_url variant}" />), image_tag(variant)
+ assert_dom_equal %(<img src="#{polymorphic_url variant}" />), image_tag(variant)
end
test "attachment" do
attachment = ActiveStorage::Attachment.new(blob: @blob)
- assert_dom_equal %(<img alt="Racecar" src="#{polymorphic_url attachment}" />), image_tag(attachment)
+ assert_dom_equal %(<img src="#{polymorphic_url attachment}" />), image_tag(attachment)
end
test "error when attachment's empty" do
diff --git a/activesupport/README.rdoc b/activesupport/README.rdoc
index 14ce204303..8b47933bd2 100644
--- a/activesupport/README.rdoc
+++ b/activesupport/README.rdoc
@@ -21,7 +21,7 @@ Source code can be downloaded as part of the Rails project on GitHub:
Active Support is released under the MIT license:
-* http://www.opensource.org/licenses/MIT
+* https://opensource.org/licenses/MIT
== Support
diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb
index 73924aaaf9..d7bd914722 100644
--- a/activesupport/lib/active_support/cache/mem_cache_store.rb
+++ b/activesupport/lib/active_support/cache/mem_cache_store.rb
@@ -14,7 +14,7 @@ require_relative "../core_ext/array/extract_options"
module ActiveSupport
module Cache
# A cache store implementation which stores data in Memcached:
- # http://memcached.org/
+ # https://memcached.org
#
# This is currently the most popular cache store for production websites.
#
diff --git a/activesupport/lib/active_support/core_ext/digest/uuid.rb b/activesupport/lib/active_support/core_ext/digest/uuid.rb
index 992e1081e4..6e949a2d72 100644
--- a/activesupport/lib/active_support/core_ext/digest/uuid.rb
+++ b/activesupport/lib/active_support/core_ext/digest/uuid.rb
@@ -14,7 +14,7 @@ module Digest
# Using Digest::MD5 generates version 3 UUIDs; Digest::SHA1 generates version 5 UUIDs.
# uuid_from_hash always generates the same UUID for a given name and namespace combination.
#
- # See RFC 4122 for details of UUID at: http://www.ietf.org/rfc/rfc4122.txt
+ # See RFC 4122 for details of UUID at: https://www.ietf.org/rfc/rfc4122.txt
def self.uuid_from_hash(hash_class, uuid_namespace, name)
if hash_class == Digest::MD5
version = 3
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index 3ffe21e559..ad2f21205f 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -85,7 +85,7 @@ module ActiveSupport #:nodoc:
# handles the new constants.
#
# If child.rb is being autoloaded, its constants will be added to
- # autoloaded_constants. If it was being `require`d, they will be discarded.
+ # autoloaded_constants. If it was being required, they will be discarded.
#
# This is handled by walking back up the watch stack and adding the constants
# found by child.rb to the list of original constants in parent.rb.
diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb
index f411bb81df..34024fa8c6 100644
--- a/activesupport/lib/active_support/duration.rb
+++ b/activesupport/lib/active_support/duration.rb
@@ -133,7 +133,7 @@ module ActiveSupport
class << self
# Creates a new Duration from string formatted according to ISO 8601 Duration.
#
- # See {ISO 8601}[http://en.wikipedia.org/wiki/ISO_8601#Durations] for more information.
+ # See {ISO 8601}[https://en.wikipedia.org/wiki/ISO_8601#Durations] for more information.
# This method allows negative parts to be present in pattern.
# If invalid string is provided, it will raise +ActiveSupport::Duration::ISO8601Parser::ParsingError+.
def parse(iso8601duration)
diff --git a/activesupport/lib/active_support/duration/iso8601_parser.rb b/activesupport/lib/active_support/duration/iso8601_parser.rb
index 14b2c27d82..a002424cd9 100644
--- a/activesupport/lib/active_support/duration/iso8601_parser.rb
+++ b/activesupport/lib/active_support/duration/iso8601_parser.rb
@@ -7,7 +7,7 @@ module ActiveSupport
class Duration
# Parses a string formatted according to ISO 8601 Duration into the hash.
#
- # See {ISO 8601}[http://en.wikipedia.org/wiki/ISO_8601#Durations] for more information.
+ # See {ISO 8601}[https://en.wikipedia.org/wiki/ISO_8601#Durations] for more information.
#
# This parser allows negative parts to be present in pattern.
class ISO8601Parser # :nodoc:
diff --git a/activesupport/lib/active_support/message_encryptor.rb b/activesupport/lib/active_support/message_encryptor.rb
index 952306b482..27620f56be 100644
--- a/activesupport/lib/active_support/message_encryptor.rb
+++ b/activesupport/lib/active_support/message_encryptor.rb
@@ -119,13 +119,13 @@ module ActiveSupport
end
# Encrypt and sign a message. We need to sign the message in order to avoid
- # padding attacks. Reference: http://www.limited-entropy.com/padding-oracle-attacks.
+ # padding attacks. Reference: https://www.limited-entropy.com/padding-oracle-attacks/.
def encrypt_and_sign(value, expires_at: nil, expires_in: nil, purpose: nil)
verifier.generate(_encrypt(value, expires_at: expires_at, expires_in: expires_in, purpose: purpose))
end
# Decrypt and verify a message. We need to verify the message in order to
- # avoid padding attacks. Reference: http://www.limited-entropy.com/padding-oracle-attacks.
+ # avoid padding attacks. Reference: https://www.limited-entropy.com/padding-oracle-attacks/.
def decrypt_and_verify(data, purpose: nil)
_decrypt(verifier.verify(data), purpose)
end
diff --git a/activesupport/lib/active_support/xml_mini/jdom.rb b/activesupport/lib/active_support/xml_mini/jdom.rb
index 60c7277028..ebed376c7a 100644
--- a/activesupport/lib/active_support/xml_mini/jdom.rb
+++ b/activesupport/lib/active_support/xml_mini/jdom.rb
@@ -40,7 +40,7 @@ module ActiveSupport
else
@dbf = DocumentBuilderFactory.new_instance
# secure processing of java xml
- # http://www.ibm.com/developerworks/xml/library/x-tipcfsx/index.html
+ # https://archive.is/9xcQQ
@dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
@dbf.setFeature("http://xml.org/sax/features/external-general-entities", false)
@dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false)
diff --git a/guides/source/2_3_release_notes.md b/guides/source/2_3_release_notes.md
index 6976848e95..3f5a3c7ade 100644
--- a/guides/source/2_3_release_notes.md
+++ b/guides/source/2_3_release_notes.md
@@ -10,7 +10,7 @@ Rails 2.3 delivers a variety of new and improved features, including pervasive R
Application Architecture
------------------------
-There are two major changes in the architecture of Rails applications: complete integration of the [Rack](http://rack.github.io/) modular web server interface, and renewed support for Rails Engines.
+There are two major changes in the architecture of Rails applications: complete integration of the [Rack](https://rack.github.io/) modular web server interface, and renewed support for Rails Engines.
### Rack Integration
diff --git a/guides/source/3_0_release_notes.md b/guides/source/3_0_release_notes.md
index 517b38be07..f0e2cb3b63 100644
--- a/guides/source/3_0_release_notes.md
+++ b/guides/source/3_0_release_notes.md
@@ -88,7 +88,7 @@ $ cd myapp
Rails now uses a `Gemfile` in the application root to determine the gems you require for your application to start. This `Gemfile` is processed by the [Bundler](https://github.com/bundler/bundler) which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems.
-More information: - [bundler homepage](http://bundler.io/)
+More information: - [bundler homepage](https://bundler.io/)
### Living on the Edge
diff --git a/guides/source/3_1_release_notes.md b/guides/source/3_1_release_notes.md
index fd90cf9886..17d4ac23b6 100644
--- a/guides/source/3_1_release_notes.md
+++ b/guides/source/3_1_release_notes.md
@@ -151,7 +151,7 @@ $ cd myapp
Rails now uses a `Gemfile` in the application root to determine the gems you require for your application to start. This `Gemfile` is processed by the [Bundler](https://github.com/carlhuda/bundler) gem, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems.
-More information: - [bundler homepage](http://bundler.io/)
+More information: - [bundler homepage](https://bundler.io/)
### Living on the Edge
diff --git a/guides/source/3_2_release_notes.md b/guides/source/3_2_release_notes.md
index f16d509f77..6570b19f97 100644
--- a/guides/source/3_2_release_notes.md
+++ b/guides/source/3_2_release_notes.md
@@ -81,7 +81,7 @@ $ cd myapp
Rails now uses a `Gemfile` in the application root to determine the gems you require for your application to start. This `Gemfile` is processed by the [Bundler](https://github.com/carlhuda/bundler) gem, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems.
-More information: [Bundler homepage](http://bundler.io/)
+More information: [Bundler homepage](https://bundler.io/)
### Living on the Edge
@@ -295,7 +295,7 @@ Action Pack
```ruby
@items.each do |item|
content_tag_for(:li, item) do
- Title: <%= item.title %>
+ Title: <%= item.title %>
end
end
```
diff --git a/guides/source/4_0_release_notes.md b/guides/source/4_0_release_notes.md
index 4615cf18e6..6f1b75a42b 100644
--- a/guides/source/4_0_release_notes.md
+++ b/guides/source/4_0_release_notes.md
@@ -36,7 +36,7 @@ $ cd myapp
Rails now uses a `Gemfile` in the application root to determine the gems you require for your application to start. This `Gemfile` is processed by the [Bundler](https://github.com/carlhuda/bundler) gem, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems.
-More information: [Bundler homepage](http://bundler.io)
+More information: [Bundler homepage](https://bundler.io)
### Living on the Edge
@@ -60,7 +60,7 @@ Major Features
### Upgrade
* **Ruby 1.9.3** ([commit](https://github.com/rails/rails/commit/a0380e808d3dbd2462df17f5d3b7fcd8bd812496)) - Ruby 2.0 preferred; 1.9.3+ required
-* **[New deprecation policy](http://www.youtube.com/watch?v=z6YgD6tVPQs)** - Deprecated features are warnings in Rails 4.0 and will be removed in Rails 4.1.
+* **[New deprecation policy](https://www.youtube.com/watch?v=z6YgD6tVPQs)** - Deprecated features are warnings in Rails 4.0 and will be removed in Rails 4.1.
* **ActionPack page and action caching** ([commit](https://github.com/rails/rails/commit/b0a7068564f0c95e7ef28fc39d0335ed17d93e90)) - Page and action caching are extracted to a separate gem. Page and action caching requires too much manual intervention (manually expiring caches when the underlying model objects are updated). Instead, use Russian doll caching.
* **ActiveRecord observers** ([commit](https://github.com/rails/rails/commit/ccecab3ba950a288b61a516bf9b6962e384aae0b)) - Observers are extracted to a separate gem. Observers are only needed for page and action caching, and can lead to spaghetti code.
* **ActiveRecord session store** ([commit](https://github.com/rails/rails/commit/0ffe19056c8e8b2f9ae9d487b896cad2ce9387ad)) - The ActiveRecord session store is extracted to a separate gem. Storing sessions in SQL is costly. Instead, use cookie sessions, memcache sessions, or a custom session store.
diff --git a/guides/source/5_0_release_notes.md b/guides/source/5_0_release_notes.md
index 5f4be07351..3805fd2a63 100644
--- a/guides/source/5_0_release_notes.md
+++ b/guides/source/5_0_release_notes.md
@@ -55,7 +55,7 @@ information.
### API Applications
Rails can now be used to create slimmed down API only applications.
-This is useful for creating and serving APIs similar to [Twitter](https://dev.twitter.com) or [GitHub](http://developer.github.com) API,
+This is useful for creating and serving APIs similar to [Twitter](https://dev.twitter.com) or [GitHub](https://developer.github.com) API,
that can be used to serve public facing, as well as, for custom applications.
You can generate a new api Rails app using:
@@ -74,11 +74,11 @@ This will do three main things:
Controller modules that provide functionalities primarily used by browser
applications.
- Configure the generators to skip generating views, helpers and assets when
- you generate a new resource.
+ you generate a new resource.
+
+The application provides a base for APIs,
+that can then be [configured to pull in functionality](api_app.html) as suitable for the application's needs.
-The application provides a base for APIs,
-that can then be [configured to pull in functionality](api_app.html) as suitable for the application's needs.
-
See the [Using Rails for API-only Applications](api_app.html) guide for more
information.
diff --git a/guides/source/action_controller_overview.md b/guides/source/action_controller_overview.md
index 7de6542f4a..b3b5f19b61 100644
--- a/guides/source/action_controller_overview.md
+++ b/guides/source/action_controller_overview.md
@@ -23,7 +23,7 @@ What Does a Controller Do?
Action Controller is the C in MVC. After the router has determined which controller to use for a request, the controller is responsible for making sense of the request and producing the appropriate output. Luckily, Action Controller does most of the groundwork for you and uses smart conventions to make this as straightforward as possible.
-For most conventional [RESTful](http://en.wikipedia.org/wiki/Representational_state_transfer) applications, the controller will receive the request (this is invisible to you as the developer), fetch or save data from a model and use a view to create HTML output. If your controller needs to do things a little differently, that's not a problem, this is just the most common way for a controller to work.
+For most conventional [RESTful](https://en.wikipedia.org/wiki/Representational_state_transfer) applications, the controller will receive the request (this is invisible to you as the developer), fetch or save data from a model and use a view to create HTML output. If your controller needs to do things a little differently, that's not a problem, this is just the most common way for a controller to work.
A controller can thus be thought of as a middleman between models and views. It makes the model data available to the view so it can display that data to the user, and it saves or updates user data to the model.
diff --git a/guides/source/action_mailer_basics.md b/guides/source/action_mailer_basics.md
index 6562dc3a98..96ef9c4450 100644
--- a/guides/source/action_mailer_basics.md
+++ b/guides/source/action_mailer_basics.md
@@ -413,7 +413,7 @@ inside of Action Controller, so you can use all the same options, such as
#### Caching mailer view
-You can do cache in mailer views like in application views using `cache` method.
+You can perform fragment caching in mailer views like in application views using the `cache` method.
```
<% cache do %>
@@ -427,6 +427,9 @@ And in order to use this feature, you need to configure your application with th
config.action_mailer.perform_caching = true
```
+Fragment caching is also supported in multipart emails.
+Read more about caching in the [Rails caching guide](caching_with_rails.html).
+
### Action Mailer Layouts
Just like controller views, you can also have mailer layouts. The layout name
@@ -560,7 +563,7 @@ Unlike controllers, the mailer instance doesn't have any context about the
incoming request so you'll need to provide the `:asset_host` parameter yourself.
As the `:asset_host` usually is consistent across the application you can
-configure it globally in config/application.rb:
+configure it globally in `config/application.rb`:
```ruby
config.action_mailer.asset_host = 'http://example.com'
diff --git a/guides/source/action_view_overview.md b/guides/source/action_view_overview.md
index e5f4e0ec30..ea72567c03 100644
--- a/guides/source/action_view_overview.md
+++ b/guides/source/action_view_overview.md
@@ -414,7 +414,7 @@ By default, Rails links to these assets on the current host in the public folder
```ruby
config.action_controller.asset_host = "assets.example.com"
-image_tag("rails.png") # => <img src="http://assets.example.com/images/rails.png" alt="Rails" />
+image_tag("rails.png") # => <img src="http://assets.example.com/images/rails.png" />
```
#### auto_discovery_link_tag
@@ -453,7 +453,7 @@ image_url("edit.png") # => http://www.example.com/assets/edit.png
Returns an HTML image tag for the source. The source can be a full path or a file that exists in your `app/assets/images` directory.
```ruby
-image_tag("icon.png") # => <img src="/assets/icon.png" alt="Icon" />
+image_tag("icon.png") # => <img src="/assets/icon.png" />
```
#### javascript_include_tag
diff --git a/guides/source/active_job_basics.md b/guides/source/active_job_basics.md
index 2606bfe280..9fc95954bc 100644
--- a/guides/source/active_job_basics.md
+++ b/guides/source/active_job_basics.md
@@ -379,7 +379,7 @@ class GuestsCleanupJob < ApplicationJob
queue_as :default
rescue_from(ActiveRecord::RecordNotFound) do |exception|
- # Do something with the exception
+ # Do something with the exception
end
def perform
diff --git a/guides/source/active_record_basics.md b/guides/source/active_record_basics.md
index 2ac80d8f89..11aefcb05f 100644
--- a/guides/source/active_record_basics.md
+++ b/guides/source/active_record_basics.md
@@ -20,7 +20,7 @@ After reading this guide, you will know:
What is Active Record?
----------------------
-Active Record is the M in [MVC](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) - the
+Active Record is the M in [MVC](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) - the
model - which is the layer of the system responsible for representing business
data and logic. Active Record facilitates the creation and use of business
objects whose data requires persistent storage to a database. It is an
diff --git a/guides/source/active_record_migrations.md b/guides/source/active_record_migrations.md
index 7fdb5901f3..f8f36bf600 100644
--- a/guides/source/active_record_migrations.md
+++ b/guides/source/active_record_migrations.md
@@ -21,7 +21,7 @@ Migration Overview
------------------
Migrations are a convenient way to
-[alter your database schema over time](http://en.wikipedia.org/wiki/Schema_migration)
+[alter your database schema over time](https://en.wikipedia.org/wiki/Schema_migration)
in a consistent and easy way. They use a Ruby DSL so that you don't have to
write SQL by hand, allowing your schema and changes to be database independent.
diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md
index c79c86ac0c..678b80516f 100644
--- a/guides/source/active_record_querying.md
+++ b/guides/source/active_record_querying.md
@@ -1393,7 +1393,7 @@ end
```
NOTE: The `default_scope` is also applied while creating/building a record
-when the scope arguments are given as a `Hash`. It is not applied while
+when the scope arguments are given as a `Hash`. It is not applied while
updating a record. E.g.:
```ruby
@@ -1539,7 +1539,7 @@ Read the full documentation about enums
Understanding The Method Chaining
---------------------------------
-The Active Record pattern implements [Method Chaining](http://en.wikipedia.org/wiki/Method_chaining),
+The Active Record pattern implements [Method Chaining](https://en.wikipedia.org/wiki/Method_chaining),
which allow us to use multiple Active Record methods together in a simple and straightforward way.
You can chain methods in a statement when the previous method called returns an
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md
index 4c37f6aba9..9f89e666dc 100644
--- a/guides/source/active_support_core_extensions.md
+++ b/guides/source/active_support_core_extensions.md
@@ -135,9 +135,9 @@ NOTE: Defined in `active_support/core_ext/object/blank.rb`.
### `duplicable?`
-In Ruby 2.4 most objects can be duplicated via `dup` or `clone` except
+In Ruby 2.4 most objects can be duplicated via `dup` or `clone` except
methods and certain numbers. Though Ruby 2.2 and 2.3 can't duplicate `nil`,
-`false`, `true`, and symbols as well as instances `Float`, `Fixnum`,
+`false`, `true`, and symbols as well as instances `Float`, `Fixnum`,
and `Bignum` instances.
```ruby
@@ -1709,7 +1709,7 @@ Specifically performs these transformations:
* Capitalizes the first word.
The capitalization of the first word can be turned off by setting the
-+:capitalize+ option to false (default is true).
+`:capitalize` option to false (default is true).
```ruby
"name".humanize # => "Name"
@@ -1989,7 +1989,7 @@ Extensions to `BigDecimal`
The method `to_s` provides a default specifier of "F". This means that a simple call to `to_s` will result in floating point representation instead of engineering notation:
```ruby
-BigDecimal.new(5.00, 6).to_s # => "5.0"
+BigDecimal.new(5.00, 6).to_s # => "5.0"
```
and that symbol specifiers are also supported:
@@ -2359,7 +2359,7 @@ This method is similar in purpose to `Kernel#Array`, but there are some differen
* If the argument responds to `to_ary` the method is invoked. `Kernel#Array` moves on to try `to_a` if the returned value is `nil`, but `Array.wrap` returns an array with the argument as its single element right away.
* If the returned value from `to_ary` is neither `nil` nor an `Array` object, `Kernel#Array` raises an exception, while `Array.wrap` does not, it just returns the value.
-* It does not call `to_a` on the argument, if the argument does not respond to +to_ary+ it returns an array with the argument as its single element.
+* It does not call `to_a` on the argument, if the argument does not respond to `to_ary` it returns an array with the argument as its single element.
The last point is particularly worth comparing for some enumerables:
@@ -3641,7 +3641,7 @@ Durations can be added to and subtracted from time objects:
now = Time.current
# => Mon, 09 Aug 2010 23:20:05 UTC +00:00
now + 1.year
-# => Tue, 09 Aug 2011 23:21:11 UTC +00:00
+# => Tue, 09 Aug 2011 23:21:11 UTC +00:00
now - 1.week
# => Mon, 02 Aug 2010 23:21:11 UTC +00:00
```
diff --git a/guides/source/api_app.md b/guides/source/api_app.md
index 64200ec242..da1b7b25ef 100644
--- a/guides/source/api_app.md
+++ b/guides/source/api_app.md
@@ -18,7 +18,7 @@ What is an API Application?
Traditionally, when people said that they used Rails as an "API", they meant
providing a programmatically accessible API alongside their web application.
-For example, GitHub provides [an API](http://developer.github.com) that you
+For example, GitHub provides [an API](https://developer.github.com) that you
can use from your own custom clients.
With the advent of client-side frameworks, more developers are using Rails to
@@ -66,9 +66,9 @@ Handled at the middleware layer:
about the request environment, database queries, and basic performance
information.
- Security: Rails detects and thwarts [IP spoofing
- attacks](http://en.wikipedia.org/wiki/IP_address_spoofing) and handles
+ attacks](https://en.wikipedia.org/wiki/IP_address_spoofing) and handles
cryptographic signatures in a [timing
- attack](http://en.wikipedia.org/wiki/Timing_attack) aware way. Don't know what
+ attack](https://en.wikipedia.org/wiki/Timing_attack) aware way. Don't know what
an IP spoofing attack or a timing attack is? Exactly.
- Parameter Parsing: Want to specify your parameters as JSON instead of as a
URL-encoded String? No problem. Rails will decode the JSON for you and make
@@ -94,7 +94,7 @@ Handled at the Action Pack layer:
means not having to spend time thinking about how to model your API in terms
of HTTP.
- URL Generation: The flip side of routing is URL generation. A good API based
- on HTTP includes URLs (see [the GitHub Gist API](http://developer.github.com/v3/gists/)
+ on HTTP includes URLs (see [the GitHub Gist API](https://developer.github.com/v3/gists/)
for an example).
- Header and Redirection Responses: `head :no_content` and
`redirect_to user_url(current_user)` come in handy. Sure, you could manually
diff --git a/guides/source/api_documentation_guidelines.md b/guides/source/api_documentation_guidelines.md
index c3c7367304..2c153d3783 100644
--- a/guides/source/api_documentation_guidelines.md
+++ b/guides/source/api_documentation_guidelines.md
@@ -82,12 +82,12 @@ used. Instead of:
English
-------
-Please use American English (*color*, *center*, *modularize*, etc). See [a list of American and British English spelling differences here](http://en.wikipedia.org/wiki/American_and_British_English_spelling_differences).
+Please use American English (*color*, *center*, *modularize*, etc). See [a list of American and British English spelling differences here](https://en.wikipedia.org/wiki/American_and_British_English_spelling_differences).
Oxford Comma
------------
-Please use the [Oxford comma](http://en.wikipedia.org/wiki/Serial_comma)
+Please use the [Oxford comma](https://en.wikipedia.org/wiki/Serial_comma)
("red, white, and blue", instead of "red, white and blue").
Example Code
@@ -350,7 +350,7 @@ into account, one such example is
```ruby
# image_tag("icon.png")
-# # => <img alt="Icon" src="/assets/icon.png" />
+# # => <img src="/assets/icon.png" />
```
Although the default behavior for `#image_tag` is to always return
diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md
index 383e972f74..17ab9c7600 100644
--- a/guides/source/asset_pipeline.md
+++ b/guides/source/asset_pipeline.md
@@ -383,7 +383,7 @@ it would make sense to have an image in one of the asset load paths, such as
already available in `public/assets` as a fingerprinted file, then that path is
referenced.
-If you want to use a [data URI](http://en.wikipedia.org/wiki/Data_URI_scheme) -
+If you want to use a [data URI](https://en.wikipedia.org/wiki/Data_URI_scheme) -
a method of embedding the image data directly into the CSS file - you can use
the `asset_data_uri` helper.
@@ -861,7 +861,7 @@ end
### CDNs
CDN stands for [Content Delivery
-Network](http://en.wikipedia.org/wiki/Content_delivery_network), they are
+Network](https://en.wikipedia.org/wiki/Content_delivery_network), they are
primarily designed to cache assets all over the world so that when a browser
requests the asset, a cached copy will be geographically close to that browser.
If you are serving assets directly from your Rails server in production, the
@@ -909,7 +909,7 @@ domain, you do not need to specify a protocol or "scheme" such as `http://` or
that is generated will match how the webpage is accessed by default.
You can also set this value through an [environment
-variable](http://en.wikipedia.org/wiki/Environment_variable) to make running a
+variable](https://en.wikipedia.org/wiki/Environment_variable) to make running a
staging copy of your site easier:
```
@@ -1069,7 +1069,7 @@ Customizing the Pipeline
### CSS Compression
One of the options for compressing CSS is YUI. The [YUI CSS
-compressor](http://yui.github.io/yuicompressor/css.html) provides
+compressor](https://yui.github.io/yuicompressor/css.html) provides
minification.
The following line enables YUI compression, and requires the `yui-compressor`
diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md
index 1212ae53bc..b5bd24d027 100644
--- a/guides/source/association_basics.md
+++ b/guides/source/association_basics.md
@@ -663,11 +663,11 @@ By default, associations look for objects only within the current module's scope
module MyApplication
module Business
class Supplier < ApplicationRecord
- has_one :account
+ has_one :account
end
class Account < ApplicationRecord
- belongs_to :supplier
+ belongs_to :supplier
end
end
end
@@ -679,13 +679,13 @@ This will work fine, because both the `Supplier` and the `Account` class are def
module MyApplication
module Business
class Supplier < ApplicationRecord
- has_one :account
+ has_one :account
end
end
module Billing
class Account < ApplicationRecord
- belongs_to :supplier
+ belongs_to :supplier
end
end
end
@@ -697,14 +697,14 @@ To associate a model with a model in a different namespace, you must specify the
module MyApplication
module Business
class Supplier < ApplicationRecord
- has_one :account,
+ has_one :account,
class_name: "MyApplication::Billing::Account"
end
end
module Billing
class Account < ApplicationRecord
- belongs_to :supplier,
+ belongs_to :supplier,
class_name: "MyApplication::Business::Supplier"
end
end
@@ -968,13 +968,12 @@ side of the association.
Counter cache columns are added to the containing model's list of read-only attributes through `attr_readonly`.
##### `:dependent`
-Controls what happens to associated objects when their owner is destroyed:
+If you set the `:dependent` option to:
-* `:destroy` causes the associated objects to also be destroyed.
-* `:delete_all` causes the associated objects to be deleted directly from the database (callbacks are not executed).
-* `:nullify` causes the foreign keys to be set to `NULL` (callbacks are not executed).
-* `:restrict_with_exception` causes an exception to be raised if there are associated records.
-* `:restrict_with_error` causes an error to be added to the owner if there are associated objects.
+* `:destroy`, when the object is destroyed, `destroy` will be called on its
+associated objects.
+* `:delete`, when the object is destroyed, all its associated objects will be
+deleted directly from the database without calling their `destroy` method.
WARNING: You should not specify this option on a `belongs_to` association that is connected with a `has_many` association on the other class. Doing so can lead to orphaned records in your database.
diff --git a/guides/source/autoloading_and_reloading_constants.md b/guides/source/autoloading_and_reloading_constants.md
index 05743ee4ce..c62194faf4 100644
--- a/guides/source/autoloading_and_reloading_constants.md
+++ b/guides/source/autoloading_and_reloading_constants.md
@@ -475,12 +475,21 @@ it is (edited):
```
$ bin/rails r 'puts ActiveSupport::Dependencies.autoload_paths'
.../app/assets
+.../app/channels
.../app/controllers
+.../app/controllers/concerns
.../app/helpers
+.../app/jobs
.../app/mailers
.../app/models
-.../app/controllers/concerns
.../app/models/concerns
+.../activestorage/app/assets
+.../activestorage/app/controllers
+.../activestorage/app/javascript
+.../activestorage/app/jobs
+.../activestorage/app/models
+.../actioncable/app/assets
+.../actionview/app/assets
.../test/mailers/previews
```
diff --git a/guides/source/caching_with_rails.md b/guides/source/caching_with_rails.md
index 6cdce5c2f4..910a531068 100644
--- a/guides/source/caching_with_rails.md
+++ b/guides/source/caching_with_rails.md
@@ -175,10 +175,28 @@ class Game < ApplicationRecord
end
```
-With `touch` set to true, any action which changes `updated_at` for a game
+With `touch` set to `true`, any action which changes `updated_at` for a game
record will also change it for the associated product, thereby expiring the
cache.
+### Shared Partial Caching
+
+It is possible to share partials and associated caching between files with different mime types. For example shared partial caching allows template writers to share a partial between HTML and Javascript files. When templates are collected in the template resolver file paths they only include the template language extension and not the mime type. Because of this templates can be used for multiple mime types. Both HTML and JavaScript requests will respond to the following code:
+
+```ruby
+render(partial: 'hotels/hotel', collection: @hotels, cached: true)
+```
+
+Will load a file named `hotels/hotel.erb`.
+
+Another option is to include the full filename of the partial to render.
+
+```ruby
+render(partial: 'hotels/hotel.html.erb', collection: @hotels, cached: true)
+```
+
+Will load a file named `hotels/hotel.html.erb` in any file mime type, for example you could include this partial in a Javascript file.
+
### Managing dependencies
In order to correctly invalidate the cache, you need to properly define the
@@ -272,7 +290,7 @@ Sometimes you need to cache a particular value or query result instead of cachin
The most efficient way to implement low-level caching is using the `Rails.cache.fetch` method. This method does both reading and writing to the cache. When passed only a single argument, the key is fetched and value from the cache is returned. If a block is passed, that block will be executed in the event of a cache miss. The return value of the block will be written to the cache under the given cache key, and that return value will be returned. In case of cache hit, the cached value will be returned without executing the block.
-Consider the following example. An application has a `Product` model with an instance method that looks up the product’s price on a competing website. The data returned by this method would be perfect for low-level caching:
+Consider the following example. An application has a `Product` model with an instance method that looks up the product's price on a competing website. The data returned by this method would be perfect for low-level caching:
```ruby
class Product < ApplicationRecord
@@ -284,7 +302,7 @@ class Product < ApplicationRecord
end
```
-NOTE: Notice that in this example we used the `cache_key` method, so the resulting cache-key will be something like `products/233-20140225082222765838000/competing_price`. `cache_key` generates a string based on the model’s `id` and `updated_at` attributes. This is a common convention and has the benefit of invalidating the cache whenever the product is updated. In general, when you use low-level caching for instance level information, you need to generate a cache key.
+NOTE: Notice that in this example we used the `cache_key` method, so the resulting cache key will be something like `products/233-20140225082222765838000/competing_price`. `cache_key` generates a string based on the model's `id` and `updated_at` attributes. This is a common convention and has the benefit of invalidating the cache whenever the product is updated. In general, when you use low-level caching for instance level information, you need to generate a cache key.
### SQL Caching
@@ -387,9 +405,9 @@ store is not appropriate for large application deployments. However, it can
work well for small, low traffic sites with only a couple of server processes,
as well as development and test environments.
-New Rails projects are configured to use this implementation in development environment by default.
+New Rails projects are configured to use this implementation in development environment by default.
-NOTE: Since processes will not share cache data when using `:memory_store`,
+NOTE: Since processes will not share cache data when using `:memory_store`,
it will not be possible to manually read, write or expire the cache via the Rails console.
### ActiveSupport::Cache::FileStore
@@ -580,7 +598,7 @@ Caching in Development
----------------------
It's common to want to test the caching strategy of your application
-in development mode. Rails provides the rake task `dev:cache` to
+in development mode. Rails provides the rake task `dev:cache` to
easily toggle caching on/off.
```bash
diff --git a/guides/source/command_line.md b/guides/source/command_line.md
index 8ae01286e4..2cd8e02a77 100644
--- a/guides/source/command_line.md
+++ b/guides/source/command_line.md
@@ -645,13 +645,16 @@ $ cat config/database.yml
# Configure Using Gemfile
# gem 'pg'
#
-development:
+default: &default
adapter: postgresql
encoding: unicode
+ # For details on connection pooling, see Rails configuration guide
+ # http://guides.rubyonrails.org/configuring.html#database-pooling
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
+
+development:
+ <<: *default
database: gitapp_development
- pool: 5
- username: gitapp
- password:
...
...
```
diff --git a/guides/source/configuring.md b/guides/source/configuring.md
index f6b7b3b5a7..d4e1d7b5dd 100644
--- a/guides/source/configuring.md
+++ b/guides/source/configuring.md
@@ -1004,7 +1004,7 @@ Once you've configured the application server, you must proxy requests to it by
```
upstream application_server {
- server 0.0.0.0:8080
+ server 0.0.0.0:8080;
}
server {
diff --git a/guides/source/contributing_to_ruby_on_rails.md b/guides/source/contributing_to_ruby_on_rails.md
index 2f2962a3e6..7424818757 100644
--- a/guides/source/contributing_to_ruby_on_rails.md
+++ b/guides/source/contributing_to_ruby_on_rails.md
@@ -13,7 +13,7 @@ After reading this guide, you will know:
* How to contribute to the Ruby on Rails documentation.
* How to contribute to the Ruby on Rails code.
-Ruby on Rails is not "someone else's framework." Over the years, hundreds of people have contributed to Ruby on Rails ranging from a single character to massive architectural changes or significant documentation - all with the goal of making Ruby on Rails better for everyone. Even if you don't feel up to writing code or documentation yet, there are a variety of other ways that you can contribute, from reporting issues to testing patches.
+Ruby on Rails is not "someone else's framework." Over the years, thousands of people have contributed to Ruby on Rails ranging from a single character to massive architectural changes or significant documentation - all with the goal of making Ruby on Rails better for everyone. Even if you don't feel up to writing code or documentation yet, there are a variety of other ways that you can contribute, from reporting issues to testing patches.
As mentioned in [Rails'
README](https://github.com/rails/rails/blob/master/README.md), everyone interacting in Rails and its sub-projects' codebases, issue trackers, chat rooms, and mailing lists is expected to follow the Rails [code of conduct](http://rubyonrails.org/conduct/).
@@ -92,7 +92,7 @@ For starters, it helps just to verify bug reports. Can you reproduce the reporte
If an issue is very vague, can you help narrow it down to something more specific? Maybe you can provide additional information to help reproduce a bug, or help by eliminating needless steps that aren't required to demonstrate the problem.
-If you find a bug report without a test, it's very useful to contribute a failing test. This is also a great way to get started exploring the source code: looking at the existing test files will teach you how to write more tests. New tests are best contributed in the form of a patch, as explained later on in the "Contributing to the Rails Code" section.
+If you find a bug report without a test, it's very useful to contribute a failing test. This is also a great way to get started exploring the source code: looking at the existing test files will teach you how to write more tests. New tests are best contributed in the form of a patch, as explained later on in the "[Contributing to the Rails Code](#contributing-to-the-rails-code)" section.
Anything you can do to make bug reports more succinct or easier to reproduce helps folks trying to write code to fix those bugs - whether you end up writing the code yourself or not.
@@ -164,11 +164,11 @@ NOTE: The instructions are for Rails > 4. The Redcarpet Gem doesn't work with JR
Translation efforts we know about (various versions):
* **Italian**: [https://github.com/rixlabs/docrails](https://github.com/rixlabs/docrails)
-* **Spanish**: [http://wiki.github.com/gramos/docrails](http://wiki.github.com/gramos/docrails)
-* **Polish**: [https://github.com/apohllo/docrails/tree/master](https://github.com/apohllo/docrails/tree/master)
+* **Spanish**: [https://github.com/gramos/docrails/wiki](https://github.com/gramos/docrails/wiki)
+* **Polish**: [https://github.com/apohllo/docrails](https://github.com/apohllo/docrails)
* **French** : [https://github.com/railsfrance/docrails](https://github.com/railsfrance/docrails)
* **Czech** : [https://github.com/rubyonrails-cz/docrails/tree/czech](https://github.com/rubyonrails-cz/docrails/tree/czech)
-* **Turkish** : [https://github.com/ujk/docrails/tree/master](https://github.com/ujk/docrails/tree/master)
+* **Turkish** : [https://github.com/ujk/docrails](https://github.com/ujk/docrails)
* **Korean** : [https://github.com/rorlakr/rails-guides](https://github.com/rorlakr/rails-guides)
* **Simplified Chinese** : [https://github.com/ruby-china/guides](https://github.com/ruby-china/guides)
* **Traditional Chinese** : [https://github.com/docrails-tw/guides](https://github.com/docrails-tw/guides)
@@ -184,7 +184,7 @@ To move on from submitting bugs to helping resolve existing issues or contributi
#### The Easy Way
-The easiest and recommended way to get a development environment ready to hack is to use the [Rails development box](https://github.com/rails/rails-dev-box).
+The easiest and recommended way to get a development environment ready to hack is to use the [rails-dev-box](https://github.com/rails/rails-dev-box).
#### The Hard Way
@@ -324,7 +324,7 @@ file.
#### Testing Active Record
-First, create the databases you'll need. You can find a list of the required
+First, create the databases you'll need. You can find a list of the required
table names, usernames, and passwords in `activerecord/test/config.example.yml`.
For MySQL and PostgreSQL, running the SQL statements `create database
@@ -480,7 +480,7 @@ Navigate to the Rails [GitHub repository](https://github.com/rails/rails) and pr
Add the new remote to your local repository on your local machine:
```bash
-$ git remote add mine https://github.com:<your user name>/rails.git
+$ git remote add mine https://github.com/<your user name>/rails.git
```
Push to your remote:
@@ -554,7 +554,7 @@ is the open source life.
If it's been over a week, and you haven't heard anything, you might want to try
and nudge things along. You can use the [rubyonrails-core mailing
-list](http://groups.google.com/group/rubyonrails-core/) for this. You can also
+list](https://groups.google.com/forum/#!forum/rubyonrails-core) for this. You can also
leave another comment on the pull request.
While you're waiting for feedback on your pull request, open up a few other
diff --git a/guides/source/debugging_rails_applications.md b/guides/source/debugging_rails_applications.md
index 7ea3646c30..07c78be3db 100644
--- a/guides/source/debugging_rails_applications.md
+++ b/guides/source/debugging_rails_applications.md
@@ -186,21 +186,17 @@ end
Here's an example of the log generated when this controller action is executed:
```
-Processing ArticlesController#create (for 127.0.0.1 at 2008-09-08 11:52:54) [POST]
- Session ID: BAh7BzoMY3NyZl9pZCIlMDY5MWU1M2I1ZDRjODBlMzkyMWI1OTg2NWQyNzViZjYiCmZsYXNoSUM6J0FjdGl
-vbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA=--b18cd92fba90eacf8137e5f6b3b06c4d724596a4
- Parameters: {"commit"=>"Create", "article"=>{"title"=>"Debugging Rails",
- "body"=>"I'm learning how to print in logs!!!", "published"=>"0"},
- "authenticity_token"=>"2059c1286e93402e389127b1153204e0d1e275dd", "action"=>"create", "controller"=>"articles"}
-New article: {"updated_at"=>nil, "title"=>"Debugging Rails", "body"=>"I'm learning how to print in logs!!!",
- "published"=>false, "created_at"=>nil}
+Started POST "/articles" for 127.0.0.1 at 2017-08-20 20:53:10 +0900
+Processing by ArticlesController#create as HTML
+ Parameters: {"utf8"=>"✓", "authenticity_token"=>"xhuIbSBFytHCE1agHgvrlKnSVIOGD6jltW2tO+P6a/ACjQ3igjpV4OdbsZjIhC98QizWH9YdKokrqxBCJrtoqQ==", "article"=>{"title"=>"Debugging Rails", "body"=>"I'm learning how to print in logs!!!", "published"=>"0"}, "commit"=>"Create Article"}
+New article: {"id"=>nil, "title"=>"Debugging Rails", "body"=>"I'm learning how to print in logs!!!", "published"=>false, "created_at"=>nil, "updated_at"=>nil}
Article should be valid: true
- Article Create (0.000443) INSERT INTO "articles" ("updated_at", "title", "body", "published",
- "created_at") VALUES('2008-09-08 14:52:54', 'Debugging Rails',
- 'I''m learning how to print in logs!!!', 'f', '2008-09-08 14:52:54')
+ (0.1ms) BEGIN
+ SQL (0.4ms) INSERT INTO "articles" ("title", "body", "published", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["title", "Debugging Rails"], ["body", "I'm learning how to print in logs!!!"], ["published", "f"], ["created_at", "2017-08-20 11:53:10.010435"], ["updated_at", "2017-08-20 11:53:10.010435"]]
+ (0.3ms) COMMIT
The article was saved and now the user is going to be redirected...
-Redirected to # Article:0x20af760>
-Completed in 0.01224 (81 reqs/sec) | DB: 0.00044 (3%) | 302 Found [http://localhost/articles]
+Redirected to http://localhost:3000/articles/1
+Completed 302 Found in 4ms (ActiveRecord: 0.8ms)
```
Adding extra logging like this makes it easy to search for unexpected or unusual behavior in your logs. If you add extra logging, be sure to make sensible use of log levels to avoid filling your production logs with useless trivia.
@@ -405,7 +401,7 @@ To see the previous ten lines you should type `list-` (or `l-`).
7 byebug
8 @articles = Article.find_recent
9
- 10 respond_to do |format|
+ 10 respond_to do |format|
```
This way you can move inside the file and see the code above the line where you
@@ -544,9 +540,9 @@ command later in this guide).
7 byebug
8 @articles = Article.find_recent
9
-=> 10 respond_to do |format|
- 11 format.html # index.html.erb
- 12 format.json { render json: @articles }
+=> 10 respond_to do |format|
+ 11 format.html # index.html.erb
+ 12 format.json { render json: @articles }
13 end
14 end
15
diff --git a/guides/source/development_dependencies_install.md b/guides/source/development_dependencies_install.md
index 77b036b20f..50274d700b 100644
--- a/guides/source/development_dependencies_install.md
+++ b/guides/source/development_dependencies_install.md
@@ -30,7 +30,7 @@ Ruby on Rails uses Git for source code control. The [Git homepage](https://git-s
* [Try Git course](https://try.github.io/) is an interactive course that will teach you the basics.
* The [official Documentation](https://git-scm.com/documentation) is pretty comprehensive and also contains some videos with the basics of Git.
-* [Everyday Git](http://schacon.github.io/git/everyday.html) will teach you just enough about Git to get by.
+* [Everyday Git](https://schacon.github.io/git/everyday.html) will teach you just enough about Git to get by.
* [GitHub](https://help.github.com/) offers links to a variety of Git resources.
* [Pro Git](https://git-scm.com/book) is an entire book about Git with a Creative Commons license.
@@ -80,7 +80,7 @@ For FreeBSD users, you're done with:
Or compile the `databases/sqlite3` port.
-Get a recent version of [Bundler](http://bundler.io/)
+Get a recent version of [Bundler](https://bundler.io/)
```bash
$ gem install bundler
@@ -364,7 +364,7 @@ sudo apt-get update && sudo apt-get install yarn
On Fedora or CentOS, just run:
-``bash
+```bash
sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo
sudo yum install yarn
diff --git a/guides/source/generators.md b/guides/source/generators.md
index 37af7a1310..b7b8262e4a 100644
--- a/guides/source/generators.md
+++ b/guides/source/generators.md
@@ -90,13 +90,15 @@ $ bin/rails generate generator initializer
create lib/generators/initializer/initializer_generator.rb
create lib/generators/initializer/USAGE
create lib/generators/initializer/templates
+ invoke test_unit
+ create test/lib/generators/initializer_generator_test.rb
```
This is the generator just created:
```ruby
class InitializerGenerator < Rails::Generators::NamedBase
- source_root File.expand_path("templates", __dir__)
+ source_root File.expand_path('templates', __dir__)
end
```
@@ -122,7 +124,7 @@ And now let's change the generator to copy this template when invoked:
```ruby
class InitializerGenerator < Rails::Generators::NamedBase
- source_root File.expand_path("templates", __dir__)
+ source_root File.expand_path('templates', __dir__)
def copy_initializer_file
copy_file "initializer.rb", "config/initializers/#{file_name}.rb"
@@ -241,6 +243,8 @@ $ bin/rails generate generator rails/my_helper
create lib/generators/rails/my_helper/my_helper_generator.rb
create lib/generators/rails/my_helper/USAGE
create lib/generators/rails/my_helper/templates
+ invoke test_unit
+ create test/lib/generators/rails/my_helper_generator_test.rb
```
After that, we can delete both the `templates` directory and the `source_root`
@@ -510,13 +514,13 @@ Available options are:
Any additional options passed to this method are put on the end of the line:
```ruby
-gem "devise", git: "git://github.com/plataformatec/devise", branch: "master"
+gem "devise", git: "https://github.com/plataformatec/devise.git", branch: "master"
```
The above code will put the following line into `Gemfile`:
```ruby
-gem "devise", git: "git://github.com/plataformatec/devise", branch: "master"
+gem "devise", git: "https://github.com/plataformatec/devise.git", branch: "master"
```
### `gem_group`
diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md
index 2ed1883ede..1e5c6fe3d0 100644
--- a/guides/source/getting_started.md
+++ b/guides/source/getting_started.md
@@ -174,11 +174,11 @@ of the files and folders that Rails created by default:
|config/|Configure your application's routes, database, and more. This is covered in more detail in [Configuring Rails Applications](configuring.html).|
|config.ru|Rack configuration for Rack based servers used to start the application.|
|db/|Contains your current database schema, as well as the database migrations.|
-|Gemfile<br>Gemfile.lock|These files allow you to specify what gem dependencies are needed for your Rails application. These files are used by the Bundler gem. For more information about Bundler, see the [Bundler website](http://bundler.io).|
+|Gemfile<br>Gemfile.lock|These files allow you to specify what gem dependencies are needed for your Rails application. These files are used by the Bundler gem. For more information about Bundler, see the [Bundler website](https://bundler.io).|
|lib/|Extended modules for your application.|
|log/|Application log files.|
|public/|The only folder seen by the world as-is. Contains static files and compiled assets.|
-|Rakefile|This file locates and loads tasks that can be run from the command line. The task definitions are defined throughout the components of Rails. Rather than changing Rakefile, you should add your own tasks by adding files to the lib/tasks directory of your application.|
+|Rakefile|This file locates and loads tasks that can be run from the command line. The task definitions are defined throughout the components of Rails. Rather than changing Rakefile, you should add your own tasks by adding files to the `lib/tasks` directory of your application.|
|README.md|This is a brief instruction manual for your application. You should edit this file to tell others what your application does, how to set it up, and so on.|
|test/|Unit tests, fixtures, and other test apparatus. These are covered in [Testing Rails Applications](testing.html).|
|tmp/|Temporary files (like cache and pid files).|
@@ -309,7 +309,7 @@ end
```
This is your application's _routing file_ which holds entries in a special
-[DSL (domain-specific language)](http://en.wikipedia.org/wiki/Domain-specific_language)
+[DSL (domain-specific language)](https://en.wikipedia.org/wiki/Domain-specific_language)
that tells Rails how to connect incoming requests to
controllers and actions.
Edit this file by adding the line of code `root 'welcome#index'`.
@@ -509,23 +509,23 @@ harmoniously! It's time to create the form for a new article.
To create a form within this template, you will use a *form
builder*. The primary form builder for Rails is provided by a helper
-method called `form_for`. To use this method, add this code into
+method called `form_with`. To use this method, add this code into
`app/views/articles/new.html.erb`:
```html+erb
-<%= form_for :article do |f| %>
+<%= form_with scope: :article, local: true do |form| %>
<p>
- <%= f.label :title %><br>
- <%= f.text_field :title %>
+ <%= form.label :title %><br>
+ <%= form.text_field :title %>
</p>
<p>
- <%= f.label :text %><br>
- <%= f.text_area :text %>
+ <%= form.label :text %><br>
+ <%= form.text_area :text %>
</p>
<p>
- <%= f.submit %>
+ <%= form.submit %>
</p>
<% end %>
```
@@ -533,12 +533,12 @@ method called `form_for`. To use this method, add this code into
If you refresh the page now, you'll see the exact same form from our example above.
Building forms in Rails is really just that easy!
-When you call `form_for`, you pass it an identifying object for this
-form. In this case, it's the symbol `:article`. This tells the `form_for`
+When you call `form_with`, you pass it an identifying scope for this
+form. In this case, it's the symbol `:article`. This tells the `form_with`
helper what this form is for. Inside the block for this method, the
-`FormBuilder` object - represented by `f` - is used to build two labels and two
+`FormBuilder` object - represented by `form` - is used to build two labels and two
text fields, one each for the title and text of an article. Finally, a call to
-`submit` on the `f` object will create a submit button for the form.
+`submit` on the `form` object will create a submit button for the form.
There's one problem with this form though. If you inspect the HTML that is
generated, by viewing the source of the page, you will see that the `action`
@@ -547,15 +547,15 @@ this route goes to the very page that you're on right at the moment, and that
route should only be used to display the form for a new article.
The form needs to use a different URL in order to go somewhere else.
-This can be done quite simply with the `:url` option of `form_for`.
+This can be done quite simply with the `:url` option of `form_with`.
Typically in Rails, the action that is used for new form submissions
like this is called "create", and so the form should be pointed to that action.
-Edit the `form_for` line inside `app/views/articles/new.html.erb` to look like
+Edit the `form_with` line inside `app/views/articles/new.html.erb` to look like
this:
```html+erb
-<%= form_for :article, url: articles_path do |f| %>
+<%= form_with scope: :article, url: articles_path, local: true do |form| %>
```
In this example, the `articles_path` helper is passed to the `:url` option.
@@ -592,6 +592,10 @@ familiar error:
You now need to create the `create` action within the `ArticlesController` for
this to work.
+NOTE: by default `form_with` submits forms using Ajax thereby skipping full page
+redirects. To make this guide easier to get into we've disabled that with
+`local: true` for now.
+
### Creating articles
To make the "Unknown action" go away, you can define a `create` action within
@@ -956,7 +960,7 @@ Now, add another link in `app/views/articles/new.html.erb`, underneath the
form, to go back to the `index` action:
```erb
-<%= form_for :article, url: articles_path do |f| %>
+<%= form_with scope: :article, url: articles_path, local: true do |form| %>
...
<% end %>
@@ -1067,7 +1071,7 @@ something went wrong. To do that, you'll modify
`app/views/articles/new.html.erb` to check for error messages:
```html+erb
-<%= form_for :article, url: articles_path do |f| %>
+<%= form_with scope: :article, url: articles_path, local: true do |form| %>
<% if @article.errors.any? %>
<div id="error_explanation">
@@ -1084,17 +1088,17 @@ something went wrong. To do that, you'll modify
<% end %>
<p>
- <%= f.label :title %><br>
- <%= f.text_field :title %>
+ <%= form.label :title %><br>
+ <%= form.text_field :title %>
</p>
<p>
- <%= f.label :text %><br>
- <%= f.text_area :text %>
+ <%= form.label :text %><br>
+ <%= form.text_area :text %>
</p>
<p>
- <%= f.submit %>
+ <%= form.submit %>
</p>
<% end %>
@@ -1159,7 +1163,7 @@ it look as follows:
```html+erb
<h1>Edit article</h1>
-<%= form_for(@article) do |f| %>
+<%= form_with(model: @article) do |form| %>
<% if @article.errors.any? %>
<div id="error_explanation">
@@ -1176,17 +1180,17 @@ it look as follows:
<% end %>
<p>
- <%= f.label :title %><br>
- <%= f.text_field :title %>
+ <%= form.label :title %><br>
+ <%= form.text_field :title %>
</p>
<p>
- <%= f.label :text %><br>
- <%= f.text_area :text %>
+ <%= form.label :text %><br>
+ <%= form.text_area :text %>
</p>
<p>
- <%= f.submit %>
+ <%= form.submit %>
</p>
<% end %>
@@ -1202,12 +1206,11 @@ This option tells Rails that we want this form to be submitted
via the `PATCH` HTTP method which is the HTTP method you're expected to use to
**update** resources according to the REST protocol.
-The first parameter of `form_for` can be an object, say, `@article` which would
+The arguments to `form_with` could be model objects, say, `model: @article` which would
cause the helper to fill in the form with the fields of the object. Passing in a
-symbol (`:article`) with the same name as the instance variable (`@article`)
-also automagically leads to the same behavior.
-More details can be found in [form_for documentation]
-(http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for).
+symbol scope (`scope: :article`) just creates the fields but without anything filled into them.
+More details can be found in [form_with documentation]
+(http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_with).
Next, we need to create the `update` action in
`app/controllers/articles_controller.rb`.
@@ -1304,7 +1307,7 @@ Create a new file `app/views/articles/_form.html.erb` with the following
content:
```html+erb
-<%= form_for @article do |f| %>
+<%= form_with model: @article, local: true do |form| %>
<% if @article.errors.any? %>
<div id="error_explanation">
@@ -1321,29 +1324,29 @@ content:
<% end %>
<p>
- <%= f.label :title %><br>
- <%= f.text_field :title %>
+ <%= form.label :title %><br>
+ <%= form.text_field :title %>
</p>
<p>
- <%= f.label :text %><br>
- <%= f.text_area :text %>
+ <%= form.label :text %><br>
+ <%= form.text_area :text %>
</p>
<p>
- <%= f.submit %>
+ <%= form.submit %>
</p>
<% end %>
```
-Everything except for the `form_for` declaration remained the same.
-The reason we can use this shorter, simpler `form_for` declaration
+Everything except for the `form_with` declaration remained the same.
+The reason we can use this shorter, simpler `form_with` declaration
to stand in for either of the other forms is that `@article` is a *resource*
corresponding to a full set of RESTful routes, and Rails is able to infer
which URI and method to use.
-For more information about this use of `form_for`, see [Resource-oriented style]
-(http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for-label-Resource-oriented+style).
+For more information about this use of `form_with`, see [Resource-oriented style]
+(http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_with-label-Resource-oriented+style).
Now, let's update the `app/views/articles/new.html.erb` view to use this new
partial, rewriting it completely:
@@ -1682,17 +1685,17 @@ So first, we'll wire up the Article show template
</p>
<h2>Add a comment:</h2>
-<%= form_for([@article, @article.comments.build]) do |f| %>
+<%= form_with(model: [ @article, @article.comments.build ], local: true) do |form| %>
<p>
- <%= f.label :commenter %><br>
- <%= f.text_field :commenter %>
+ <%= form.label :commenter %><br>
+ <%= form.text_field :commenter %>
</p>
<p>
- <%= f.label :body %><br>
- <%= f.text_area :body %>
+ <%= form.label :body %><br>
+ <%= form.text_area :body %>
</p>
<p>
- <%= f.submit %>
+ <%= form.submit %>
</p>
<% end %>
@@ -1701,7 +1704,7 @@ So first, we'll wire up the Article show template
```
This adds a form on the `Article` show page that creates a new comment by
-calling the `CommentsController` `create` action. The `form_for` call here uses
+calling the `CommentsController` `create` action. The `form_with` call here uses
an array, which will build a nested route, such as `/articles/1/comments`.
Let's wire up the `create` in `app/controllers/comments_controller.rb`:
@@ -1763,17 +1766,17 @@ add that to the `app/views/articles/show.html.erb`.
<% end %>
<h2>Add a comment:</h2>
-<%= form_for([@article, @article.comments.build]) do |f| %>
+<%= form_with(model: [ @article, @article.comments.build ]) do |form| %>
<p>
- <%= f.label :commenter %><br>
- <%= f.text_field :commenter %>
+ <%= form.label :commenter %><br>
+ <%= form.text_field :commenter %>
</p>
<p>
- <%= f.label :body %><br>
- <%= f.text_area :body %>
+ <%= form.label :body %><br>
+ <%= form.text_area :body %>
</p>
<p>
- <%= f.submit %>
+ <%= form.submit %>
</p>
<% end %>
@@ -1829,17 +1832,17 @@ following:
<%= render @article.comments %>
<h2>Add a comment:</h2>
-<%= form_for([@article, @article.comments.build]) do |f| %>
+<%= form_with(model: [ @article, @article.comments.build ]) do |form| %>
<p>
- <%= f.label :commenter %><br>
- <%= f.text_field :commenter %>
+ <%= form.label :commenter %><br>
+ <%= form.text_field :commenter %>
</p>
<p>
- <%= f.label :body %><br>
- <%= f.text_area :body %>
+ <%= form.label :body %><br>
+ <%= form.text_area :body %>
</p>
<p>
- <%= f.submit %>
+ <%= form.submit %>
</p>
<% end %>
@@ -1859,17 +1862,17 @@ Let us also move that new comment section out to its own partial. Again, you
create a file `app/views/comments/_form.html.erb` containing:
```html+erb
-<%= form_for([@article, @article.comments.build]) do |f| %>
+<%= form_with(model: [ @article, @article.comments.build ]) do |form| %>
<p>
- <%= f.label :commenter %><br>
- <%= f.text_field :commenter %>
+ <%= form.label :commenter %><br>
+ <%= form.text_field :commenter %>
</p>
<p>
- <%= f.label :body %><br>
- <%= f.text_area :body %>
+ <%= form.label :body %><br>
+ <%= form.text_area :body %>
</p>
<p>
- <%= f.submit %>
+ <%= form.submit %>
</p>
<% end %>
```
diff --git a/guides/source/i18n.md b/guides/source/i18n.md
index aa2b7d1ba9..cb24822f86 100644
--- a/guides/source/i18n.md
+++ b/guides/source/i18n.md
@@ -105,7 +105,7 @@ This means, that in the `:en` locale, the key _hello_ will map to the _Hello wor
The I18n library will use **English** as a **default locale**, i.e. if a different locale is not set, `:en` will be used for looking up translations.
-NOTE: The i18n library takes a **pragmatic approach** to locale keys (after [some discussion](http://groups.google.com/group/rails-i18n/browse_thread/thread/14dede2c7dbe9470/80eec34395f64f3c?hl=en)), including only the _locale_ ("language") part, like `:en`, `:pl`, not the _region_ part, like `:en-US` or `:en-GB`, which are traditionally used for separating "languages" and "regional setting" or "dialects". Many international applications use only the "language" element of a locale such as `:cs`, `:th` or `:es` (for Czech, Thai and Spanish). However, there are also regional differences within different language groups that may be important. For instance, in the `:en-US` locale you would have $ as a currency symbol, while in `:en-GB`, you would have £. Nothing stops you from separating regional and other settings in this way: you just have to provide full "English - United Kingdom" locale in a `:en-GB` dictionary. Few gems such as [Globalize3](https://github.com/globalize/globalize) may help you implement it.
+NOTE: The i18n library takes a **pragmatic approach** to locale keys (after [some discussion](https://groups.google.com/forum/#!topic/rails-i18n/FN7eLH2-lHA)), including only the _locale_ ("language") part, like `:en`, `:pl`, not the _region_ part, like `:en-US` or `:en-GB`, which are traditionally used for separating "languages" and "regional setting" or "dialects". Many international applications use only the "language" element of a locale such as `:cs`, `:th` or `:es` (for Czech, Thai and Spanish). However, there are also regional differences within different language groups that may be important. For instance, in the `:en-US` locale you would have $ as a currency symbol, while in `:en-GB`, you would have £. Nothing stops you from separating regional and other settings in this way: you just have to provide full "English - United Kingdom" locale in a `:en-GB` dictionary. Few gems such as [Globalize3](https://github.com/globalize/globalize) may help you implement it.
The **translations load path** (`I18n.load_path`) is an array of paths to files that will be loaded automatically. Configuring this path allows for customization of translations directory structure and file naming scheme.
@@ -310,10 +310,10 @@ In general, this approach is far less reliable than using the language header an
#### Storing the Locale from the Session or Cookies
-WARNING: You may be tempted to store the chosen locale in a _session_ or a *cookie*. However, **do not do this**. The locale should be transparent and a part of the URL. This way you won't break people's basic assumptions about the web itself: if you send a URL to a friend, they should see the same page and content as you. A fancy word for this would be that you're being [*RESTful*](http://en.wikipedia.org/wiki/Representational_State_Transfer). Read more about the RESTful approach in [Stefan Tilkov's articles](http://www.infoq.com/articles/rest-introduction). Sometimes there are exceptions to this rule and those are discussed below.
+WARNING: You may be tempted to store the chosen locale in a _session_ or a *cookie*. However, **do not do this**. The locale should be transparent and a part of the URL. This way you won't break people's basic assumptions about the web itself: if you send a URL to a friend, they should see the same page and content as you. A fancy word for this would be that you're being [*RESTful*](https://en.wikipedia.org/wiki/Representational_State_Transfer). Read more about the RESTful approach in [Stefan Tilkov's articles](https://www.infoq.com/articles/rest-introduction). Sometimes there are exceptions to this rule and those are discussed below.
Internationalization and Localization
------------------------------------
+-------------------------------------
OK! Now you've initialized I18n support for your Ruby on Rails application and told it which locale to use and how to preserve it between requests.
@@ -371,7 +371,7 @@ end
```html+erb
# app/views/home/index.html.erb
-<h1><%=t :hello_world %></h1>
+<h1><%= t :hello_world %></h1>
<p><%= flash[:notice] %></p>
```
@@ -416,7 +416,7 @@ If your translations are stored in YAML files, certain keys must be escaped. The
Examples:
-```erb
+```yaml
# config/locales/en.yml
en:
success:
@@ -430,12 +430,12 @@ en:
```
```ruby
-I18n.t 'success.true' # => 'True!'
-I18n.t 'success.on' # => 'On!'
+I18n.t 'success.true' # => 'True!'
+I18n.t 'success.on' # => 'On!'
I18n.t 'success.false' # => 'False!'
I18n.t 'failure.false' # => Translation Missing
-I18n.t 'failure.off' # => Translation Missing
-I18n.t 'failure.true' # => Translation Missing
+I18n.t 'failure.off' # => Translation Missing
+I18n.t 'failure.true' # => Translation Missing
```
### Passing Variables to Translations
@@ -502,7 +502,7 @@ OK! Now let's add a timestamp to the view, so we can demo the **date/time locali
```erb
# app/views/home/index.html.erb
-<h1><%=t :hello_world %></h1>
+<h1><%= t :hello_world %></h1>
<p><%= flash[:notice] %></p>
<p><%= l Time.now, format: :short %></p>
```
@@ -1050,7 +1050,7 @@ The Simple backend shipped with Active Support allows you to store translations
For example a Ruby Hash providing translations can look like this:
-```yaml
+```ruby
{
pt: {
foo: {
@@ -1187,7 +1187,7 @@ If you find your own locale (language) missing from our [example translations da
Resources
---------
-* [Google group: rails-i18n](http://groups.google.com/group/rails-i18n) - The project's mailing list.
+* [Google group: rails-i18n](https://groups.google.com/forum/#!forum/rails-i18n) - The project's mailing list.
* [GitHub: rails-i18n](https://github.com/svenfuchs/rails-i18n) - Code repository and issue tracker for the rails-i18n project. Most importantly you can find lots of [example translations](https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale) for Rails that should work for your application in most cases.
* [GitHub: i18n](https://github.com/svenfuchs/i18n) - Code repository and issue tracker for the i18n gem.
@@ -1201,7 +1201,7 @@ Authors
Footnotes
---------
-[^1]: Or, to quote [Wikipedia](http://en.wikipedia.org/wiki/Internationalization_and_localization): _"Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. Localization is the process of adapting software for a specific region or language by adding locale-specific components and translating text."_
+[^1]: Or, to quote [Wikipedia](https://en.wikipedia.org/wiki/Internationalization_and_localization): _"Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. Localization is the process of adapting software for a specific region or language by adding locale-specific components and translating text."_
[^2]: Other backends might allow or require to use other formats, e.g. a GetText backend might allow to read GetText files.
diff --git a/guides/source/initialization.md b/guides/source/initialization.md
index ccad10f07d..0cfabe2a66 100644
--- a/guides/source/initialization.md
+++ b/guides/source/initialization.md
@@ -99,13 +99,15 @@ configure the load path for your Gemfile's dependencies.
A standard Rails application depends on several gems, specifically:
+* actioncable
* actionmailer
* actionpack
* actionview
+* activejob
* activemodel
* activerecord
+* activestorage
* activesupport
-* activejob
* arel
* builder
* bundler
@@ -131,7 +133,7 @@ Once `config/boot.rb` has finished, the next file that is required is
`ARGV` array simply contains `server` which will be passed over:
```ruby
-require "rails/command"
+require_relative "command"
aliases = {
"g" => "generate",
@@ -170,7 +172,7 @@ module Rails::Command
namespace = namespace.to_s
namespace = "help" if namespace.blank? || HELP_MAPPINGS.include?(namespace)
namespace = "version" if %w( -v --version ).include? namespace
-
+
if command = find_by_namespace(namespace)
command.perform(namespace, args, config)
else
@@ -189,7 +191,7 @@ module Rails
class ServerCommand < Base # :nodoc:
def perform
set_application_directory!
-
+
Rails::Server.new.tap do |server|
# Require application after server sets environment to propagate
# the --environment option.
@@ -311,7 +313,7 @@ def parse!(args)
args, options = args.dup, {}
option_parser(options).parse! args
-
+
options[:log_stdout] = options[:daemonize].blank? && (options[:environment] || Rails.env) == "development"
options[:server] = args.shift
options
@@ -366,11 +368,11 @@ private
def log_to_stdout
wrapped_app # touch the app so the logger is set up
-
+
console = ActiveSupport::Logger.new(STDOUT)
console.formatter = Rails.logger.formatter
console.level = Rails.logger.level
-
+
unless ActiveSupport::Logger.logger_outputs_to?(Rails.logger, STDOUT)
Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
end
@@ -537,6 +539,7 @@ require "rails"
action_mailer/railtie
active_job/railtie
action_cable/engine
+ active_storage/engine
rails/test_unit/railtie
sprockets/railtie
).each do |railtie|
diff --git a/guides/source/kindle/toc.html.erb b/guides/source/kindle/toc.html.erb
index f310edd3a1..0f4228ed6b 100644
--- a/guides/source/kindle/toc.html.erb
+++ b/guides/source/kindle/toc.html.erb
@@ -14,7 +14,7 @@ Ruby on Rails Guides
<% if document['work_in_progress']%>(WIP)<% end %>
</li>
<% end %>
- </ul>
+ </ul>
<% end %>
<hr />
<ul>
diff --git a/guides/source/layout.html.erb b/guides/source/layout.html.erb
index bb50761b30..334595e4d2 100644
--- a/guides/source/layout.html.erb
+++ b/guides/source/layout.html.erb
@@ -32,7 +32,7 @@
<li class="more-info"><a href="http://weblog.rubyonrails.org/">Blog</a></li>
<li class="more-info"><a href="http://guides.rubyonrails.org/">Guides</a></li>
<li class="more-info"><a href="http://api.rubyonrails.org/">API</a></li>
- <li class="more-info"><a href="http://stackoverflow.com/questions/tagged/ruby-on-rails">Ask for help</a></li>
+ <li class="more-info"><a href="https://stackoverflow.com/questions/tagged/ruby-on-rails">Ask for help</a></li>
<li class="more-info"><a href="https://github.com/rails/rails">Contribute on GitHub</a></li>
</ul>
</div>
diff --git a/guides/source/plugins.md b/guides/source/plugins.md
index 164207a9f9..0f0cde7634 100644
--- a/guides/source/plugins.md
+++ b/guides/source/plugins.md
@@ -135,7 +135,7 @@ To test that your method does what it says it does, run the unit tests with `bin
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
```
-To see this in action, change to the test/dummy directory, fire up a console and start squawking:
+To see this in action, change to the `test/dummy` directory, fire up a console and start squawking:
```bash
$ bin/rails console
@@ -439,7 +439,7 @@ send("#{self.class.yaffle_text_field}=", string.to_squawk)
Generators
----------
-Generators can be included in your gem simply by creating them in a lib/generators directory of your plugin. More information about
+Generators can be included in your gem simply by creating them in a `lib/generators` directory of your plugin. More information about
the creation of generators can be found in the [Generators Guide](generators.html).
Publishing Your Gem
diff --git a/guides/source/rails_on_rack.md b/guides/source/rails_on_rack.md
index cef8450ee4..aa1476ecc0 100644
--- a/guides/source/rails_on_rack.md
+++ b/guides/source/rails_on_rack.md
@@ -125,7 +125,7 @@ use ActionDispatch::Flash
use Rack::Head
use Rack::ConditionalGet
use Rack::ETag
-run MyApp.application.routes
+run MyApp::Application.routes
```
The default middlewares shown here (and some others) are each summarized in the [Internal Middlewares](#internal-middleware-stack) section, below.
@@ -302,7 +302,7 @@ Resources
### Learning Rack
-* [Official Rack Website](http://rack.github.io)
+* [Official Rack Website](https://rack.github.io)
* [Introducing Rack](http://chneukirchen.org/blog/archive/2007/02/introducing-rack.html)
### Understanding Middlewares
diff --git a/guides/source/security.md b/guides/source/security.md
index 56969c7aea..d0d7e12b0a 100644
--- a/guides/source/security.md
+++ b/guides/source/security.md
@@ -687,7 +687,7 @@ The most common entry points are message posts, user comments, and guest books,
XSS attacks work like this: An attacker injects some code, the web application saves it and displays it on a page, later presented to a victim. Most XSS examples simply display an alert box, but it is more powerful than that. XSS can steal the cookie, hijack the session, redirect the victim to a fake website, display advertisements for the benefit of the attacker, change elements on the web site to get confidential information or install malicious software through security holes in the web browser.
-During the second half of 2007, there were 88 vulnerabilities reported in Mozilla browsers, 22 in Safari, 18 in IE, and 12 in Opera. The [Symantec Global Internet Security threat report](http://eval.symantec.com/mktginfo/enterprise/white_papers/b-whitepaper_internet_security_threat_report_xiii_04-2008.en-us.pdf) also documented 239 browser plug-in vulnerabilities in the last six months of 2007. [Mpack](http://pandalabs.pandasecurity.com/mpack-uncovered/) is a very active and up-to-date attack framework which exploits these vulnerabilities. For criminal hackers, it is very attractive to exploit an SQL-Injection vulnerability in a web application framework and insert malicious code in every textual table column. In April 2008 more than 510,000 sites were hacked like this, among them the British government, United Nations, and many more high targets.
+During the second half of 2007, there were 88 vulnerabilities reported in Mozilla browsers, 22 in Safari, 18 in IE, and 12 in Opera. The [Symantec Global Internet Security threat report](http://eval.symantec.com/mktginfo/enterprise/white_papers/b-whitepaper_internet_security_threat_report_xiii_04-2008.en-us.pdf) also documented 239 browser plug-in vulnerabilities in the last six months of 2007. [Mpack](http://pandalabs.pandasecurity.com/mpack-uncovered/) is a very active and up-to-date attack framework which exploits these vulnerabilities. For criminal hackers, it is very attractive to exploit an SQL-Injection vulnerability in a web application framework and insert malicious code in every textual table column. In April 2008 more than 510,000 sites were hacked like this, among them the British government, United Nations, and many more high profile targets.
#### HTML/JavaScript Injection
@@ -1025,7 +1025,7 @@ Here is a list of common headers:
* **X-Content-Type-Options:** _'nosniff' in Rails by default_ - stops the browser from guessing the MIME type of a file.
* **X-Content-Security-Policy:** [A powerful mechanism for controlling which sites certain content types can be loaded from](http://w3c.github.io/webappsec/specs/content-security-policy/csp-specification.dev.html)
* **Access-Control-Allow-Origin:** Used to control which sites are allowed to bypass same origin policies and send cross-origin requests.
-* **Strict-Transport-Security:** [Used to control if the browser is allowed to only access a site over a secure connection](http://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security)
+* **Strict-Transport-Security:** [Used to control if the browser is allowed to only access a site over a secure connection](https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security)
Environmental Security
----------------------
@@ -1060,7 +1060,7 @@ Additional Resources
The security landscape shifts and it is important to keep up to date, because missing a new vulnerability can be catastrophic. You can find additional resources about (Rails) security here:
-* Subscribe to the Rails security [mailing list](http://groups.google.com/group/rubyonrails-security).
-* [Brakeman - Rails Security Scanner](http://brakemanscanner.org/) - To perform static security analysis for Rails applications.
+* Subscribe to the Rails security [mailing list](https://groups.google.com/forum/#!forum/rubyonrails-security).
+* [Brakeman - Rails Security Scanner](https://brakemanscanner.org/) - To perform static security analysis for Rails applications.
* [Keep up to date on the other application layers](http://secunia.com/) (they have a weekly newsletter, too).
* A [good security blog](https://www.owasp.org) including the [Cross-Site scripting Cheat Sheet](https://www.owasp.org/index.php/DOM_based_XSS_Prevention_Cheat_Sheet).
diff --git a/guides/source/testing.md b/guides/source/testing.md
index 8141713e1e..4ee3267261 100644
--- a/guides/source/testing.md
+++ b/guides/source/testing.md
@@ -928,7 +928,7 @@ each of the seven default actions, you can use the following command:
$ bin/rails generate test_unit:scaffold article
...
invoke test_unit
-create test/controllers/articles_controller_test.rb
+create test/controllers/articles_controller_test.rb
...
```
@@ -1064,9 +1064,9 @@ end
### Setting Headers and CGI variables
-[HTTP headers](http://tools.ietf.org/search/rfc2616#section-5.3)
+[HTTP headers](https://tools.ietf.org/search/rfc2616#section-5.3)
and
-[CGI variables](http://tools.ietf.org/search/rfc3875#section-4.1)
+[CGI variables](https://tools.ietf.org/search/rfc3875#section-4.1)
can be passed as headers:
```ruby
diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md
index 651b86275a..d932fc8d8f 100644
--- a/guides/source/upgrading_ruby_on_rails.md
+++ b/guides/source/upgrading_ruby_on_rails.md
@@ -1106,7 +1106,7 @@ on the Rails blog.
The errata for the `PATCH` verb [specifies that a 'diff' media type should be
used with `PATCH`](http://www.rfc-editor.org/errata_search.php?rfc=5789). One
-such format is [JSON Patch](http://tools.ietf.org/html/rfc6902). While Rails
+such format is [JSON Patch](https://tools.ietf.org/html/rfc6902). While Rails
does not support JSON Patch natively, it's easy enough to add support:
```
@@ -1310,7 +1310,7 @@ get 'こんにちは', controller: 'welcome', action: 'index'
get '/' => 'root#index'
```
-* Rails 4.0 has removed `ActionDispatch::BestStandardsSupport` middleware, `<!DOCTYPE html>` already triggers standards mode per http://msdn.microsoft.com/en-us/library/jj676915(v=vs.85).aspx and ChromeFrame header has been moved to `config.action_dispatch.default_headers`.
+* Rails 4.0 has removed `ActionDispatch::BestStandardsSupport` middleware, `<!DOCTYPE html>` already triggers standards mode per https://msdn.microsoft.com/en-us/library/jj676915(v=vs.85).aspx and ChromeFrame header has been moved to `config.action_dispatch.default_headers`.
Remember you must also remove any references to the middleware from your application code, for example:
diff --git a/guides/source/working_with_javascript_in_rails.md b/guides/source/working_with_javascript_in_rails.md
index 304ac97b32..27cef2bd27 100644
--- a/guides/source/working_with_javascript_in_rails.md
+++ b/guides/source/working_with_javascript_in_rails.md
@@ -24,11 +24,11 @@ In order to understand Ajax, you must first understand what a web browser does
normally.
When you type `http://localhost:3000` into your browser's address bar and hit
-'Go,' the browser (your 'client') makes a request to the server. It parses the
+'Go', the browser (your 'client') makes a request to the server. It parses the
response, then fetches all associated assets, like JavaScript files,
stylesheets and images. It then assembles the page. If you click a link, it
does the same process: fetch the page, fetch the assets, put it all together,
-show you the results. This is called the 'request response cycle.'
+show you the results. This is called the 'request response cycle'.
JavaScript can also make requests to the server, and parse the response. It
also has the ability to update information on the page. Combining these two
@@ -57,7 +57,7 @@ will show you how Rails can help you write websites in this way, but it's
all built on top of this fairly simple technique.
Unobtrusive JavaScript
--------------------------------------
+----------------------
Rails uses a technique called "Unobtrusive JavaScript" to handle attaching
JavaScript to the DOM. This is generally considered to be a best-practice
@@ -139,7 +139,7 @@ JavaScript) in this style, and you can expect that many libraries will also
follow this pattern.
Built-in Helpers
-----------------------
+----------------
### Remote elements
@@ -256,7 +256,7 @@ attributes to accomplish this.
#### `data-method`
Activating hyperlinks always results in an HTTP GET request. However, if your
-application is [RESTful](http://en.wikipedia.org/wiki/Representational_State_Transfer),
+application is [RESTful](https://en.wikipedia.org/wiki/Representational_State_Transfer),
some links are in fact actions that change data on the server, and must be
performed with non-GET requests. This attribute allows marking up such links
with an explicit method such as "post", "put" or "delete".
@@ -372,9 +372,9 @@ is also useful for manipulating form data before serialization. The
`ajax:beforeSend` event is also useful for adding custom request headers.
If you stop the `ajax:aborted:file` event, the default behavior of allowing the
-browser to submit the form via normal means (i.e. non-AJAX submission) will be
+browser to submit the form via normal means (i.e. non-Ajax submission) will be
canceled and the form will not be submitted at all. This is useful for
-implementing your own AJAX file upload workaround.
+implementing your own Ajax file upload workaround.
### Rails-ujs event handlers
diff --git a/railties/RDOC_MAIN.rdoc b/railties/RDOC_MAIN.rdoc
index 654c7bae57..c70a9f0ba0 100644
--- a/railties/RDOC_MAIN.rdoc
+++ b/railties/RDOC_MAIN.rdoc
@@ -1,35 +1,50 @@
== Welcome to \Rails
-\Rails is a web-application framework that includes everything needed to create
-database-backed web applications according to the {Model-View-Controller (MVC)}[http://en.wikipedia.org/wiki/Model-view-controller] pattern.
-
-Understanding the MVC pattern is key to understanding \Rails. MVC divides your application
-into three layers, each with a specific responsibility.
-
-The View layer is composed of "templates" that are responsible for providing
-appropriate representations of your application's resources. Templates
-can come in a variety of formats, but most view templates are \HTML with embedded Ruby
-code (.erb files).
-
-The Model layer represents your domain model (such as Account, Product, Person, Post)
-and encapsulates the business logic that is specific to your application. In \Rails,
-database-backed model classes are derived from ActiveRecord::Base. Active Record allows
-you to present the data from database rows as objects and embellish these data objects
-with business logic methods. Although most \Rails models are backed by a database, models
-can also be ordinary Ruby classes, or Ruby classes that implement a set of interfaces as
-provided by the ActiveModel module. You can read more about Active Record in its
-{README}[link:files/activerecord/README_rdoc.html].
-
-The Controller layer is responsible for handling incoming HTTP requests and providing a
-suitable response. Usually this means returning \HTML, but \Rails controllers can also
-generate XML, JSON, PDFs, mobile-specific views, and more. Controllers manipulate models
-and render view templates in order to generate the appropriate HTTP response.
-
-In \Rails, the Controller and View layers are handled together by Action Pack.
-These two layers are bundled in a single package due to their heavy interdependence.
-This is unlike the relationship between Active Record and Action Pack, which are
-independent. Each of these packages can be used independently outside of \Rails. You
-can read more about Action Pack in its {README}[link:files/actionpack/README_rdoc.html].
+\Rails is a web-application framework that includes everything needed to
+create database-backed web applications according to the
+{Model-View-Controller (MVC)}[http://en.wikipedia.org/wiki/Model-view-controller]
+pattern.
+
+Understanding the MVC pattern is key to understanding \Rails. MVC divides your
+application into three layers, each with a specific responsibility.
+
+The <em>Model layer</em> represents your domain model (such as Account, Product,
+Person, Post, etc.) and encapsulates the business logic that is specific to
+your application. In \Rails, database-backed model classes are derived from
+ActiveRecord::Base. Active Record allows you to present the data from
+database rows as objects and embellish these data objects with business logic
+methods. You can read more about Active Record in its {README}[link:files/activerecord/README_rdoc.html].
+Although most \Rails models are backed by a database, models can also be ordinary
+Ruby classes, or Ruby classes that implement a set of interfaces as provided by
+the Active Model module. You can read more about Active Model in its {README}[link:files/activemodel/README_rdoc.html].
+
+The <em>Controller layer</em> is responsible for handling incoming HTTP requests and
+providing a suitable response. Usually this means returning \HTML, but \Rails controllers
+can also generate XML, JSON, PDFs, mobile-specific views, and more. Controllers load and
+manipulate models, and render view templates in order to generate the appropriate HTTP response.
+In \Rails, incoming requests are routed by Action Dispatch to an appropriate controller, and
+controller classes are derived from ActionController::Base. Action Dispatch and Action Controller
+are bundled together in Action Pack. You can read more about Action Pack in its
+{README}[link:files/actionpack/README_rdoc.html].
+
+The <em>View layer</em> is composed of "templates" that are responsible for providing
+appropriate representations of your application's resources. Templates can
+come in a variety of formats, but most view templates are \HTML with embedded
+Ruby code (ERB files). Views are typically rendered to generate a controller response,
+or to generate the body of an email. In \Rails, View generation is handled by Action View.
+You can read more about Action View in its {README}[link:files/actionview/README_rdoc.html].
+
+Active Record, Active Model, Action Pack, and Action View can each be used independently outside \Rails.
+In addition to that, \Rails also comes with Action Mailer ({README}[link:files/actionmailer/README_rdoc.html]), a library
+to generate and send emails; Active Job ({README}[link:files/activejob/README_md.html]), a
+framework for declaring jobs and making them run on a variety of queueing
+backends; Action Cable ({README}[link:files/actioncable/README_md.html]), a framework to
+integrate WebSockets with a \Rails application;
+Active Storage ({README}[link:files/activestorage/README_md.html]), a library to attach cloud
+and local files to \Rails applications;
+and Active Support ({README}[link:files/activesupport/README_rdoc.html]), a collection
+of utility classes and standard library extensions that are useful for \Rails,
+and may also be used independently outside \Rails.
== Getting Started
@@ -45,29 +60,32 @@ can read more about Action Pack in its {README}[link:files/actionpack/README_rdo
3. Change directory to +myapp+ and start the web server:
- $ cd myapp; rails server
+ $ cd myapp
+ $ rails server
Run with <tt>--help</tt> or <tt>-h</tt> for options.
-4. Go to http://localhost:3000 and you'll see:
-
- "Yay! You’re on Rails!"
+4. Go to <tt>http://localhost:3000</tt> and you'll see: "Yay! You’re on \Rails!"
5. Follow the guidelines to start developing your application. You may find the following resources handy:
-* The \README file created within your application.
-* {Getting Started with \Rails}[http://guides.rubyonrails.org/getting_started.html].
-* {Ruby on \Rails Tutorial}[https://www.railstutorial.org/book].
-* {Ruby on \Rails Guides}[http://guides.rubyonrails.org].
-* {The API Documentation}[http://api.rubyonrails.org].
+ * The \README file created within your application.
+ * {Getting Started with \Rails}[http://guides.rubyonrails.org/getting_started.html].
+ * {Ruby on \Rails Guides}[http://guides.rubyonrails.org].
+ * {The API Documentation}[http://api.rubyonrails.org].
+ * {Ruby on \Rails Tutorial}[https://www.railstutorial.org/book].
== Contributing
-We encourage you to contribute to Ruby on \Rails! Please check out the {Contributing to Rails
-guide}[http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html] for guidelines about how
-to proceed. {Join us}[http://contributors.rubyonrails.org]!
+We encourage you to contribute to Ruby on \Rails! Please check out the
+{Contributing to Ruby on \Rails guide}[http://guides.rubyonrails.org/contributing_to_ruby_on_rails.html] for guidelines about how to proceed. {Join us!}[http://contributors.rubyonrails.org]
+
+Trying to report a possible security vulnerability in \Rails? Please
+check out our {security policy}[http://rubyonrails.org/security/] for
+guidelines about how to proceed.
+Everyone interacting in \Rails and its sub-projects' codebases, issue trackers, chat rooms, and mailing lists is expected to follow the \Rails {code of conduct}[http://rubyonrails.org/conduct/].
== License
-Ruby on \Rails is released under the {MIT License}[http://www.opensource.org/licenses/MIT].
+Ruby on \Rails is released under the {MIT License}[https://opensource.org/licenses/MIT].
diff --git a/railties/README.rdoc b/railties/README.rdoc
index a25658668c..2715ccac3f 100644
--- a/railties/README.rdoc
+++ b/railties/README.rdoc
@@ -23,7 +23,7 @@ Source code can be downloaded as part of the Rails project on GitHub
Railties is released under the MIT license:
-* http://www.opensource.org/licenses/MIT
+* https://opensource.org/licenses/MIT
== Support
@@ -38,4 +38,3 @@ Bug reports can be filed for the Ruby on Rails project here:
Feature requests should be discussed on the rails-core mailing list here:
* https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-core
-
diff --git a/railties/lib/rails/api/generator.rb b/railties/lib/rails/api/generator.rb
index 6e5eec2e34..3405560b74 100644
--- a/railties/lib/rails/api/generator.rb
+++ b/railties/lib/rails/api/generator.rb
@@ -6,8 +6,11 @@ class RDoc::Generator::API < RDoc::Generator::SDoc # :nodoc:
RDoc::RDoc.add_generator self
def generate_class_tree_level(classes, visited = {})
- # Only process core extensions on the first visit.
+ # Only process core extensions on the first visit and remove
+ # Active Storage duplicated classes that are at the top level
+ # since they aren't nested under a definition of the `ActiveStorage` module.
if visited.empty?
+ classes = classes.reject { |klass| active_storage?(klass) }
core_exts, classes = classes.partition { |klass| core_extension?(klass) }
super.unshift([ "Core extensions", "", "", build_core_ext_subtree(core_exts, visited) ])
@@ -27,4 +30,8 @@ class RDoc::Generator::API < RDoc::Generator::SDoc # :nodoc:
def core_extension?(klass)
klass.name != "ActiveSupport" && klass.in_files.any? { |file| file.absolute_name.include?("core_ext") }
end
+
+ def active_storage?(klass)
+ klass.name != "ActiveStorage" && klass.in_files.all? { |file| file.absolute_name.include?("active_storage") }
+ end
end
diff --git a/railties/lib/rails/api/task.rb b/railties/lib/rails/api/task.rb
index 595079e45f..184f5b14f1 100644
--- a/railties/lib/rails/api/task.rb
+++ b/railties/lib/rails/api/task.rb
@@ -69,6 +69,7 @@ module Rails
"activestorage" => {
include: %w(
README.md
+ app/**/active_storage/**/*.rb
lib/active_storage/**/*.rb
)
},
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index 31e2a45bff..b65289177f 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -151,7 +151,7 @@ module Rails
end
# Loads and returns the entire raw configuration of database from
- # values stored in `config/database.yml`.
+ # values stored in <tt>config/database.yml</tt>.
def database_configuration
path = paths["config/database"].existent.first
yaml = Pathname.new(path) if path
diff --git a/railties/lib/rails/command/actions.rb b/railties/lib/rails/command/actions.rb
index 2f6827b7f4..cbb743346b 100644
--- a/railties/lib/rails/command/actions.rb
+++ b/railties/lib/rails/command/actions.rb
@@ -3,9 +3,9 @@
module Rails
module Command
module Actions
- # Change to the application's path if there is no config.ru file in current directory.
- # This allows us to run `rails server` from other directories, but still get
- # the main config.ru and properly set the tmp directory.
+ # Change to the application's path if there is no <tt>config.ru</tt> file in current directory.
+ # This allows us to run <tt>rails server</tt> from other directories, but still get
+ # the main <tt>config.ru</tt> and properly set the <tt>tmp</tt> directory.
def set_application_directory!
Dir.chdir(File.expand_path("../..", APP_PATH)) unless File.exist?(File.expand_path("config.ru"))
end
diff --git a/railties/lib/rails/command/base.rb b/railties/lib/rails/command/base.rb
index e92b2042bd..8df4f98d3e 100644
--- a/railties/lib/rails/command/base.rb
+++ b/railties/lib/rails/command/base.rb
@@ -112,8 +112,8 @@ module Rails
# Default file root to place extra files a command might need, placed
# one folder above the command file.
#
- # For a `Rails::Command::TestCommand` placed in `rails/command/test_command.rb`
- # would return `rails/test`.
+ # For a Rails::Command::TestCommand placed in <tt>rails/command/test_command.rb</tt>
+ # would return <tt>rails/test</tt>.
def default_command_root
path = File.expand_path(File.join("../commands", command_root_namespace), __dir__)
path if File.exist?(path)
diff --git a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb
index 6296c95a87..5234969743 100644
--- a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb
+++ b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb
@@ -75,7 +75,7 @@ module Rails
args += ["-P", "#{config['password']}"] if config["password"]
if config["host"]
- host_arg = "#{config['host']}"
+ host_arg = "#{config['host']}".dup
host_arg << ":#{config['port']}" if config["port"]
args += ["-S", host_arg]
end
diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb
index 88e5698714..785265d766 100644
--- a/railties/lib/rails/commands/server/server_command.rb
+++ b/railties/lib/rails/commands/server/server_command.rb
@@ -126,6 +126,7 @@ module Rails
desc: "Specifies the PID file."
class_option "dev-caching", aliases: "-C", type: :boolean, default: nil,
desc: "Specifies whether to perform caching in development."
+ class_option "restart", type: :boolean, default: nil, hide: true
def initialize(args = [], local_options = {}, config = {})
@original_options = local_options
@@ -136,6 +137,7 @@ module Rails
def perform
set_application_directory!
+ prepare_restart
Rails::Server.new(server_options).tap do |server|
# Require application after server sets environment to propagate
# the --environment option.
@@ -222,7 +224,7 @@ module Rails
end
def restart_command
- "bin/rails server #{@server} #{@original_options.join(" ")}"
+ "bin/rails server #{@server} #{@original_options.join(" ")} --restart"
end
def pid
@@ -232,6 +234,10 @@ module Rails
def self.banner(*)
"rails server [puma, thin etc] [options]"
end
+
+ def prepare_restart
+ FileUtils.rm_f(options[:pid]) if options[:restart]
+ end
end
end
end
diff --git a/railties/lib/rails/dev_caching.rb b/railties/lib/rails/dev_caching.rb
index efb523de4c..ff629b2527 100644
--- a/railties/lib/rails/dev_caching.rb
+++ b/railties/lib/rails/dev_caching.rb
@@ -19,7 +19,6 @@ module Rails
end
FileUtils.touch "tmp/restart.txt"
- FileUtils.rm_f("tmp/pids/server.pid")
end
def enable_by_argument(caching)
diff --git a/railties/lib/rails/generators/rails/app/templates/Rakefile b/railties/lib/rails/generators/rails/app/templates/Rakefile
index 488c551fee..e85f913914 100644
--- a/railties/lib/rails/generators/rails/app/templates/Rakefile
+++ b/railties/lib/rails/generators/rails/app/templates/Rakefile
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
diff --git a/railties/lib/rails/generators/rails/app/templates/app/channels/application_cable/channel.rb b/railties/lib/rails/generators/rails/app/templates/app/channels/application_cable/channel.rb
index 9aec230539..d672697283 100644
--- a/railties/lib/rails/generators/rails/app/templates/app/channels/application_cable/channel.rb
+++ b/railties/lib/rails/generators/rails/app/templates/app/channels/application_cable/channel.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
diff --git a/railties/lib/rails/generators/rails/app/templates/app/channels/application_cable/connection.rb b/railties/lib/rails/generators/rails/app/templates/app/channels/application_cable/connection.rb
index 8d6c2a1bf4..0ff5442f47 100644
--- a/railties/lib/rails/generators/rails/app/templates/app/channels/application_cable/connection.rb
+++ b/railties/lib/rails/generators/rails/app/templates/app/channels/application_cable/connection.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
diff --git a/railties/lib/rails/generators/rails/app/templates/app/helpers/application_helper.rb b/railties/lib/rails/generators/rails/app/templates/app/helpers/application_helper.rb
index 15b06f0f67..de6be7945c 100644
--- a/railties/lib/rails/generators/rails/app/templates/app/helpers/application_helper.rb
+++ b/railties/lib/rails/generators/rails/app/templates/app/helpers/application_helper.rb
@@ -1,4 +1,2 @@
-# frozen_string_literal: true
-
module ApplicationHelper
end
diff --git a/railties/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb b/railties/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb
index d92ffddcb5..a009ace51c 100644
--- a/railties/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb
+++ b/railties/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb
@@ -1,4 +1,2 @@
-# frozen_string_literal: true
-
class ApplicationJob < ActiveJob::Base
end
diff --git a/railties/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb b/railties/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb
index d84cb6e71e..286b2239d1 100644
--- a/railties/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb
+++ b/railties/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout 'mailer'
diff --git a/railties/lib/rails/generators/rails/app/templates/app/models/application_record.rb b/railties/lib/rails/generators/rails/app/templates/app/models/application_record.rb
index 71fbba5b32..10a4cba84d 100644
--- a/railties/lib/rails/generators/rails/app/templates/app/models/application_record.rb
+++ b/railties/lib/rails/generators/rails/app/templates/app/models/application_record.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb
index eec973caa5..dde09edb94 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/application.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
require_relative 'boot'
<% if include_all_railties? -%>
diff --git a/railties/lib/rails/generators/rails/app/templates/config/boot.rb b/railties/lib/rails/generators/rails/app/templates/config/boot.rb
index c04863fa7d..b9e460cef3 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/boot.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/boot.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' # Set up gems listed in the Gemfile.
diff --git a/railties/lib/rails/generators/rails/app/templates/config/cable.yml b/railties/lib/rails/generators/rails/app/templates/config/cable.yml
index 1da4913082..8e53156c71 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/cable.yml
+++ b/railties/lib/rails/generators/rails/app/templates/config/cable.yml
@@ -6,5 +6,5 @@ test:
production:
adapter: redis
- url: redis://localhost:6379/1
+ url: <%%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: <%= app_name %>_production
diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml
index 8bc8735a8e..2a67bdca25 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml
+++ b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml
@@ -7,7 +7,7 @@
# gem 'activerecord-jdbcmysql-adapter'
#
# And be sure to use new-style password hashing:
-# http://dev.mysql.com/doc/refman/5.7/en/old-client.html
+# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
#
default: &default
adapter: mysql
diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml
index 269af1470d..04afaa0596 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml
+++ b/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml
@@ -7,7 +7,7 @@
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
-# http://dev.mysql.com/doc/refman/5.7/en/old-client.html
+# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
#
default: &default
adapter: mysql2
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environment.rb b/railties/lib/rails/generators/rails/app/templates/config/environment.rb
index d5abe55806..426333bb46 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environment.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/environment.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
# Load the Rails application.
require_relative 'application'
diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb b/railties/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb
index 6d56e43900..89d2efab2b 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
# Be sure to restart your server when you modify this file.
# ActiveSupport::Reloader.to_prepare do
diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb b/railties/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb
index 4b63f2893d..59385cdf37 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb b/railties/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb
index ee8dff9c99..5a6a32d371 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
# Be sure to restart your server when you modify this file.
# Specify a serializer for the signed and encrypted cookie jars.
diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/cors.rb b/railties/lib/rails/generators/rails/app/templates/config/initializers/cors.rb
index 82eafe5ca4..3b1c1b5ed1 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/initializers/cors.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/cors.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
# Be sure to restart your server when you modify this file.
# Avoid CORS issues when API is called from the frontend app.
diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb b/railties/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb
index 7a4f47b4c2..4a994e1e7b 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
# Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb b/railties/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb
index dc84742212..ac033bf9dc 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections
diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/mime_types.rb b/railties/lib/rails/generators/rails/app/templates/config/initializers/mime_types.rb
index be6fedc535..dc1899682b 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/initializers/mime_types.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/mime_types.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
diff --git a/railties/lib/rails/generators/rails/app/templates/config/puma.rb b/railties/lib/rails/generators/rails/app/templates/config/puma.rb
index 55bd3da2a7..1e19380dcb 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/puma.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/puma.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
diff --git a/railties/lib/rails/generators/rails/app/templates/config/routes.rb b/railties/lib/rails/generators/rails/app/templates/config/routes.rb
index 47cc16ea2f..787824f888 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/routes.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/routes.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
diff --git a/railties/lib/rails/generators/rails/app/templates/config/spring.rb b/railties/lib/rails/generators/rails/app/templates/config/spring.rb
index c5933e491b..9fa7863f99 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/spring.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/spring.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
%w[
.ruby-version
.rbenv-vars
diff --git a/railties/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb b/railties/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb
index c05709aff8..d19212abd5 100644
--- a/railties/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb
+++ b/railties/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
require "test_helper"
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
diff --git a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb
index b64e90522a..6ad1f11781 100644
--- a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb
+++ b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
require_relative '../config/environment'
require 'rails/test_help'
diff --git a/railties/lib/rails/generators/rails/controller/templates/controller.rb b/railties/lib/rails/generators/rails/controller/templates/controller.rb
index 835b2923f3..633e0b3177 100644
--- a/railties/lib/rails/generators/rails/controller/templates/controller.rb
+++ b/railties/lib/rails/generators/rails/controller/templates/controller.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
<% if namespaced? -%>
require_dependency "<%= namespaced_path %>/application_controller"
diff --git a/railties/lib/rails/generators/rails/helper/templates/helper.rb b/railties/lib/rails/generators/rails/helper/templates/helper.rb
index 538ab221e7..b4173151b4 100644
--- a/railties/lib/rails/generators/rails/helper/templates/helper.rb
+++ b/railties/lib/rails/generators/rails/helper/templates/helper.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
<% module_namespacing do -%>
module <%= class_name %>Helper
end
diff --git a/railties/lib/rails/generators/rails/plugin/templates/README.md b/railties/lib/rails/generators/rails/plugin/templates/README.md
index 9d2b74416e..1632409bea 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/README.md
+++ b/railties/lib/rails/generators/rails/plugin/templates/README.md
@@ -25,4 +25,4 @@ $ gem install <%= name %>
Contribution directions go here.
## License
-The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
+The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
diff --git a/railties/lib/rails/generators/rails/plugin/templates/Rakefile b/railties/lib/rails/generators/rails/plugin/templates/Rakefile
index 86307fa053..f3efe21cf1 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/Rakefile
+++ b/railties/lib/rails/generators/rails/plugin/templates/Rakefile
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
begin
require 'bundler/setup'
rescue LoadError
diff --git a/railties/lib/rails/generators/rails/plugin/templates/config/routes.rb b/railties/lib/rails/generators/rails/plugin/templates/config/routes.rb
index 791e76f1c3..154452bfe5 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/config/routes.rb
+++ b/railties/lib/rails/generators/rails/plugin/templates/config/routes.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
<% if mountable? -%>
<%= camelized_modules %>::Engine.routes.draw do
<% else -%>
diff --git a/railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb b/railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb
index a3071ba45a..3285055eb7 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb
+++ b/railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
<% if engine? -%>
require "<%= namespaced_name %>/engine"
<% else -%>
diff --git a/railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb b/railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb
index 91faa26120..8938770fc4 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb
+++ b/railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
<%= wrap_in_modules <<-rb.strip_heredoc
class Engine < ::Rails::Engine
#{mountable? ? ' isolate_namespace ' + camelized_modules : ' '}
diff --git a/railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb b/railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb
index efae25ca4a..7bdf4ee5fb 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb
+++ b/railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
<%= wrap_in_modules <<-rb.strip_heredoc
class Railtie < ::Rails::Railtie
end
diff --git a/railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb b/railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb
index c30d3460f3..b08f4ef9ae 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb
+++ b/railties/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb
@@ -1,3 +1 @@
-# frozen_string_literal: true
-
<%= wrap_in_modules "VERSION = '0.1.0'" %>
diff --git a/railties/lib/rails/generators/rails/plugin/templates/lib/tasks/%namespaced_name%_tasks.rake b/railties/lib/rails/generators/rails/plugin/templates/lib/tasks/%namespaced_name%_tasks.rake
index 9c8c0544b7..88a2c4120f 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/lib/tasks/%namespaced_name%_tasks.rake
+++ b/railties/lib/rails/generators/rails/plugin/templates/lib/tasks/%namespaced_name%_tasks.rake
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
# desc "Explaining what the task does"
# task :<%= underscored_name %> do
# # Task goes here
diff --git a/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb b/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb
index 9f9da645f9..47b56ae3df 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb
+++ b/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
require_relative 'boot'
<% if include_all_railties? -%>
diff --git a/railties/lib/rails/generators/rails/plugin/templates/rails/boot.rb b/railties/lib/rails/generators/rails/plugin/templates/rails/boot.rb
index 6d2cba07a2..c9aef85d40 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/rails/boot.rb
+++ b/railties/lib/rails/generators/rails/plugin/templates/rails/boot.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
diff --git a/railties/lib/rails/generators/rails/plugin/templates/rails/routes.rb b/railties/lib/rails/generators/rails/plugin/templates/rails/routes.rb
index f571f201a1..694510edc0 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/rails/routes.rb
+++ b/railties/lib/rails/generators/rails/plugin/templates/rails/routes.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
Rails.application.routes.draw do
mount <%= camelized_modules %>::Engine => "/<%= name %>"
end
diff --git a/railties/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb b/railties/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb
index f37369420f..1ee05d7871 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb
+++ b/railties/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
require 'test_helper'
class <%= camelized_modules %>::Test < ActiveSupport::TestCase
diff --git a/railties/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb b/railties/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb
index c05709aff8..d19212abd5 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb
+++ b/railties/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
require "test_helper"
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
diff --git a/railties/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb b/railties/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb
index dc58e44e8b..29e59d8407 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb
+++ b/railties/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
require 'test_helper'
class NavigationTest < ActionDispatch::IntegrationTest
@@ -7,4 +5,3 @@ class NavigationTest < ActionDispatch::IntegrationTest
# assert true
# end
end
-
diff --git a/railties/lib/rails/generators/rails/plugin/templates/test/test_helper.rb b/railties/lib/rails/generators/rails/plugin/templates/test/test_helper.rb
index 2fa05a9146..2af7e06041 100644
--- a/railties/lib/rails/generators/rails/plugin/templates/test/test_helper.rb
+++ b/railties/lib/rails/generators/rails/plugin/templates/test/test_helper.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
require_relative "<%= File.join('..', options[:dummy_path], 'config/environment') -%>"
<% unless options[:skip_active_record] -%>
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../<%= options[:dummy_path] -%>/db/migrate", __dir__)]
diff --git a/railties/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb b/railties/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb
index 50fae26c80..400afec6dc 100644
--- a/railties/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb
+++ b/railties/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
<% if namespaced? -%>
require_dependency "<%= namespaced_path %>/application_controller"
diff --git a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb
index fb3e778252..42b9e34274 100644
--- a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb
+++ b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
<% if namespaced? -%>
require_dependency "<%= namespaced_path %>/application_controller"
diff --git a/railties/lib/rails/generators/rails/task/templates/task.rb b/railties/lib/rails/generators/rails/task/templates/task.rb
index 82626afce0..1e3ed5f158 100644
--- a/railties/lib/rails/generators/rails/task/templates/task.rb
+++ b/railties/lib/rails/generators/rails/task/templates/task.rb
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
namespace :<%= file_name %> do
<% actions.each do |action| -%>
desc "TODO"
diff --git a/railties/lib/rails/secrets.rb b/railties/lib/rails/secrets.rb
index 33821dd759..aea72b2d01 100644
--- a/railties/lib/rails/secrets.rb
+++ b/railties/lib/rails/secrets.rb
@@ -44,7 +44,7 @@ module Rails
<<-end_of_template.strip_heredoc
# See `secrets.yml` for tips on generating suitable keys.
# production:
- # external_api_key: 1466aac22e6a869134be3d09b9e89232fc2c2289
+ # external_api_key: 1466aac22e6a869134be3d09b9e89232fc2c2289
end_of_template
end
diff --git a/railties/lib/rails/source_annotation_extractor.rb b/railties/lib/rails/source_annotation_extractor.rb
index d6cde227c5..1db6c98537 100644
--- a/railties/lib/rails/source_annotation_extractor.rb
+++ b/railties/lib/rails/source_annotation_extractor.rb
@@ -21,7 +21,7 @@ class SourceAnnotationExtractor
end
# Registers additional directories to be included
- # SourceAnnotationExtractor::Annotation.register_directories("spec","another")
+ # SourceAnnotationExtractor::Annotation.register_directories("spec", "another")
def self.register_directories(*dirs)
directories.push(*dirs)
end
diff --git a/railties/lib/rails/tasks/restart.rake b/railties/lib/rails/tasks/restart.rake
index 5b6bb8ddd6..074e3e89a1 100644
--- a/railties/lib/rails/tasks/restart.rake
+++ b/railties/lib/rails/tasks/restart.rake
@@ -5,6 +5,5 @@ task :restart do
verbose(false) do
mkdir_p "tmp"
touch "tmp/restart.txt"
- rm_f "tmp/pids/server.pid"
end
end
diff --git a/railties/lib/rails/test_unit/line_filtering.rb b/railties/lib/rails/test_unit/line_filtering.rb
index e8b891d07b..f8ca77fe4a 100644
--- a/railties/lib/rails/test_unit/line_filtering.rb
+++ b/railties/lib/rails/test_unit/line_filtering.rb
@@ -1,6 +1,5 @@
# frozen_string_literal: true
-require "method_source"
require "rails/test_unit/runner"
module Rails
diff --git a/railties/test/application/rake/dev_test.rb b/railties/test/application/rake/dev_test.rb
index d56f315455..b25593ee1c 100644
--- a/railties/test/application/rake/dev_test.rb
+++ b/railties/test/application/rake/dev_test.rb
@@ -32,12 +32,16 @@ module ApplicationTests
end
end
- test "dev:cache removes server.pid also" do
+ test "dev:cache touches tmp/restart.txt" do
Dir.chdir(app_path) do
- FileUtils.mkdir_p("tmp/pids")
- FileUtils.touch("tmp/pids/server.pid")
`rails dev:cache`
- assert_not File.exist?("tmp/pids/server.pid")
+ assert File.exist?("tmp/restart.txt")
+
+ prev_mtime = File.mtime("tmp/restart.txt")
+ sleep(1)
+ `rails dev:cache`
+ curr_mtime = File.mtime("tmp/restart.txt")
+ assert_not_equal prev_mtime, curr_mtime
end
end
end
diff --git a/railties/test/application/rake/restart_test.rb b/railties/test/application/rake/restart_test.rb
index bf06f4c522..ed96dcb6b1 100644
--- a/railties/test/application/rake/restart_test.rb
+++ b/railties/test/application/rake/restart_test.rb
@@ -35,15 +35,6 @@ module ApplicationTests
assert File.exist?("tmp/restart.txt")
end
end
-
- test "rails restart removes server.pid also" do
- Dir.chdir(app_path) do
- FileUtils.mkdir_p("tmp/pids")
- FileUtils.touch("tmp/pids/server.pid")
- `bin/rails restart`
- assert_not File.exist?("tmp/pids/server.pid")
- end
- end
end
end
end
diff --git a/railties/test/application/server_test.rb b/railties/test/application/server_test.rb
index 97b3b4f6b3..6db9a3b9e8 100644
--- a/railties/test/application/server_test.rb
+++ b/railties/test/application/server_test.rb
@@ -1,12 +1,14 @@
# frozen_string_literal: true
require "isolation/abstract_unit"
+require "console_helpers"
require "rails/command"
require "rails/commands/server/server_command"
module ApplicationTests
class ServerTest < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation
+ include ConsoleHelpers
def setup
build_app
@@ -29,5 +31,31 @@ module ApplicationTests
log = File.read(Rails.application.config.paths["log"].first)
assert_match(/DEPRECATION WARNING: Use `Rails::Application` subclass to start the server is deprecated/, log)
end
+
+ test "restart rails server with custom pid file path" do
+ skip "PTY unavailable" unless available_pty?
+
+ master, slave = PTY.open
+ pid = nil
+
+ begin
+ pid = Process.spawn("#{app_path}/bin/rails server -P tmp/dummy.pid", in: slave, out: slave, err: slave)
+ assert_output("Listening", master)
+
+ Dir.chdir(app_path) { system("bin/rails restart") }
+
+ assert_output("Restarting", master)
+ assert_output("Inherited", master)
+ ensure
+ kill(pid) if pid
+ end
+ end
+
+ private
+ def kill(pid)
+ Process.kill("TERM", pid)
+ Process.wait(pid)
+ rescue Errno::ESRCH
+ end
end
end
diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb
index e922a23e15..6ad96b28c7 100644
--- a/railties/test/commands/dbconsole_test.rb
+++ b/railties/test/commands/dbconsole_test.rb
@@ -206,6 +206,12 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase
assert_equal ["sqlplus", "user/secret@db"], dbconsole.find_cmd_and_exec_args
end
+ def test_sqlserver
+ start(adapter: "sqlserver", database: "db", username: "user", password: "secret", host: "localhost", port: 1433)
+ assert_not aborted
+ assert_equal ["sqsh", "-D", "db", "-U", "user", "-P", "secret", "-S", "localhost:1433"], dbconsole.find_cmd_and_exec_args
+ end
+
def test_unknown_command_line_client
start(adapter: "unknown", database: "db")
assert aborted
diff --git a/railties/test/commands/server_test.rb b/railties/test/commands/server_test.rb
index eb739db9d1..556c2289e7 100644
--- a/railties/test/commands/server_test.rb
+++ b/railties/test/commands/server_test.rb
@@ -190,7 +190,7 @@ class Rails::ServerTest < ActiveSupport::TestCase
ARGV.replace args
options = parse_arguments(args)
- expected = "bin/rails server -p 4567 -b 127.0.0.1 -c dummy_config.ru -d -e test -P tmp/server.pid -C"
+ expected = "bin/rails server -p 4567 -b 127.0.0.1 -c dummy_config.ru -d -e test -P tmp/server.pid -C --restart"
assert_equal expected, options[:restart_cmd]
ensure
diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb
index c015395962..3ecfb4edd9 100644
--- a/railties/test/generators/actions_test.rb
+++ b/railties/test/generators/actions_test.rb
@@ -390,7 +390,6 @@ class ActionsTest < Rails::Generators::TestCase
File.open(route_path, "wb") { |file| file.write(content) }
routes = <<-F
-# frozen_string_literal: true
Rails.application.routes.draw do
root 'welcome#index'
end
@@ -401,7 +400,6 @@ F
action :route, "resources :product_lines"
routes = <<-F
-# frozen_string_literal: true
Rails.application.routes.draw do
resources :product_lines
root 'welcome#index'
diff --git a/railties/test/generators/encrypted_secrets_generator_test.rb b/railties/test/generators/encrypted_secrets_generator_test.rb
index 205827e498..eacb5166c0 100644
--- a/railties/test/generators/encrypted_secrets_generator_test.rb
+++ b/railties/test/generators/encrypted_secrets_generator_test.rb
@@ -17,8 +17,8 @@ class EncryptedSecretsGeneratorTest < Rails::Generators::TestCase
assert_file "config/secrets.yml.key", /\w+/
assert File.exist?("config/secrets.yml.enc")
- assert_no_match(/production:\n# external_api_key: \w+/, IO.binread("config/secrets.yml.enc"))
- assert_match(/production:\n# external_api_key: \w+/, Rails::Secrets.read)
+ assert_no_match(/# production:\n# external_api_key: \w+/, IO.binread("config/secrets.yml.enc"))
+ assert_match(/# production:\n# external_api_key: \w+/, Rails::Secrets.read)
end
def test_appends_to_gitignore
diff --git a/railties/test/secrets_test.rb b/railties/test/secrets_test.rb
index 445e216f16..ff6f955a78 100644
--- a/railties/test/secrets_test.rb
+++ b/railties/test/secrets_test.rb
@@ -47,7 +47,7 @@ class Rails::SecretsTest < ActiveSupport::TestCase
ENV["RAILS_MASTER_KEY"] = IO.binread("config/secrets.yml.key").strip
FileUtils.rm("config/secrets.yml.key")
- assert_match "production:\n# external_api_key", Rails::Secrets.read
+ assert_match "# production:\n# external_api_key:", Rails::Secrets.read
ensure
ENV["RAILS_MASTER_KEY"] = old_key
end
@@ -69,7 +69,7 @@ class Rails::SecretsTest < ActiveSupport::TestCase
Rails::Secrets.read_for_editing do |tmp_path|
decrypted_path = tmp_path
- assert_match(/production:\n# external_api_key/, File.read(tmp_path))
+ assert_match(/# production:\n# external_api_key/, File.read(tmp_path))
File.write(tmp_path, "Empty streets, empty nights. The Downtown Lights.")
end