Skip to content

Commit dca96e0

Browse files
authored
Merge pull request #45 from Shopify/vs/find_correct_project_root_when_using_custom_bundle
Find the correct project root when using custom bundle
2 parents a691c13 + ae7e03d commit dca96e0

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

bin/rails

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# installed from the root of your application.
66

77
ENGINE_ROOT = File.expand_path("..", __dir__)
8-
ENGINE_PATH = File.expand_path("../lib/ruby_lsp_rails/engine", __dir__)
98
APP_PATH = File.expand_path("../test/dummy/config/application", __dir__)
109

1110
# Set up gems listed in the Gemfile.

lib/ruby_lsp/ruby_lsp_rails/rails_client.rb

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ class NeedsRestartError < StandardError; end
2222
sig { void }
2323
def initialize
2424
project_root = Pathname.new(ENV["BUNDLE_GEMFILE"]).dirname
25+
26+
if project_root.basename.to_s == ".ruby-lsp"
27+
project_root = project_root.join("../")
28+
end
29+
2530
dummy_path = File.join(project_root, "test", "dummy")
2631
@root = T.let(Dir.exist?(dummy_path) ? dummy_path : project_root.to_s, String)
2732
app_uri_path = "#{@root}/tmp/app_uri.txt"

test/dummy/db/schema.rb

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# typed: true
2-
# frozen_string_literal: true
3-
41
# This file is auto-generated from the current state of the database. Instead
52
# of editing this file, please use the migrations feature of Active Record to
63
# incrementally modify your database, and then regenerate this schema definition.
@@ -15,10 +12,11 @@
1512

1613
ActiveRecord::Schema[7.0].define(version: 2023_03_30_202955) do
1714
create_table "users", force: :cascade do |t|
18-
t.string("first_name")
19-
t.string("last_name")
20-
t.integer("age")
21-
t.datetime("created_at", null: false)
22-
t.datetime("updated_at", null: false)
15+
t.string "first_name"
16+
t.string "last_name"
17+
t.integer "age"
18+
t.datetime "created_at", null: false
19+
t.datetime "updated_at", null: false
2320
end
21+
2422
end

test/lib/rails_client_test.rb

+15
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ class RailsClientTest < ActiveSupport::TestCase
3838
ensure
3939
File.write(T.must(app_uri_path), "http://localhost:3000")
4040
end
41+
42+
test "instantiation finds the right directory when bundle gemfile points to .ruby-lsp" do
43+
previous_bundle_gemfile = ENV["BUNDLE_GEMFILE"]
44+
project_root = Pathname.new(previous_bundle_gemfile).dirname
45+
46+
# If the RailsClient singleton was initialized in a different test successfully, then there would be no chance
47+
# for this assertion to pass. We need to reset the singleton instance in order to force `initialize` to be
48+
# executed again
49+
Singleton.send(:__init__, RailsClient)
50+
51+
ENV["BUNDLE_GEMFILE"] = "#{project_root}/.ruby-lsp/Gemfile"
52+
assert_equal("#{project_root}/test/dummy", RailsClient.instance.root)
53+
ensure
54+
ENV["BUNDLE_GEMFILE"] = previous_bundle_gemfile
55+
end
4156
end
4257
end
4358
end

0 commit comments

Comments
 (0)