Skip to content

Commit

Permalink
Fix for Rails 7.2 (#270)
Browse files Browse the repository at this point in the history
* Test against Rails 7.2
* Forward all params. Rails 7.2 adds a required `connection` param. This passes whatever comes in to the super method.
* Fix for type casts with Rails 7.2
* Lean on rails for handling nil instead of forwarding to DB
- `.where(user: user)` will grab the correct class/id
- `if user` only filters if the user is provided, otherwise grab everything

---------

Co-authored-by: Pangratios Cosma <[email protected]>
  • Loading branch information
jbennett and subzero10 authored Sep 16, 2024
1 parent 04c1e15 commit 49b03f1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
- rails_6.1
- rails_7.0
- rails_7.1
- rails_7.2
ruby:
- 3.2
- 3.1
Expand All @@ -44,6 +45,10 @@ jobs:
rails: rails_6.0
- ruby: 3.0
rails: rails_5.2
- ruby: 3.0
rails: rails_7.2
- ruby: 2.7
rails: rails_7.2

env:
PGHOST: localhost
Expand Down
4 changes: 4 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ end
appraise "rails-7.1" do
gem "rails", "~> 7.1.0"
end

appraise "rails-7.2" do
gem "rails", "~> 7.2.0"
end
15 changes: 3 additions & 12 deletions app/models/heya/campaign_membership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,9 @@ class CampaignMembership < ApplicationRecord
}

scope :to_process, ->(now: Time.now, user: nil) {
upcoming
.where(<<~SQL, now: now.utc, user_type: user&.class&.base_class&.name, user_id: user&.id)
("heya_campaign_memberships".last_sent_at <= (TIMESTAMP :now - make_interval(secs := "heya_steps".wait)))
AND (
(:user_type IS NULL OR :user_id IS NULL)
OR (
"heya_campaign_memberships".user_type = :user_type
AND
"heya_campaign_memberships".user_id = :user_id
)
)
SQL
query = upcoming.where('heya_campaign_memberships.last_sent_at <= (:now::timestamp - make_interval(secs := "heya_steps".wait))', now: now.utc)
query = query.where(user: user) if user
query
}

def self.migrate_next_step!
Expand Down
17 changes: 17 additions & 0 deletions gemfiles/rails_7.2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "minitest-ci", group: :test
gem "simplecov", require: false, group: :test
gem "timecop", "~> 0.9.2"
gem "pry", "~> 0.14.0"
gem "pry-rails", "~> 0.3.9"
gem "rails", "~> 7.2.0"

group :development, :test do
gem "standard", "~> 1.37.0"
gem "yard", "~> 0.9.26"
end

gemspec path: "../"
4 changes: 2 additions & 2 deletions lib/heya/active_record_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module Heya
module ActiveRecordRelationExtension
TABLE_REGEXP = /heya_steps/

def build_arel(aliases = nil)
arel = super(aliases)
def build_arel(...) # forward all params. Handles differences between 7.1 -> 7.2
arel = super(...)

if table_name == "heya_campaign_memberships" && arel.to_sql =~ TABLE_REGEXP
# https://www.postgresql.org/docs/9.4/queries-values.html
Expand Down

0 comments on commit 49b03f1

Please sign in to comment.