Commit 2cd8bfbb06a3e4a386898e93427fd192054bcd2e
1 parent
8b3a53b8
Exists in
ratings_minor_fixes
and in
3 other branches
comment_paragraph: use start_date and end_date to order discussions
Showing
2 changed files
with
14 additions
and
1 deletions
Show diff stats
plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion_block.rb
| @@ -22,7 +22,7 @@ class CommentParagraphPlugin::DiscussionBlock < Block | @@ -22,7 +22,7 @@ class CommentParagraphPlugin::DiscussionBlock < Block | ||
| 22 | 22 | ||
| 23 | def discussions | 23 | def discussions |
| 24 | current_time = Time.now | 24 | current_time = Time.now |
| 25 | - discussions = holder.articles.where(type: VALID_CONTENT).order('created_at DESC').limit(self.total_items) | 25 | + discussions = holder.articles.where(type: VALID_CONTENT).order('start_date ASC, end_date DESC, created_at DESC').limit(self.total_items) |
| 26 | case discussion_status | 26 | case discussion_status |
| 27 | when STATUS_NOT_OPENED | 27 | when STATUS_NOT_OPENED |
| 28 | discussions = discussions.where("start_date > ?", current_time) | 28 | discussions = discussions.where("start_date > ?", current_time) |
plugins/comment_paragraph/test/unit/discussion_block_test.rb
| @@ -188,4 +188,17 @@ class DiscussionBlockViewTest < ActionView::TestCase | @@ -188,4 +188,17 @@ class DiscussionBlockViewTest < ActionView::TestCase | ||
| 188 | assert_equivalent [a2.id, a1.id], b.api_content['articles'].map {|a| a[:id]} | 188 | assert_equivalent [a2.id, a1.id], b.api_content['articles'].map {|a| a[:id]} |
| 189 | end | 189 | end |
| 190 | 190 | ||
| 191 | + should 'sort discussions by start_date, end_date and created_at' do | ||
| 192 | + community = fast_create(Community) | ||
| 193 | + community.boxes << Box.new | ||
| 194 | + b = CommentParagraphPlugin::DiscussionBlock.new | ||
| 195 | + b.box = community.boxes.last | ||
| 196 | + b.save | ||
| 197 | + a1 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, start_date: Time.now) | ||
| 198 | + a2 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, start_date: Time.now + 1, end_date: Time.now) | ||
| 199 | + a3 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, start_date: Time.now + 1, end_date: Time.now + 1.day) | ||
| 200 | + a4 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, start_date: Time.now + 1, end_date: Time.now + 1.day) | ||
| 201 | + assert_equal [a1.id, a2.id, a3.id, a4.id], b.discussions.map(&:id) | ||
| 202 | + end | ||
| 203 | + | ||
| 191 | end | 204 | end |