DEV: Correct syntax_tree violations

This commit is contained in:
David Taylor 2023-02-02 12:24:42 +00:00
parent 488b8b369a
commit 54f165beae
3 changed files with 19 additions and 26 deletions

View File

@ -6,7 +6,8 @@ class SearchRankingWeightsValidator
end
WEIGHT_REGEXP = "1\.0|0\.[0-9]+"
WEIGHTS_REGEXP = /{(?<d_weight>#{WEIGHT_REGEXP}),(?<c_weight>#{WEIGHT_REGEXP}),(?<b_weight>#{WEIGHT_REGEXP}),(?<a_weight>#{WEIGHT_REGEXP})}/
WEIGHTS_REGEXP =
/{(?<d_weight>#{WEIGHT_REGEXP}),(?<c_weight>#{WEIGHT_REGEXP}),(?<b_weight>#{WEIGHT_REGEXP}),(?<a_weight>#{WEIGHT_REGEXP})}/
def valid_value?(value)
return true if value.blank?

View File

@ -1,25 +1,23 @@
# frozen_string_literal: true
RSpec.describe SearchRankingWeightsValidator do
it 'allows a blank value to be set' do
expect do
SiteSetting.search_ranking_weights = ''
end.not_to raise_error
it "allows a blank value to be set" do
expect { SiteSetting.search_ranking_weights = "" }.not_to raise_error
end
it 'raises the right error when value is invalid' do
expect do
SiteSetting.search_ranking_weights = 'test'
end.to raise_error(Discourse::InvalidParameters, /#{I18n.t("site_settings.errors.invalid_search_ranking_weights")}/)
it "raises the right error when value is invalid" do
expect { SiteSetting.search_ranking_weights = "test" }.to raise_error(
Discourse::InvalidParameters,
/#{I18n.t("site_settings.errors.invalid_search_ranking_weights")}/,
)
expect do
SiteSetting.search_ranking_weights = '{1.1,0.1,0.2,0.3}'
end.to raise_error(Discourse::InvalidParameters, /#{I18n.t("site_settings.errors.invalid_search_ranking_weights")}/)
expect { SiteSetting.search_ranking_weights = "{1.1,0.1,0.2,0.3}" }.to raise_error(
Discourse::InvalidParameters,
/#{I18n.t("site_settings.errors.invalid_search_ranking_weights")}/,
)
end
it 'sets the site setting when value is valid' do
expect do
SiteSetting.search_ranking_weights = '{0.001,0.2,0.003,1.0}'
end.to_not raise_error
it "sets the site setting when value is valid" do
expect { SiteSetting.search_ranking_weights = "{0.001,0.2,0.003,1.0}" }.to_not raise_error
end
end

View File

@ -58,18 +58,12 @@ RSpec.describe ImportScripts::Base do
describe "#create_post" do
let(:importer) { described_class.new }
fab!(:user) { Fabricate(:user) }
let(:post_params) {
{
user_id: user.id,
raw: "Test post [b]content[/b]",
title: "Test topic for post"
}
}
let(:post_params) do
{ user_id: user.id, raw: "Test post [b]content[/b]", title: "Test topic for post" }
end
it "creates a Post" do
expect {
importer.create_post(post_params, 123)
}.to change { Post.count }.by(1)
expect { importer.create_post(post_params, 123) }.to change { Post.count }.by(1)
end
if ENV["IMPORT"] == "1"