File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
lib/ruby_lsp/ruby_lsp_rails Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ def execute(request, params)
82
82
sig { params ( model_name : String ) . returns ( T ::Hash [ Symbol , T . untyped ] ) }
83
83
def resolve_database_info_from_model ( model_name )
84
84
const = ActiveSupport ::Inflector . safe_constantize ( model_name )
85
- unless const && defined? ( ActiveRecord ) && const < ActiveRecord :: Base && ! const . abstract_class?
85
+ unless active_record_model? ( const )
86
86
return {
87
87
result : nil ,
88
88
}
@@ -104,6 +104,16 @@ def resolve_database_info_from_model(model_name)
104
104
rescue => e
105
105
{ error : e . full_message ( highlight : false ) }
106
106
end
107
+
108
+ sig { params ( const : T . untyped ) . returns ( T ::Boolean ) }
109
+ def active_record_model? ( const )
110
+ !!(
111
+ const &&
112
+ defined? ( ActiveRecord ) &&
113
+ ActiveRecord ::Base > const && # We do this 'backwards' in case the class overwrites `<`
114
+ !const . abstract_class?
115
+ )
116
+ end
107
117
end
108
118
end
109
119
end
Original file line number Diff line number Diff line change @@ -24,6 +24,19 @@ class ServerTest < ActiveSupport::TestCase
24
24
assert_nil ( response . fetch ( :result ) )
25
25
end
26
26
27
+ test "doesn't fail if the class overrides `<`" do
28
+ class TestClassWithOverwrittenLessThan
29
+ class << self
30
+ def <( other )
31
+ raise
32
+ end
33
+ end
34
+ end
35
+
36
+ response = @server . execute ( "model" , { name : "TestClassWithOverwrittenLessThan" } )
37
+ assert_nil ( response . fetch ( :result ) )
38
+ end
39
+
27
40
test "handles older Rails version which don't have `schema_dump_path`" do
28
41
ActiveRecord ::Tasks ::DatabaseTasks . send ( :alias_method , :old_schema_dump_path , :schema_dump_path )
29
42
ActiveRecord ::Tasks ::DatabaseTasks . undef_method ( :schema_dump_path )
You can’t perform that action at this time.
0 commit comments