Skip to content

Commit b58cd72

Browse files
committed
Handle schema_dump_path being unavailable in Rails 6
1 parent 237d92f commit b58cd72

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/ruby_lsp/ruby_lsp_rails/server.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def resolve_database_info_from_model(model_name)
4242
}
4343

4444
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+
4648
end
4749
info
4850
rescue => e

test/ruby_lsp_rails/runner_client_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ class RunnerClientTest < ActiveSupport::TestCase
3131
assert_match(%r{db/schema\.rb$}, response.fetch(:schema_file))
3232
end
3333

34+
test "handles older Rails version which don't have `schema_dump_path`" do
35+
ActiveRecord::Tasks::DatabaseTasks.send(:alias_method, :old_schema_dump_path, :schema_dump_path)
36+
ActiveRecord::Tasks::DatabaseTasks.undef_method(:schema_dump_path)
37+
response = T.must(@client.model("User"))
38+
assert_nil(response[:schema_file])
39+
ensure
40+
ActiveRecord::Tasks::DatabaseTasks.send(:alias_method, :schema_dump_path, :old_schema_dump_path)
41+
end
42+
3443
test "returns nil if model doesn't exist" do
3544
assert_nil @client.model("Foo")
3645
end

0 commit comments

Comments
 (0)