-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revise testing approach #319
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,21 +24,6 @@ class HoverTest < ActiveSupport::TestCase | |
end | ||
|
||
test "hook returns model column information" do | ||
expected_response = { | ||
schema_file: "#{dummy_root}/db/schema.rb", | ||
columns: [ | ||
["id", "integer"], | ||
["first_name", "string"], | ||
["last_name", "string"], | ||
["age", "integer"], | ||
["created_at", "datetime"], | ||
["updated_at", "datetime"], | ||
], | ||
primary_keys: ["id"], | ||
} | ||
|
||
RunnerClient.any_instance.stubs(model: expected_response) | ||
|
||
response = hover_on_source(<<~RUBY, { line: 3, character: 0 }) | ||
class User < ApplicationRecord | ||
end | ||
|
@@ -70,40 +55,23 @@ class User < ApplicationRecord | |
end | ||
|
||
test "return column information for namespaced models" do | ||
expected_response = { | ||
schema_file: "#{dummy_root}/db/schema.rb", | ||
columns: [ | ||
["id", "integer"], | ||
["first_name", "string"], | ||
["last_name", "string"], | ||
["age", "integer"], | ||
["created_at", "datetime"], | ||
["updated_at", "datetime"], | ||
], | ||
primary_keys: ["id"], | ||
} | ||
|
||
RunnerClient.any_instance.stubs(model: expected_response) | ||
|
||
response = hover_on_source(<<~RUBY, { line: 4, character: 6 }) | ||
module Blog | ||
class User < ApplicationRecord | ||
class Post < ApplicationRecord | ||
end | ||
end | ||
|
||
Blog::User | ||
Blog::Post | ||
RUBY | ||
|
||
assert_equal(<<~CONTENT.chomp, response.contents.value) | ||
[Schema](#{URI::Generic.from_path(path: dummy_root + "/db/schema.rb")}) | ||
|
||
**id**: integer (PK) | ||
|
||
**first_name**: string | ||
**title**: string | ||
|
||
**last_name**: string | ||
|
||
**age**: integer | ||
**body**: text | ||
|
||
**created_at**: datetime | ||
|
||
|
@@ -112,20 +80,6 @@ class User < ApplicationRecord | |
end | ||
|
||
test "returns column information for models with composite primary keys" do | ||
expected_response = { | ||
schema_file: "#{dummy_root}/db/schema.rb", | ||
columns: [ | ||
["order_id", "integer"], | ||
["product_id", "integer"], | ||
["note", "string"], | ||
["created_at", "datetime"], | ||
["updated_at", "datetime"], | ||
], | ||
primary_keys: ["order_id", "product_id"], | ||
} | ||
|
||
RunnerClient.any_instance.stubs(model: expected_response) | ||
|
||
response = hover_on_source(<<~RUBY, { line: 3, character: 0 }) | ||
class CompositePrimaryKey < ApplicationRecord | ||
end | ||
|
@@ -146,7 +100,7 @@ class CompositePrimaryKey < ApplicationRecord | |
|
||
**product_id**: integer (PK) | ||
|
||
**note**: string | ||
**note**: text | ||
|
||
**created_at**: datetime | ||
|
||
|
@@ -238,6 +192,8 @@ class ActiveRecord::Base | |
|
||
def hover_on_source(source, position) | ||
with_server(source) do |server, uri| | ||
sleep(0.1) while RubyLsp::Addon.addons.first.instance_variable_get(:@client).is_a?(NullClient) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same approach as we're using in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that we should extract it into a helper. And I also think in that helper we should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we can extract that part out too, e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does feel like something addons can use during testing 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
server.process_message( | ||
id: 1, | ||
method: "textDocument/hover", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(the stubbed response was incorrect!)