Skip to content

Rename model parameter #35

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 1 commit into from
Apr 19, 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
2 changes: 1 addition & 1 deletion app/controllers/ruby_lsp/rails/models_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ModelsController < ApplicationController

sig { returns(T.untyped) }
def show
const = Object.const_get(params[:id]) # rubocop:disable Sorbet/ConstantsFromStrings
const = Object.const_get(params[:model]) # rubocop:disable Sorbet/ConstantsFromStrings

begin
schema_file = ActiveRecord::Tasks::DatabaseTasks.schema_dump_path(const.connection.pool.db_config)
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# frozen_string_literal: true

RubyLsp::Rails::Engine.routes.draw do
resources :models, only: [:show]
resources :models, only: [:show], param: :model
end
4 changes: 2 additions & 2 deletions sorbet/rbi/shims/actiondispatch.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

module ActionDispatch
class IntegrationTest
sig { params(id: String).returns(String) }
def model_url(id:); end
sig { params(model: String).returns(String) }
def model_url(model:); end
end
end
6 changes: 3 additions & 3 deletions test/controllers/ruby_lsp_rails/models_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ModelsControllerTest < ActionDispatch::IntegrationTest
T.unsafe(self).include(Engine.routes.url_helpers)

test "GET show returns column information for existing models" do
get model_url(id: "User")
get model_url(model: "User")
assert_response(:success)
assert_equal(
{
Expand All @@ -28,12 +28,12 @@ class ModelsControllerTest < ActionDispatch::IntegrationTest
end

test "GET show returns not_found if model doesn't exist" do
get model_url(id: "NonExistentModel")
get model_url(model: "NonExistentModel")
assert_response(:not_found)
end

test "GET show returns not_found if class is not a model" do
get model_url(id: "ApplicationJob")
get model_url(model: "ApplicationJob")
assert_response(:not_found)
end
end
Expand Down