From c18f2c545ec0d38de5bc2b195f1fd8eecaade3ea Mon Sep 17 00:00:00 2001 From: Jon Sullivan Date: Thu, 21 Dec 2023 10:11:02 -0500 Subject: [PATCH 1/2] Warnings: Use `alias_method` > `alias_attribute` for non-attributes --- app/models/caffeinate/campaign_subscription.rb | 2 +- app/models/caffeinate/mailing.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/caffeinate/campaign_subscription.rb b/app/models/caffeinate/campaign_subscription.rb index af2f6ec..8436713 100644 --- a/app/models/caffeinate/campaign_subscription.rb +++ b/app/models/caffeinate/campaign_subscription.rb @@ -38,7 +38,7 @@ class CampaignSubscription < ApplicationRecord has_one :previous_mailing, -> { sent.order(sent_at: :desc) }, class_name: '::Caffeinate::Mailing', foreign_key: :caffeinate_campaign_subscription_id belongs_to :caffeinate_campaign, class_name: 'Caffeinate::Campaign', foreign_key: :caffeinate_campaign_id - alias_attribute :campaign, :caffeinate_campaign + alias_method :campaign, :caffeinate_campaign belongs_to :subscriber, polymorphic: true belongs_to :user, polymorphic: true, optional: true diff --git a/app/models/caffeinate/mailing.rb b/app/models/caffeinate/mailing.rb index ebc627d..67b266e 100644 --- a/app/models/caffeinate/mailing.rb +++ b/app/models/caffeinate/mailing.rb @@ -20,9 +20,9 @@ class Mailing < ApplicationRecord self.table_name = 'caffeinate_mailings' belongs_to :caffeinate_campaign_subscription, class_name: 'Caffeinate::CampaignSubscription' - alias_attribute :subscription, :caffeinate_campaign_subscription has_one :caffeinate_campaign, through: :caffeinate_campaign_subscription - alias_attribute :campaign, :caffeinate_campaign + alias_method :subscription, :caffeinate_campaign_subscription + alias_method :campaign, :caffeinate_campaign scope :upcoming, -> { joins(:caffeinate_campaign_subscription).where(caffeinate_campaign_subscription: ::Caffeinate::CampaignSubscription.active).unsent.unskipped.where('send_at < ?', ::Caffeinate.config.time_now).order('send_at asc') } scope :unsent, -> { unskipped.where(sent_at: nil) } From ae31ce5bc08a84fd83daea0ceb02dfd12f2eb0ac Mon Sep 17 00:00:00 2001 From: Jon Sullivan Date: Thu, 21 Dec 2023 10:15:58 -0500 Subject: [PATCH 2/2] fix specs --- spec/caffeinate/schedule_evaluator_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/caffeinate/schedule_evaluator_spec.rb b/spec/caffeinate/schedule_evaluator_spec.rb index dc5d8c9..834053a 100644 --- a/spec/caffeinate/schedule_evaluator_spec.rb +++ b/spec/caffeinate/schedule_evaluator_spec.rb @@ -16,7 +16,7 @@ campaign end - let(:sub) { create(:caffeinate_campaign_subscription, campaign: campaign) } + let(:sub) { create(:caffeinate_campaign_subscription, caffeinate_campaign: campaign) } it 'succeeds' do expect(sub.caffeinate_mailings.first.send_at.to_i).to eq 3.days.from_now.to_i @@ -31,7 +31,7 @@ campaign end - let(:sub) { create(:caffeinate_campaign_subscription, campaign: campaign) } + let(:sub) { create(:caffeinate_campaign_subscription, caffeinate_campaign: campaign) } it 'succeeds' do expect(sub.mailings.first.send_at.to_i).to eq 2.days.from_now.to_i @@ -58,7 +58,7 @@ def five_pm(evaluator, mailing) campaign end - let(:sub) { create(:caffeinate_campaign_subscription, campaign: campaign) } + let(:sub) { create(:caffeinate_campaign_subscription, caffeinate_campaign: campaign) } it 'succeeds' do expect(sub.mailings.first.send_at.to_i).to eq(3.days.from_now.change(hour: 17, min: 2, sec: 2).to_i)