Skip to content

Commit

Permalink
Add support for Rails 7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ledermann committed Aug 17, 2024
1 parent 67eafa8 commit 675b744
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 17 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ '3.0', '3.1', '3.2', '3.3' ]
rails: [ '6.1', '7.0', '7.1' ]
ruby: ['3.1', '3.2', '3.3']
rails: ['6.1', '7.0', '7.1', '7.2']

name: SQLite / Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}

Expand Down Expand Up @@ -58,8 +58,8 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ '3.0', '3.1', '3.2', '3.3' ]
rails: [ '6.1', '7.0', '7.1' ]
ruby: ['3.1', '3.2', '3.3']
rails: ['6.1', '7.0', '7.1', '7.2']

name: MySQL / Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}

Expand Down Expand Up @@ -107,8 +107,8 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ '3.0', '3.1', '3.2', '3.3' ]
rails: [ '6.1', '7.0', '7.1' ]
ruby: ['3.1', '3.2', '3.3']
rails: ['6.1', '7.0', '7.1', '7.2']

name: PostgreSQL / Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}

Expand Down
8 changes: 7 additions & 1 deletion Appraisals
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
appraise "rails-7.2" do
gem "activerecord", "~> 7.2.0"
gem "mysql2", "~> 0.5"
gem "pg", "~> 1.3"
gem "sqlite3", ">= 2.0"
end

appraise "rails-7.1" do
gem "activerecord", "~> 7.1.0"
gem "mysql2", "~> 0.5"
Expand All @@ -18,4 +25,3 @@ appraise "rails-6.1" do
gem "pg", "~> 1.1"
gem "sqlite3", "~> 1.4"
end

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Ruby gem to manage read/unread status of ActiveRecord objects - and it's fast.

## Requirements

* Ruby 3.0 or newer
* Rails 6.1 or newer (including Rails 7.1)
* Ruby 3.1 or newer
* Rails 6.1 or newer (including Rails 7.2)
* MySQL, PostgreSQL or SQLite
* Needs a timestamp field in your models (like created_at or updated_at) with a database index on it

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

source "https://rubygems.org"

gem "activerecord", "~> 7.2.0"
gem "mysql2", "~> 0.5"
gem "pg", "~> 1.3"
gem "sqlite3", ">= 2.0"

gemspec path: "../"
16 changes: 12 additions & 4 deletions lib/unread/readable_scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def join_read_marks(reader)
joins "LEFT JOIN #{ReadMark.quoted_table_name}
ON #{ReadMark.quoted_table_name}.readable_type = '#{readable_parent.name}'
AND #{ReadMark.quoted_table_name}.readable_id = #{quoted_table_name}.#{quoted_primary_key}
AND #{ReadMark.quoted_table_name}.reader_id = #{quote_bound_value(reader.id)}
AND #{ReadMark.quoted_table_name}.reader_type = #{quote_bound_value(reader.class.base_class.name)}
AND #{ReadMark.quoted_table_name}.reader_id = #{quoted(reader.id)}
AND #{ReadMark.quoted_table_name}.reader_type = #{quoted(reader.class.base_class.name)}
AND #{ReadMark.quoted_table_name}.timestamp >= #{quoted_table_name}.#{connection.quote_column_name(readable_options[:on])}"
end

Expand Down Expand Up @@ -39,8 +39,16 @@ def with_read_marks_for(reader)

join_read_marks(reader).select("#{quoted_table_name}.*,
#{ReadMark.quoted_table_name}.id AS read_mark_id,
#{quote_bound_value(reader.class.base_class.name)}#{postgresql_string_cast} AS read_mark_reader_type,
#{quote_bound_value(reader.id)} AS read_mark_reader_id")
#{quoted(reader.class.base_class.name)}#{postgresql_string_cast} AS read_mark_reader_type,
#{quoted(reader.id)} AS read_mark_reader_id")
end

def quoted(value)
if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('7.2')
quote_bound_value(connection, value)
else
quote_bound_value(value)
end
end
end
end
Expand Down
14 changes: 11 additions & 3 deletions lib/unread/reader_scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def join_read_marks(readable)

joins "LEFT JOIN #{ReadMark.quoted_table_name}
ON #{ReadMark.quoted_table_name}.readable_type = '#{readable.class.readable_parent.name}'
AND (#{ReadMark.quoted_table_name}.readable_id = #{quote_bound_value(readable.id)} OR #{ReadMark.quoted_table_name}.readable_id IS NULL)
AND (#{ReadMark.quoted_table_name}.readable_id = #{quoted(readable.id)} OR #{ReadMark.quoted_table_name}.readable_id IS NULL)
AND #{ReadMark.quoted_table_name}.reader_id = #{quoted_table_name}.#{quoted_primary_key}
AND #{ReadMark.quoted_table_name}.reader_type = '#{connection.quote_string base_class.name}'
AND #{ReadMark.quoted_table_name}.timestamp >= '#{connection.quoted_date readable.send(readable.class.readable_options[:on])}'"
Expand All @@ -31,8 +31,16 @@ def with_read_marks_for(readable)

join_read_marks(readable).select("#{quoted_table_name}.*,
#{ReadMark.quoted_table_name}.id AS read_mark_id,
#{quote_bound_value(readable.class.name)}#{postgresql_string_cast} AS read_mark_readable_type,
#{quote_bound_value(readable.id)} AS read_mark_readable_id")
#{quoted(readable.class.name)}#{postgresql_string_cast} AS read_mark_readable_type,
#{quoted(readable.id)} AS read_mark_readable_id")
end

def quoted(value)
if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('7.2')
quote_bound_value(connection, value)
else
quote_bound_value(value)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion unread.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.homepage = "https://github.com/ledermann/unread"
s.summary = %q{Manages read/unread status of ActiveRecord objects}
s.description = %q{This gem creates a scope for unread objects and adds methods to mark objects as read }
s.required_ruby_version = '>= 3.0'
s.required_ruby_version = '>= 3.1'

s.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
Expand Down

0 comments on commit 675b744

Please sign in to comment.