Skip to content

Handle schema_dump_path being unavailable in older Rails versions #264

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

Merged
merged 5 commits into from
Feb 21, 2024

Conversation

andyw8
Copy link
Contributor

@andyw8 andyw8 commented Feb 20, 2024

Closes #260. For older Rails versions we will show the fields but won't provide a link to the schema file.

@andyw8 andyw8 changed the title WIP: Handle shema dump path being unavailable in older Rails versions WIP: Handle schema_dump_path being unavailable in older Rails versions Feb 20, 2024
@andyw8 andyw8 force-pushed the andyw8/schema_dump_path-not-in-rails-6 branch from b58cd72 to 77150d4 Compare February 20, 2024 18:29
@@ -26,7 +26,7 @@ class Server

extend T::Sig

sig { params(model_name: String).returns(T.nilable(T::Hash[Symbol, T.untyped])) }
sig { params(model_name: String).returns(T::Hash[Symbol, T.untyped]) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realised that we always return a hash.

@andyw8 andyw8 force-pushed the andyw8/schema_dump_path-not-in-rails-6 branch from 77150d4 to 739fba6 Compare February 20, 2024 18:32
require "test_helper"
require "ruby_lsp/ruby_lsp_rails/server"

class ServerTest < ActiveSupport::TestCase
Copy link
Contributor Author

@andyw8 andyw8 Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vinistock since the server is in a different process, this needs to be tested differently from the other aspects in runner_client_test.rb. But I think it would make sense to move some of the other tests to here too, and leave just #model returns information for the requested model as an integration test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a commit to show how that would look.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine, but let's put the server in an instance variable instead of doing Server.new on every test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine, but let's put the server in an instance variable instead of doing Server.new on every test.

@andyw8 andyw8 changed the title WIP: Handle schema_dump_path being unavailable in older Rails versions Handle schema_dump_path being unavailable in older Rails versions Feb 20, 2024
@andyw8 andyw8 marked this pull request as ready for review February 20, 2024 19:05
@andyw8 andyw8 requested a review from a team as a code owner February 20, 2024 19:06
@andyw8 andyw8 requested review from egiurleo and KaanOzkan February 20, 2024 19:06
@andyw8 andyw8 force-pushed the andyw8/schema_dump_path-not-in-rails-6 branch from 1469313 to 4aadd0b Compare February 20, 2024 19:10
},
}

if ActiveRecord::Tasks::DatabaseTasks.respond_to?(:schema_dump_path)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible we can make this also work in Rails 6 and earlier, if someone wants to open a PR.

@andyw8 andyw8 force-pushed the andyw8/schema_dump_path-not-in-rails-6 branch from 4aadd0b to 2749956 Compare February 20, 2024 19:56
Comment on lines 34 to 44
test "returns nil if model doesn't exist" do
assert_nil @client.model("Foo")
end

test "returns nil if class is not a model" do
assert_nil @client.model("Time")
end

test "returns nil if class is an abstract model" do
assert_nil @client.model("ApplicationRecord")
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we keep this? It looks like model returns nilable information since result could be nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, restored.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you restore all of them? I'm only seeing the abstract one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one, to validate the nil return. I don't think it's necessary to re-verify the behaviour already covered in server_test.rb?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. It's covered in the new test. 👍

require "test_helper"
require "ruby_lsp/ruby_lsp_rails/server"

class ServerTest < ActiveSupport::TestCase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine, but let's put the server in an instance variable instead of doing Server.new on every test.

require "test_helper"
require "ruby_lsp/ruby_lsp_rails/server"

class ServerTest < ActiveSupport::TestCase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine, but let's put the server in an instance variable instead of doing Server.new on every test.

@andyw8 andyw8 force-pushed the andyw8/schema_dump_path-not-in-rails-6 branch from 562cdf1 to efe472b Compare February 21, 2024 15:24
@egiurleo egiurleo removed their request for review February 21, 2024 20:47
@andyw8 andyw8 merged commit 315db8e into main Feb 21, 2024
@andyw8 andyw8 deleted the andyw8/schema_dump_path-not-in-rails-6 branch February 21, 2024 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rails 6.x compatibility broken due to schema_dump_path
2 participants