demarches-normaliennes/spec/models/drop_down_list_spec.rb

64 lines
1.6 KiB
Ruby
Raw Normal View History

2016-12-16 10:07:40 +01:00
require 'spec_helper'
describe DropDownList do
let(:dropdownlist) { create :drop_down_list, value: value }
2016-12-16 10:07:40 +01:00
describe '#options' do
let(:value) do
<<~EOS
Cohésion sociale
Dév.Eco / Emploi
Cadre de vie / Urb.
Pilotage / Ingénierie
EOS
end
2016-12-16 10:07:40 +01:00
it { expect(dropdownlist.options).to eq ['', 'Cohésion sociale', 'Dév.Eco / Emploi', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] }
2016-12-16 10:07:40 +01:00
context 'when one value is empty' do
let(:value) do
<<~EOS
Cohésion sociale
Cadre de vie / Urb.
Pilotage / Ingénierie
EOS
end
2016-12-16 10:07:40 +01:00
it { expect(dropdownlist.options).to eq ['', 'Cohésion sociale', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] }
end
end
describe 'disabled_options' do
let(:value) do
<<~EOS
tip
--top--
--troupt--
ouaich
EOS
end
it { expect(dropdownlist.disabled_options).to match(['--top--', '--troupt--']) }
end
describe 'selected_options' do
let(:dropdownlist) do
create(:drop_down_list, type_de_champ: type_de_champ)
end
context 'when multiple' do
2018-02-14 15:12:57 +01:00
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list) }
2018-02-09 17:50:10 +01:00
let(:champ) { type_de_champ.champ.build(value: '["1","2"]').decorate }
it { expect(dropdownlist.selected_options(champ)).to match(['1', '2']) }
end
context 'when simple' do
2018-02-14 15:12:57 +01:00
let(:type_de_champ) { build(:type_de_champ_drop_down_list) }
2018-02-09 17:50:10 +01:00
let(:champ) { type_de_champ.champ.build(value: '1').decorate }
it { expect(dropdownlist.selected_options(champ)).to match(['1']) }
2016-12-16 10:07:40 +01:00
end
end
end