adds poll comments to API
This commit is contained in:
@@ -30,9 +30,11 @@ class Comment < ActiveRecord::Base
|
||||
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
|
||||
scope :public_for_api, -> do
|
||||
where(%{(comments.commentable_type = 'Debate' and comments.commentable_id in (?)) or
|
||||
(comments.commentable_type = 'Proposal' and comments.commentable_id in (?))},
|
||||
(comments.commentable_type = 'Proposal' and comments.commentable_id in (?)) or
|
||||
(comments.commentable_type = 'Poll' and comments.commentable_id in (?))},
|
||||
Debate.public_for_api.pluck(:id),
|
||||
Proposal.public_for_api.pluck(:id))
|
||||
Proposal.public_for_api.pluck(:id),
|
||||
Poll.public_for_api.pluck(:id))
|
||||
end
|
||||
|
||||
scope :sort_by_most_voted, -> { order(confidence_score: :desc, created_at: :desc) }
|
||||
|
||||
@@ -28,6 +28,7 @@ class Poll < ActiveRecord::Base
|
||||
scope :recounting, -> { Poll.where(ends_at: (Date.current.beginning_of_day - RECOUNT_DURATION)..Date.current.beginning_of_day) }
|
||||
scope :published, -> { where('published = ?', true) }
|
||||
scope :by_geozone_id, ->(geozone_id) { where(geozones: {id: geozone_id}.joins(:geozones)) }
|
||||
scope :public_for_api, -> { all }
|
||||
|
||||
scope :sort_for_list, -> { order(:geozone_restricted, :starts_at, :name) }
|
||||
|
||||
|
||||
@@ -282,15 +282,16 @@ describe 'ConsulSchema' do
|
||||
end
|
||||
|
||||
describe 'Comments' do
|
||||
it 'only returns comments from proposals and debates' do
|
||||
it 'only returns comments from proposals, debates and polls' do
|
||||
proposal_comment = create(:comment, commentable: create(:proposal))
|
||||
debate_comment = create(:comment, commentable: create(:debate))
|
||||
poll_comment = create(:comment, commentable: create(:poll))
|
||||
spending_proposal_comment = build(:comment, commentable: create(:spending_proposal)).save(skip_validation: true)
|
||||
|
||||
response = execute('{ comments { edges { node { commentable_type } } } }')
|
||||
received_commentables = extract_fields(response, 'comments', 'commentable_type')
|
||||
|
||||
expect(received_commentables).to match_array ['Proposal', 'Debate']
|
||||
expect(received_commentables).to match_array ['Proposal', 'Debate', 'Poll']
|
||||
end
|
||||
|
||||
it 'displays comments of authors even if public activity is set to false' do
|
||||
@@ -355,6 +356,19 @@ describe 'ConsulSchema' do
|
||||
expect(received_comments).to match_array [visible_debate_comment.body]
|
||||
end
|
||||
|
||||
it 'does not include comments from hidden polls' do
|
||||
visible_poll = create(:poll)
|
||||
hidden_poll = create(:poll, hidden_at: Time.current)
|
||||
|
||||
visible_poll_comment = create(:comment, commentable: visible_poll)
|
||||
hidden_poll_comment = create(:comment, commentable: hidden_poll)
|
||||
|
||||
response = execute('{ comments { edges { node { body } } } }')
|
||||
received_comments = extract_fields(response, 'comments', 'body')
|
||||
|
||||
expect(received_comments).to match_array [visible_poll_comment.body]
|
||||
end
|
||||
|
||||
it 'does not include comments of debates that are not public' do
|
||||
not_public_debate = create(:debate, :hidden)
|
||||
not_public_debate_comment = create(:comment, commentable: not_public_debate)
|
||||
@@ -377,6 +391,17 @@ describe 'ConsulSchema' do
|
||||
expect(received_comments).to_not include(not_public_proposal_comment.body)
|
||||
end
|
||||
|
||||
it 'does not include comments of polls that are not public' do
|
||||
not_public_poll = create(:poll)
|
||||
not_public_poll_comment = create(:comment, commentable: not_public_poll)
|
||||
allow(Comment).to receive(:public_for_api).and_return([])
|
||||
|
||||
response = execute('{ comments { edges { node { body } } } }')
|
||||
received_comments = extract_fields(response, 'comments', 'body')
|
||||
|
||||
expect(received_comments).to_not include(not_public_poll_comment.body)
|
||||
end
|
||||
|
||||
it 'only returns date and hour for created_at' do
|
||||
created_at = Time.zone.parse("2017-12-31 9:30:15")
|
||||
create(:comment, created_at: created_at)
|
||||
|
||||
Reference in New Issue
Block a user