Remove the now useless #formatted_value method
This commit is contained in:
parent
c00aac2f80
commit
f5a31be36a
3 changed files with 1 additions and 82 deletions
|
@ -9,21 +9,4 @@ module ChampHelper
|
||||||
raw(champ.to_render_data.to_json)
|
raw(champ.to_render_data.to_json)
|
||||||
# rubocop:enable Rails/OutputSafety
|
# rubocop:enable Rails/OutputSafety
|
||||||
end
|
end
|
||||||
|
|
||||||
def formatted_value(champ)
|
|
||||||
value = champ.value
|
|
||||||
type = champ.type_champ
|
|
||||||
|
|
||||||
if type == TypeDeChamp.type_champs.fetch(:date)
|
|
||||||
champ.to_s
|
|
||||||
elsif type.in? [TypeDeChamp.type_champs.fetch(:checkbox), TypeDeChamp.type_champs.fetch(:engagement)]
|
|
||||||
champ.to_s
|
|
||||||
elsif type == TypeDeChamp.type_champs.fetch(:yes_no)
|
|
||||||
champ.to_s
|
|
||||||
elsif type == TypeDeChamp.type_champs.fetch(:multiple_drop_down_list)
|
|
||||||
champ.to_s
|
|
||||||
else
|
|
||||||
value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
%tbody
|
%tbody
|
||||||
- champs.reject(&:exclude_from_view?).each do |c|
|
- champs.reject(&:exclude_from_view?).each do |c|
|
||||||
%tr
|
%tr
|
||||||
- value = formatted_value(c)
|
- value = c.to_s
|
||||||
- case c.type_champ
|
- case c.type_champ
|
||||||
- when TypeDeChamp.type_champs.fetch(:header_section)
|
- when TypeDeChamp.type_champs.fetch(:header_section)
|
||||||
%th.header-section{ colspan: 3 }
|
%th.header-section{ colspan: 3 }
|
||||||
|
|
|
@ -1,64 +0,0 @@
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe ChampHelper, type: :helper do
|
|
||||||
let(:type_de_champ) { create(:type_de_champ) }
|
|
||||||
let(:champ) { type_de_champ.champ.create }
|
|
||||||
|
|
||||||
describe '.formatted_value' do
|
|
||||||
subject { formatted_value(champ) }
|
|
||||||
|
|
||||||
describe 'for a checkbox' do
|
|
||||||
let(:type_de_champ) { create(:type_de_champ_checkbox) }
|
|
||||||
|
|
||||||
context 'when value is on' do
|
|
||||||
before { champ.update value: 'on' }
|
|
||||||
it { is_expected.to eq 'Oui' }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when value is other' do
|
|
||||||
it { is_expected.to eq 'Non' }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'for a engagement' do
|
|
||||||
let(:type_de_champ) { create(:type_de_champ_engagement) }
|
|
||||||
|
|
||||||
context 'when value is on' do
|
|
||||||
before { champ.update value: 'on' }
|
|
||||||
it { is_expected.to eq 'Oui' }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when value is other' do
|
|
||||||
it { is_expected.to eq 'Non' }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'for a multiple_drop_down_list' do
|
|
||||||
let(:type_de_champ) { create(:type_de_champ_multiple_drop_down_list) }
|
|
||||||
|
|
||||||
context 'when value is an array' do
|
|
||||||
before { champ.update value: '["1", "2"]' }
|
|
||||||
it { is_expected.to eq '1, 2' }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when value is empty' do
|
|
||||||
before { champ.update value: '' }
|
|
||||||
it { is_expected.to eq '' }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "for a date" do
|
|
||||||
let(:type_de_champ) { create(:type_de_champ_date) }
|
|
||||||
|
|
||||||
context "when value is an ISO date" do
|
|
||||||
before { champ.update value: "2017-12-31" }
|
|
||||||
it { is_expected.to eq "31/12/2017" }
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when value is empty" do
|
|
||||||
before { champ.update value: nil }
|
|
||||||
it { is_expected.to eq nil }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Add table
Add a link
Reference in a new issue