From cd8d0dc29ed9abc55dccc107d80b9003b41fb0d1 Mon Sep 17 00:00:00 2001 From: Paul Bob <69730720+Paul-Bob@users.noreply.github.com> Date: Tue, 3 Sep 2024 13:45:35 +0300 Subject: [PATCH] fix: resource fails to show when title is numeric (#3208) --- lib/avo/resources/base.rb | 4 ++++ spec/features/avo/resource_title_spec.rb | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 spec/features/avo/resource_title_spec.rb diff --git a/lib/avo/resources/base.rb b/lib/avo/resources/base.rb index 8675eb844..f72cb01ee 100644 --- a/lib/avo/resources/base.rb +++ b/lib/avo/resources/base.rb @@ -395,6 +395,10 @@ def model_class end def record_title + fetch_record_title.to_s + end + + def fetch_record_title return name if @record.nil? # Get the title from the record if title is not set, try to get the name, title or label, or fallback to the to_param diff --git a/spec/features/avo/resource_title_spec.rb b/spec/features/avo/resource_title_spec.rb new file mode 100644 index 000000000..354ecc3a3 --- /dev/null +++ b/spec/features/avo/resource_title_spec.rb @@ -0,0 +1,11 @@ +require "rails_helper" + +RSpec.feature "Resource title option", type: :feature do + let!(:project) { create :project } + + it "dont raise any error while visiting show viw with title as id" do + with_temporary_class_option(Avo::Resources::Project, :title, :id) do + expect { visit avo.resources_project_path(project) }.not_to raise_error + end + end +end