From e4562a10e6073b0928f15247ea23eee862c8b6e6 Mon Sep 17 00:00:00 2001 From: tnicolas1 Date: Tue, 26 Nov 2024 15:10:58 +0100 Subject: [PATCH] Suppression de l'attribut 'asp_file_reference' de 'Student' --- app/models/student.rb | 20 ------------ ...add_administrative_number_to_schoolings.rb | 1 - ...remove_asp_file_reference_from_students.rb | 7 +++++ db/schema.rb | 4 +-- spec/models/schooling_spec.rb | 2 +- spec/models/student_spec.rb | 31 ------------------- 6 files changed, 9 insertions(+), 56 deletions(-) create mode 100644 db/migrate/20241126140427_remove_asp_file_reference_from_students.rb diff --git a/app/models/student.rb b/app/models/student.rb index 1bf3997a3..918a72d12 100644 --- a/app/models/student.rb +++ b/app/models/student.rb @@ -5,10 +5,8 @@ class Student < ApplicationRecord # rubocop:disable Metrics/ClassLength :first_name, :last_name, :birthdate, - :asp_file_reference, presence: true - validates :asp_file_reference, uniqueness: true validates :address_city_insee_code, length: { maximum: 5 }, allow_blank: true enum :biological_sex, { sex_unknown: 0, male: 1, female: 2 }, validate: { allow_nil: true }, default: :sex_unknown @@ -85,8 +83,6 @@ def self.asp_ready .with_valid_address end - before_validation :check_asp_file_reference - def lives_in_france? InseeCodes.in_france?(address_country_code) rescue InseeCountryCodeMapper::UnusableCountryCode @@ -159,20 +155,4 @@ def retry_pfmps_payment_requests!(reasons) def unsyncable? ine_not_found || current_schooling&.removed? || establishment.blank? end - - private - - def check_asp_file_reference - return if asp_file_reference.present? - - loop do - self.asp_file_reference = generate_asp_file_reference - - break unless Student.exists?(asp_file_reference: asp_file_reference) - end - end - - def generate_asp_file_reference - SecureRandom.alphanumeric(10).upcase - end end diff --git a/db/migrate/20240219100348_add_administrative_number_to_schoolings.rb b/db/migrate/20240219100348_add_administrative_number_to_schoolings.rb index 63d706ef5..7b6232ceb 100644 --- a/db/migrate/20240219100348_add_administrative_number_to_schoolings.rb +++ b/db/migrate/20240219100348_add_administrative_number_to_schoolings.rb @@ -8,7 +8,6 @@ def migrate_single_attributive_decision! .merge(Schooling.with_attributive_decisions) .group(:id) .having("count(schoolings.id) = 1") - .pluck(:id, :asp_file_reference) .to_h Schooling diff --git a/db/migrate/20241126140427_remove_asp_file_reference_from_students.rb b/db/migrate/20241126140427_remove_asp_file_reference_from_students.rb new file mode 100644 index 000000000..e6ae8a56f --- /dev/null +++ b/db/migrate/20241126140427_remove_asp_file_reference_from_students.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class RemoveASPFileReferenceFromStudents < ActiveRecord::Migration[7.2] + def change + remove_column :students, :asp_file_reference, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index d557957db..79128eebc 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.2].define(version: 2024_11_06_195543) do +ActiveRecord::Schema[7.2].define(version: 2024_11_26_140427) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -256,7 +256,6 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.date "birthdate", null: false - t.string "asp_file_reference", null: false t.string "address_line1" t.string "address_line2" t.string "address_postal_code" @@ -268,7 +267,6 @@ t.integer "biological_sex", default: 0 t.string "asp_individu_id" t.boolean "ine_not_found", default: false, null: false - t.index ["asp_file_reference"], name: "index_students_on_asp_file_reference", unique: true t.index ["asp_individu_id"], name: "index_students_on_asp_individu_id", unique: true t.index ["ine"], name: "index_students_on_ine", unique: true end diff --git a/spec/models/schooling_spec.rb b/spec/models/schooling_spec.rb index 904e708f0..3ca8ccbbe 100644 --- a/spec/models/schooling_spec.rb +++ b/spec/models/schooling_spec.rb @@ -191,7 +191,7 @@ before do schooling.classe.update!(label: "1ERE APEX TEST") - schooling.student.update!(first_name: "Jeanne", last_name: "DUPONT", asp_file_reference: "ref123") + schooling.student.update!(first_name: "Jeanne", last_name: "DUPONT") end it "creates a sane filename" do diff --git a/spec/models/student_spec.rb b/spec/models/student_spec.rb index 8bb69ec42..abc60322c 100644 --- a/spec/models/student_spec.rb +++ b/spec/models/student_spec.rb @@ -13,7 +13,6 @@ it { is_expected.to validate_presence_of(:last_name) } it { is_expected.to validate_presence_of(:birthdate) } it { is_expected.to validate_presence_of(:ine) } - it { is_expected.to validate_uniqueness_of(:asp_file_reference) } describe "#rib" do subject(:student) { classe.students.first } @@ -52,36 +51,6 @@ end end - describe "asp_file_reference" do - subject(:student) { build(:student, asp_file_reference: nil) } - - it "is generated before_save" do - expect { student.save! }.to change(student, :asp_file_reference) - end - - # rubocop:disable RSpec/SubjectStub - context "when there is a collision" do - let(:used_values) { %w[A B C] } - - before do - used_values.each { |value| create(:student, asp_file_reference: value) } - - allow(student) - .to receive(:generate_asp_file_reference) - .and_return(*used_values, "D") - end - - it "tries until it is unique" do - student.save! - - expect(student) - .to have_received(:generate_asp_file_reference) - .exactly(4).times - end - end - # rubocop:enable RSpec/SubjectStub - end - describe "current_schooling" do subject(:current_schooling) { student.reload.current_schooling }