From 155ffcb4baaf665c37e34d6bbd844bec960a3c20 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 4 Apr 2018 13:49:52 +0200 Subject: [PATCH 1/2] Individual: change birthdate column type --- .../20180404113409_change_birthdate_type_from_individual.rb | 6 ++++++ db/schema.rb | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20180404113409_change_birthdate_type_from_individual.rb diff --git a/db/migrate/20180404113409_change_birthdate_type_from_individual.rb b/db/migrate/20180404113409_change_birthdate_type_from_individual.rb new file mode 100644 index 000000000..0b0e750ec --- /dev/null +++ b/db/migrate/20180404113409_change_birthdate_type_from_individual.rb @@ -0,0 +1,6 @@ +class ChangeBirthdateTypeFromIndividual < ActiveRecord::Migration[5.2] + def up + remove_column :individuals, :birthdate, :string + rename_column :individuals, :second_birthdate, :birthdate + end +end diff --git a/db/schema.rb b/db/schema.rb index 303a660fd..51e42562f 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.define(version: 2018_04_03_094135) do +ActiveRecord::Schema.define(version: 2018_04_04_113409) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -361,12 +361,11 @@ ActiveRecord::Schema.define(version: 2018_04_03_094135) do create_table "individuals", id: :serial, force: :cascade do |t| t.string "nom" t.string "prenom" - t.string "birthdate" t.integer "dossier_id" t.string "gender" t.datetime "created_at" t.datetime "updated_at" - t.date "second_birthdate" + t.date "birthdate" t.index ["dossier_id"], name: "index_individuals_on_dossier_id" end From 3c8d1f13b64cf3f95b7f060b5ff3e44ca140e735 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 4 Apr 2018 15:27:30 +0200 Subject: [PATCH 2/2] Individual: remove birthdate proxy --- app/models/individual.rb | 8 -------- spec/models/individual_spec.rb | 3 --- 2 files changed, 11 deletions(-) diff --git a/app/models/individual.rb b/app/models/individual.rb index 5e3fd2ea6..8ab792ab4 100644 --- a/app/models/individual.rb +++ b/app/models/individual.rb @@ -5,12 +5,4 @@ class Individual < ApplicationRecord validates :gender, presence: true, allow_nil: false, on: :update validates :nom, presence: true, allow_blank: false, allow_nil: false, on: :update validates :prenom, presence: true, allow_blank: false, allow_nil: false, on: :update - - def birthdate - second_birthdate - end - - def birthdate=(date) - self.second_birthdate = date - end end diff --git a/spec/models/individual_spec.rb b/spec/models/individual_spec.rb index 6b11324f1..41c7b5a2f 100644 --- a/spec/models/individual_spec.rb +++ b/spec/models/individual_spec.rb @@ -21,21 +21,18 @@ describe Individual do let(:birthdate_from_user) { "12/11/1980" } it { expect(individual.birthdate).to eq(Date.new(1980, 11, 12)) } - it { expect(individual.second_birthdate).to eq(Date.new(1980, 11, 12)) } end context "and the format is ISO" do let(:birthdate_from_user) { "1980-11-12" } it { expect(individual.birthdate).to eq(Date.new(1980, 11, 12)) } - it { expect(individual.second_birthdate).to eq(Date.new(1980, 11, 12)) } end context "and the format is WTF" do let(:birthdate_from_user) { "1980 1 12" } it { expect(individual.birthdate).to be_nil } - it { expect(individual.second_birthdate).to be_nil } end end end