Skip to content

Warnings: Use alias_method > alias_attribute for non-attributes#45

Open
jon-sully wants to merge 2 commits intomasterfrom
rails-7-1-alias
Open

Warnings: Use alias_method > alias_attribute for non-attributes#45
jon-sully wants to merge 2 commits intomasterfrom
rails-7-1-alias

Conversation

@jon-sully
Copy link
Copy Markdown
Collaborator

Eliminate nags!

Fixes #43

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 21, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.68%. Comparing base (3f41563) to head (ae31ce5).

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #45   +/-   ##
=======================================
  Coverage   98.68%   98.68%           
=======================================
  Files         102      102           
  Lines        2664     2664           
=======================================
  Hits         2629     2629           
  Misses         35       35           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jon-sully jon-sully requested a review from joshmn December 21, 2023 15:17
@jon-sully
Copy link
Copy Markdown
Collaborator Author

This one's ready. No functional change at all, just swapping a method for a Rails 7.2 compatibility

@jon-sully
Copy link
Copy Markdown
Collaborator Author

@joshmn any chance you could take a peek at this one?

@cloke
Copy link
Copy Markdown

cloke commented Sep 10, 2024

Any chance of getting this merged in? With rails 7.2 being officially released this is a blocker for sure.

@jon-sully
Copy link
Copy Markdown
Collaborator Author

All, I've reached out to @joshmn a couple of times... if he remains unavailable for another week or two, I will (sadly) fork this project and keep it up to date. I'm not sure exactly why he's been MIA lately. This gem should never block Rails upgrades.

@jon-sully
Copy link
Copy Markdown
Collaborator Author

Welp, figured that out.

https://www.yahoo.com/tech/man-ran-website-illegally-streamed-214600421.html?guccounter=1

Guess a fork is on the way.

@jon-sully
Copy link
Copy Markdown
Collaborator Author

For folks that are watching and/or find this issue, I've been pretty busy in life so I haven't had time to spin up a proper fork and try to wrestle all the side-effects that come with that. For now, I offer a monkey-patch. I've stuffed this code into my ~/config/initializers/caffeinate.rb, just under my Caffeinate.setup block:

require_dependency 'caffeinate/application_record'
require_dependency 'caffeinate/campaign_subscription'
require_dependency 'caffeinate/mailing'

Caffeinate::CampaignSubscription.class_eval do
  # Define caffeinate_campaign as a virtual attribute
  attribute :caffeinate_campaign, :string # Use the appropriate type if it's not a string

  # Alias campaign to caffeinate_campaign
  alias_method :campaign, :caffeinate_campaign
end

Caffeinate::Mailing.class_eval do
  # Define caffeinate_campaign_subscription as a virtual attribute
  attribute :caffeinate_campaign_subscription, :string # Use the appropriate type if it's not a string
  attribute :caffeinate_campaign, :string # Use the appropriate type if it's not a string

  # Alias subscription to caffeinate_campaign_subscription
  alias_method :subscription, :caffeinate_campaign_subscription
  alias_method :campaign, :caffeinate_campaign
end

This matches the three places I resolved in this PR and sets up a virtual attribute (which will immediately get overridden by ActiveRecord) to prevent the Rails 8 error from occurring, then an alias_method (proper) to stick with current style.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rails 7.2: DEPRECATION WARNING: Caffeinate::CampaignSubscription model aliases caffeinate_campaign, but caffeinate_campaign is not an attribute.

3 participants