diff --git a/app/models/log_validation.rb b/app/models/log_validation.rb new file mode 100644 index 000000000..f818c21c2 --- /dev/null +++ b/app/models/log_validation.rb @@ -0,0 +1,2 @@ +class LogValidation < ApplicationRecord +end diff --git a/app/models/validation.rb b/app/models/validation.rb deleted file mode 100644 index 172d31ebc..000000000 --- a/app/models/validation.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Validation < ApplicationRecord -end diff --git a/app/services/documentation_generator.rb b/app/services/documentation_generator.rb index a6cde8586..f69d69b2c 100644 --- a/app/services/documentation_generator.rb +++ b/app/services/documentation_generator.rb @@ -13,7 +13,7 @@ class DocumentationGenerator form = FormHandler.instance.forms["current_#{log_type}"] 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") next 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) 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}") next 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) result["cases"].each do |case_info| case_info["errors"].each do |error| - Validation.create!(log_type:, + LogValidation.create!(log_type:, validation_name: meth.to_s, description: result["description"], 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 = [error["field"]] if error_fields.empty? error_fields.each do |error_field| - Validation.create!(log_type:, + LogValidation.create!(log_type:, validation_name: meth.to_s, description: result["description"], field: error_field, @@ -333,7 +333,7 @@ Look at these helper methods where needed to understand what is being checked in return 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}") return 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") 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, description: result["description"], field: page_the_validation_applied_to.questions.first.id, diff --git a/db/migrate/20240529133005_rename_validations_table.rb b/db/migrate/20240529133005_rename_validations_table.rb new file mode 100644 index 000000000..7ea6227f4 --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index 259d37297..1430da65f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # 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 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" 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| t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" } 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 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| t.string "item_type", limit: 191, null: false t.bigint "item_id", null: false diff --git a/lib/tasks/generate_lettings_documentation.rake b/lib/tasks/generate_lettings_documentation.rake index 42dc865dd..5ffb0dabd 100644 --- a/lib/tasks/generate_lettings_documentation.rake +++ b/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" 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}") next end - Validation.create!(log_type: "lettings", + LogValidation.create!(log_type: "lettings", validation_name:, description: validation_description, field:, diff --git a/spec/lib/tasks/generate_lettings_documentation_spec.rb b/spec/lib/tasks/generate_lettings_documentation_spec.rb index c494fd0e5..9434dcfcd 100644 --- a/spec/lib/tasks/generate_lettings_documentation_spec.rb +++ b/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 expect(Rails.logger).to receive(:info).with(/described/).at_least(:once) expect { task.invoke }.to change(Validation, :count) - expect(Validation.where(validation_name: "validate_numeric_min_max").count).to eq(1) - expect(Validation.where(validation_name: "validate_layear").count).to eq(1) - any_validation = Validation.first + expect(LogValidation.where(validation_name: "validate_numeric_min_max").count).to eq(1) + expect(LogValidation.where(validation_name: "validate_layear").count).to eq(1) + any_validation = LogValidation.first expect(any_validation.description).to eq("Validates the format.") expect(any_validation.field).to eq("ppostcode_full") 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 it "creates new validation documentation records" do expect { task.invoke }.to change(Validation, :count) - expect(Validation.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 - any_validation = Validation.first + expect(LogValidation.where(validation_name: "rent_in_soft_min_range?").count).to be_positive + expect(LogValidation.where(validation_name: "major_repairs_date_in_soft_range?").count).to be_positive + any_validation = LogValidation.first expect(any_validation.description).to eq("Validates the format.") expect(any_validation.field).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 expect(Rails.logger).to receive(:info).with(/described/).at_least(:once) expect { task.invoke }.to change(Validation, :count) - expect(Validation.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) - any_validation = Validation.first + expect(LogValidation.where(validation_name: "validate_needs_type_present").count).to eq(2) # for both years + expect(LogValidation.where(validation_name: "validate_data_types").count).to eq(2) + any_validation = LogValidation.first expect(any_validation.description).to eq("Validates the format.") expect(any_validation.field).to eq("ppostcode_full") 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 it "creates new validation documentation records" do expect { task.invoke }.to change(Validation, :count) - expect(Validation.where(validation_name: "minimum").count).to be_positive - expect(Validation.where(validation_name: "range").count).to be_positive - any_min_validation = Validation.where(validation_name: "minimum").first + expect(LogValidation.where(validation_name: "minimum").count).to be_positive + expect(LogValidation.where(validation_name: "range").count).to be_positive + 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.field).not_to be_empty expect(any_min_validation.error_message).to include("must be at least") diff --git a/spec/lib/tasks/generate_sales_documentation_spec.rb b/spec/lib/tasks/generate_sales_documentation_spec.rb index 010ffbe4f..cd9bff037 100644 --- a/spec/lib/tasks/generate_sales_documentation_spec.rb +++ b/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 expect(Rails.logger).to receive(:info).with(/described/).at_least(:once) expect { task.invoke }.to change(Validation, :count) - expect(Validation.where(validation_name: "validate_saledate_collection_year").count).to eq(1) - expect(Validation.where(validation_name: "validate_partner_count").count).to eq(1) - any_validation = Validation.first + expect(LogValidation.where(validation_name: "validate_saledate_collection_year").count).to eq(1) + expect(LogValidation.where(validation_name: "validate_partner_count").count).to eq(1) + any_validation = LogValidation.first expect(any_validation.description).to eq("Validates the format.") expect(any_validation.field).to eq("ppostcode_full") 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 it "creates new validation documentation records" do expect { task.invoke }.to change(Validation, :count) - expect(Validation.where(validation_name: "income2_under_soft_min?").count).to be_positive - expect(Validation.where(validation_name: "deposit_over_soft_max?").count).to be_positive - any_validation = Validation.first + expect(LogValidation.where(validation_name: "income2_under_soft_min?").count).to be_positive + expect(LogValidation.where(validation_name: "deposit_over_soft_max?").count).to be_positive + any_validation = LogValidation.first expect(any_validation.description).to eq("Validates the format.") expect(any_validation.field).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 expect(Rails.logger).to receive(:info).with(/described/).at_least(:once) 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(Validation.where(validation_name: "validate_assigned_to_exists").count).to eq(2) - any_validation = Validation.first + expect(LogValidation.where(validation_name: "validate_owning_org_data_given").count).to eq(2) # for both years + expect(LogValidation.where(validation_name: "validate_assigned_to_exists").count).to eq(2) + any_validation = LogValidation.first expect(any_validation.description).to eq("Validates the format.") expect(any_validation.field).to eq("ppostcode_full") 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 it "creates new validation documentation records" do expect { task.invoke }.to change(Validation, :count) - expect(Validation.where(validation_name: "minimum").count).to be_positive - expect(Validation.where(validation_name: "range").count).to be_positive - any_min_validation = Validation.where(validation_name: "minimum").first + expect(LogValidation.where(validation_name: "minimum").count).to be_positive + expect(LogValidation.where(validation_name: "range").count).to be_positive + 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.field).not_to be_empty expect(any_min_validation.error_message).to include("must be at least")