Disallow to modify the start date for an already started poll
We need to update a couple of tests because a poll is created in the tests with a timestamp that includes nanoseconds and in the form to edit the time of the poll the nanoseconds are not sent, meaning it was detected as a change.
This commit is contained in:
committed by
Javi Martín
parent
a774456b51
commit
471096c698
@@ -152,10 +152,14 @@ class Poll < ApplicationRecord
|
||||
end
|
||||
|
||||
def start_date_change
|
||||
if will_save_change_to_starts_at? && starts_at < Time.current
|
||||
if will_save_change_to_starts_at?
|
||||
if starts_at_in_database < Time.current
|
||||
errors.add(:starts_at, I18n.t("errors.messages.cannot_change_date.poll_started"))
|
||||
elsif starts_at < Time.current
|
||||
errors.add(:starts_at, I18n.t("errors.messages.past_date"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def generate_slug?
|
||||
slug.nil?
|
||||
|
||||
@@ -138,6 +138,8 @@ en:
|
||||
user_not_found: User not found
|
||||
invalid_date_range: "Invalid date range"
|
||||
past_date: "Must not be a past date"
|
||||
cannot_change_date:
|
||||
poll_started: "Cannot be changed if voting has already started"
|
||||
form:
|
||||
accept_terms: I agree to the %{policy} and the %{conditions}
|
||||
accept_terms_title: I agree to the Privacy Policy and the Terms and conditions of use
|
||||
|
||||
@@ -138,6 +138,8 @@ es:
|
||||
user_not_found: Usuario no encontrado
|
||||
invalid_date_range: "El rango de fechas no es válido"
|
||||
past_date: "No puede ser una fecha pasada"
|
||||
cannot_change_date:
|
||||
poll_started: "No puede ser cambiada si la votación ha comenzado"
|
||||
form:
|
||||
accept_terms: Acepto la %{policy} y las %{conditions}
|
||||
accept_terms_title: Acepto la Política de privacidad y las Condiciones de uso
|
||||
|
||||
@@ -62,6 +62,13 @@ describe Poll do
|
||||
poll.starts_at = 1.minute.ago
|
||||
expect(poll).not_to be_valid
|
||||
end
|
||||
|
||||
it "is not valid if changing the start date for an already started poll" do
|
||||
poll = create(:poll, starts_at: 10.days.ago)
|
||||
|
||||
poll.starts_at = 10.days.from_now
|
||||
expect(poll).not_to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -553,7 +553,7 @@ describe "Admin polls", :admin do
|
||||
end
|
||||
|
||||
scenario "edit poll with sdg related list" do
|
||||
poll = create(:poll, name: "Upcoming poll with SDG related content")
|
||||
poll = create(:poll, :future, name: "Upcoming poll with SDG related content")
|
||||
poll.sdg_goals = [SDG::Goal[1], SDG::Goal[17]]
|
||||
visit edit_admin_poll_path(poll)
|
||||
|
||||
|
||||
@@ -242,7 +242,7 @@ describe "Admin edit translatable records", :admin do
|
||||
end
|
||||
|
||||
context "Change value of a translated field to blank" do
|
||||
let(:translatable) { create(:poll) }
|
||||
let(:translatable) { create(:poll, :future) }
|
||||
let(:path) { edit_admin_poll_path(translatable) }
|
||||
|
||||
scenario "Updates the field to a blank value" do
|
||||
|
||||
Reference in New Issue
Block a user