Commit 6d54bf95f04f5c64e4fb6688b044ded5597e70dd
1 parent
174e0852
Exists in
staging
and in
29 other branches
comment_paragraph: filter discussions by block status
Showing
2 changed files
with
14 additions
and
2 deletions
Show diff stats
plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion_block.rb
| ... | ... | @@ -21,7 +21,18 @@ class CommentParagraphPlugin::DiscussionBlock < Block |
| 21 | 21 | end |
| 22 | 22 | |
| 23 | 23 | def discussions |
| 24 | - holder.articles.where(type: VALID_CONTENT).order('created_at DESC').limit(self.total_items) | |
| 24 | + current_time = Time.now | |
| 25 | + discussions = holder.articles.where(type: VALID_CONTENT).order('created_at DESC').limit(self.total_items) | |
| 26 | + case discussion_status | |
| 27 | + when STATUS_NOT_OPENED | |
| 28 | + discussions = discussions.where("start_date > ?", current_time) | |
| 29 | + when STATUS_AVAILABLE | |
| 30 | + discussions = discussions.where("start_date is null or start_date <= ?", current_time) | |
| 31 | + discussions = discussions.where("end_date is null or end_date >= ?", current_time) | |
| 32 | + when STATUS_CLOSED | |
| 33 | + discussions = discussions.where("end_date < ?", current_time) | |
| 34 | + end | |
| 35 | + discussions | |
| 25 | 36 | end |
| 26 | 37 | |
| 27 | 38 | def holder | ... | ... |
plugins/comment_paragraph/test/unit/discussion_block_test.rb
| ... | ... | @@ -104,7 +104,8 @@ class DiscussionBlockTest < ActiveSupport::TestCase |
| 104 | 104 | a2 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => DateTime.now ) |
| 105 | 105 | a3 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => DateTime.now - 1.day) |
| 106 | 106 | a4 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => DateTime.now - 2.day, :end_date => DateTime.now - 1.day) |
| 107 | - assert_equivalent [a2,a3], b.discussions | |
| 107 | + a5 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :end_date => DateTime.now + 1.day) | |
| 108 | + assert_equivalent [a2, a3, a5], b.discussions | |
| 108 | 109 | end |
| 109 | 110 | |
| 110 | 111 | should 'return only closed discussions if discussion status is closed' do | ... | ... |