Skip to content

Commit

Permalink
Added support for Active Record 8
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Sep 27, 2024
1 parent a4d8b90 commit 42e8fd0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ jobs:
fail-fast: false
matrix:
include:
- ruby: 3.3
gemfile: gemfiles/activerecord80.gemfile
- ruby: 3.3
gemfile: Gemfile
- ruby: 3.2
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.0 (unreleased)

- Added support for Active Record 8

## 0.3.2 (2024-02-09)

- Fixed incorrect rollups with `time_zone: false` when `Rollup.time_zone` has a negative UTC offset
Expand Down
12 changes: 12 additions & 0 deletions gemfiles/activerecord80.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
source "https://rubygems.org"

gemspec path: ".."

gem "rake"
gem "minitest", ">= 5"
gem "activerecord", "~> 8.0.0.beta1"
gem "pg"
gem "mysql2"
gem "trilogy"
gem "sqlite3"
gem "railties", "~> 8.0.0.beta1", require: false
6 changes: 6 additions & 0 deletions lib/rollup/aggregator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ def save_records(records)
conflict_target << :dimensions if Utils.dimensions_supported?

options = Utils.mysql? ? {} : {unique_by: conflict_target}
if ActiveRecord::VERSION::MAJOR >= 8
utc = ActiveSupport::TimeZone["Etc/UTC"]
records.each do |v|
v[:time] = v[:time].in_time_zone(utc) if v[:time].is_a?(Date)
end
end
Rollup.unscoped.upsert_all(records, **options)
end
end
Expand Down
6 changes: 5 additions & 1 deletion test/rollup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ def test_inspect
def test_upsert_date
create_users
User.rollup("Test")
assert_match "'#{now.to_date}'", $sql.find { |s| s =~ /ON (CONFLICT|DUPLICATE KEY)/i }
if ActiveRecord::VERSION::MAJOR >= 8
assert_match "'#{now.to_date} 00:00:00'", $sql.find { |s| s =~ /ON (CONFLICT|DUPLICATE KEY)/i }
else
assert_match "'#{now.to_date}'", $sql.find { |s| s =~ /ON (CONFLICT|DUPLICATE KEY)/i }
end
end

def test_rollup_rollup
Expand Down
5 changes: 5 additions & 0 deletions test/support/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def dimensions_supported?

if ActiveRecord::VERSION::STRING.to_f >= 7.2
ActiveRecord::Base.attributes_for_inspect = :all
end

if ActiveRecord::VERSION::STRING.to_f == 8.0
ActiveSupport.to_time_preserves_timezone = :zone
elsif ActiveRecord::VERSION::STRING.to_f == 7.2
ActiveSupport.to_time_preserves_timezone = true
end

Expand Down

0 comments on commit 42e8fd0

Please sign in to comment.