FIX: do not attempt to validate a post from a topic with no calendar

This commit is contained in:
Joffrey JAFFEUX 2019-08-09 10:14:21 +02:00
parent 0a1e734628
commit ab1bc19a18
2 changed files with 13 additions and 0 deletions

View File

@ -124,6 +124,7 @@ after_initialize do
end
validate(:post, :validate_post) do |force = nil|
return if !self.custom_fields[DiscourseCalendar::CALENDAR_CUSTOM_FIELD]
return unless self.raw_changed? || force
return if self.is_first_post?

View File

@ -72,4 +72,16 @@ describe DiscourseCalendar::EventUpdater do
expect(from).to eq("2018-06-05T00:00:00+02:00")
expect(to).to eq("2018-06-11T13:45:33-07:00")
end
it "will validate a post with more than two dates if not a calendar" do
op = create_post(raw: "This is a tets of a topic")
raw = %{Rome [date="2018-06-05" timezone="Europe/Paris"] [date="2018-06-11" time="13:45:33" timezone="America/Los_Angeles"] [date="2018-06-05" timezone="Europe/Paris"]}
post = create_post(raw: raw, topic: op.topic)
CookedPostProcessor.new(post).post_process
op.reload
expect(post).to be_valid
end
end