SPEC: Add test method for ensure_expired_event_destruction job

This commit is contained in:
Vinoth Kannan 2018-09-14 10:10:05 +05:30
parent 4c9d42ecc2
commit 01e874a48d
1 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,40 @@
require 'rails_helper'
describe DiscourseSimpleCalendar::EnsuredExpiredEventDestruction do
before do
SiteSetting.queue_jobs = false
raw = <<~MD
[calendar]
[/calendar]
MD
topic = Fabricate(:topic, first_post: create_post(raw: raw))
@op = topic.first_post
details = @op.custom_fields[DiscourseSimpleCalendar::CALENDAR_DETAILS_CUSTOM_FIELD]
expect(details).to eq({})
raw = <<~MD
Rome [date="2018-06-05" time="10:20:00"] to [date="2018-06-06" time="11:20:00"]
MD
@post = create_post(raw: raw, topic: topic)
CookedPostProcessor.new(@post).post_process
end
it "will correctly remove the post number from calendar details" do
freeze_time Time.strptime("2018-06-03 09:21:00 UTC", "%Y-%m-%d %H:%M:%S %Z")
DiscourseSimpleCalendar::EnsuredExpiredEventDestruction.new.execute(nil)
@op.reload
expect(@op.custom_fields[DiscourseSimpleCalendar::CALENDAR_DETAILS_CUSTOM_FIELD][@post.post_number.to_s]).to eq([
"Rome to", "2018-06-05T10:20:00Z", "2018-06-06T11:20:00Z", @post.user.username_lower
])
freeze_time Time.strptime("2018-06-06 13:21:00 UTC", "%Y-%m-%d %H:%M:%S %Z")
DiscourseSimpleCalendar::EnsuredExpiredEventDestruction.new.execute(nil)
@op.reload
expect(@op.custom_fields[DiscourseSimpleCalendar::CALENDAR_DETAILS_CUSTOM_FIELD][@post.post_number.to_s]).to be_nil
end
end