2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-09-17 20:48:43 +08:00
|
|
|
describe Post do
|
|
|
|
|
|
|
|
before do
|
2019-03-14 22:47:38 +08:00
|
|
|
Jobs.run_immediately!
|
2018-09-17 20:48:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#local_dates' do
|
|
|
|
it "should have correct custom fields" do
|
|
|
|
post = Fabricate(:post, raw: <<~SQL)
|
2018-10-16 07:34:55 +08:00
|
|
|
[date=2018-09-17 time=01:39:00 format="LLL" timezone="Europe/Paris" timezones="Europe/Paris|America/Los_Angeles"]
|
2018-09-17 20:48:43 +08:00
|
|
|
SQL
|
|
|
|
CookedPostProcessor.new(post).post_process
|
|
|
|
|
2018-09-17 21:09:59 +08:00
|
|
|
expect(post.local_dates.count).to eq(1)
|
|
|
|
expect(post.local_dates[0]["date"]).to eq("2018-09-17")
|
|
|
|
expect(post.local_dates[0]["time"]).to eq("01:39:00")
|
2018-10-16 07:34:55 +08:00
|
|
|
expect(post.local_dates[0]["timezone"]).to eq("Europe/Paris")
|
2018-09-17 20:48:43 +08:00
|
|
|
|
|
|
|
post.raw = "Text removed"
|
|
|
|
post.save
|
|
|
|
CookedPostProcessor.new(post).post_process
|
|
|
|
|
|
|
|
expect(post.local_dates).to eq([])
|
|
|
|
end
|
2020-01-21 23:42:41 +08:00
|
|
|
|
|
|
|
it "should not contain dates from quotes" do
|
|
|
|
post = Fabricate(:post, raw: <<~SQL)
|
|
|
|
[quote]
|
|
|
|
[date=2018-09-17 time=01:39:00 format="LLL" timezone="Europe/Paris" timezones="Europe/Paris|America/Los_Angeles"]
|
|
|
|
[/quote]
|
|
|
|
SQL
|
|
|
|
CookedPostProcessor.new(post).post_process
|
|
|
|
|
|
|
|
expect(post.local_dates.count).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not contain dates from examples" do
|
|
|
|
Oneboxer.stubs(:cached_onebox).with('https://example.com').returns(<<-HTML)
|
|
|
|
<aside class="onebox githubcommit">
|
|
|
|
<span class="discourse-local-date" data-format="ll" data-date="2020-01-20" data-time="15:06:58" data-timezone="UTC">03:06PM - 20 Jan 20 UTC</span>
|
|
|
|
</aside>
|
|
|
|
HTML
|
|
|
|
post = Fabricate(:post, raw: "https://example.com")
|
|
|
|
CookedPostProcessor.new(post).post_process
|
|
|
|
|
|
|
|
expect(post.local_dates.count).to eq(0)
|
|
|
|
end
|
2018-09-17 20:48:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|