Add administrateur#feature_enabled? method

This commit is contained in:
Paul Chavard 2018-03-27 15:43:59 +02:00
parent d1b3530da0
commit 322f93afbe
3 changed files with 18 additions and 1 deletions

View file

@ -2,7 +2,7 @@ module TypeDeChampHelper
def tdc_options(current_administrateur)
tdcs = TypeDeChamp.type_de_champs_list_fr
if !current_administrateur.id.in?(Features.champ_pj_allowed_for_admin_ids)
if !current_administrateur.feature_enabled?(:champ_pj_allowed)
tdcs.reject! { |tdc| tdc.last == "piece_justificative" }
end

View file

@ -73,6 +73,11 @@ class Administrateur < ApplicationRecord
administrateur
end
def feature_enabled?(feature)
ids = Features.send(:"#{feature}_for_admin_ids")
ids.present? ? id.in?(ids) : false
end
private
def generate_api_token

View file

@ -66,4 +66,16 @@ describe Administrateur, type: :model do
it { expect(Administrateur.reset_password('123', '12345678').errors).not_to be_empty }
it { expect(Administrateur.reset_password(reset_password_token, '').errors).not_to be_empty }
end
describe '#feature_enabled?' do
let(:administrateur) { create(:administrateur) }
before do
allow(Features).to receive(:champ_pj_allowed_for_admin_ids)
.and_return([administrateur.id])
end
it { expect(administrateur.feature_enabled?(:yolo)).to be_falsey }
it { expect(administrateur.feature_enabled?(:champ_pj_allowed)).to be_truthy }
end
end