Skip to content

Commit a44dc3f

Browse files
committed
Revise testing approach
1 parent 2a30aca commit a44dc3f

File tree

1 file changed

+7
-92
lines changed

1 file changed

+7
-92
lines changed

test/ruby_lsp_rails/hover_test.rb

+7-92
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,6 @@ class HoverTest < ActiveSupport::TestCase
2424
end
2525

2626
test "hook returns model column information" do
27-
expected_response = {
28-
schema_file: "#{dummy_root}/db/schema.rb",
29-
columns: [
30-
["id", "integer"],
31-
["first_name", "string"],
32-
["last_name", "string"],
33-
["age", "integer"],
34-
["created_at", "datetime"],
35-
["updated_at", "datetime"],
36-
],
37-
primary_keys: ["id"],
38-
}
39-
40-
RunnerClient.any_instance.stubs(model: expected_response)
41-
4227
response = hover_on_source(<<~RUBY, { line: 3, character: 0 })
4328
class User < ApplicationRecord
4429
end
@@ -70,40 +55,23 @@ class User < ApplicationRecord
7055
end
7156

7257
test "return column information for namespaced models" do
73-
expected_response = {
74-
schema_file: "#{dummy_root}/db/schema.rb",
75-
columns: [
76-
["id", "integer"],
77-
["first_name", "string"],
78-
["last_name", "string"],
79-
["age", "integer"],
80-
["created_at", "datetime"],
81-
["updated_at", "datetime"],
82-
],
83-
primary_keys: ["id"],
84-
}
85-
86-
RunnerClient.any_instance.stubs(model: expected_response)
87-
8858
response = hover_on_source(<<~RUBY, { line: 4, character: 6 })
8959
module Blog
90-
class User < ApplicationRecord
60+
class Post < ApplicationRecord
9161
end
9262
end
9363
94-
Blog::User
64+
Blog::Post
9565
RUBY
9666

9767
assert_equal(<<~CONTENT.chomp, response.contents.value)
9868
[Schema](file://#{dummy_root}/db/schema.rb)
9969
10070
**id**: integer (PK)
10171
102-
**first_name**: string
103-
104-
**last_name**: string
72+
**title**: string
10573
106-
**age**: integer
74+
**body**: text
10775
10876
**created_at**: datetime
10977
@@ -112,20 +80,6 @@ class User < ApplicationRecord
11280
end
11381

11482
test "returns column information for models with composite primary keys" do
115-
expected_response = {
116-
schema_file: "#{dummy_root}/db/schema.rb",
117-
columns: [
118-
["order_id", "integer"],
119-
["product_id", "integer"],
120-
["note", "string"],
121-
["created_at", "datetime"],
122-
["updated_at", "datetime"],
123-
],
124-
primary_keys: ["order_id", "product_id"],
125-
}
126-
127-
RunnerClient.any_instance.stubs(model: expected_response)
128-
12983
response = hover_on_source(<<~RUBY, { line: 3, character: 0 })
13084
class CompositePrimaryKey < ApplicationRecord
13185
end
@@ -146,55 +100,14 @@ class CompositePrimaryKey < ApplicationRecord
146100
147101
**product_id**: integer (PK)
148102
149-
**note**: string
103+
**note**: text
150104
151105
**created_at**: datetime
152106
153107
**updated_at**: datetime
154108
CONTENT
155109
end
156110

157-
test "handles `db/structure.sql` instead of `db/schema.rb`" do
158-
expected_response = {
159-
schema_file: "#{dummy_root}/db/structure.sql",
160-
columns: [],
161-
primary_keys: [],
162-
}
163-
164-
RunnerClient.any_instance.stubs(model: expected_response)
165-
166-
response = hover_on_source(<<~RUBY, { line: 3, character: 0 })
167-
class User < ApplicationRecord
168-
end
169-
170-
User
171-
RUBY
172-
173-
assert_includes(
174-
response.contents.value,
175-
"[Schema](file://#{dummy_root}/db/structure.sql)",
176-
)
177-
end
178-
179-
test "handles neither `db/structure.sql` nor `db/schema.rb` being present" do
180-
expected_response = {
181-
schema_file: nil,
182-
columns: [],
183-
primary_keys: [],
184-
}
185-
186-
RunnerClient.any_instance.stubs(model: expected_response)
187-
188-
response = hover_on_source(<<~RUBY, { line: 3, character: 0 })
189-
class User < ApplicationRecord
190-
end
191-
192-
User
193-
RUBY
194-
195-
refute_match(/Schema/, response.contents.value)
196-
end
197-
198111
test "shows documentation for routes DSLs" do
199112
value = hover_on_source("root 'projects#index'", { line: 0, character: 0 }).contents.value
200113

@@ -238,6 +151,8 @@ class ActiveRecord::Base
238151

239152
def hover_on_source(source, position)
240153
with_server(source) do |server, uri|
154+
sleep(0.1) while RubyLsp::Addon.addons.first.instance_variable_get(:@client).is_a?(NullClient)
155+
241156
server.process_message(
242157
id: 1,
243158
method: "textDocument/hover",

0 commit comments

Comments
 (0)