Merge pull request #1794 from betagouv/change_individual_birthdate_type
Individual: change birthdate column type
This commit is contained in:
commit
1bbf1fc86b
4 changed files with 8 additions and 14 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue