File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
lib/ruby_lsp/ruby_lsp_rails Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ class Server
26
26
27
27
extend T ::Sig
28
28
29
- sig { params ( model_name : String ) . returns ( T . nilable ( T ::Hash [ Symbol , T . untyped ] ) ) }
29
+ sig { params ( model_name : String ) . returns ( T ::Hash [ Symbol , T . untyped ] ) }
30
30
def resolve_database_info_from_model ( model_name )
31
31
const = ActiveSupport ::Inflector . safe_constantize ( model_name )
32
32
unless const && const < ActiveRecord ::Base && !const . abstract_class?
@@ -42,7 +42,9 @@ def resolve_database_info_from_model(model_name)
42
42
}
43
43
44
44
if ActiveRecord ::Tasks ::DatabaseTasks . respond_to? ( :schema_dump_path )
45
- info [ :schema_file ] = ActiveRecord ::Tasks ::DatabaseTasks . schema_dump_path ( const . connection . pool . db_config )
45
+ info [ :result ] [ :schema_file ] =
46
+ ActiveRecord ::Tasks ::DatabaseTasks . schema_dump_path ( const . connection . pool . db_config )
47
+
46
48
end
47
49
info
48
50
rescue => e
Original file line number Diff line number Diff line change
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require "test_helper"
5
+ require "ruby_lsp/ruby_lsp_rails/server"
6
+
7
+ require "test_helper"
8
+ class ServerTest < ActiveSupport ::TestCase
9
+ test "handles older Rails version which don't have `schema_dump_path`" do
10
+ ActiveRecord ::Tasks ::DatabaseTasks . send ( :alias_method , :old_schema_dump_path , :schema_dump_path )
11
+ ActiveRecord ::Tasks ::DatabaseTasks . undef_method ( :schema_dump_path )
12
+ response = RubyLsp ::Rails ::Server . new . resolve_database_info_from_model ( "User" )
13
+ assert_nil ( response . fetch ( :result ) [ :schema_file ] )
14
+ ensure
15
+ ActiveRecord ::Tasks ::DatabaseTasks . send ( :alias_method , :schema_dump_path , :old_schema_dump_path )
16
+ end
17
+ end
You can’t perform that action at this time.
0 commit comments