2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-04 08:47:53 +08:00
|
|
|
require "highline/import"
|
|
|
|
require "highline/simulate"
|
2017-01-28 02:42:39 +08:00
|
|
|
|
|
|
|
RSpec.describe "Post rake tasks" do
|
2019-05-07 11:12:20 +08:00
|
|
|
fab!(:post) { Fabricate(:post, raw: "The quick brown fox jumps over the lazy dog") }
|
|
|
|
fab!(:tricky_post) { Fabricate(:post, raw: "Today ^Today") }
|
2017-10-25 02:49:00 +08:00
|
|
|
|
2024-11-20 12:17:36 +08:00
|
|
|
before { STDOUT.stubs(:write) }
|
2017-01-28 02:42:39 +08:00
|
|
|
|
|
|
|
describe "remap" do
|
|
|
|
it "should remap posts" do
|
2024-11-20 12:17:36 +08:00
|
|
|
HighLine::Simulate.with("y") { invoke_rake_task("posts:remap", "brown", "red") }
|
2017-10-04 08:47:53 +08:00
|
|
|
|
2017-01-28 02:42:39 +08:00
|
|
|
post.reload
|
|
|
|
expect(post.raw).to eq("The quick red fox jumps over the lazy dog")
|
|
|
|
end
|
2017-10-04 08:47:53 +08:00
|
|
|
|
|
|
|
context "when type == string" do
|
|
|
|
it "remaps input as string" do
|
|
|
|
HighLine::Simulate.with("y") do
|
2024-11-20 12:17:36 +08:00
|
|
|
invoke_rake_task("posts:remap", "^Today", "Yesterday", "string")
|
2017-10-04 08:47:53 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
expect(tricky_post.reload.raw).to eq("Today Yesterday")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when type == regex" do
|
|
|
|
it "remaps input as regex" do
|
|
|
|
HighLine::Simulate.with("y") do
|
2024-11-20 12:17:36 +08:00
|
|
|
invoke_rake_task("posts:remap", "^Today", "Yesterday", "regex")
|
2017-10-04 08:47:53 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
expect(tricky_post.reload.raw).to eq("Yesterday ^Today")
|
|
|
|
end
|
|
|
|
end
|
2017-01-28 02:42:39 +08:00
|
|
|
end
|
2017-10-25 02:49:00 +08:00
|
|
|
|
|
|
|
describe "rebake_match" do
|
|
|
|
it "rebakes matched posts" do
|
2019-04-29 15:32:25 +08:00
|
|
|
post.update(cooked: "")
|
2017-10-25 02:49:00 +08:00
|
|
|
|
2024-11-20 12:17:36 +08:00
|
|
|
HighLine::Simulate.with("y") { invoke_rake_task("posts:rebake_match", "brown") }
|
2017-10-25 02:49:00 +08:00
|
|
|
|
|
|
|
expect(post.reload.cooked).to eq("<p>The quick brown fox jumps over the lazy dog</p>")
|
|
|
|
end
|
|
|
|
end
|
2019-04-09 04:37:35 +08:00
|
|
|
|
|
|
|
describe "missing_uploads" do
|
2019-04-10 21:43:38 +08:00
|
|
|
let(:url) do
|
|
|
|
"/uploads/#{RailsMultisite::ConnectionManagement.current_db}/original/1X/d1c2d40ab994e8410c.png"
|
2023-01-09 19:18:21 +08:00
|
|
|
end
|
2019-04-10 21:43:38 +08:00
|
|
|
let(:upload) { Fabricate(:upload, url: url) }
|
2019-04-09 04:37:35 +08:00
|
|
|
|
|
|
|
it "should create post custom field for missing upload" do
|
2019-04-10 21:43:38 +08:00
|
|
|
post = Fabricate(:post, raw: "A sample post <img src='#{url}'>")
|
2019-04-09 04:37:35 +08:00
|
|
|
upload.destroy!
|
|
|
|
|
2024-11-20 12:17:36 +08:00
|
|
|
invoke_rake_task("posts:missing_uploads")
|
2019-04-09 04:37:35 +08:00
|
|
|
|
2019-04-10 21:43:38 +08:00
|
|
|
post.reload
|
|
|
|
expect(post.custom_fields[Post::MISSING_UPLOADS]).to eq([url])
|
2019-04-09 04:37:35 +08:00
|
|
|
end
|
2019-05-09 07:41:15 +08:00
|
|
|
|
|
|
|
it 'should skip all the posts with "ignored" custom field' do
|
|
|
|
post = Fabricate(:post, raw: "A sample post <img src='#{url}'>")
|
|
|
|
post.custom_fields[Post::MISSING_UPLOADS_IGNORED] = true
|
|
|
|
post.save_custom_fields
|
|
|
|
upload.destroy!
|
|
|
|
|
2024-11-20 12:17:36 +08:00
|
|
|
invoke_rake_task("posts:missing_uploads")
|
2019-05-09 07:41:15 +08:00
|
|
|
|
|
|
|
post.reload
|
|
|
|
expect(post.custom_fields[Post::MISSING_UPLOADS]).to be_nil
|
|
|
|
end
|
2019-04-09 04:37:35 +08:00
|
|
|
end
|
2017-01-28 02:42:39 +08:00
|
|
|
end
|