Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.0', '3.1', '3.2', '3.3']
activerecord: ['7.0', '7.1', '7.2']
ruby-version: ['3.1', '3.2', '3.3', '3.4']
activerecord: ['7.2', '8.0', '8.1']
exclude:
- ruby-version: '3.0'
activerecord: '7.2'
# Rails 8.x requires Ruby >= 3.2
- ruby-version: '3.1'
activerecord: '8.0'
- ruby-version: '3.1'
activerecord: '8.1'
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.activerecord }}.gemfile
steps:
Expand Down
12 changes: 6 additions & 6 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
appraise "rails-7.0" do
gem 'rails', '~> 7.0'
appraise "rails-7.2" do
gem 'rails', '~> 7.2.0'
end

appraise "rails-7.1" do
gem 'rails', '~> 7.1'
appraise "rails-8.0" do
gem 'rails', '~> 8.0.0'
end

appraise "rails-7.2" do
gem 'rails', '~> 7.2'
appraise "rails-8.1" do
gem 'rails', '~> 8.1.0'
end
13 changes: 6 additions & 7 deletions active_record-acts_as.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,24 @@ Gem::Specification.new do |spec|
spec.authors = ["Hassan Zamani", "Manuel Meurer", "Bivan Alzacky Harmanto", "Adi Suryanata Herwana"]
spec.email = ["hsn.zamani@gmail.com", "manuel@krautcomputing.com"]
spec.summary = %q{Simulate multi-table inheritance for activerecord models}
spec.description = %q{Simulate multi-table inheritance for activerecord models using a plymorphic association}
spec.homepage = "http://github.com/krautcomputing/active_record-acts_as"
spec.description = %q{Simulate multi-table inheritance for activerecord models using a polymorphic association}
spec.homepage = "https://github.com/Coursemology/active_record-acts_as"
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 3.0"
spec.required_ruby_version = ">= 3.1"

spec.add_development_dependency "sqlite3", "~> 1.7"
spec.add_development_dependency "sqlite3", ">= 2.1"
spec.add_development_dependency "bundler"
spec.add_development_dependency "rspec", "~> 3"
spec.add_development_dependency "psych", "3.3.2"
spec.add_development_dependency "rake"
spec.add_development_dependency "appraisal", "~> 2.1"
spec.add_development_dependency "guard-rspec", "~> 4.7"

spec.add_dependency "activesupport", ">= 7.0"
spec.add_dependency "activerecord", ">= 7.0"
spec.add_dependency "activesupport", ">= 7.2"
spec.add_dependency "activerecord", ">= 7.2"
end
2 changes: 1 addition & 1 deletion gemfiles/rails_7.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
source "https://rubygems.org"

gem "coveralls_reborn", require: false
gem "rails", "~> 7.2"
gem "rails", "~> 7.2.0"

gemspec path: "../"
2 changes: 1 addition & 1 deletion gemfiles/rails_7.0.gemfile → gemfiles/rails_8.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
source "https://rubygems.org"

gem "coveralls_reborn", require: false
gem "rails", "~> 7.0"
gem "rails", "~> 8.0.0"

gemspec path: "../"
2 changes: 1 addition & 1 deletion gemfiles/rails_7.1.gemfile → gemfiles/rails_8.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
source "https://rubygems.org"

gem "coveralls_reborn", require: false
gem "rails", "~> 7.1"
gem "rails", "~> 8.1.0"

gemspec path: "../"
13 changes: 7 additions & 6 deletions lib/active_record/acts_as/instance_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ def column_for_attribute(name)
end
end

# Rails 6 introduces the additional argument time, which allows the setup of time
# while touching the model (updating the updated_at or anything time-related). How-
# ever, since our Coursemology usage does not need this, we don't add the arg here.
def touch(*args)
# Rails 6+ adds a `time:` keyword to #touch. Rails' own deferred-touch flow
# (TouchLater#touch_deferred_attributes, run in before_committed!) calls `touch(time:)`, so the
# override MUST accept it — otherwise the kwarg hash is misread as a column name and raises
# ActiveModel::MissingAttributeError. Mirrors upstream (chaadow) v5.x.
def touch(*args, time: nil)
self_args, acting_as_args = args.partition { |arg| has_attribute?(arg, true) }
super(*self_args) if self_args.any?
acting_as.touch(*acting_as_args) if acting_as.persisted?
super(*self_args, time: time) if self_args.any?
acting_as.touch(*acting_as_args, time: time) if acting_as.persisted?
end

def respond_to?(name, include_private = false, as_original_class = false)
Expand Down
2 changes: 1 addition & 1 deletion lib/active_record/acts_as/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ActiveRecord
module ActsAs
VERSION = "4.0.1"
VERSION = "4.1.0"
end
end
10 changes: 5 additions & 5 deletions spec/actable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@

it "raises NoMethodError for undefined methods on specific" do
pen.save
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.3.0')
expect{ pen.product.raise_error }.to raise_error(NoMethodError, /undefined method `non_existant_method' for #<Pen/)
else
expect{ pen.product.raise_error }.to raise_error(NoMethodError, /undefined method `non_existant_method' for an instance of Pen/)
end
# Ruby < 3.3.0: "undefined method `non_existant_method' for #<Pen:..."
# Ruby 3.3.0: "undefined method `non_existant_method' for an instance of Pen"
# Ruby 3.4.0+: "undefined method 'non_existant_method' for an instance of Pen"

expect { pen.product.raise_error }.to raise_error(NoMethodError, /undefined method.*non_existant_method.*for.*Pen/)
end

it "deletes specific subclass on destroy" do
Expand Down
16 changes: 14 additions & 2 deletions spec/acts_as_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
describe '#touch with arguments' do
it "forwards supermodel arguments tothe supermodel" do
pen.save!
expect(pen.product).to receive(:touch).with(:updated_at)
expect(pen.product).to receive(:touch).with(:updated_at, time: nil)
pen.touch(:updated_at, :designed_at)
end

Expand All @@ -242,11 +242,23 @@
describe '#touch without arguments' do
it "touches the supermodel" do
pen.save!
expect(pen.product).to receive(:touch).with(no_args)
expect(pen.product).to receive(:touch).with(time: nil)
pen.touch
end
end

# Regression: Rails 6+ passes a `time:` kwarg to #touch (e.g. the deferred-touch flow that
# belongs_to(touch: true) triggers in before_committed!). The override must accept it rather
# than mistaking the kwarg hash for a column name (ActiveModel::MissingAttributeError).
describe '#touch with a time: keyword' do
it "does not raise and forwards time: to the supermodel" do
pen.save!
now = Time.now
expect(pen.product).to receive(:touch).with(time: now)
expect { pen.touch(time: now) }.not_to raise_error
end
end

describe 'saving' do
it "touches supermodel on save" do
pen.save
Expand Down
Loading