mirror of
https://github.com/discourse/discourse.git
synced 2025-04-17 12:59:07 +08:00
DEV: Correct syntax_tree violations
This commit is contained in:
parent
488b8b369a
commit
54f165beae
@ -6,7 +6,8 @@ class SearchRankingWeightsValidator
|
|||||||
end
|
end
|
||||||
|
|
||||||
WEIGHT_REGEXP = "1\.0|0\.[0-9]+"
|
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)
|
def valid_value?(value)
|
||||||
return true if value.blank?
|
return true if value.blank?
|
||||||
|
@ -1,25 +1,23 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
RSpec.describe SearchRankingWeightsValidator do
|
RSpec.describe SearchRankingWeightsValidator do
|
||||||
it 'allows a blank value to be set' do
|
it "allows a blank value to be set" do
|
||||||
expect do
|
expect { SiteSetting.search_ranking_weights = "" }.not_to raise_error
|
||||||
SiteSetting.search_ranking_weights = ''
|
|
||||||
end.not_to raise_error
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'raises the right error when value is invalid' do
|
it "raises the right error when value is invalid" do
|
||||||
expect do
|
expect { SiteSetting.search_ranking_weights = "test" }.to raise_error(
|
||||||
SiteSetting.search_ranking_weights = 'test'
|
Discourse::InvalidParameters,
|
||||||
end.to raise_error(Discourse::InvalidParameters, /#{I18n.t("site_settings.errors.invalid_search_ranking_weights")}/)
|
/#{I18n.t("site_settings.errors.invalid_search_ranking_weights")}/,
|
||||||
|
)
|
||||||
|
|
||||||
expect do
|
expect { SiteSetting.search_ranking_weights = "{1.1,0.1,0.2,0.3}" }.to raise_error(
|
||||||
SiteSetting.search_ranking_weights = '{1.1,0.1,0.2,0.3}'
|
Discourse::InvalidParameters,
|
||||||
end.to raise_error(Discourse::InvalidParameters, /#{I18n.t("site_settings.errors.invalid_search_ranking_weights")}/)
|
/#{I18n.t("site_settings.errors.invalid_search_ranking_weights")}/,
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the site setting when value is valid' do
|
it "sets the site setting when value is valid" do
|
||||||
expect do
|
expect { SiteSetting.search_ranking_weights = "{0.001,0.2,0.003,1.0}" }.to_not raise_error
|
||||||
SiteSetting.search_ranking_weights = '{0.001,0.2,0.003,1.0}'
|
|
||||||
end.to_not raise_error
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -58,18 +58,12 @@ RSpec.describe ImportScripts::Base do
|
|||||||
describe "#create_post" do
|
describe "#create_post" do
|
||||||
let(:importer) { described_class.new }
|
let(:importer) { described_class.new }
|
||||||
fab!(:user) { Fabricate(:user) }
|
fab!(:user) { Fabricate(:user) }
|
||||||
let(:post_params) {
|
let(:post_params) do
|
||||||
{
|
{ user_id: user.id, raw: "Test post [b]content[/b]", title: "Test topic for post" }
|
||||||
user_id: user.id,
|
end
|
||||||
raw: "Test post [b]content[/b]",
|
|
||||||
title: "Test topic for post"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
it "creates a Post" do
|
it "creates a Post" do
|
||||||
expect {
|
expect { importer.create_post(post_params, 123) }.to change { Post.count }.by(1)
|
||||||
importer.create_post(post_params, 123)
|
|
||||||
}.to change { Post.count }.by(1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if ENV["IMPORT"] == "1"
|
if ENV["IMPORT"] == "1"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user