Skip to content

Commit

Permalink
Merge pull request #1007 from kivikakk/sole-adjustments
Browse files Browse the repository at this point in the history
Dsl::Compilers::ActiveRecordRelations: fix #find_sole_by, #sole
  • Loading branch information
paracycle committed Jul 1, 2022
1 parent 8effdb0 commit 1084e37
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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

0 comments on commit 1084e37

Please sign in to comment.