Add original_heading_id to investments
Investments can be reclassified to a different heading during the participatory budget process. Whilst we are recording this change of heading in the `previous_heading_id` attribute, we are only keeping the _last_ heading. If there are multiple reclassifications we lose this chain of reclassifications. In this commit we are adding an `original_heading_id` attribute, that will only be set once, when creating the investment, and will not get lost with multiple reclassificaitons of an investment.
This commit is contained in:
committed by
Javi Martín
parent
8670cafa2e
commit
488e19f8a0
@@ -104,6 +104,7 @@ class Budget
|
||||
|
||||
scope :for_render, -> { includes(:heading) }
|
||||
|
||||
before_create :set_original_heading_id
|
||||
before_save :calculate_confidence_score
|
||||
after_save :recalculate_heading_winners
|
||||
before_validation :set_responsible_name
|
||||
@@ -404,6 +405,10 @@ class Budget
|
||||
self.budget_id ||= heading&.group&.budget_id
|
||||
end
|
||||
|
||||
def set_original_heading_id
|
||||
self.original_heading_id = heading_id
|
||||
end
|
||||
|
||||
def change_log
|
||||
self.changed.each do |field|
|
||||
unless field == "updated_at"
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddOriginalHeadingIdToInvestments < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
add_column :budget_investments, :original_heading_id, :integer
|
||||
end
|
||||
end
|
||||
@@ -294,6 +294,7 @@ ActiveRecord::Schema.define(version: 20190607160900) do
|
||||
t.datetime "ignored_flag_at"
|
||||
t.integer "flags_count", default: 0
|
||||
t.integer "tracker_assignments_count"
|
||||
t.integer "original_heading_id"
|
||||
t.index ["administrator_id"], name: "index_budget_investments_on_administrator_id", using: :btree
|
||||
t.index ["author_id"], name: "index_budget_investments_on_author_id", using: :btree
|
||||
t.index ["community_id"], name: "index_budget_investments_on_community_id", using: :btree
|
||||
|
||||
@@ -56,6 +56,29 @@ describe Budget::Investment do
|
||||
expect(investment.group_id).to eq group_2.id
|
||||
end
|
||||
|
||||
it "logs previous heading value if it is changed" do
|
||||
budget = create(:budget, phase: "balloting")
|
||||
|
||||
group = create(:budget_group, budget: budget)
|
||||
|
||||
heading_1 = create(:budget_heading, group: group)
|
||||
heading_2 = create(:budget_heading, group: group)
|
||||
|
||||
investment = create(:budget_investment, heading: heading_1)
|
||||
|
||||
expect(investment.previous_heading_id).to eq nil
|
||||
|
||||
investment.update(heading: heading_2)
|
||||
|
||||
expect(investment.previous_heading_id).to eq heading_1.id
|
||||
end
|
||||
|
||||
it "stores original heading id" do
|
||||
investment = create(:budget_investment)
|
||||
|
||||
expect(investment.original_heading_id).to eq investment.heading_id
|
||||
end
|
||||
|
||||
describe "#unfeasibility_explanation blank" do
|
||||
it "is valid if valuation not finished" do
|
||||
investment.unfeasibility_explanation = ""
|
||||
|
||||
Reference in New Issue
Block a user