Skip to content

Find the correct project root when using custom bundle #45

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 2 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bin/rails
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# installed from the root of your application.

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

# Set up gems listed in the Gemfile.
Expand Down
5 changes: 5 additions & 0 deletions lib/ruby_lsp/ruby_lsp_rails/rails_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class NeedsRestartError < StandardError; end
sig { void }
def initialize
project_root = Pathname.new(ENV["BUNDLE_GEMFILE"]).dirname

if project_root.basename.to_s == ".ruby-lsp"
project_root = project_root.join("../")
end

dummy_path = File.join(project_root, "test", "dummy")
@root = T.let(Dir.exist?(dummy_path) ? dummy_path : project_root.to_s, String)
app_uri_path = "#{@root}/tmp/app_uri.txt"
Expand Down
14 changes: 6 additions & 8 deletions test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# typed: true
# frozen_string_literal: true

# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
Expand All @@ -15,10 +12,11 @@

ActiveRecord::Schema[7.0].define(version: 2023_03_30_202955) do
create_table "users", force: :cascade do |t|
t.string("first_name")
t.string("last_name")
t.integer("age")
t.datetime("created_at", null: false)
t.datetime("updated_at", null: false)
t.string "first_name"
t.string "last_name"
t.integer "age"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

end
15 changes: 15 additions & 0 deletions test/lib/rails_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ class RailsClientTest < ActiveSupport::TestCase
ensure
File.write(T.must(app_uri_path), "http://localhost:3000")
end

test "instantiation finds the right directory when bundle gemfile points to .ruby-lsp" do
previous_bundle_gemfile = ENV["BUNDLE_GEMFILE"]
project_root = Pathname.new(previous_bundle_gemfile).dirname

# If the RailsClient singleton was initialized in a different test successfully, then there would be no chance
# for this assertion to pass. We need to reset the singleton instance in order to force `initialize` to be
# executed again
Singleton.send(:__init__, RailsClient)

ENV["BUNDLE_GEMFILE"] = "#{project_root}/.ruby-lsp/Gemfile"
assert_equal("#{project_root}/test/dummy", RailsClient.instance.root)
ensure
ENV["BUNDLE_GEMFILE"] = previous_bundle_gemfile
end
end
end
end