clean: tdc.drop_down_options
This commit is contained in:
parent
d8a0adc6ed
commit
317c4344fc
2 changed files with 58 additions and 0 deletions
|
@ -0,0 +1,24 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
namespace :after_party do
|
||||||
|
desc 'Deployment task: clean_drop_down_options'
|
||||||
|
task clean_drop_down_options: :environment do
|
||||||
|
puts "Running deploy task 'clean_drop_down_options'"
|
||||||
|
|
||||||
|
ids = TypeDeChamp
|
||||||
|
.where(type_champ: ['drop_down_list', 'multiple_drop_down_list'])
|
||||||
|
.where("EXISTS ( select 1 FROM jsonb_array_elements_text(options->'drop_down_options') AS element WHERE element ~ '^--.*--$')").ids
|
||||||
|
|
||||||
|
progress = ProgressReport.new(ids.count)
|
||||||
|
|
||||||
|
TypeDeChamp.where(id: ids).find_each do |type_de_champ|
|
||||||
|
type_de_champ.drop_down_options = type_de_champ.drop_down_options.reject { |option| option.match?(/^--.*--$/) }
|
||||||
|
type_de_champ.save!(validate: false)
|
||||||
|
|
||||||
|
progress.inc
|
||||||
|
end
|
||||||
|
|
||||||
|
AfterParty::TaskRecord
|
||||||
|
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,34 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
describe '20240912091625_clean_drop_down_options.rake' do
|
||||||
|
let(:rake_task) { Rake::Task['after_party:clean_drop_down_options'] }
|
||||||
|
|
||||||
|
let!(:dashed_drop_down_list) do
|
||||||
|
drop_down_list_value = ['1', '-- nop --', '2'].join("\r\n")
|
||||||
|
create(:type_de_champ_drop_down_list, drop_down_list_value:)
|
||||||
|
end
|
||||||
|
|
||||||
|
let!(:witness_drop_down_list) do
|
||||||
|
drop_down_list_value = ['1', 'hi', '2'].join("\r\n")
|
||||||
|
create(:type_de_champ_drop_down_list, drop_down_list_value:)
|
||||||
|
end
|
||||||
|
|
||||||
|
let!(:multiple_drop_down_list) do
|
||||||
|
drop_down_list_value = ['1', '-- nop --', '2'].join("\r\n")
|
||||||
|
create(:type_de_champ_multiple_drop_down_list, drop_down_list_value:)
|
||||||
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
|
rake_task.invoke
|
||||||
|
|
||||||
|
[dashed_drop_down_list, witness_drop_down_list, multiple_drop_down_list].each(&:reload)
|
||||||
|
end
|
||||||
|
|
||||||
|
after { rake_task.reenable }
|
||||||
|
|
||||||
|
it 'removes the hidden options' do
|
||||||
|
expect(dashed_drop_down_list.drop_down_list_value).to eq(['1', '2'].join("\r\n"))
|
||||||
|
expect(witness_drop_down_list.drop_down_list_value).to eq(['1', 'hi', '2'].join("\r\n"))
|
||||||
|
expect(multiple_drop_down_list.drop_down_list_value).to eq(['1', '2'].join("\r\n"))
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue