Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Make scopes available for abstract classes" #1431

Merged
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
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/active_record_relations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class << self

sig { override.returns(T::Enumerable[Module]) }
def gather_constants
descendants_of(ActiveRecord::Base).reject(&:abstract_class?)
ActiveRecord::Base.descendants.reject(&:abstract_class?)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/active_record_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def decorate
class << self
sig { override.returns(T::Enumerable[Module]) }
def gather_constants
descendants_of(::ActiveRecord::Base)
descendants_of(::ActiveRecord::Base).reject(&:abstract_class?)
end
end

Expand Down
45 changes: 6 additions & 39 deletions spec/tapioca/dsl/compilers/active_record_scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ActiveRecordScopeSpec < ::DslSpec
assert_empty(gathered_constants)
end

it "gathers ActiveRecord constants including abstract classes" do
it "gathers only ActiveRecord constants with no abstract classes" do
add_ruby_file("conversation.rb", <<~RUBY)
class Post < ActiveRecord::Base
end
Expand All @@ -26,7 +26,7 @@ class User
end
RUBY

assert_equal(["Post", "Product"], gathered_constants)
assert_equal(["Post"], gathered_constants)
end
end

Expand Down Expand Up @@ -174,25 +174,7 @@ class Post < ApplicationRecord
end
RUBY

expected_application_record = <<~RBI
# typed: strong

class ApplicationRecord
extend GeneratedRelationMethods

module GeneratedAssociationRelationMethods
sig { params(args: T.untyped, blk: T.untyped).returns(PrivateAssociationRelation) }
def app_scope(*args, &blk); end
end

module GeneratedRelationMethods
sig { params(args: T.untyped, blk: T.untyped).returns(PrivateRelation) }
def app_scope(*args, &blk); end
end
end
RBI

expected_post = <<~RBI
expected = <<~RBI
# typed: strong

class Post
Expand All @@ -216,8 +198,7 @@ def post_scope(*args, &blk); end
end
RBI

assert_equal(expected_application_record, rbi_for(:ApplicationRecord))
assert_equal(expected_post, rbi_for(:Post))
assert_equal(expected, rbi_for(:Post))
end
end

Expand Down Expand Up @@ -367,20 +348,7 @@ class Post < ApplicationRecord
end
RUBY

expected_application_record = <<~RBI
# typed: strong

class ApplicationRecord
extend GeneratedRelationMethods

module GeneratedRelationMethods
sig { params(args: T.untyped, blk: T.untyped).returns(T.untyped) }
def app_scope(*args, &blk); end
end
end
RBI

expected_post = <<~RBI
expected = <<~RBI
# typed: strong

class Post
Expand All @@ -396,8 +364,7 @@ def post_scope(*args, &blk); end
end
RBI

assert_equal(expected_application_record, rbi_for(:ApplicationRecord))
assert_equal(expected_post, rbi_for(:Post))
assert_equal(expected, rbi_for(:Post))
end
end
end
Expand Down