Add rake to move external_url to description
This rake move this field for Proposals and Legislation proposals.
This commit is contained in:
23
lib/tasks/proposals.rake
Normal file
23
lib/tasks/proposals.rake
Normal file
@@ -0,0 +1,23 @@
|
||||
namespace :proposals do
|
||||
|
||||
desc "Move external_url to description"
|
||||
task move_external_url_to_description: :environment do
|
||||
include ActionView::Helpers::SanitizeHelper
|
||||
include TextWithLinksHelper
|
||||
|
||||
models = [Proposal, Legislation::Proposal]
|
||||
|
||||
models.each do |model|
|
||||
print "Move external_url to description for #{model}s"
|
||||
model.find_each do |resource|
|
||||
if resource.external_url.present?
|
||||
resource.update_columns(description: "#{resource.description} "\
|
||||
"<p>#{text_with_links(resource.external_url)}</p>",
|
||||
external_url: "")
|
||||
print "."
|
||||
end
|
||||
end
|
||||
puts " ✅ "
|
||||
end
|
||||
end
|
||||
end
|
||||
66
spec/lib/tasks/proposals_spec.rb
Normal file
66
spec/lib/tasks/proposals_spec.rb
Normal file
@@ -0,0 +1,66 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Proposals do
|
||||
|
||||
describe "Move external_url to description" do
|
||||
|
||||
let :run_rake_task do
|
||||
Rake::Task["proposals:move_external_url_to_description"].reenable
|
||||
Rake.application.invoke_task "proposals:move_external_url_to_description"
|
||||
end
|
||||
|
||||
context "Move external_url to description for Proposals" do
|
||||
|
||||
it "When proposal has external_url" do
|
||||
proposal = create(:proposal, description: "<p>Lorem ipsum dolor sit amet</p>",
|
||||
external_url: "http://consul.dev")
|
||||
|
||||
run_rake_task
|
||||
proposal.reload
|
||||
|
||||
expect(proposal.description).to eq "<p>Lorem ipsum dolor sit amet</p> "\
|
||||
'<p><a href="http://consul.dev" '\
|
||||
'target="_blank" rel="nofollow">'\
|
||||
"http://consul.dev</a></p>"
|
||||
expect(proposal.external_url).to eq ""
|
||||
end
|
||||
|
||||
it "When proposal has not external_url" do
|
||||
proposal = create(:proposal, description: "<p>Lorem ipsum dolor sit amet</p>",
|
||||
external_url: "")
|
||||
|
||||
run_rake_task
|
||||
proposal.reload
|
||||
|
||||
expect(proposal.description).to eq "<p>Lorem ipsum dolor sit amet</p>"
|
||||
expect(proposal.external_url).to eq ""
|
||||
end
|
||||
end
|
||||
|
||||
context "Move external_url to description for Legislation proposals" do
|
||||
|
||||
it "When legislation proposal has external_url" do
|
||||
legislation_proposal = create(:legislation_proposal, description: "<p>Ut enim ad minim</p>",
|
||||
external_url: "http://consulproject.org")
|
||||
run_rake_task
|
||||
legislation_proposal.reload
|
||||
|
||||
expect(legislation_proposal.description).to eq "<p>Ut enim ad minim</p> "\
|
||||
'<p><a href="http://consulproject.org" '\
|
||||
'target="_blank" rel="nofollow">'\
|
||||
"http://consulproject.org</a></p>"
|
||||
expect(legislation_proposal.external_url).to eq ""
|
||||
end
|
||||
|
||||
it "When legislation proposal has not external_url" do
|
||||
legislation_proposal = create(:legislation_proposal, description: "<p>Ut enim ad minim</p>",
|
||||
external_url: "")
|
||||
run_rake_task
|
||||
legislation_proposal.reload
|
||||
|
||||
expect(legislation_proposal.description).to eq "<p>Ut enim ad minim</p>"
|
||||
expect(legislation_proposal.external_url).to eq ""
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user