Add rake task to set the original_heading_id value
By default we want this attribute to be the current heading id for existing investments. If there have been reclassifications, this field should be updated accordingly.
This commit is contained in:
committed by
Javi Martín
parent
488e19f8a0
commit
71e6c5713a
@@ -23,4 +23,14 @@ namespace :budgets do
|
||||
|
||||
end
|
||||
|
||||
desc "Update investments original_heading_id with current heading_id"
|
||||
task set_original_heading_id: :environment do
|
||||
puts "Starting"
|
||||
Budget::Investment.find_each do |investment|
|
||||
investment.update_column(:original_heading_id, investment.heading_id)
|
||||
print "."
|
||||
end
|
||||
puts "Finished"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
22
spec/lib/tasks/budgets_spec.rb
Normal file
22
spec/lib/tasks/budgets_spec.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Budget do
|
||||
|
||||
let(:run_rake_task) do
|
||||
Rake.application.invoke_task("budgets:set_original_heading_id")
|
||||
end
|
||||
|
||||
it "sets attribute original_heading_id for existing investments" do
|
||||
heading = create(:budget_heading)
|
||||
investment = create(:budget_investment, heading: heading)
|
||||
investment.update(original_heading_id: nil)
|
||||
|
||||
expect(investment.original_heading_id).to equal(nil)
|
||||
|
||||
run_rake_task
|
||||
investment.reload
|
||||
|
||||
expect(investment.original_heading_id).to equal(heading.id)
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user