adds time limit between notifications
This commit is contained in:
@@ -5,4 +5,13 @@ class ProposalNotification < ActiveRecord::Base
|
||||
validates :title, presence: true
|
||||
validates :body, presence: true
|
||||
validates :proposal, presence: true
|
||||
validate :minimum_interval
|
||||
|
||||
def minimum_interval
|
||||
return true if proposal.notifications.blank?
|
||||
if proposal.notifications.last.created_at > (Time.now - Setting[:proposal_notification_minimum_interval_in_days].to_i.days).to_datetime
|
||||
errors.add(:minimum_interval, I18n.t('activerecord.errors.models.proposal_notification.minimum_interval', interval: Setting[:proposal_notification_minimum_interval]))
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -84,3 +84,6 @@ en:
|
||||
attributes:
|
||||
tag_list:
|
||||
less_than_or_equal_to: "tags must be less than or equal to %{count}"
|
||||
proposal_notification:
|
||||
attributes:
|
||||
minimum_interval: "You have to wait a minium of %{interval} days between notifications"
|
||||
@@ -84,3 +84,6 @@ es:
|
||||
attributes:
|
||||
tag_list:
|
||||
less_than_or_equal_to: "los temas deben ser menor o igual que %{count}"
|
||||
proposal_notification:
|
||||
attributes:
|
||||
minimum_interval: "Debes esperar un mínimo de %{interval} días entre notificaciones"
|
||||
@@ -74,3 +74,6 @@ Setting['banner-style.banner-style-three'] = "Banner style 3"
|
||||
Setting['banner-img.banner-img-one'] = "Banner image 1"
|
||||
Setting['banner-img.banner-img-two'] = "Banner image 2"
|
||||
Setting['banner-img.banner-img-three'] = "Banner image 3"
|
||||
|
||||
# Proposal notifications
|
||||
Setting['proposal_notification_minimum_interval_in_days '] = 3
|
||||
|
||||
@@ -84,4 +84,14 @@ feature 'Proposal Notifications' do
|
||||
expect(page).to have_content error_message
|
||||
end
|
||||
|
||||
context "Limits" do
|
||||
|
||||
pending "Cannot send more than one notification within established interval" do
|
||||
end
|
||||
|
||||
pending "use timecop to make sure notifications can be sent after time interval" do
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -22,4 +22,38 @@ describe ProposalNotification do
|
||||
expect(notification).to_not be_valid
|
||||
end
|
||||
|
||||
describe "minimum interval between notifications" do
|
||||
|
||||
before(:each) do
|
||||
Setting[:proposal_notification_minimum_interval_in_days] = 3
|
||||
end
|
||||
|
||||
it "should not be valid if below minium interval" do
|
||||
proposal = create(:proposal)
|
||||
|
||||
notification1 = create(:proposal_notification, proposal: proposal)
|
||||
notification2 = build(:proposal_notification, proposal: proposal)
|
||||
|
||||
proposal.reload
|
||||
expect(notification2).to_not be_valid
|
||||
end
|
||||
|
||||
it "should be valid if notifications above minium interval" do
|
||||
proposal = create(:proposal)
|
||||
|
||||
notification1 = create(:proposal_notification, proposal: proposal, created_at: 4.days.ago)
|
||||
notification2 = build(:proposal_notification, proposal: proposal)
|
||||
|
||||
proposal.reload
|
||||
expect(notification2).to be_valid
|
||||
end
|
||||
|
||||
it "should be valid if no notifications sent" do
|
||||
notification1 = build(:proposal_notification)
|
||||
|
||||
expect(notification1).to be_valid
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user