Commit f8391bd7 authored by Shinya Maeda's avatar Shinya Maeda

Remove validates :key, uniqueness due to new validator covers the case

parent 07c7edd3
...@@ -4,7 +4,5 @@ module Ci ...@@ -4,7 +4,5 @@ module Ci
include HasVariable include HasVariable
belongs_to :pipeline_schedule belongs_to :pipeline_schedule
validates :key, uniqueness: { scope: :pipeline_schedule_id }
end end
end end
...@@ -189,7 +189,6 @@ describe Projects::PipelineSchedulesController do ...@@ -189,7 +189,6 @@ describe Projects::PipelineSchedulesController do
key: 'CCC', pipeline_schedule: pipeline_schedule) key: 'CCC', pipeline_schedule: pipeline_schedule)
end end
context 'when params include one variable' do
context 'when adds a new variable' do context 'when adds a new variable' do
let(:schedule) do let(:schedule) do
basic_param.merge({ basic_param.merge({
...@@ -205,6 +204,21 @@ describe Projects::PipelineSchedulesController do ...@@ -205,6 +204,21 @@ describe Projects::PipelineSchedulesController do
end end
end end
context 'when adds a new duplicated variable' do
let(:schedule) do
basic_param.merge({
variables_attributes: [{ key: 'CCC', value: 'AAA123' }]
})
end
it 'returns an error' do
expect { go }.not_to change { Ci::PipelineScheduleVariable.count }
pipeline_schedule.reload
expect(assigns(:schedule).errors['variables']).not_to be_empty
end
end
context 'when updates a variable' do context 'when updates a variable' do
let(:schedule) do let(:schedule) do
basic_param.merge({ basic_param.merge({
...@@ -231,6 +245,22 @@ describe Projects::PipelineSchedulesController do ...@@ -231,6 +245,22 @@ describe Projects::PipelineSchedulesController do
expect { go }.to change { Ci::PipelineScheduleVariable.count }.by(-1) expect { go }.to change { Ci::PipelineScheduleVariable.count }.by(-1)
end end
end end
context 'when deletes and creates a same key simultaneously' do
let(:schedule) do
basic_param.merge({
variables_attributes: [{ id: pipeline_schedule_variable.id, _destroy: true },
{ key: 'CCC', value: 'CCC123' }]
})
end
it 'updates the variable' do
expect { go }.not_to change { Ci::PipelineScheduleVariable.count }
pipeline_schedule.reload
expect(pipeline_schedule.variables.last.key).to eq('CCC')
expect(pipeline_schedule.variables.last.value).to eq('CCC123')
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment