refactor spec

This commit is contained in:
simon lehericey 2022-07-07 15:22:23 +02:00
parent 16d58d0204
commit 3eadff9111

View file

@ -1,65 +1,48 @@
describe Administrateurs::TypesDeChampController, type: :controller do
let(:admin) { create(:administrateur) }
let(:procedure) { create(:procedure) }
describe '#types_de_champs editor' do
let(:procedure) { create(:procedure) }
before { sign_in(procedure.administrateurs.first.user) }
before do
admin.procedures << procedure
sign_in(admin.user)
describe '#create' do
let(:params) { default_params }
let(:default_params) do
{
procedure_id: procedure.id,
type_de_champ: {
type_champ: type_champ,
libelle: 'Nouveau champ',
private: false,
placeholder: "custom placeholder"
}
}
end
let(:type_champ) { TypeDeChamp.type_champs.fetch(:text) }
subject { post :create, params: params, format: :turbo_stream }
context "create type_de_champ text" do
before do
post :create, params: {
procedure_id: procedure.id,
type_de_champ: {
type_champ: type_champ,
libelle: 'Nouveau champ',
private: false,
placeholder: "custom placeholder"
}
}, format: :turbo_stream
end
let(:type_champ) { TypeDeChamp.type_champs.fetch(:text) }
it { expect(response).to have_http_status(:ok) }
it { is_expected.to have_http_status(:ok) }
end
context "validate type_de_champ linked_drop_down_list" do
let(:type_champ) { TypeDeChamp.type_champs.fetch(:linked_drop_down_list) }
before do
post :create, params: {
procedure_id: procedure.id,
type_de_champ: {
type_champ: type_champ,
libelle: 'Nouveau champ',
private: false
}
}, format: :turbo_stream
it do
is_expected.to have_http_status(:ok)
expect(flash.alert).to eq(nil)
end
it { expect(response).to have_http_status(:ok) }
end
context "create type_de_champ linked_drop_down_list" do
let(:type_champ) { TypeDeChamp.type_champs.fetch(:linked_drop_down_list) }
let(:params) { default_params.deep_merge(type_de_champ: { drop_down_list_value: '--value--' }) }
before do
post :create, params: {
procedure_id: procedure.id,
type_de_champ: {
type_champ: type_champ,
libelle: 'Nouveau champ',
drop_down_list_value: '--value--',
private: false
}
}, format: :turbo_stream
it do
is_expected.to have_http_status(:ok)
expect(flash.alert).to eq(nil)
end
it { expect(response).to have_http_status(:ok) }
end
end
end