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

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

diff --git a/plugin.rb b/plugin.rb
index cb98cfe..916d359 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -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?
 
diff --git a/spec/lib/event_updater_spec.rb b/spec/lib/event_updater_spec.rb
index 103a374..b867faa 100644
--- a/spec/lib/event_updater_spec.rb
+++ b/spec/lib/event_updater_spec.rb
@@ -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

GitHub sha: ab1bc19a

1 Like