Revised public fields, wrote more exhaustive specs

This commit is contained in:
Alberto Miedes Garcés
2017-05-15 20:13:20 +02:00
parent 3c7f60d625
commit ad8aba0739
9 changed files with 665 additions and 52 deletions

View File

@@ -29,4 +29,8 @@ module Graphqlable
end
def public_created_at
self.created_at.change(min: 0)
end
end

View File

@@ -286,6 +286,18 @@ class User < ActiveRecord::Base
end
delegate :can?, :cannot?, to: :ability
def public_proposals
public_activity? ? proposals : []
end
def public_debates
public_activity? ? debates : []
end
def public_comments
public_activity? ? comments : []
end
private
def clean_document_number

View File

@@ -1,15 +1,19 @@
class Vote < ActsAsVotable::Vote
include Graphqlable
def self.public_for_api
joins("FULL OUTER JOIN debates ON votable_type = 'Debate' AND votable_id = debates.id").
joins("FULL OUTER JOIN proposals ON votable_type = 'Proposal' AND votable_id = proposals.id").
joins("FULL OUTER JOIN comments ON votable_type = 'Comment' AND votable_id = comments.id").
where("votable_type = 'Proposal' AND proposals.hidden_at IS NULL OR votable_type = 'Debate' AND debates.hidden_at IS NULL OR votable_type = 'Comment' AND comments.hidden_at IS NULL")
end
def public_timestamp
self.created_at.change(min: 0)
where("(votable_type = 'Proposal' AND proposals.hidden_at IS NULL) OR \
(votable_type = 'Debate' AND debates.hidden_at IS NULL) OR \
( \
(votable_type = 'Comment' AND comments.hidden_at IS NULL) AND \
( \
(comments.commentable_type = 'Proposal' AND (comments.commentable_id IN (SELECT id FROM proposals WHERE hidden_at IS NULL GROUP BY id))) OR \
(comments.commentable_type = 'Debate' AND (comments.commentable_id IN (SELECT id FROM debates WHERE hidden_at IS NULL GROUP BY id))) \
) \
)")
end
end