Merge pull request #1794 from betagouv/change_individual_birthdate_type

Individual: change birthdate column type
This commit is contained in:
LeSim 2018-04-04 16:05:52 +02:00 committed by GitHub
commit 1bbf1fc86b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 14 deletions

View file

@ -5,12 +5,4 @@ class Individual < ApplicationRecord
validates :gender, presence: true, allow_nil: false, on: :update validates :gender, presence: true, allow_nil: false, on: :update
validates :nom, presence: true, allow_blank: false, 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 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 end

View file

@ -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

View file

@ -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.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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" 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| create_table "individuals", id: :serial, force: :cascade do |t|
t.string "nom" t.string "nom"
t.string "prenom" t.string "prenom"
t.string "birthdate"
t.integer "dossier_id" t.integer "dossier_id"
t.string "gender" t.string "gender"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.date "second_birthdate" t.date "birthdate"
t.index ["dossier_id"], name: "index_individuals_on_dossier_id" t.index ["dossier_id"], name: "index_individuals_on_dossier_id"
end end

View file

@ -21,21 +21,18 @@ describe Individual do
let(:birthdate_from_user) { "12/11/1980" } let(:birthdate_from_user) { "12/11/1980" }
it { expect(individual.birthdate).to eq(Date.new(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 end
context "and the format is ISO" do context "and the format is ISO" do
let(:birthdate_from_user) { "1980-11-12" } let(:birthdate_from_user) { "1980-11-12" }
it { expect(individual.birthdate).to eq(Date.new(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 end
context "and the format is WTF" do context "and the format is WTF" do
let(:birthdate_from_user) { "1980 1 12" } let(:birthdate_from_user) { "1980 1 12" }
it { expect(individual.birthdate).to be_nil } it { expect(individual.birthdate).to be_nil }
it { expect(individual.second_birthdate).to be_nil }
end end
end end
end end