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
7 changes: 0 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ jobs:
matrix:
ruby-version: ["3.3", "3.4", "4.0"]
active-record:
- label: AR 7.2
env: ACTIVE_RECORD_VERSION=~> 7.2.0
- label: AR 8.0
env: ACTIVE_RECORD_VERSION=~> 8.0.0
- label: AR 8.1
Expand All @@ -52,11 +50,6 @@ jobs:
label: AR 8-0-stable
env: ACTIVE_RECORD_BRANCH=8-0-stable
allow-failure: true
- ruby-version: "4.0"
active-record:
label: AR 7-2-stable
env: ACTIVE_RECORD_BRANCH=7-2-stable
allow-failure: true
# A canary for the next Ruby, which cannot fail the build.
- ruby-version: ruby-head
active-record:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
### Unreleased

- Require Active Record 8.0 or later.

### 2.3.1

- Honor Active Record destruction callbacks and dependent associations when
Expand Down
14 changes: 3 additions & 11 deletions lib/with_model/descendants_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ def descendants
end
end

class ActiveRecord::Base
extend WithModel::DescendantsTracker::DestroyedClassesFiltering
end

module ActiveSupport
module DescendantsTracker
class << self
attr_reader :clear_disabled
end
end
end
ActiveRecord::Base.singleton_class.prepend(
WithModel::DescendantsTracker::DestroyedClassesFiltering
)
13 changes: 0 additions & 13 deletions lib/with_model/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ def destroy
# can only do so while the class still has its name.
table.teardown(@model)
stubber.unstub_const
cleanup_descendants_tracking
reset_dependencies_cache
WithModel::DescendantsTracker.clear([@model])
@model = nil
end
Expand Down Expand Up @@ -132,17 +130,6 @@ def setup_model
@model.reset_column_information
end

def cleanup_descendants_tracking
ActiveSupport::DescendantsTracker.clear([@model]) \
unless ActiveSupport::DescendantsTracker.clear_disabled
end

def reset_dependencies_cache
return unless defined?(ActiveSupport::Dependencies::Reference)

ActiveSupport::Dependencies::Reference.clear!
end

def stubber
@stubber ||= ConstantStubber.new const_name
end
Expand Down
8 changes: 1 addition & 7 deletions lib/with_model/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ def destroy

attr_reader :connection

def exists?
if connection.respond_to?(:data_source_exists?)
connection.data_source_exists?(@name)
else
connection.table_exists?(@name)
end
end
def exists? = connection.data_source_exists?(@name)
end
end
22 changes: 20 additions & 2 deletions spec/descendants_tracking_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def blog_post_classes

context "with ActiveSupport::DescendantsTracker (cache_classes: true)" do
before do
expect(ActiveSupport::DescendantsTracker.clear_disabled).to be_falsey
expect { ActiveSupport::DescendantsTracker.clear([]) }.not_to raise_exception
end

Expand All @@ -40,10 +39,29 @@ def blog_post_classes
context "without ActiveSupport::DescendantsTracker (cache_classes: false)" do
before do
ActiveSupport::DescendantsTracker.disable_clear!
expect(ActiveSupport::DescendantsTracker.clear_disabled).to be_truthy
expect { ActiveSupport::DescendantsTracker.clear([]) }.to raise_exception(RuntimeError)
end

include_examples "clearing descendants between test runs"
end

it "keeps filtering ahead of later class method extensions" do
raw_subclasses = Class.instance_method(:subclasses).super_method
raw_descendants = Class.instance_method(:descendants).super_method
override = Module.new do
define_method(:subclasses) { raw_subclasses.bind_call(self) }
define_method(:descendants) { raw_descendants.bind_call(self) }
end
destroyed_model = stub_const("DestroyedModel", Class.new(ActiveRecord::Base))
WithModel::DescendantsTracker.clear([destroyed_model])

ActiveRecord::Base.extend override

expect(ActiveRecord::Base.descendants).not_to include(destroyed_model)
ensure
override&.module_eval do
remove_method :subclasses
remove_method :descendants
end
end
end
4 changes: 0 additions & 4 deletions spec/table_false_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ def stub_active_record_class(name, superclass: ActiveRecord::Base)
classes = @stubbed_active_record_classes
next unless classes

ActiveSupport::DescendantsTracker.clear(classes) \
unless ActiveSupport::DescendantsTracker.clear_disabled
ActiveSupport::Dependencies::Reference.clear! \
if defined?(ActiveSupport::Dependencies::Reference)
WithModel::DescendantsTracker.clear(classes)
end

Expand Down
2 changes: 1 addition & 1 deletion with_model.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = ">= 3.3"

spec.add_dependency "activerecord", ">= 7.2"
spec.add_dependency "activerecord", ">= 8.0"
end