diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5995fbb..4d78f68 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 }} @@ -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 }} @@ -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 }} diff --git a/Appraisals b/Appraisals index d2bf2e1..17deb80 100644 --- a/Appraisals +++ b/Appraisals @@ -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" @@ -18,4 +25,3 @@ appraise "rails-6.1" do gem "pg", "~> 1.1" gem "sqlite3", "~> 1.4" end - diff --git a/README.md b/README.md index 413a21a..b8e0e02 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/gemfiles/rails_7.2.gemfile b/gemfiles/rails_7.2.gemfile new file mode 100644 index 0000000..8254482 --- /dev/null +++ b/gemfiles/rails_7.2.gemfile @@ -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: "../" diff --git a/lib/unread/readable_scopes.rb b/lib/unread/readable_scopes.rb index ca1ca4d..eeff7b1 100644 --- a/lib/unread/readable_scopes.rb +++ b/lib/unread/readable_scopes.rb @@ -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 @@ -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 diff --git a/lib/unread/reader_scopes.rb b/lib/unread/reader_scopes.rb index 992e982..00a4831 100644 --- a/lib/unread/reader_scopes.rb +++ b/lib/unread/reader_scopes.rb @@ -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])}'" @@ -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 diff --git a/lib/unread/version.rb b/lib/unread/version.rb index 8339375..5008351 100644 --- a/lib/unread/version.rb +++ b/lib/unread/version.rb @@ -1,3 +1,3 @@ module Unread - VERSION = '0.13.1' + VERSION = '0.14.0' end diff --git a/unread.gemspec b/unread.gemspec index bd356f0..3dcfbca 100644 --- a/unread.gemspec +++ b/unread.gemspec @@ -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)/})