Add ProposalNotification to api
This commit is contained in:
@@ -7,6 +7,8 @@ class ProposalNotification < ActiveRecord::Base
|
|||||||
validates :proposal, presence: true
|
validates :proposal, presence: true
|
||||||
validate :minimum_interval
|
validate :minimum_interval
|
||||||
|
|
||||||
|
scope :public_for_api, -> { joins(:proposal).where("proposals.hidden_at IS NULL") }
|
||||||
|
|
||||||
def minimum_interval
|
def minimum_interval
|
||||||
return true if proposal.try(:notifications).blank?
|
return true if proposal.try(:notifications).blank?
|
||||||
if proposal.notifications.last.created_at > (Time.current - Setting[:proposal_notification_minimum_interval_in_days].to_i.days).to_datetime
|
if proposal.notifications.last.created_at > (Time.current - Setting[:proposal_notification_minimum_interval_in_days].to_i.days).to_datetime
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
API_TYPE_DEFINITIONS = {
|
API_TYPE_DEFINITIONS = {
|
||||||
User => %I[ id username proposals ],
|
User => %I[ id username proposals ],
|
||||||
Debate => %I[ id title description created_at cached_votes_total cached_votes_up cached_votes_down comments_count hot_score confidence_score geozone_id geozone comments public_author ],
|
Debate => %I[ id title description created_at cached_votes_total cached_votes_up cached_votes_down comments_count hot_score confidence_score geozone_id geozone comments public_author ],
|
||||||
Proposal => %I[ id title description external_url cached_votes_up comments_count hot_score confidence_score created_at summary video_url geozone_id retired_at retired_reason retired_explanation geozone comments public_author ],
|
Proposal => %I[ id title description external_url cached_votes_up comments_count hot_score confidence_score created_at summary video_url geozone_id retired_at retired_reason retired_explanation geozone comments proposal_notifications public_author ],
|
||||||
Comment => %I[ id commentable_id commentable_type body created_at cached_votes_total cached_votes_up cached_votes_down ancestry confidence_score public_author ],
|
Comment => %I[ id commentable_id commentable_type body created_at cached_votes_total cached_votes_up cached_votes_down ancestry confidence_score public_author ],
|
||||||
Geozone => %I[ id name ]
|
Geozone => %I[ id name ]
|
||||||
|
ProposalNotification => %I[ title body proposal_id created_at proposal ],
|
||||||
}
|
}
|
||||||
|
|
||||||
type_creator = GraphQL::TypeCreator.new
|
type_creator = GraphQL::TypeCreator.new
|
||||||
|
|||||||
@@ -22,6 +22,22 @@ describe ProposalNotification do
|
|||||||
expect(notification).to_not be_valid
|
expect(notification).to_not be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "public_for_api scope" do
|
||||||
|
it "returns proposal notifications" do
|
||||||
|
proposal = create(:proposal)
|
||||||
|
notification = create(:proposal_notification, proposal: proposal)
|
||||||
|
|
||||||
|
expect(ProposalNotification.public_for_api).to include(notification)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "blocks notifications whose proposal is hidden" do
|
||||||
|
proposal = create(:proposal, :hidden)
|
||||||
|
notification = create(:proposal_notification, proposal: proposal)
|
||||||
|
|
||||||
|
expect(ProposalNotification.public_for_api).not_to include(notification)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "minimum interval between notifications" do
|
describe "minimum interval between notifications" do
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
|||||||
Reference in New Issue
Block a user