790704ef58
Currently, when running specs, the output of rake tasks is spamming the tests results. This PR configures Rake so that it runs in quiet mode during specs. This disables the internal messages of rake during tests. However our own `puts` also need to be conditionned to the verbosity of rake. Using a simple `rake_puts` helper allows the info messages to be displayed when running the rake task manually, but not during tests. Before: ``` $ bin/rspec spec/lib/rake Randomized with seed 6544 1 Mails::ClosedMail to clean cleaning Mails::ClosedMail #1 1 Mails::InitiatedMail to clean cleaning Mails::InitiatedMail #1 1 Mails::ReceivedMail to clean cleaning Mails::ReceivedMail #1 1 Mails::RefusedMail to clean cleaning Mails::RefusedMail #1 1 Mails::WithoutContinuationMail to clean cleaning Mails::WithoutContinuationMail #1 .....Champ 0/1 .Champ 0/1 . ``` After: ``` $ bin/rspec spec/lib/rake Randomized with seed 6544 ....... ```
24 lines
685 B
Ruby
24 lines
685 B
Ruby
require Rails.root.join("lib", "tasks", "task_helper")
|
|
require Rails.root.join("app", "helpers", "html_to_string_helper")
|
|
|
|
namespace :'2018_03_06_clean_html_textareas' do
|
|
task clean: :environment do
|
|
include ActionView::Helpers::TextHelper
|
|
include HtmlToStringHelper
|
|
|
|
rake_puts "PUTS Will migrate champs"
|
|
|
|
champs = Champ.joins(:type_de_champ)
|
|
.where(types_de_champ: { type_champ: "textarea" })
|
|
.where("value LIKE '%<%'")
|
|
|
|
total = champs.count
|
|
|
|
champs.find_each(batch_size: 100).with_index do |c, i|
|
|
if (i % 100) == 0
|
|
rake_puts "Champ #{i}/#{total}\n"
|
|
end
|
|
c.update_column(:value, html_to_string(c.value))
|
|
end
|
|
end
|
|
end
|