remove empty value in drop_down_list in db
This commit is contained in:
parent
061c9cc6f3
commit
d3667bbd6c
2 changed files with 57 additions and 0 deletions
|
@ -0,0 +1,22 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
namespace :after_party do
|
||||||
|
desc 'Deployment task: remove_empty_options_from_drop_down_list'
|
||||||
|
task remove_empty_options_from_drop_down_list: :environment do
|
||||||
|
ids = TypeDeChamp
|
||||||
|
.where(type_champ: ['drop_down_list', 'multiple_drop_down_list', 'linked_drop_down_list'])
|
||||||
|
.where("options->'drop_down_options' @> '[\"\"]'::jsonb").ids
|
||||||
|
|
||||||
|
progress = ProgressReport.new(ids.count)
|
||||||
|
|
||||||
|
TypeDeChamp.where(id: ids).select(:id, :options, :type_champ).find_each do |drop_down_list|
|
||||||
|
drop_down_list.drop_down_options.delete('')
|
||||||
|
drop_down_list.save!(validate: false)
|
||||||
|
|
||||||
|
progress.inc
|
||||||
|
end
|
||||||
|
|
||||||
|
AfterParty::TaskRecord
|
||||||
|
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,35 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
describe '20240917131034_remove_empty_options_from_drop_down_list.rake' do
|
||||||
|
let(:rake_task) { Rake::Task['after_party:remove_empty_options_from_drop_down_list'] }
|
||||||
|
|
||||||
|
let!(:drop_down_list_with_empty_option) do
|
||||||
|
create(:type_de_champ_drop_down_list, drop_down_options: ['', '1', '2'])
|
||||||
|
end
|
||||||
|
|
||||||
|
let!(:drop_down_list_with_other_empty_option) do
|
||||||
|
create(:type_de_champ_drop_down_list, drop_down_options: ['1', '', '2', ''])
|
||||||
|
end
|
||||||
|
|
||||||
|
let!(:witness_drop_down_list) do
|
||||||
|
create(:type_de_champ_drop_down_list, drop_down_options: ['1', '2'])
|
||||||
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
|
rake_task.invoke
|
||||||
|
|
||||||
|
[
|
||||||
|
drop_down_list_with_empty_option,
|
||||||
|
drop_down_list_with_other_empty_option,
|
||||||
|
witness_drop_down_list
|
||||||
|
].each(&:reload)
|
||||||
|
end
|
||||||
|
|
||||||
|
after { rake_task.reenable }
|
||||||
|
|
||||||
|
it 'removes the empty option' do
|
||||||
|
expect(drop_down_list_with_empty_option.drop_down_options).to eq(['1', '2'])
|
||||||
|
expect(drop_down_list_with_other_empty_option.drop_down_options).to eq(['1', '2'])
|
||||||
|
expect(witness_drop_down_list.drop_down_options).to eq(['1', '2'])
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue