From 21dc35215e3c6d8f4b0dac975b846203b0698909 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Fri, 16 Dec 2016 10:07:40 +0100 Subject: [PATCH] Add test for DropDownList model --- spec/factories/drop_down_list.rb | 5 +++++ spec/models/drop_down_list_spec.rb | 32 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 spec/factories/drop_down_list.rb create mode 100644 spec/models/drop_down_list_spec.rb diff --git a/spec/factories/drop_down_list.rb b/spec/factories/drop_down_list.rb new file mode 100644 index 000000000..6b81511cf --- /dev/null +++ b/spec/factories/drop_down_list.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :drop_down_list do + value '' + end +end diff --git a/spec/models/drop_down_list_spec.rb b/spec/models/drop_down_list_spec.rb new file mode 100644 index 000000000..523ab2ae1 --- /dev/null +++ b/spec/models/drop_down_list_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe DropDownList do + describe 'database columns' do + it { is_expected.to have_db_column(:value) } + end + + describe 'associations' do + it { is_expected.to belong_to(:type_de_champ) } + end + + describe '#options' do + let(:value) { "Cohésion sociale +Dév.Eco / Emploi +Cadre de vie / Urb. +Pilotage / Ingénierie +" } + let(:dropdownlist) { create :drop_down_list, value: value } + + it { expect(dropdownlist.options).to eq ["Cohésion sociale", "Dév.Eco / Emploi", "Cadre de vie / Urb.", "Pilotage / Ingénierie"] } + + context 'when one value is empty' do + let(:value) { "Cohésion sociale + +Cadre de vie / Urb. +Pilotage / Ingénierie +" } + + it { expect(dropdownlist.options).to eq ["Cohésion sociale", "Cadre de vie / Urb.", "Pilotage / Ingénierie"] } + end + end +end