diff --git a/app/models/budget/phase.rb b/app/models/budget/phase.rb index 6432a13b1..de90075a7 100644 --- a/app/models/budget/phase.rb +++ b/app/models/budget/phase.rb @@ -11,7 +11,7 @@ class Budget include Globalizable include Sanitizable - belongs_to :budget + belongs_to :budget, touch: true belongs_to :next_phase, class_name: self.name, inverse_of: :prev_phase has_one :prev_phase, class_name: self.name, foreign_key: :next_phase_id, inverse_of: :next_phase @@ -24,7 +24,6 @@ class Budget validate :next_phase_dates_valid? after_save :adjust_date_ranges - after_save :touch_budget scope :enabled, -> { where(enabled: true) } scope :published, -> { enabled.where.not(kind: "drafting") } @@ -70,10 +69,6 @@ class Budget end end - def touch_budget - budget.touch - end - def prev_phase_dates_valid? if enabled? && starts_at.present? && prev_enabled_phase.present? prev_enabled_phase.assign_attributes(ends_at: starts_at) diff --git a/spec/models/budget/phase_spec.rb b/spec/models/budget/phase_spec.rb index c0b4852b7..e44a2e234 100644 --- a/spec/models/budget/phase_spec.rb +++ b/spec/models/budget/phase_spec.rb @@ -115,6 +115,18 @@ describe Budget::Phase do end end + describe "#save" do + it "touches the budget when it's updated" do + budget = create(:budget) + + travel(10.seconds) do + budget.current_phase.update!(enabled: false) + + expect(budget.updated_at).to eq Time.current + end + end + end + describe "#adjust_date_ranges" do let(:prev_enabled_phase) { second_phase.prev_enabled_phase } let(:next_enabled_phase) { second_phase.next_enabled_phase }