Browse Source

Rename validation table

pull/2438/head
Kat 2 years ago
parent
commit
ea79422c46
  1. 2
      app/models/log_validation.rb
  2. 2
      app/models/validation.rb
  3. 12
      app/services/documentation_generator.rb
  4. 5
      db/migrate/20240529133005_rename_validations_table.rb
  5. 38
      db/schema.rb
  6. 4
      lib/tasks/generate_lettings_documentation.rake
  7. 24
      spec/lib/tasks/generate_lettings_documentation_spec.rb
  8. 24
      spec/lib/tasks/generate_sales_documentation_spec.rb

2
app/models/log_validation.rb

@ -0,0 +1,2 @@
class LogValidation < ApplicationRecord
end

2
app/models/validation.rb

@ -1,2 +0,0 @@
class Validation < ApplicationRecord
end

12
app/services/documentation_generator.rb

@ -13,7 +13,7 @@ class DocumentationGenerator
form = FormHandler.instance.forms["current_#{log_type}"] form = FormHandler.instance.forms["current_#{log_type}"]
validation_methods.each do |meth| validation_methods.each do |meth|
if Validation.where(validation_name: meth.to_s, bulk_upload_specific: false).exists? if LogValidation.where(validation_name: meth.to_s, bulk_upload_specific: false).exists?
Rails.logger.info("Validation #{meth} already exists") Rails.logger.info("Validation #{meth} already exists")
next next
end end
@ -41,7 +41,7 @@ class DocumentationGenerator
def describe_bu_validations(client, form, row_parser_class, validation_methods, all_helper_methods, field_mapping_for_errors, log_type) def describe_bu_validations(client, form, row_parser_class, validation_methods, all_helper_methods, field_mapping_for_errors, log_type)
validation_methods.each do |meth| validation_methods.each do |meth|
if Validation.where(validation_name: meth.to_s, bulk_upload_specific: true, from: form.start_date).exists? if LogValidation.where(validation_name: meth.to_s, bulk_upload_specific: true, from: form.start_date).exists?
Rails.logger.info("Validation #{meth} already exists for #{form.start_date.year}") Rails.logger.info("Validation #{meth} already exists for #{form.start_date.year}")
next next
end end
@ -264,7 +264,7 @@ Look at these helper methods where needed to understand what is being checked in
def save_hard_validation(result, meth, form, log_type) def save_hard_validation(result, meth, form, log_type)
result["cases"].each do |case_info| result["cases"].each do |case_info|
case_info["errors"].each do |error| case_info["errors"].each do |error|
Validation.create!(log_type:, LogValidation.create!(log_type:,
validation_name: meth.to_s, validation_name: meth.to_s,
description: result["description"], description: result["description"],
field: error["field"], field: error["field"],
@ -288,7 +288,7 @@ Look at these helper methods where needed to understand what is being checked in
error_fields = field_mapping_for_errors.select { |_key, values| values.include?(error["field"].to_sym) }.keys error_fields = field_mapping_for_errors.select { |_key, values| values.include?(error["field"].to_sym) }.keys
error_fields = [error["field"]] if error_fields.empty? error_fields = [error["field"]] if error_fields.empty?
error_fields.each do |error_field| error_fields.each do |error_field|
Validation.create!(log_type:, LogValidation.create!(log_type:,
validation_name: meth.to_s, validation_name: meth.to_s,
description: result["description"], description: result["description"],
field: error_field, field: error_field,
@ -333,7 +333,7 @@ Look at these helper methods where needed to understand what is being checked in
return return
end end
if Validation.where(validation_name: validation_depends_on_hash.keys.first, field: page_the_validation_applied_to.questions.first.id, from: form.start_date).exists? if LogValidation.where(validation_name: validation_depends_on_hash.keys.first, field: page_the_validation_applied_to.questions.first.id, from: form.start_date).exists?
Rails.logger.info("Validation #{validation_depends_on_hash.keys.first} already exists for #{page_the_validation_applied_to.questions.first.id} for start year #{form.start_date.year}") Rails.logger.info("Validation #{validation_depends_on_hash.keys.first} already exists for #{page_the_validation_applied_to.questions.first.id} for start year #{form.start_date.year}")
return return
end end
@ -353,7 +353,7 @@ Look at these helper methods where needed to understand what is being checked in
error_message = [title_text, informative_text, page.questions.first.hint_text].compact.join("\n") error_message = [title_text, informative_text, page.questions.first.hint_text].compact.join("\n")
case_info = page.depends_on.first.values.first ? "Provided values fulfill the description" : "Provided values do not fulfill the description" case_info = page.depends_on.first.values.first ? "Provided values fulfill the description" : "Provided values do not fulfill the description"
Validation.create!(log_type:, LogValidation.create!(log_type:,
validation_name: validation_depends_on_hash.keys.first.to_s, validation_name: validation_depends_on_hash.keys.first.to_s,
description: result["description"], description: result["description"],
field: page_the_validation_applied_to.questions.first.id, field: page_the_validation_applied_to.questions.first.id,

5
db/migrate/20240529133005_rename_validations_table.rb

@ -0,0 +1,5 @@
class RenameValidationsTable < ActiveRecord::Migration[7.0]
def change
rename_table :validations, :log_validations
end
end

38
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2024_05_23_153434) do ActiveRecord::Schema[7.0].define(version: 2024_05_29_133005) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -381,6 +381,24 @@ ActiveRecord::Schema[7.0].define(version: 2024_05_23_153434) do
t.index ["scheme_id"], name: "index_locations_on_scheme_id" t.index ["scheme_id"], name: "index_locations_on_scheme_id"
end end
create_table "log_validations", force: :cascade do |t|
t.string "log_type"
t.string "section"
t.string "validation_name"
t.string "description"
t.string "case"
t.string "field"
t.string "error_message"
t.datetime "from"
t.datetime "to"
t.string "validation_type"
t.string "hard_soft"
t.boolean "bulk_upload_specific", default: false
t.string "other_validated_models"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "logs_exports", force: :cascade do |t| create_table "logs_exports", force: :cascade do |t|
t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" } t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" }
t.datetime "started_at", null: false t.datetime "started_at", null: false
@ -777,24 +795,6 @@ ActiveRecord::Schema[7.0].define(version: 2024_05_23_153434) do
t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true
end end
create_table "validations", force: :cascade do |t|
t.string "log_type"
t.string "section"
t.string "validation_name"
t.string "description"
t.string "case"
t.string "field"
t.string "error_message"
t.datetime "from"
t.datetime "to"
t.string "validation_type"
t.string "hard_soft"
t.boolean "bulk_upload_specific", default: false
t.string "other_validated_models"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "versions", force: :cascade do |t| create_table "versions", force: :cascade do |t|
t.string "item_type", limit: 191, null: false t.string "item_type", limit: 191, null: false
t.bigint "item_id", null: false t.bigint "item_id", null: false

4
lib/tasks/generate_lettings_documentation.rake

@ -70,13 +70,13 @@ namespace :generate_lettings_documentation do
validation_description = "Field value is lower than the minimum value or higher than the maximum value" validation_description = "Field value is lower than the minimum value or higher than the maximum value"
end end
if Validation.where(validation_name:, field:).exists? if LogValidation.where(validation_name:, field:).exists?
Rails.logger.info("Validation #{validation_name} already exists for #{field}") Rails.logger.info("Validation #{validation_name} already exists for #{field}")
next next
end end
Validation.create!(log_type: "lettings", LogValidation.create!(log_type: "lettings",
validation_name:, validation_name:,
description: validation_description, description: validation_description,
field:, field:,

24
spec/lib/tasks/generate_lettings_documentation_spec.rb

@ -23,9 +23,9 @@ RSpec.describe "generate_lettings_documentation" do
it "creates new validation documentation records" do it "creates new validation documentation records" do
expect(Rails.logger).to receive(:info).with(/described/).at_least(:once) expect(Rails.logger).to receive(:info).with(/described/).at_least(:once)
expect { task.invoke }.to change(Validation, :count) expect { task.invoke }.to change(Validation, :count)
expect(Validation.where(validation_name: "validate_numeric_min_max").count).to eq(1) expect(LogValidation.where(validation_name: "validate_numeric_min_max").count).to eq(1)
expect(Validation.where(validation_name: "validate_layear").count).to eq(1) expect(LogValidation.where(validation_name: "validate_layear").count).to eq(1)
any_validation = Validation.first any_validation = LogValidation.first
expect(any_validation.description).to eq("Validates the format.") expect(any_validation.description).to eq("Validates the format.")
expect(any_validation.field).to eq("ppostcode_full") expect(any_validation.field).to eq("ppostcode_full")
expect(any_validation.error_message).to eq("Enter a valid postcode") expect(any_validation.error_message).to eq("Enter a valid postcode")
@ -90,9 +90,9 @@ RSpec.describe "generate_lettings_documentation" do
context "when the rake task is run" do context "when the rake task is run" do
it "creates new validation documentation records" do it "creates new validation documentation records" do
expect { task.invoke }.to change(Validation, :count) expect { task.invoke }.to change(Validation, :count)
expect(Validation.where(validation_name: "rent_in_soft_min_range?").count).to be_positive expect(LogValidation.where(validation_name: "rent_in_soft_min_range?").count).to be_positive
expect(Validation.where(validation_name: "major_repairs_date_in_soft_range?").count).to be_positive expect(LogValidation.where(validation_name: "major_repairs_date_in_soft_range?").count).to be_positive
any_validation = Validation.first any_validation = LogValidation.first
expect(any_validation.description).to eq("Validates the format.") expect(any_validation.description).to eq("Validates the format.")
expect(any_validation.field).not_to be_empty expect(any_validation.field).not_to be_empty
expect(any_validation.error_message).not_to be_empty expect(any_validation.error_message).not_to be_empty
@ -138,9 +138,9 @@ RSpec.describe "generate_lettings_documentation" do
it "creates new validation documentation records" do it "creates new validation documentation records" do
expect(Rails.logger).to receive(:info).with(/described/).at_least(:once) expect(Rails.logger).to receive(:info).with(/described/).at_least(:once)
expect { task.invoke }.to change(Validation, :count) expect { task.invoke }.to change(Validation, :count)
expect(Validation.where(validation_name: "validate_needs_type_present").count).to eq(2) # for both years expect(LogValidation.where(validation_name: "validate_needs_type_present").count).to eq(2) # for both years
expect(Validation.where(validation_name: "validate_data_types").count).to eq(2) expect(LogValidation.where(validation_name: "validate_data_types").count).to eq(2)
any_validation = Validation.first any_validation = LogValidation.first
expect(any_validation.description).to eq("Validates the format.") expect(any_validation.description).to eq("Validates the format.")
expect(any_validation.field).to eq("ppostcode_full") expect(any_validation.field).to eq("ppostcode_full")
expect(any_validation.error_message).to eq("Enter a valid postcode") expect(any_validation.error_message).to eq("Enter a valid postcode")
@ -197,9 +197,9 @@ RSpec.describe "generate_lettings_documentation" do
context "when the rake task is run" do context "when the rake task is run" do
it "creates new validation documentation records" do it "creates new validation documentation records" do
expect { task.invoke }.to change(Validation, :count) expect { task.invoke }.to change(Validation, :count)
expect(Validation.where(validation_name: "minimum").count).to be_positive expect(LogValidation.where(validation_name: "minimum").count).to be_positive
expect(Validation.where(validation_name: "range").count).to be_positive expect(LogValidation.where(validation_name: "range").count).to be_positive
any_min_validation = Validation.where(validation_name: "minimum").first any_min_validation = LogValidation.where(validation_name: "minimum").first
expect(any_min_validation.description).to include("Field value is lower than the minimum value") expect(any_min_validation.description).to include("Field value is lower than the minimum value")
expect(any_min_validation.field).not_to be_empty expect(any_min_validation.field).not_to be_empty
expect(any_min_validation.error_message).to include("must be at least") expect(any_min_validation.error_message).to include("must be at least")

24
spec/lib/tasks/generate_sales_documentation_spec.rb

@ -23,9 +23,9 @@ RSpec.describe "generate_sales_documentation" do
it "creates new validation documentation records" do it "creates new validation documentation records" do
expect(Rails.logger).to receive(:info).with(/described/).at_least(:once) expect(Rails.logger).to receive(:info).with(/described/).at_least(:once)
expect { task.invoke }.to change(Validation, :count) expect { task.invoke }.to change(Validation, :count)
expect(Validation.where(validation_name: "validate_saledate_collection_year").count).to eq(1) expect(LogValidation.where(validation_name: "validate_saledate_collection_year").count).to eq(1)
expect(Validation.where(validation_name: "validate_partner_count").count).to eq(1) expect(LogValidation.where(validation_name: "validate_partner_count").count).to eq(1)
any_validation = Validation.first any_validation = LogValidation.first
expect(any_validation.description).to eq("Validates the format.") expect(any_validation.description).to eq("Validates the format.")
expect(any_validation.field).to eq("ppostcode_full") expect(any_validation.field).to eq("ppostcode_full")
expect(any_validation.error_message).to eq("Enter a valid postcode") expect(any_validation.error_message).to eq("Enter a valid postcode")
@ -90,9 +90,9 @@ RSpec.describe "generate_sales_documentation" do
context "when the rake task is run" do context "when the rake task is run" do
it "creates new validation documentation records" do it "creates new validation documentation records" do
expect { task.invoke }.to change(Validation, :count) expect { task.invoke }.to change(Validation, :count)
expect(Validation.where(validation_name: "income2_under_soft_min?").count).to be_positive expect(LogValidation.where(validation_name: "income2_under_soft_min?").count).to be_positive
expect(Validation.where(validation_name: "deposit_over_soft_max?").count).to be_positive expect(LogValidation.where(validation_name: "deposit_over_soft_max?").count).to be_positive
any_validation = Validation.first any_validation = LogValidation.first
expect(any_validation.description).to eq("Validates the format.") expect(any_validation.description).to eq("Validates the format.")
expect(any_validation.field).not_to be_empty expect(any_validation.field).not_to be_empty
expect(any_validation.error_message).not_to be_empty expect(any_validation.error_message).not_to be_empty
@ -138,9 +138,9 @@ RSpec.describe "generate_sales_documentation" do
it "creates new validation documentation records" do it "creates new validation documentation records" do
expect(Rails.logger).to receive(:info).with(/described/).at_least(:once) expect(Rails.logger).to receive(:info).with(/described/).at_least(:once)
expect { task.invoke }.to change(Validation, :count) expect { task.invoke }.to change(Validation, :count)
expect(Validation.where(validation_name: "validate_owning_org_data_given").count).to eq(2) # for both years expect(LogValidation.where(validation_name: "validate_owning_org_data_given").count).to eq(2) # for both years
expect(Validation.where(validation_name: "validate_assigned_to_exists").count).to eq(2) expect(LogValidation.where(validation_name: "validate_assigned_to_exists").count).to eq(2)
any_validation = Validation.first any_validation = LogValidation.first
expect(any_validation.description).to eq("Validates the format.") expect(any_validation.description).to eq("Validates the format.")
expect(any_validation.field).to eq("ppostcode_full") expect(any_validation.field).to eq("ppostcode_full")
expect(any_validation.error_message).to eq("Enter a valid postcode") expect(any_validation.error_message).to eq("Enter a valid postcode")
@ -197,9 +197,9 @@ RSpec.describe "generate_sales_documentation" do
context "when the rake task is run" do context "when the rake task is run" do
it "creates new validation documentation records" do it "creates new validation documentation records" do
expect { task.invoke }.to change(Validation, :count) expect { task.invoke }.to change(Validation, :count)
expect(Validation.where(validation_name: "minimum").count).to be_positive expect(LogValidation.where(validation_name: "minimum").count).to be_positive
expect(Validation.where(validation_name: "range").count).to be_positive expect(LogValidation.where(validation_name: "range").count).to be_positive
any_min_validation = Validation.where(validation_name: "minimum").first any_min_validation = LogValidation.where(validation_name: "minimum").first
expect(any_min_validation.description).to include("Field value is lower than the minimum value") expect(any_min_validation.description).to include("Field value is lower than the minimum value")
expect(any_min_validation.field).not_to be_empty expect(any_min_validation.field).not_to be_empty
expect(any_min_validation.error_message).to include("must be at least") expect(any_min_validation.error_message).to include("must be at least")

Loading…
Cancel
Save