2020-08-21 16:16:28 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Jobs::CreateRecentPostSearchIndexes do
|
2023-06-21 22:00:19 +08:00
|
|
|
subject(:job) { described_class.new }
|
2020-08-21 16:16:28 +08:00
|
|
|
|
2023-05-04 09:20:52 +08:00
|
|
|
fab!(:post) { with_search_indexer_enabled { Fabricate(:post) } }
|
|
|
|
fab!(:post_2) { with_search_indexer_enabled { Fabricate(:post) } }
|
2020-08-21 16:16:28 +08:00
|
|
|
|
|
|
|
before { SearchIndexer.enable }
|
|
|
|
|
|
|
|
describe "#execute" do
|
|
|
|
it "should not create the index if requried posts size has not been reached" do
|
|
|
|
SiteSetting.search_recent_posts_size = 1
|
|
|
|
SiteSetting.search_enable_recent_regular_posts_offset_size = 3
|
|
|
|
|
2023-06-21 22:00:19 +08:00
|
|
|
expect { job.execute({}) }.to_not change {
|
2020-08-21 16:16:28 +08:00
|
|
|
SiteSetting.search_recent_regular_posts_offset_post_id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should create the right index" do
|
|
|
|
SiteSetting.search_recent_posts_size = 1
|
|
|
|
SiteSetting.search_enable_recent_regular_posts_offset_size = 1
|
|
|
|
|
2023-06-21 22:00:19 +08:00
|
|
|
job.execute({})
|
2020-08-21 16:16:28 +08:00
|
|
|
|
|
|
|
expect(SiteSetting.search_recent_regular_posts_offset_post_id).to eq(post_2.id)
|
|
|
|
|
|
|
|
expect(DB.query_single(<<~SQL).first).to eq(1)
|
|
|
|
SELECT 1 FROM pg_indexes WHERE indexname = '#{described_class::REGULAR_POST_SEARCH_DATA_INDEX_NAME}'
|
|
|
|
SQL
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|