diff options
-rw-r--r-- | Gemfile.lock | 4 | ||||
-rw-r--r-- | actiontext/app/helpers/action_text/tag_helper.rb | 4 | ||||
-rw-r--r-- | actiontext/test/template/form_helper_test.rb | 50 | ||||
-rw-r--r-- | actionview/test/template/form_helper/form_with_test.rb | 17 | ||||
-rw-r--r-- | actionview/test/template/form_helper_test.rb | 72 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 42 | ||||
-rw-r--r-- | activesupport/activesupport.gemspec | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/dependencies/zeitwerk_integration.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/autoloaders.rb | 3 | ||||
-rw-r--r-- | railties/test/application/zeitwerk_integration_test.rb | 12 |
11 files changed, 145 insertions, 67 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index ce50c043e2..cd75cf0837 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -70,7 +70,7 @@ PATH i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - zeitwerk (~> 1.2) + zeitwerk (~> 1.3) rails (6.0.0.beta1) actioncable (= 6.0.0.beta1) actionmailbox (= 6.0.0.beta1) @@ -517,7 +517,7 @@ GEM websocket-extensions (0.1.3) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (1.2.0) + zeitwerk (1.3.0) PLATFORMS java diff --git a/actiontext/app/helpers/action_text/tag_helper.rb b/actiontext/app/helpers/action_text/tag_helper.rb index 8434f2c611..1dc6202ae1 100644 --- a/actiontext/app/helpers/action_text/tag_helper.rb +++ b/actiontext/app/helpers/action_text/tag_helper.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "action_view/helpers/tags/placeholderable" + module ActionText module TagHelper cattr_accessor(:id, instance_accessor: false) { 0 } @@ -35,6 +37,8 @@ end module ActionView::Helpers class Tags::ActionText < Tags::Base + include Tags::Placeholderable + delegate :dom_id, to: ActionView::RecordIdentifier def render diff --git a/actiontext/test/template/form_helper_test.rb b/actiontext/test/template/form_helper_test.rb index a8c7a4dae2..cf7e4c0c69 100644 --- a/actiontext/test/template/form_helper_test.rb +++ b/actiontext/test/template/form_helper_test.rb @@ -5,6 +5,26 @@ require "test_helper" class ActionText::FormHelperTest < ActionView::TestCase tests ActionText::TagHelper + def form_with(*) + @output_buffer = super + end + + teardown do + I18n.backend.reload! + end + + setup do + I18n.backend.store_translations("placeholder", + activerecord: { + attributes: { + message: { + title: "Story title" + } + } + } + ) + end + test "form with rich text area" do form_with model: Message.new, scope: :message do |form| form.rich_text_area :content @@ -61,7 +81,33 @@ class ActionText::FormHelperTest < ActionView::TestCase output_buffer end - def form_with(*) - @output_buffer = super + test "form with rich text area having placeholder without locale" do + form_with model: Message.new, scope: :message do |form| + form.rich_text_area :content, placeholder: true + end + + assert_dom_equal \ + '<form action="/messages" accept-charset="UTF-8" data-remote="true" method="post">' \ + '<input type="hidden" name="message[content]" id="message_content_trix_input_message" />' \ + '<trix-editor placeholder="Content" id="message_content" input="message_content_trix_input_message" class="trix-content" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" data-blob-url-template="http://test.host/rails/active_storage/blobs/:signed_id/:filename">' \ + "</trix-editor>" \ + "</form>", + output_buffer + end + + test "form with rich text area having placeholder with locale" do + I18n.with_locale :placeholder do + form_with model: Message.new, scope: :message do |form| + form.rich_text_area :title, placeholder: true + end + end + + assert_dom_equal \ + '<form action="/messages" accept-charset="UTF-8" data-remote="true" method="post">' \ + '<input type="hidden" name="message[title]" id="message_title_trix_input_message" />' \ + '<trix-editor placeholder="Story title" id="message_title" input="message_title_trix_input_message" class="trix-content" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" data-blob-url-template="http://test.host/rails/active_storage/blobs/:signed_id/:filename">' \ + "</trix-editor>" \ + "</form>", + output_buffer end end diff --git a/actionview/test/template/form_helper/form_with_test.rb b/actionview/test/template/form_helper/form_with_test.rb index f84c9b2b73..42069340f1 100644 --- a/actionview/test/template/form_helper/form_with_test.rb +++ b/actionview/test/template/form_helper/form_with_test.rb @@ -994,7 +994,7 @@ class FormWithActsLikeFormForTest < FormWithTest end def test_submit_with_object_as_new_record_and_locale_strings - with_locale :submit do + I18n.with_locale :submit do @post.persisted = false @post.stub(:to_key, nil) do form_with(model: @post) do |f| @@ -1011,7 +1011,7 @@ class FormWithActsLikeFormForTest < FormWithTest end def test_submit_with_object_as_existing_record_and_locale_strings - with_locale :submit do + I18n.with_locale :submit do form_with(model: @post) do |f| concat f.submit end @@ -1025,7 +1025,7 @@ class FormWithActsLikeFormForTest < FormWithTest end def test_submit_without_object_and_locale_strings - with_locale :submit do + I18n.with_locale :submit do form_with(scope: :post) do |f| concat f.submit class: "extra" end @@ -1039,7 +1039,7 @@ class FormWithActsLikeFormForTest < FormWithTest end def test_submit_with_object_which_is_overwritten_by_scope_option - with_locale :submit do + I18n.with_locale :submit do form_with(model: @post, scope: :another_post) do |f| concat f.submit end @@ -1054,7 +1054,7 @@ class FormWithActsLikeFormForTest < FormWithTest def test_submit_with_object_which_is_namespaced blog_post = Blog::Post.new("And his name will be forty and four.", 44) - with_locale :submit do + I18n.with_locale :submit do form_with(model: blog_post) do |f| concat f.submit end @@ -2357,11 +2357,4 @@ class FormWithActsLikeFormForTest < FormWithTest def protect_against_forgery? false end - - def with_locale(testing_locale = :label) - old_locale, I18n.locale = I18n.locale, testing_locale - yield - ensure - I18n.locale = old_locale - end end diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index 5972946074..91052e5ae2 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -203,31 +203,31 @@ class FormHelperTest < ActionView::TestCase end def test_label_with_locales_strings - with_locale :label do + I18n.with_locale :label do assert_dom_equal('<label for="post_body">Write entire text here</label>', label("post", "body")) end end def test_label_with_human_attribute_name - with_locale :label do + I18n.with_locale :label do assert_dom_equal('<label for="post_cost">Total cost</label>', label(:post, :cost)) end end def test_label_with_human_attribute_name_and_options - with_locale :label do + I18n.with_locale :label do assert_dom_equal('<label for="post_language_spanish">Espanol</label>', label(:post, :language, value: "spanish")) end end def test_label_with_locales_symbols - with_locale :label do + I18n.with_locale :label do assert_dom_equal('<label for="post_body">Write entire text here</label>', label(:post, :body)) end end def test_label_with_locales_and_options - with_locale :label do + I18n.with_locale :label do assert_dom_equal( '<label for="post_body" class="post_body">Write entire text here</label>', label(:post, :body, class: "post_body") @@ -236,13 +236,13 @@ class FormHelperTest < ActionView::TestCase end def test_label_with_locales_and_value - with_locale :label do + I18n.with_locale :label do assert_dom_equal('<label for="post_color_red">Rojo</label>', label(:post, :color, value: "red")) end end def test_label_with_locales_and_nested_attributes - with_locale :label do + I18n.with_locale :label do form_for(@post, html: { id: "create-post" }) do |f| f.fields_for(:comments) do |cf| concat cf.label(:body) @@ -258,7 +258,7 @@ class FormHelperTest < ActionView::TestCase end def test_label_with_locales_fallback_and_nested_attributes - with_locale :label do + I18n.with_locale :label do form_for(@post, html: { id: "create-post" }) do |f| f.fields_for(:tags) do |cf| concat cf.label(:value) @@ -358,7 +358,7 @@ class FormHelperTest < ActionView::TestCase end def test_label_with_block_and_builder - with_locale :label do + I18n.with_locale :label do assert_dom_equal( '<label for="post_body"><b>Write entire text here</b></label>', label(:post, :body) { |b| raw("<b>#{b.translation}</b>") } @@ -381,7 +381,7 @@ class FormHelperTest < ActionView::TestCase end def test_label_with_to_model_and_overridden_model_name - with_locale :label do + I18n.with_locale :label do assert_dom_equal( %{<label for="post_delegator_title">Delegate model_name title</label>}, label(:post_delegator, :title) @@ -390,19 +390,19 @@ class FormHelperTest < ActionView::TestCase end def test_text_field_placeholder_without_locales - with_locale :placeholder do + I18n.with_locale :placeholder do assert_dom_equal('<input id="post_body" name="post[body]" placeholder="Body" type="text" value="Back to the hill and over it again!" />', text_field(:post, :body, placeholder: true)) end end def test_text_field_placeholder_with_locales - with_locale :placeholder do + I18n.with_locale :placeholder do assert_dom_equal('<input id="post_title" name="post[title]" placeholder="What is this about?" type="text" value="Hello World" />', text_field(:post, :title, placeholder: true)) end end def test_text_field_placeholder_with_locales_and_to_model - with_locale :placeholder do + I18n.with_locale :placeholder do assert_dom_equal( '<input id="post_delegator_title" name="post_delegator[title]" placeholder="Delegate model_name title" type="text" value="Hello World" />', text_field(:post_delegator, :title, placeholder: true) @@ -411,7 +411,7 @@ class FormHelperTest < ActionView::TestCase end def test_text_field_placeholder_with_human_attribute_name - with_locale :placeholder do + I18n.with_locale :placeholder do assert_dom_equal('<input id="post_cost" name="post[cost]" placeholder="Total cost" type="text" />', text_field(:post, :cost, placeholder: true)) end end @@ -424,25 +424,25 @@ class FormHelperTest < ActionView::TestCase end def test_text_field_placeholder_with_string_value - with_locale :placeholder do + I18n.with_locale :placeholder do assert_dom_equal('<input id="post_cost" name="post[cost]" placeholder="HOW MUCH?" type="text" />', text_field(:post, :cost, placeholder: "HOW MUCH?")) end end def test_text_field_placeholder_with_human_attribute_name_and_value - with_locale :placeholder do + I18n.with_locale :placeholder do assert_dom_equal('<input id="post_cost" name="post[cost]" placeholder="Pounds" type="text" />', text_field(:post, :cost, placeholder: :uk)) end end def test_text_field_placeholder_with_locales_and_value - with_locale :placeholder do + I18n.with_locale :placeholder do assert_dom_equal('<input id="post_written_on" name="post[written_on]" placeholder="Escrito en" type="text" value="2004-06-15" />', text_field(:post, :written_on, placeholder: :spanish)) end end def test_text_field_placeholder_with_locales_and_nested_attributes - with_locale :placeholder do + I18n.with_locale :placeholder do form_for(@post, html: { id: "create-post" }) do |f| f.fields_for(:comments) do |cf| concat cf.text_field(:body, placeholder: true) @@ -458,7 +458,7 @@ class FormHelperTest < ActionView::TestCase end def test_text_field_placeholder_with_locales_fallback_and_nested_attributes - with_locale :placeholder do + I18n.with_locale :placeholder do form_for(@post, html: { id: "create-post" }) do |f| f.fields_for(:tags) do |cf| concat cf.text_field(:value, placeholder: true) @@ -861,7 +861,7 @@ class FormHelperTest < ActionView::TestCase end def test_text_area_placeholder_without_locales - with_locale :placeholder do + I18n.with_locale :placeholder do assert_dom_equal( %{<textarea id="post_body" name="post[body]" placeholder="Body">\nBack to the hill and over it again!</textarea>}, text_area(:post, :body, placeholder: true) @@ -870,7 +870,7 @@ class FormHelperTest < ActionView::TestCase end def test_text_area_placeholder_with_locales - with_locale :placeholder do + I18n.with_locale :placeholder do assert_dom_equal( %{<textarea id="post_title" name="post[title]" placeholder="What is this about?">\nHello World</textarea>}, text_area(:post, :title, placeholder: true) @@ -879,7 +879,7 @@ class FormHelperTest < ActionView::TestCase end def test_text_area_placeholder_with_human_attribute_name - with_locale :placeholder do + I18n.with_locale :placeholder do assert_dom_equal( %{<textarea id="post_cost" name="post[cost]" placeholder="Total cost">\n</textarea>}, text_area(:post, :cost, placeholder: true) @@ -888,7 +888,7 @@ class FormHelperTest < ActionView::TestCase end def test_text_area_placeholder_with_string_value - with_locale :placeholder do + I18n.with_locale :placeholder do assert_dom_equal( %{<textarea id="post_cost" name="post[cost]" placeholder="HOW MUCH?">\n</textarea>}, text_area(:post, :cost, placeholder: "HOW MUCH?") @@ -897,7 +897,7 @@ class FormHelperTest < ActionView::TestCase end def test_text_area_placeholder_with_human_attribute_name_and_value - with_locale :placeholder do + I18n.with_locale :placeholder do assert_dom_equal( %{<textarea id="post_cost" name="post[cost]" placeholder="Pounds">\n</textarea>}, text_area(:post, :cost, placeholder: :uk) @@ -906,7 +906,7 @@ class FormHelperTest < ActionView::TestCase end def test_text_area_placeholder_with_locales_and_value - with_locale :placeholder do + I18n.with_locale :placeholder do assert_dom_equal( %{<textarea id="post_written_on" name="post[written_on]" placeholder="Escrito en">\n2004-06-15</textarea>}, text_area(:post, :written_on, placeholder: :spanish) @@ -915,7 +915,7 @@ class FormHelperTest < ActionView::TestCase end def test_text_area_placeholder_with_locales_and_nested_attributes - with_locale :placeholder do + I18n.with_locale :placeholder do form_for(@post, html: { id: "create-post" }) do |f| f.fields_for(:comments) do |cf| concat cf.text_area(:body, placeholder: true) @@ -931,7 +931,7 @@ class FormHelperTest < ActionView::TestCase end def test_text_area_placeholder_with_locales_fallback_and_nested_attributes - with_locale :placeholder do + I18n.with_locale :placeholder do form_for(@post, html: { id: "create-post" }) do |f| f.fields_for(:tags) do |cf| concat cf.text_area(:value, placeholder: true) @@ -2260,7 +2260,7 @@ class FormHelperTest < ActionView::TestCase end def test_submit_with_object_as_new_record_and_locale_strings - with_locale :submit do + I18n.with_locale :submit do @post.persisted = false @post.stub(:to_key, nil) do form_for(@post) do |f| @@ -2277,7 +2277,7 @@ class FormHelperTest < ActionView::TestCase end def test_submit_with_object_as_existing_record_and_locale_strings - with_locale :submit do + I18n.with_locale :submit do form_for(@post) do |f| concat f.submit end @@ -2291,7 +2291,7 @@ class FormHelperTest < ActionView::TestCase end def test_submit_without_object_and_locale_strings - with_locale :submit do + I18n.with_locale :submit do form_for(:post) do |f| concat f.submit class: "extra" end @@ -2305,7 +2305,7 @@ class FormHelperTest < ActionView::TestCase end def test_submit_with_object_which_is_overwritten_by_as_option - with_locale :submit do + I18n.with_locale :submit do form_for(@post, as: :another_post) do |f| concat f.submit end @@ -2320,7 +2320,7 @@ class FormHelperTest < ActionView::TestCase def test_submit_with_object_which_is_namespaced blog_post = Blog::Post.new("And his name will be forty and four.", 44) - with_locale :submit do + I18n.with_locale :submit do form_for(blog_post) do |f| concat f.submit end @@ -3554,7 +3554,6 @@ class FormHelperTest < ActionView::TestCase end private - def hidden_fields(options = {}) method = options[:method] @@ -3593,13 +3592,6 @@ class FormHelperTest < ActionView::TestCase false end - def with_locale(testing_locale = :label) - old_locale, I18n.locale = I18n.locale, testing_locale - yield - ensure - I18n.locale = old_locale - end - def with_default_enforce_utf8(value) old_value = ActionView::Helpers::FormTagHelper.default_enforce_utf8 ActionView::Helpers::FormTagHelper.default_enforce_utf8 = value diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 5563dfb6c9..f69b85af66 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -1068,8 +1068,10 @@ module ActiveRecord def arel_column(field) field = klass.attribute_alias(field) if klass.attribute_alias?(field) + from = from_clause.name || from_clause.value - if klass.columns_hash.key?(field) && !from_clause.value + if klass.columns_hash.key?(field) && + (!from || from == table.name || from == connection.quote_table_name(table.name)) arel_attribute(field) else yield diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index adc50a694e..b27815539b 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -182,6 +182,48 @@ class RelationTest < ActiveRecord::TestCase end end + def test_select_with_original_table_name_in_from + relation = Comment.joins(:post).select(:id).order(:id) + subquery = Comment.from(Comment.table_name).joins(:post).select(:id).order(:id) + assert_equal relation.map(&:id), subquery.map(&:id) + end + + def test_pluck_with_original_table_name_in_from + relation = Comment.joins(:post).order(:id) + subquery = Comment.from(Comment.table_name).joins(:post).order(:id) + assert_equal relation.pluck(:id), subquery.pluck(:id) + end + + def test_select_with_quoted_original_table_name_in_from + relation = Comment.joins(:post).select(:id).order(:id) + subquery = Comment.from(Comment.quoted_table_name).joins(:post).select(:id).order(:id) + assert_equal relation.map(&:id), subquery.map(&:id) + end + + def test_pluck_with_quoted_original_table_name_in_from + relation = Comment.joins(:post).order(:id) + subquery = Comment.from(Comment.quoted_table_name).joins(:post).order(:id) + assert_equal relation.pluck(:id), subquery.pluck(:id) + end + + def test_select_with_subquery_in_from_uses_original_table_name + if current_adapter?(:SQLite3Adapter) && (ENV["TRAVIS"] || ENV["BUILDKITE"]) + skip <<~MSG + https://travis-ci.org/rails/rails/jobs/496726410#L1198-L1208 + https://buildkite.com/rails/rails/builds/58981#2423c707-7c56-4639-a76e-8db4fd1e5cf3/102-111 + MSG + end + relation = Comment.joins(:post).select(:id).order(:id) + subquery = Comment.from(Comment.all, Comment.quoted_table_name).joins(:post).select(:id).order(:id) + assert_equal relation.map(&:id), subquery.map(&:id) + end + + def test_pluck_with_subquery_in_from_uses_original_table_name + relation = Comment.joins(:post).order(:id) + subquery = Comment.from(Comment.all, Comment.quoted_table_name).joins(:post).order(:id) + assert_equal relation.pluck(:id), subquery.pluck(:id) + end + def test_select_with_subquery_in_from_does_not_use_original_table_name relation = Comment.group(:type).select("COUNT(post_id) AS post_count, type") subquery = Comment.from(relation).select("type", "post_count") diff --git a/activesupport/activesupport.gemspec b/activesupport/activesupport.gemspec index 2fa0623a9c..3913ce19c5 100644 --- a/activesupport/activesupport.gemspec +++ b/activesupport/activesupport.gemspec @@ -34,5 +34,5 @@ Gem::Specification.new do |s| s.add_dependency "tzinfo", "~> 1.1" s.add_dependency "minitest", "~> 5.1" s.add_dependency "concurrent-ruby", "~> 1.0", ">= 1.0.2" - s.add_dependency "zeitwerk", "~> 1.2" + s.add_dependency "zeitwerk", "~> 1.3" end diff --git a/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb b/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb index 939ada123d..297bde5534 100644 --- a/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb +++ b/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb @@ -28,7 +28,7 @@ module ActiveSupport end def verbose=(verbose) - l = verbose ? (logger || Rails.logger).method(:debug) : nil + l = verbose ? logger || Rails.logger : nil Rails.autoloaders.each { |autoloader| autoloader.logger = l } end diff --git a/railties/lib/rails/autoloaders.rb b/railties/lib/rails/autoloaders.rb index 4b41e1faf9..a6974cc207 100644 --- a/railties/lib/rails/autoloaders.rb +++ b/railties/lib/rails/autoloaders.rb @@ -25,8 +25,7 @@ module Rails end def logger=(logger) - callable_or_nil = logger.respond_to?(:debug) ? logger.method(:debug) : logger - each { |loader| loader.logger = callable_or_nil } + each { |loader| loader.logger = logger } end def zeitwerk_enabled? diff --git a/railties/test/application/zeitwerk_integration_test.rb b/railties/test/application/zeitwerk_integration_test.rb index 8a8ca18ebf..18e53f88b7 100644 --- a/railties/test/application/zeitwerk_integration_test.rb +++ b/railties/test/application/zeitwerk_integration_test.rb @@ -164,7 +164,7 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase assert_equal %i(main_autoloader), $zeitwerk_integration_reload_test end - test "verbose = true sets the debug method of the dependencies logger if present" do + test "verbose = true sets the dependencies logger if present" do boot logger = Logger.new(File::NULL) @@ -172,17 +172,17 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase ActiveSupport::Dependencies.verbose = true Rails.autoloaders.each do |autoloader| - assert_equal logger.method(:debug), autoloader.logger + assert_same logger, autoloader.logger end end - test "verbose = true sets the debug method of the Rails logger as fallback" do + test "verbose = true sets the Rails logger as fallback" do boot ActiveSupport::Dependencies.verbose = true Rails.autoloaders.each do |autoloader| - assert_equal Rails.logger.method(:debug), autoloader.logger + assert_same Rails.logger, autoloader.logger end end @@ -214,13 +214,13 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase Rails.autoloaders.logger = logger Rails.autoloaders.each do |autoloader| - assert_equal logger, autoloader.logger + assert_same logger, autoloader.logger end Rails.autoloaders.logger = Rails.logger Rails.autoloaders.each do |autoloader| - assert_equal Rails.logger.method(:debug), autoloader.logger + assert_same Rails.logger, autoloader.logger end Rails.autoloaders.logger = nil |