diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3a4c4af..d4309ab 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: services: postgres: - image: postgres:14 + image: postgres:16 env: POSTGRES_DB: hoardable POSTGRES_PASSWORD: password @@ -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 diff --git a/Gemfile b/Gemfile index b061c6d..45d5b51 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/lib/hoardable/version_model.rb b/lib/hoardable/version_model.rb index ff2c7b9..8bf954c 100644 --- a/lib/hoardable/version_model.rb +++ b/lib/hoardable/version_model.rb @@ -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 diff --git a/test/config/application.rb b/test/config/application.rb index 990344e..482266f 100644 --- a/test/config/application.rb +++ b/test/config/application.rb @@ -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 diff --git a/test/test_model.rb b/test/test_model.rb index 55ff8f4..59be802 100644 --- a/test/test_model.rb +++ b/test/test_model.rb @@ -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! @@ -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