mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
more specs and move texts to locale file
This commit is contained in:
@@ -16,3 +16,13 @@ en:
|
||||
default_step_title: "Converting %{type}"
|
||||
max_progress_calculation: "Calculating items took %{duration}"
|
||||
|
||||
schema:
|
||||
validator:
|
||||
schema_file_directory_not_found: "Directory of `schema_file` does not exist"
|
||||
models_directory_not_found: "`models_directory` does not exist"
|
||||
models_namespace_undefined: "`models_namespace` is not defined"
|
||||
excluded_table_missing: "Excluded table does not exist in database: %{table_name}"
|
||||
excluded_table_used: "Excluded table can't be configured in `schema/tables` section: %{table_name}"
|
||||
table_not_configured: "Table needs to be configured in `schema/tables` section or excluded in `global/tables`: %{table_name}"
|
||||
plugins_not_installed: "Configured plugins not installed: %{plugin_names}"
|
||||
additional_plugins_installed: "Additional plugins installed. Uninstall them or add to configuration: %{plugin_names}"
|
||||
|
||||
@@ -49,10 +49,14 @@ module Migrations::Database::Schema
|
||||
|
||||
schema_file_path = File.dirname(output_config[:schema_file])
|
||||
schema_file_path = File.expand_path(schema_file_path, ::Migrations.root_path)
|
||||
@errors << "Directory of `schema_file` does not exist" if !Dir.exist?(schema_file_path)
|
||||
if !Dir.exist?(schema_file_path)
|
||||
@errors << I18n.t("schema.validator.schema_file_directory_not_found")
|
||||
end
|
||||
|
||||
models_directory = File.expand_path(output_config[:models_directory], ::Migrations.root_path)
|
||||
@errors << "`models_directory` does not exist" if !Dir.exist?(models_directory)
|
||||
if !Dir.exist?(models_directory)
|
||||
@errors << I18n.t("schema.validator.models_directory_not_found")
|
||||
end
|
||||
|
||||
existing_namespace =
|
||||
begin
|
||||
@@ -60,7 +64,7 @@ module Migrations::Database::Schema
|
||||
rescue NameError
|
||||
false
|
||||
end
|
||||
@errors << "`models_namespace` is not defined" if !existing_namespace
|
||||
@errors << I18n.t("schema.validator.models_namespace_undefined") if !existing_namespace
|
||||
end
|
||||
|
||||
def validate_schema_config(config)
|
||||
@@ -77,7 +81,7 @@ module Migrations::Database::Schema
|
||||
|
||||
excluded_table_names.sort.each do |table_name|
|
||||
if !existing_table_names.delete?(table_name)
|
||||
@errors << "Excluded table does not exist: #{table_name}"
|
||||
@errors << I18n.t("schema.validator.excluded_table_missing", table_name:)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -89,14 +93,14 @@ module Migrations::Database::Schema
|
||||
|
||||
excluded_table_names.sort.each do |table_name|
|
||||
if configured_table_names.include?(table_name)
|
||||
@errors << "Excluded table can't be configured in `schema/tables` section: #{table_name}"
|
||||
@errors << I18n.t("schema.validator.excluded_table_used", table_name:)
|
||||
end
|
||||
end
|
||||
|
||||
existing_table_names.sort.each do |table_name|
|
||||
if !configured_table_names.include?(table_name) &&
|
||||
!excluded_table_names.include?(table_name)
|
||||
@errors << "Table missing from configuration file: #{table_name}"
|
||||
@errors << I18n.t("schema.validator.table_not_configured", table_name:)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -106,11 +110,17 @@ module Migrations::Database::Schema
|
||||
all_plugin_names = Discourse.plugins.map(&:name)
|
||||
|
||||
if (additional_plugins = all_plugin_names.difference(plugin_names)).any?
|
||||
@errors << "Additional plugins installed. Uninstall them or add to configuration: #{additional_plugins.sort.join(", ")}"
|
||||
@errors << I18n.t(
|
||||
"schema.validator.additional_plugins_installed",
|
||||
plugin_names: additional_plugins.sort.join(", "),
|
||||
)
|
||||
end
|
||||
|
||||
if (missing_plugins = plugin_names.difference(all_plugin_names)).any?
|
||||
@errors << "Configured plugins not installed: #{missing_plugins.sort.join(", ")}"
|
||||
@errors << I18n.t(
|
||||
"schema.validator.plugins_not_installed",
|
||||
plugin_names: missing_plugins.sort.join(", "),
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -88,21 +88,27 @@ RSpec.describe ::Migrations::Database::Schema::ConfigValidator do
|
||||
config = minimal_config
|
||||
config[:output][:schema_file] = "foo/bar/100-base-schema.sql"
|
||||
expect(validator.validate(config)).to have_errors
|
||||
expect(validator.errors).to contain_exactly("Directory of `schema_file` does not exist")
|
||||
expect(validator.errors).to contain_exactly(
|
||||
I18n.t("schema.validator.schema_file_directory_not_found"),
|
||||
)
|
||||
end
|
||||
|
||||
it "checks if `models_directory` exists" do
|
||||
config = minimal_config
|
||||
config[:output][:models_directory] = "foo/bar"
|
||||
expect(validator.validate(config)).to have_errors
|
||||
expect(validator.errors).to contain_exactly("`models_directory` does not exist")
|
||||
expect(validator.errors).to contain_exactly(
|
||||
I18n.t("schema.validator.models_directory_not_found"),
|
||||
)
|
||||
end
|
||||
|
||||
it "checks if `models_namespace` is an existing namespace" do
|
||||
config = minimal_config
|
||||
config[:output][:models_namespace] = "Foo::Bar::IntermediateDB"
|
||||
expect(validator.validate(config)).to have_errors
|
||||
expect(validator.errors).to contain_exactly("`models_namespace` is not defined")
|
||||
expect(validator.errors).to contain_exactly(
|
||||
I18n.t("schema.validator.models_namespace_undefined"),
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -114,8 +120,8 @@ RSpec.describe ::Migrations::Database::Schema::ConfigValidator do
|
||||
|
||||
expect(validator.validate(config)).to have_errors
|
||||
expect(validator.errors).to contain_exactly(
|
||||
"Excluded table does not exist: bar",
|
||||
"Excluded table does not exist: foo",
|
||||
I18n.t("schema.validator.excluded_table_missing", table_name: "bar"),
|
||||
I18n.t("schema.validator.excluded_table_missing", table_name: "foo"),
|
||||
)
|
||||
end
|
||||
|
||||
@@ -128,8 +134,24 @@ RSpec.describe ::Migrations::Database::Schema::ConfigValidator do
|
||||
|
||||
expect(validator.validate(config)).to have_errors
|
||||
expect(validator.errors).to contain_exactly(
|
||||
"Excluded table can't be configured in `schema/tables` section: categories",
|
||||
"Excluded table can't be configured in `schema/tables` section: users",
|
||||
I18n.t("schema.validator.excluded_table_used", table_name: "categories"),
|
||||
I18n.t("schema.validator.excluded_table_used", table_name: "users"),
|
||||
)
|
||||
end
|
||||
|
||||
it "detects tables that are missing from configuration file" do
|
||||
allow(ActiveRecord::Base.connection).to receive(:tables).and_return(
|
||||
%w[categories topics posts users tags],
|
||||
)
|
||||
|
||||
config = minimal_config
|
||||
config[:schema][:global][:tables][:exclude] = %w[categories]
|
||||
config[:schema][:tables] = { topics: {}, users: {} }
|
||||
|
||||
expect(validator.validate(config)).to have_errors
|
||||
expect(validator.errors).to contain_exactly(
|
||||
I18n.t("schema.validator.table_not_configured", table_name: "posts"),
|
||||
I18n.t("schema.validator.table_not_configured", table_name: "tags"),
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -150,7 +172,9 @@ RSpec.describe ::Migrations::Database::Schema::ConfigValidator do
|
||||
config[:plugins] = %w[foo poll bar chat footnote]
|
||||
|
||||
expect(validator.validate(config)).to have_errors
|
||||
expect(validator.errors).to contain_exactly("Configured plugins not installed: bar, foo")
|
||||
expect(validator.errors).to contain_exactly(
|
||||
I18n.t("schema.validator.plugins_not_installed", plugin_names: "bar, foo"),
|
||||
)
|
||||
end
|
||||
|
||||
it "detects if an active plugin isn't configured" do
|
||||
@@ -159,7 +183,7 @@ RSpec.describe ::Migrations::Database::Schema::ConfigValidator do
|
||||
|
||||
expect(validator.validate(config)).to have_errors
|
||||
expect(validator.errors).to contain_exactly(
|
||||
"Additional plugins installed. Uninstall them or add to configuration: chat, footnote",
|
||||
I18n.t("schema.validator.additional_plugins_installed", plugin_names: "chat, footnote"),
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user