From 6bd2c973b6712b53bd873fa16de53e040393d981 Mon Sep 17 00:00:00 2001 From: Asherah Connor Date: Tue, 21 Jun 2022 22:18:42 +1000 Subject: [PATCH] Dsl::Compilers::ActiveRecordRelations: fix #find_sole_by, #sole --- .../dsl/compilers/active_record_relations.rb | 17 +++++++++++++++++ .../compilers/active_record_relations_spec.rb | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/tapioca/dsl/compilers/active_record_relations.rb b/lib/tapioca/dsl/compilers/active_record_relations.rb index 40b15e057..2ccf5d0c0 100644 --- a/lib/tapioca/dsl/compilers/active_record_relations.rb +++ b/lib/tapioca/dsl/compilers/active_record_relations.rb @@ -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, diff --git a/spec/tapioca/dsl/compilers/active_record_relations_spec.rb b/spec/tapioca/dsl/compilers/active_record_relations_spec.rb index 429de0aa5..ba181c4bf 100644 --- a/spec/tapioca/dsl/compilers/active_record_relations_spec.rb +++ b/spec/tapioca/dsl/compilers/active_record_relations_spec.rb @@ -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 @@ -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) }