diff options
5 files changed, 39 insertions, 30 deletions
diff --git a/actionpack/test/controller/parameters/accessors_test.rb b/actionpack/test/controller/parameters/accessors_test.rb index 5dd2c2c667..7b9b716a42 100644 --- a/actionpack/test/controller/parameters/accessors_test.rb +++ b/actionpack/test/controller/parameters/accessors_test.rb @@ -231,7 +231,7 @@ class ParametersAccessorsTest < ActiveSupport::TestCase test "transform_values without a block returns an enumerator" do assert_kind_of Enumerator, @params.transform_values - assert_kind_of ActionController::Parameters, @params.transform_values.each { |k| k } + assert_kind_of ActionController::Parameters, @params.transform_values.each { |v| v } end test "transform_values! converts hashes to parameters" do @@ -242,7 +242,7 @@ class ParametersAccessorsTest < ActiveSupport::TestCase test "transform_values! without a block returns an enumerator" do assert_kind_of Enumerator, @params.transform_values! - assert_kind_of ActionController::Parameters, @params.transform_values!.each { |k| k } + assert_kind_of ActionController::Parameters, @params.transform_values!.each { |v| v } end test "value? returns true if the given value is present in the params" do diff --git a/actiontext/lib/action_text/system_test_helper.rb b/actiontext/lib/action_text/system_test_helper.rb index 6c9dcc11a7..77fc9eb50b 100644 --- a/actiontext/lib/action_text/system_test_helper.rb +++ b/actiontext/lib/action_text/system_test_helper.rb @@ -24,11 +24,8 @@ module ActionText # # <input id="trix_input_1" name="message[content]" type="hidden"> # # <trix-editor input="trix_input_1"></trix-editor> # fill_in_rich_text_area "message[content]", with: "Hello <em>world!</em>" - def fill_in_rich_text_area(locator, with:) - page.execute_script(<<~JS, find(:rich_text_area, locator).native, with.to_s) - const [element, html] = arguments; - element.editor.loadHTML(html); - JS + def fill_in_rich_text_area(locator = nil, with:) + find(:rich_text_area, locator).execute_script("this.editor.loadHTML(arguments[0])", with.to_s) end end end @@ -36,12 +33,16 @@ end Capybara.add_selector :rich_text_area do label "rich-text area" xpath do |locator| - input_located_by_name = XPath.anywhere(:input).where(XPath.attr(:name) == locator).attr(:id) + if locator.nil? + XPath.descendant(:"trix-editor") + else + input_located_by_name = XPath.anywhere(:input).where(XPath.attr(:name) == locator).attr(:id) - XPath.descendant(:"trix-editor").where \ - XPath.attr(:id).equals(locator) | - XPath.attr(:placeholder).equals(locator) | - XPath.attr(:"aria-label").equals(locator) | - XPath.attr(:input).equals(input_located_by_name) + XPath.descendant(:"trix-editor").where \ + XPath.attr(:id).equals(locator) | + XPath.attr(:placeholder).equals(locator) | + XPath.attr(:"aria-label").equals(locator) | + XPath.attr(:input).equals(input_located_by_name) + end end end diff --git a/actiontext/test/system/system_test_helper_test.rb b/actiontext/test/system/system_test_helper_test.rb index b00bbafa74..460769c480 100644 --- a/actiontext/test/system/system_test_helper_test.rb +++ b/actiontext/test/system/system_test_helper_test.rb @@ -30,4 +30,10 @@ class ActionText::SystemTestHelperTest < ApplicationSystemTestCase fill_in_rich_text_area "message[content]", with: "Hello world!" assert_selector :field, "message[content]", with: /Hello world!/, type: "hidden" end + + test "filling in the first rich-text area" do + visit new_message_url + fill_in_rich_text_area with: "Hello world!" + assert_selector :field, "message[content]", with: /Hello world!/, type: "hidden" + end end diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index b8fd2fce14..50ff733dc7 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -1128,27 +1128,21 @@ module ActiveRecord association_joins = buckets[:association_join] stashed_joins = buckets[:stashed_join] - join_nodes = buckets[:join_node].uniq - string_joins = buckets[:string_join].map(&:strip).uniq + join_nodes = buckets[:join_node].tap(&:uniq!) + string_joins = buckets[:string_join].delete_if(&:blank?).map!(&:strip).tap(&:uniq!) - join_list = join_nodes + convert_join_strings_to_ast(string_joins) - alias_tracker = alias_tracker(join_list, aliases) + string_joins.map! { |join| table.create_string_join(Arel.sql(join)) } - join_dependency = construct_join_dependency(association_joins, join_type) + join_sources = manager.join_sources + join_sources.concat(join_nodes) unless join_nodes.empty? - joins = join_dependency.join_constraints(stashed_joins, alias_tracker) - joins.each { |join| manager.from(join) } - - manager.join_sources.concat(join_list) - - alias_tracker.aliases - end + unless association_joins.empty? && stashed_joins.empty? + alias_tracker = alias_tracker(join_nodes + string_joins, aliases) + join_dependency = construct_join_dependency(association_joins, join_type) + join_sources.concat(join_dependency.join_constraints(stashed_joins, alias_tracker)) + end - def convert_join_strings_to_ast(joins) - joins - .flatten - .reject(&:blank?) - .map { |join| table.create_string_join(Arel.sql(join)) } + join_sources.concat(string_joins) unless string_joins.empty? end def build_select(arel) diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index 0ab99aa6cd..affa024d77 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -58,6 +58,14 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase assert_equal preloaded, Marshal.load(Marshal.dump(preloaded)) end + def test_through_association_with_joins + assert_equal [comments(:eager_other_comment1)], authors(:mary).comments.merge(Post.joins(:comments)) + end + + def test_through_association_with_left_joins + assert_equal [comments(:eager_other_comment1)], authors(:mary).comments.merge(Post.left_joins(:comments)) + end + def test_preload_with_nested_association posts = Post.preload(:author, :author_favorites_with_scope).to_a |