Skip to content

Commit

Permalink
bump pg, fix tests, add rails version to matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
waymondo committed Dec 23, 2023
1 parent ee2152a commit 1494ae9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

services:
postgres:
image: postgres:14
image: postgres:16
env:
POSTGRES_DB: hoardable
POSTGRES_PASSWORD: password
Expand All @@ -25,18 +25,22 @@ jobs:
ports:
- 5432:5432

strategy:
strategy:
matrix:
ruby:
- 3.2
- 3.1
- 3.0
- 2.7
rails:
- 6.1
- 7.0
# - 7.1

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
env:
RAILS_VERSION: ${{ matrix.rails }}
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
Expand Down
14 changes: 5 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

source 'https://rubygems.org'

gem 'benchmark-ips', '~> 2.10'
gem 'debug', '~> 1.6'
gem 'minitest', '~> 5.0'
gem 'rails', '>= 6.1'
gem 'rake', '~> 13.0'
gem 'rubocop', '~> 1.21'
gem 'rubocop-minitest', '~> 0.20'
gem 'rubocop-rake', '~> 0.6'
gem 'yard', '~> 0.9'
gem 'benchmark-ips'
gem 'debug'
gem 'minitest'
gem 'rails', "~> #{ENV.fetch("RAILS_VERSION", "7.1")}"
gem 'rake'

gemspec
2 changes: 1 addition & 1 deletion lib/hoardable/version_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def revert!

transaction do
hoardable_source.tap do |reverted|
reverted.reload.update!(hoardable_source_attributes.without(self.class.superclass.primary_key))
reverted.reload.update!(hoardable_source_attributes.without(self.class.superclass.primary_key, 'hoardable_id'))
reverted.instance_variable_set(:@hoardable_version, self)
reverted.run_callbacks(:reverted)
end
Expand Down
1 change: 1 addition & 0 deletions test/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ class Dummy < Rails::Application
config.paths['db/migrate'] = ['tmp/db/migrate']
config.active_record.encryption&.key_derivation_salt = SecureRandom.hex
config.active_record.encryption&.primary_key = SecureRandom.hex
config.active_record.yaml_column_permitted_classes = [ActiveSupport::HashWithIndifferentAccess]
end
11 changes: 7 additions & 4 deletions test/test_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def update_post(attributes = { title: 'New Headline', status: :live })
end

it 'works with serialized attributes' do
user = User.create!(name: 'Joe Schmoe', preferences: { alerts: 'on' })
user.update!(preferences: { alerts: 'off' })
user = User.create!(name: 'Joe Schmoe', preferences: { 'alerts' => 'on' })
user.update!(preferences: { 'alerts' => 'off' })
assert_equal user.versions.last.preferences, { 'alerts' => 'on' }
user.destroy!
user.versions.last.untrash!
Expand Down Expand Up @@ -124,10 +124,13 @@ def update_post(attributes = { title: 'New Headline', status: :live })
end

it 'cannot change hoardable_id' do
post.update!(hoardable_id: 123)
assert_equal post.reload.hoardable_id, post.id
if ActiveRecord.version >= Gem::Version.new('7.1')
assert_raises ActiveRecord::ReadonlyAttributeError do
post.update!(hoardable_id: 123)
end
end
assert_raises(ActiveRecord::ActiveRecordError) { post.update_column(:hoardable_id, 123) }
assert_equal post.reload.hoardable_id, post.id
assert_raises(ActiveRecord::StatementInvalid) do
post.class.connection.execute('UPDATE posts SET hoardable_id = 123')
end
Expand Down

0 comments on commit 1494ae9

Please sign in to comment.