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

Dsl::Compilers::ActiveRecordRelations: fix #find_sole_by, #sole #1007

Merged
merged 1 commit into from
Jun 27, 2022
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
17 changes: 17 additions & 0 deletions lib/tapioca/dsl/compilers/active_record_relations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,23 @@ def create_common_methods(common_relation_methods_module)
],
return_type: constant_name
)
when :find_sole_by
create_common_method(
"find_sole_by",
common_relation_methods_module,
parameters: [
create_param("arg", type: "T.untyped"),
create_rest_param("args", type: "T.untyped"),
],
return_type: constant_name
)
when :sole
create_common_method(
"sole",
common_relation_methods_module,
parameters: [],
return_type: constant_name
)
when :first, :last, :take
create_common_method(
method_name,
Expand Down
6 changes: 3 additions & 3 deletions spec/tapioca/dsl/compilers/active_record_relations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def find_or_create_by!(attributes, &block); end
sig { params(attributes: T.untyped, block: T.nilable(T.proc.params(object: ::Post).void)).returns(::Post) }
def find_or_initialize_by(attributes, &block); end

sig { returns(T.nilable(::Post)) }
def find_sole_by; end
sig { params(arg: T.untyped, args: T.untyped).returns(::Post) }
def find_sole_by(arg, *args); end

sig { params(limit: T.untyped).returns(T.untyped) }
def first(limit = nil); end
Expand Down Expand Up @@ -183,7 +183,7 @@ def second_to_last; end
sig { returns(::Post) }
def second_to_last!; end

sig { returns(T.nilable(::Post)) }
sig { returns(::Post) }
def sole; end

sig { params(column_name: T.nilable(T.any(String, Symbol)), block: T.nilable(T.proc.params(record: T.untyped).returns(T.untyped))).returns(T.untyped) }
Expand Down