Commit fa28302c7b3fa6f2dcc7ea33e812e9c201042591
1 parent
16414139
Exists in
web_steps_improvements
and in
6 other branches
display_content: fix random failing test
Showing
2 changed files
with
12 additions
and
9 deletions
Show diff stats
plugins/display_content/lib/display_content_block.rb
... | ... | @@ -121,17 +121,20 @@ class DisplayContentBlock < Block |
121 | 121 | def content(args={}) |
122 | 122 | block = self |
123 | 123 | |
124 | - nodes_conditions = nodes.blank? ? '' : " AND articles.id IN(:nodes) " | |
125 | - nodes_conditions += ' OR articles.parent_id IN(:nodes) ' if !nodes.blank? && display_folder_children | |
126 | - | |
127 | 124 | order_string = "published_at" |
128 | 125 | order_string += " DESC" if order_by_recent |
129 | 126 | |
130 | 127 | limit_final = [limit_to_show, 0].max |
131 | 128 | |
132 | - 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) | |
133 | - | |
134 | - docs = docs.limit(limit_final) if display_folder_children | |
129 | + docs = owner.articles.order(order_string) | |
130 | + .where(articles: {type: self.types}) | |
131 | + .includes(:profile, :image, :tags) | |
132 | + if nodes.present? | |
133 | + nodes_conditions = 'articles.id IN(:nodes)' | |
134 | + nodes_conditions << ' OR articles.parent_id IN(:nodes) ' if display_folder_children | |
135 | + docs = docs.where nodes_conditions, nodes: nodes | |
136 | + end | |
137 | + docs = docs.limit limit_final if display_folder_children | |
135 | 138 | |
136 | 139 | if content_with_translations |
137 | 140 | docs = docs.native_translations | ... | ... |
plugins/display_content/test/unit/display_content_block_test.rb
... | ... | @@ -719,7 +719,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
719 | 719 | en_article = fast_create(TextileArticle, :profile_id => profile.id, :name => 'en_article', :language => 'en') |
720 | 720 | en_article2 = fast_create(TextileArticle, :profile_id => profile.id, :name => 'en_article 2', :language => 'en') |
721 | 721 | |
722 | - pt_article = fast_create(TextileArticle, :profile_id => profile.id, :name => 'pt_article', :language => 'pt') | |
722 | + pt_article = fast_create TextileArticle, profile_id: profile.id, name: 'pt_article', language: 'pt', translation_of_id: en_article.id | |
723 | 723 | |
724 | 724 | block = DisplayContentBlock.new |
725 | 725 | block.sections = [{:value => 'title', :checked => true}] |
... | ... | @@ -736,8 +736,8 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
736 | 736 | |
737 | 737 | FastGettext.stubs(:locale).returns('en') |
738 | 738 | |
739 | - assert instance_eval(&block.content).index(en_article.name).present? | |
740 | - assert instance_eval(&block.content).index(en_article2.name).present? | |
739 | + assert instance_eval(&block.content).index(en_article.name) | |
740 | + assert instance_eval(&block.content).index(en_article2.name) | |
741 | 741 | assert_nil instance_eval(&block.content).index(pt_article.name) |
742 | 742 | end |
743 | 743 | ... | ... |