diff --git a/app/models/recurring_donation.rb b/app/models/recurring_donation.rb index ece20b80..cb453abf 100644 --- a/app/models/recurring_donation.rb +++ b/app/models/recurring_donation.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later +require 'timespan' class RecurringDonation < ApplicationRecord # TODO: diff --git a/lib/timespan.rb b/lib/timespan.rb index d9f05d9c..730fa2ce 100644 --- a/lib/timespan.rb +++ b/lib/timespan.rb @@ -5,8 +5,8 @@ # Relies on activesupport Timespan = Struct.new(:interval, :time_unit) do - Units = %w[week day month year].freeze - TimeUnits = { + self::Units = %w[week day month year].freeze + self::TimeUnits = { '1_week' => 1.week.ago, '2_weeks' => 2.weeks.ago, '1_month' => 1.month.ago, diff --git a/spec/lib/update/update_recurring_donations_spec.rb b/spec/lib/update/update_recurring_donations_spec.rb index 0d668f0e..9c0f600d 100644 --- a/spec/lib/update/update_recurring_donations_spec.rb +++ b/spec/lib/update/update_recurring_donations_spec.rb @@ -23,7 +23,7 @@ describe UpdateRecurringDonations do end it 'sets cancelled_at to today' do - expect(rd['cancelled_at'].end_of_day).to eq(Time.current.end_of_day) + expect(rd['cancelled_at'].to_date.end_of_day).to eq(Time.now.end_of_day) end it 'sets the cancelled_by to the given email' do @@ -168,16 +168,22 @@ describe UpdateRecurringDonations do orig_donation = recurring_donation.donation.attributes.with_indifferent_access result = UpdateRecurringDonations.update_card_id({ id: recurring_donation.id }, source_token.token) - expectations = { + expectations = { donation: orig_donation.merge(card_id: card.id), - recurring_donation: orig_rd.merge(n_failures: 0, start_date: Time.now.to_date) + recurring_donation: orig_rd.merge(n_failures: 0, start_date: DateTime.now) } expectations[:result] = expectations[:recurring_donation].merge(nonprofit_name: nonprofit.name, card_name: card.name) - expect(result).to eq expectations[:result] + expectations[:result][:created_at] = expectations[:result]["start_date"].to_s + expectations[:result][:created_at] = expectations[:result]["created_at"].to_date.strftime('%Y-%m-%d %H:%M:%S') + expectations[:result][:updated_at] = expectations[:result]["updated_at"].to_date.strftime('%Y-%m-%d %H:%M:%S') + + expect(result).to match expectations[:result] + donation_for_rd.reload recurring_donation.reload + expect(recurring_donation.attributes).to eq expectations[:recurring_donation] expect(donation_for_rd.attributes).to eq expectations[:donation] end