Merge pull request #1422 from tchak/cleanup
Cleanup some specs and properties delegates
This commit is contained in:
commit
c38eab4c95
21 changed files with 36 additions and 47 deletions
|
@ -5,7 +5,7 @@ class Champ < ActiveRecord::Base
|
||||||
belongs_to :type_de_champ, inverse_of: :champ
|
belongs_to :type_de_champ, inverse_of: :champ
|
||||||
has_many :commentaires
|
has_many :commentaires
|
||||||
|
|
||||||
delegate :libelle, :type_champ, :order_place, :mandatory, :description, :drop_down_list, to: :type_de_champ
|
delegate :libelle, :type_champ, :order_place, :mandatory?, :description, :drop_down_list, to: :type_de_champ
|
||||||
|
|
||||||
before_save :format_date_to_iso, if: Proc.new { type_champ == 'date' }
|
before_save :format_date_to_iso, if: Proc.new { type_champ == 'date' }
|
||||||
before_save :format_datetime, if: Proc.new { type_champ == 'datetime' }
|
before_save :format_datetime, if: Proc.new { type_champ == 'datetime' }
|
||||||
|
@ -15,10 +15,6 @@ class Champ < ActiveRecord::Base
|
||||||
scope :public_only, -> { where.not(type: 'ChampPrivate').or(where(private: [false, nil])) }
|
scope :public_only, -> { where.not(type: 'ChampPrivate').or(where(private: [false, nil])) }
|
||||||
scope :private_only, -> { where(type: 'ChampPrivate').or(where(private: true)) }
|
scope :private_only, -> { where(type: 'ChampPrivate').or(where(private: true)) }
|
||||||
|
|
||||||
def mandatory?
|
|
||||||
mandatory
|
|
||||||
end
|
|
||||||
|
|
||||||
def public?
|
def public?
|
||||||
!private?
|
!private?
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,13 +52,16 @@ class TypeDeChamp < ActiveRecord::Base
|
||||||
type_champs.map { |champ| [I18n.t("activerecord.attributes.type_de_champ.type_champs.#{champ.last}"), champ.first] }
|
type_champs.map { |champ| [I18n.t("activerecord.attributes.type_de_champ.type_champs.#{champ.last}"), champ.first] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def field_for_list?
|
def check_mandatory
|
||||||
!(type_champ == 'textarea' || type_champ == 'header_section')
|
if non_fillable?
|
||||||
|
self.mandatory = false
|
||||||
|
else
|
||||||
|
true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_mandatory
|
def non_fillable?
|
||||||
self.mandatory = false if %w(header_section explication).include?(self.type_champ)
|
type_champ.in?(['header_section', 'explication'])
|
||||||
true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def private?
|
def private?
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
= form.text_field :value,
|
= form.text_field :value,
|
||||||
'data-address': 'true',
|
'data-address': 'true',
|
||||||
placeholder: champ.libelle,
|
placeholder: champ.libelle,
|
||||||
required: champ.mandatory
|
required: champ.mandatory?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
= form.label :value do
|
= form.label :value do
|
||||||
#{champ.libelle}
|
#{champ.libelle}
|
||||||
- if champ.mandatory
|
- if champ.mandatory?
|
||||||
%span.mandatory *
|
%span.mandatory *
|
||||||
|
|
||||||
- if champ.updated_at.present?
|
- if champ.updated_at.present?
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
= form.check_box :value,
|
= form.check_box :value,
|
||||||
{ required: champ.mandatory },
|
{ required: champ.mandatory? },
|
||||||
'on',
|
'on',
|
||||||
'off'
|
'off'
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
= form.date_field :value,
|
= form.date_field :value,
|
||||||
value: champ.value,
|
value: champ.value,
|
||||||
placeholder: 'JJ/MM/AAAA',
|
placeholder: 'JJ/MM/AAAA',
|
||||||
required: champ.mandatory
|
required: champ.mandatory?
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
= form.select :value,
|
= form.select :value,
|
||||||
Champ.departements,
|
Champ.departements,
|
||||||
required: champ.mandatory
|
required: champ.mandatory?
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
placeholder: "Numéro de dossier",
|
placeholder: "Numéro de dossier",
|
||||||
autocomplete: 'off',
|
autocomplete: 'off',
|
||||||
'data-type': 'dossier-link',
|
'data-type': 'dossier-link',
|
||||||
required: champ.mandatory
|
required: champ.mandatory?
|
||||||
|
|
||||||
.help-block
|
.help-block
|
||||||
%p.text-info{ style: show_text_summary ? nil : 'display: none;' }
|
%p.text-info{ style: show_text_summary ? nil : 'display: none;' }
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
= form.select :value,
|
= form.select :value,
|
||||||
champ.drop_down_list.options,
|
champ.drop_down_list.options,
|
||||||
disabled: champ.drop_down_list.disabled_options,
|
disabled: champ.drop_down_list.disabled_options,
|
||||||
required: champ.mandatory
|
required: champ.mandatory?
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
= form.email_field :value,
|
= form.email_field :value,
|
||||||
placeholder: champ.libelle,
|
placeholder: champ.libelle,
|
||||||
required: champ.mandatory
|
required: champ.mandatory?
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
= form.check_box :value,
|
= form.check_box :value,
|
||||||
{ required: champ.mandatory },
|
{ required: champ.mandatory? },
|
||||||
'on',
|
'on',
|
||||||
'off'
|
'off'
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
= form.number_field :value,
|
= form.number_field :value,
|
||||||
placeholder: champ.libelle,
|
placeholder: champ.libelle,
|
||||||
required: champ.mandatory
|
required: champ.mandatory?
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
= form.select :value,
|
= form.select :value,
|
||||||
Champ.pays,
|
Champ.pays,
|
||||||
required: champ.mandatory
|
required: champ.mandatory?
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
= form.phone_field :value,
|
= form.phone_field :value,
|
||||||
placeholder: champ.libelle,
|
placeholder: champ.libelle,
|
||||||
required: champ.mandatory
|
required: champ.mandatory?
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
= form.select :value,
|
= form.select :value,
|
||||||
Champ.regions,
|
Champ.regions,
|
||||||
required: champ.mandatory
|
required: champ.mandatory?
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
= form.text_field :value,
|
= form.text_field :value,
|
||||||
placeholder: champ.libelle,
|
placeholder: champ.libelle,
|
||||||
required: champ.mandatory
|
required: champ.mandatory?
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
~ form.text_area :value,
|
~ form.text_area :value,
|
||||||
row: 6,
|
row: 6,
|
||||||
placeholder: champ.description,
|
placeholder: champ.description,
|
||||||
required: champ.mandatory,
|
required: champ.mandatory?,
|
||||||
value: html_to_string(champ.value)
|
value: html_to_string(champ.value)
|
||||||
|
|
|
@ -47,16 +47,16 @@ describe DropDownList do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when multiple' do
|
context 'when multiple' do
|
||||||
let(:type_de_champ) { TypeDeChamp.new(type_champ: 'multiple_drop_down_list') }
|
let(:type_de_champ) { build(:type_de_champ_public, type_champ: 'multiple_drop_down_list') }
|
||||||
|
let(:champ) { type_de_champ.champ.build(value: '["1","2"]').decorate }
|
||||||
|
|
||||||
let(:champ) { Champ.new(value: '["1","2"]').decorate }
|
|
||||||
it { expect(dropdownlist.selected_options(champ)).to match(['1', '2']) }
|
it { expect(dropdownlist.selected_options(champ)).to match(['1', '2']) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when simple' do
|
context 'when simple' do
|
||||||
let(:type_de_champ) { TypeDeChamp.new(type_champ: 'drop_down_list') }
|
let(:type_de_champ) { build(:type_de_champ_public, type_champ: 'drop_down_list') }
|
||||||
|
let(:champ) { type_de_champ.champ.build(value: '1').decorate }
|
||||||
|
|
||||||
let(:champ) { Champ.new(value: '1').decorate }
|
|
||||||
it { expect(dropdownlist.selected_options(champ)).to match(['1']) }
|
it { expect(dropdownlist.selected_options(champ)).to match(['1']) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,14 +29,4 @@ shared_examples 'type_de_champ_spec' do
|
||||||
it { is_expected.to allow_value('blabla').for(:description) }
|
it { is_expected.to allow_value('blabla').for(:description) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'field_for_list?' do
|
|
||||||
let(:type_de_champ_yes) { create :type_de_champ_public, type_champ: 'text' }
|
|
||||||
let(:type_de_champ_no_1) { create :type_de_champ_public, type_champ: 'textarea' }
|
|
||||||
let(:type_de_champ_no_2) { create :type_de_champ_public, type_champ: 'header_section' }
|
|
||||||
|
|
||||||
it { expect(type_de_champ_yes.field_for_list?).to be_truthy }
|
|
||||||
it { expect(type_de_champ_no_1.field_for_list?).to be_falsey }
|
|
||||||
it { expect(type_de_champ_no_2.field_for_list?).to be_falsey }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe ChampsService do
|
describe ChampsService do
|
||||||
let!(:champ) { Champ.create(value: 'toto', type_de_champ: TypeDeChamp.new) }
|
let(:type_de_champ) { create(:type_de_champ_public) }
|
||||||
let!(:champ_mandatory_empty) { Champ.create(type_de_champ: TypeDeChamp.new(libelle: 'mandatory', mandatory: true)) }
|
let(:type_de_champ_mandatory) { create(:type_de_champ_public, libelle: 'mandatory', mandatory: true) }
|
||||||
let!(:champ_datetime) do
|
let(:type_de_champ_datetime) { create(:type_de_champ_public, type_champ: :datetime) }
|
||||||
champ_datetime = TypeDeChamp.new(type_champ: 'datetime')
|
let!(:champ) { type_de_champ.champ.create(value: 'toto') }
|
||||||
Champ.create(type_de_champ: champ_datetime)
|
let!(:champ_mandatory_empty) { type_de_champ_mandatory.champ.create }
|
||||||
end
|
let!(:champ_datetime) { type_de_champ_datetime.champ.create }
|
||||||
let!(:champs) { [champ, champ_mandatory_empty, champ_datetime] }
|
let!(:champs) { [champ, champ_mandatory_empty, champ_datetime] }
|
||||||
|
|
||||||
describe 'save_champs' do
|
describe 'save_champs' do
|
||||||
|
|
|
@ -13,7 +13,7 @@ describe 'new_gestionnaire/dossiers/champs.html.haml', type: :view do
|
||||||
context "there are some champs" do
|
context "there are some champs" do
|
||||||
let(:dossier) { create(:dossier) }
|
let(:dossier) { create(:dossier) }
|
||||||
let(:avis) { create :avis, dossier: dossier, gestionnaire: gestionnaire }
|
let(:avis) { create :avis, dossier: dossier, gestionnaire: gestionnaire }
|
||||||
let(:champ1) { create(:champ, :checkbox, value: "true") }
|
let(:champ1) { create(:champ, :checkbox, value: "on") }
|
||||||
let(:champ2) { create(:champ, :header_section, value: "Section") }
|
let(:champ2) { create(:champ, :header_section, value: "Section") }
|
||||||
let(:champ3) { create(:champ, :explication, value: "mazette") }
|
let(:champ3) { create(:champ, :explication, value: "mazette") }
|
||||||
let(:champ4) { create(:champ, :dossier_link, value: dossier.id) }
|
let(:champ4) { create(:champ, :dossier_link, value: dossier.id) }
|
||||||
|
@ -53,7 +53,7 @@ describe 'new_gestionnaire/dossiers/champs.html.haml', type: :view do
|
||||||
|
|
||||||
context "with seen_at" do
|
context "with seen_at" do
|
||||||
let(:dossier) { create(:dossier) }
|
let(:dossier) { create(:dossier) }
|
||||||
let(:champ1) { create(:champ, :checkbox, value: "true") }
|
let(:champ1) { create(:champ, :checkbox, value: "on") }
|
||||||
let(:champs) { [champ1] }
|
let(:champs) { [champ1] }
|
||||||
|
|
||||||
context "with a demande_seen_at after champ updated_at" do
|
context "with a demande_seen_at after champ updated_at" do
|
||||||
|
|
Loading…
Reference in a new issue