Skip to content

Commit

Permalink
Prevent invalid ActiveRecord check against constant (Shopify#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 authored Jun 13, 2024
1 parent 02c6014 commit 9be01d0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/ruby_lsp/ruby_lsp_rails/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def active_record_model?(const)
!!(
const &&
defined?(ActiveRecord) &&
const.is_a?(Class) &&
ActiveRecord::Base > const && # We do this 'backwards' in case the class overwrites `<`
!const.abstract_class?
)
Expand Down
5 changes: 5 additions & 0 deletions test/ruby_lsp_rails/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class ServerTest < ActiveSupport::TestCase
assert_nil(response.fetch(:result))
end

test "returns nil if constant is not a class" do
response = @server.execute("model", { name: "RUBY_VERSION" })
assert_nil(response.fetch(:result))
end

test "doesn't fail if the class overrides `<`" do
class TestClassWithOverwrittenLessThan
class << self
Expand Down

0 comments on commit 9be01d0

Please sign in to comment.