Skip to content

Commit 284da6e

Browse files
committed
Add Runner client
1 parent 00caa31 commit 284da6e

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# typed: true
2+
# frozen_string_literal: true
3+
4+
require "test_helper"
5+
require "ruby_lsp/ruby_lsp_rails/runner_client"
6+
7+
module RubyLsp
8+
module Rails
9+
class RunnerClientTest < ActiveSupport::TestCase
10+
setup do
11+
@client = T.let(RunnerClient.new, RunnerClient)
12+
end
13+
14+
teardown do
15+
@client.shutdown
16+
17+
assert_predicate @client.instance_variable_get(:@stdin), :closed?
18+
assert_predicate @client.instance_variable_get(:@stdout), :closed?
19+
assert_predicate @client.instance_variable_get(:@stderr), :closed?
20+
refute_predicate @client.instance_variable_get(:@wait_thread), :alive?
21+
end
22+
23+
test "model returns information for the requested model" do
24+
columns = [
25+
["id", "integer"],
26+
["first_name", "string"],
27+
["last_name", "string"],
28+
["age", "integer"],
29+
["created_at", "datetime"],
30+
["updated_at", "datetime"],
31+
]
32+
response = T.must(@client.model("User"))
33+
assert_equal(columns, response.fetch(:columns))
34+
assert_match(%r{db/schema\.rb$}, response.fetch(:schema_file))
35+
end
36+
37+
test "returns nil if model doesn't exist" do
38+
assert_nil @client.model("Foo")
39+
end
40+
41+
test "returns nil if class is not a model" do
42+
assert_nil @client.model("Time")
43+
end
44+
45+
test "returns nil if class is an abstract model" do
46+
assert_nil @client.model("ApplicationRecord")
47+
end
48+
end
49+
end
50+
end

0 commit comments

Comments
 (0)