diff --git a/app/models/type_de_piece_justificative.rb b/app/models/type_de_piece_justificative.rb index 6ab69f5a6..9f73f59be 100644 --- a/app/models/type_de_piece_justificative.rb +++ b/app/models/type_de_piece_justificative.rb @@ -4,4 +4,6 @@ class TypeDePieceJustificative < ActiveRecord::Base belongs_to :procedure validates :libelle, presence: true, allow_blank: false, allow_nil: false + + validates_format_of :lien_demarche, with: URI::regexp end diff --git a/app/serializers/type_de_piece_justificative_serializer.rb b/app/serializers/type_de_piece_justificative_serializer.rb index 9dc1743b0..cff798508 100644 --- a/app/serializers/type_de_piece_justificative_serializer.rb +++ b/app/serializers/type_de_piece_justificative_serializer.rb @@ -2,5 +2,6 @@ class TypeDePieceJustificativeSerializer < ActiveModel::Serializer attributes :id, :libelle, :description, - :order_place -end \ No newline at end of file + :order_place, + :lien_demarche +end diff --git a/spec/models/type_de_piece_justificative_spec.rb b/spec/models/type_de_piece_justificative_spec.rb index a2b47c14e..2983e6857 100644 --- a/spec/models/type_de_piece_justificative_spec.rb +++ b/spec/models/type_de_piece_justificative_spec.rb @@ -10,6 +10,7 @@ describe TypeDePieceJustificative do it { is_expected.to have_db_column(:created_at) } it { is_expected.to have_db_column(:updated_at) } it { is_expected.to have_db_column(:order_place) } + it { is_expected.to have_db_column(:lien_demarche) } end describe 'associations' do @@ -29,5 +30,12 @@ describe TypeDePieceJustificative do # it { is_expected.not_to allow_value('').for(:order_place) } it { is_expected.to allow_value(1).for(:order_place) } end + + context 'lien_demarche' do + it { is_expected.not_to allow_value(nil).for(:lien_demarche) } + it { is_expected.not_to allow_value('').for(:lien_demarche) } + it { is_expected.not_to allow_value('not-a-link').for(:lien_demarche) } + it { is_expected.to allow_value('http://link').for(:lien_demarche) } + end end end