select_multiple: add decoration for view of multiple_select
This commit is contained in:
parent
2f561a9cd0
commit
b3624256cd
2 changed files with 21 additions and 9 deletions
|
@ -2,9 +2,8 @@ class ChampDecorator < Draper::Decorator
|
|||
delegate_all
|
||||
|
||||
def value
|
||||
if type_champ == 'checkbox'
|
||||
return object.value == 'on' ? 'Oui' : 'Non'
|
||||
end
|
||||
return object.value == 'on' ? 'Oui' : 'Non' if type_champ == 'checkbox'
|
||||
return JSON.parse(object.value).join(', ') if type_champ == 'multiple_drop_down_list' && !object.value.blank?
|
||||
object.value
|
||||
end
|
||||
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe ChampDecorator do
|
||||
let(:champ) {create :champ, type_de_champ: (create :type_de_champ_public, type_champ: :checkbox)}
|
||||
let(:champ) {create :champ, type_de_champ: (create :type_de_champ_public, type_champ: type_champ)}
|
||||
let(:decorator) { champ.decorate }
|
||||
|
||||
|
||||
describe 'value' do
|
||||
subject { decorator.value }
|
||||
|
||||
context 'when type_champ is checkbox' do
|
||||
describe 'for a checkbox' do
|
||||
let(:type_champ) { :checkbox }
|
||||
|
||||
context 'when value is on' do
|
||||
before do
|
||||
champ.update value: 'on'
|
||||
end
|
||||
|
||||
before { champ.update value: 'on' }
|
||||
it { is_expected.to eq 'Oui' }
|
||||
end
|
||||
|
||||
|
@ -21,5 +20,19 @@ describe ChampDecorator do
|
|||
it { is_expected.to eq 'Non' }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'for a multiple_drop_down_list' do
|
||||
let(:type_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
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue