diff --git a/plugins/display_content/lib/display_content_block.rb b/plugins/display_content/lib/display_content_block.rb index c33bbc0..a1cae4f 100644 --- a/plugins/display_content/lib/display_content_block.rb +++ b/plugins/display_content/lib/display_content_block.rb @@ -121,17 +121,20 @@ class DisplayContentBlock < Block def content(args={}) block = self - nodes_conditions = nodes.blank? ? '' : " AND articles.id IN(:nodes) " - nodes_conditions += ' OR articles.parent_id IN(:nodes) ' if !nodes.blank? && display_folder_children - order_string = "published_at" order_string += " DESC" if order_by_recent limit_final = [limit_to_show, 0].max - docs = owner.articles.order(order_string).where(["articles.type IN(:types) #{nodes.blank? ? '' : nodes_conditions}", {:nodes => self.nodes, :types => self.types}]).includes(:profile, :image, :tags) - - docs = docs.limit(limit_final) if display_folder_children + docs = owner.articles.order(order_string) + .where(articles: {type: self.types}) + .includes(:profile, :image, :tags) + if nodes.present? + nodes_conditions = 'articles.id IN(:nodes)' + nodes_conditions << ' OR articles.parent_id IN(:nodes) ' if display_folder_children + docs = docs.where nodes_conditions, nodes: nodes + end + docs = docs.limit limit_final if display_folder_children if content_with_translations docs = docs.native_translations diff --git a/plugins/display_content/test/unit/display_content_block_test.rb b/plugins/display_content/test/unit/display_content_block_test.rb index cf4aa07..5718edd 100644 --- a/plugins/display_content/test/unit/display_content_block_test.rb +++ b/plugins/display_content/test/unit/display_content_block_test.rb @@ -719,7 +719,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase en_article = fast_create(TextileArticle, :profile_id => profile.id, :name => 'en_article', :language => 'en') en_article2 = fast_create(TextileArticle, :profile_id => profile.id, :name => 'en_article 2', :language => 'en') - pt_article = fast_create(TextileArticle, :profile_id => profile.id, :name => 'pt_article', :language => 'pt') + pt_article = fast_create TextileArticle, profile_id: profile.id, name: 'pt_article', language: 'pt', translation_of_id: en_article.id block = DisplayContentBlock.new block.sections = [{:value => 'title', :checked => true}] @@ -736,8 +736,8 @@ class DisplayContentBlockTest < ActiveSupport::TestCase FastGettext.stubs(:locale).returns('en') - assert instance_eval(&block.content).index(en_article.name).present? - assert instance_eval(&block.content).index(en_article2.name).present? + assert instance_eval(&block.content).index(en_article.name) + assert instance_eval(&block.content).index(en_article2.name) assert_nil instance_eval(&block.content).index(pt_article.name) end -- libgit2 0.21.2