From 2cd8bfbb06a3e4a386898e93427fd192054bcd2e Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Mon, 16 May 2016 10:42:16 -0300 Subject: [PATCH] comment_paragraph: use start_date and end_date to order discussions --- plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion_block.rb | 2 +- plugins/comment_paragraph/test/unit/discussion_block_test.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion_block.rb b/plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion_block.rb index 45bfa31..af2b473 100644 --- a/plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion_block.rb +++ b/plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion_block.rb @@ -22,7 +22,7 @@ class CommentParagraphPlugin::DiscussionBlock < Block def discussions current_time = Time.now - discussions = holder.articles.where(type: VALID_CONTENT).order('created_at DESC').limit(self.total_items) + discussions = holder.articles.where(type: VALID_CONTENT).order('start_date ASC, end_date DESC, created_at DESC').limit(self.total_items) case discussion_status when STATUS_NOT_OPENED discussions = discussions.where("start_date > ?", current_time) diff --git a/plugins/comment_paragraph/test/unit/discussion_block_test.rb b/plugins/comment_paragraph/test/unit/discussion_block_test.rb index 52bee01..035d067 100644 --- a/plugins/comment_paragraph/test/unit/discussion_block_test.rb +++ b/plugins/comment_paragraph/test/unit/discussion_block_test.rb @@ -188,4 +188,17 @@ class DiscussionBlockViewTest < ActionView::TestCase assert_equivalent [a2.id, a1.id], b.api_content['articles'].map {|a| a[:id]} end + should 'sort discussions by start_date, end_date and created_at' do + community = fast_create(Community) + community.boxes << Box.new + b = CommentParagraphPlugin::DiscussionBlock.new + b.box = community.boxes.last + b.save + a1 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, start_date: Time.now) + a2 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, start_date: Time.now + 1, end_date: Time.now) + a3 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, start_date: Time.now + 1, end_date: Time.now + 1.day) + a4 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, start_date: Time.now + 1, end_date: Time.now + 1.day) + assert_equal [a1.id, a2.id, a3.id, a4.id], b.discussions.map(&:id) + end + end -- libgit2 0.21.2