Move types_de_champ helper to service

This commit is contained in:
Paul Chavard 2018-11-06 14:59:31 +01:00
parent 2d647f9fa7
commit 1c87eda6e1
4 changed files with 40 additions and 44 deletions

View file

@ -1,19 +0,0 @@
module TypeDeChampHelper
TOGGLES = {
TypeDeChamp.type_champs.fetch(:piece_justificative) => :champ_pj?,
TypeDeChamp.type_champs.fetch(:siret) => :champ_siret?,
TypeDeChamp.type_champs.fetch(:linked_drop_down_list) => :champ_linked_dropdown?,
TypeDeChamp.type_champs.fetch(:integer_number) => :champ_integer_number?
}
def tdc_options
tdcs = TypeDeChamp.type_de_champs_list_fr
tdcs.select! do |tdc|
toggle = TOGGLES[tdc.last]
toggle.blank? || Flipflop.send(toggle)
end
tdcs
end
end

View file

@ -1,6 +1,24 @@
class TypesDeChampService
include Rails.application.routes.url_helpers
TOGGLES = {
TypeDeChamp.type_champs.fetch(:piece_justificative) => :champ_pj?,
TypeDeChamp.type_champs.fetch(:siret) => :champ_siret?,
TypeDeChamp.type_champs.fetch(:linked_drop_down_list) => :champ_linked_dropdown?,
TypeDeChamp.type_champs.fetch(:integer_number) => :champ_integer_number?
}
def options
types_de_champ = TypeDeChamp.type_de_champs_list_fr
types_de_champ.select! do |tdc|
toggle = TOGGLES[tdc.last]
toggle.blank? || Flipflop.send(toggle)
end
types_de_champ
end
def initialize(procedure, private_type_de_champ = false)
@procedure = procedure
@private_type_de_champ = private_type_de_champ

View file

@ -1,25 +0,0 @@
require 'rails_helper'
RSpec.describe TypeDeChampHelper, type: :helper do
describe ".tdc_options" do
let(:pj_option) { ["Pièce justificative", TypeDeChamp.type_champs.fetch(:piece_justificative)] }
subject { tdc_options }
context "when the champ_pj is enabled" do
before do
Flipflop::FeatureSet.current.test!.switch!(:champ_pj, true)
end
it { is_expected.to include(pj_option) }
end
context "when the champ_pj is disabled" do
before do
Flipflop::FeatureSet.current.test!.switch!(:champ_pj, false)
end
it { is_expected.not_to include(pj_option) }
end
end
end

View file

@ -101,4 +101,26 @@ describe TypesDeChampService do
end
end
end
describe ".options" do
let(:pj_option) { ["Pièce justificative", TypeDeChamp.type_champs.fetch(:piece_justificative)] }
subject { service.options }
context "when the champ_pj is enabled" do
before do
Flipflop::FeatureSet.current.test!.switch!(:champ_pj, true)
end
it { is_expected.to include(pj_option) }
end
context "when the champ_pj is disabled" do
before do
Flipflop::FeatureSet.current.test!.switch!(:champ_pj, false)
end
it { is_expected.not_to include(pj_option) }
end
end
end