From 31db419454b763f5c9cd4ee9e9819402556ef74d Mon Sep 17 00:00:00 2001 From: Martin Mochetti Date: Wed, 7 May 2025 08:47:59 -0300 Subject: [PATCH 1/2] Update annotate_models.rb Update quote method to account for default values that are objects that implement the `to_s` method --- lib/annotate/annotate_models.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/annotate/annotate_models.rb b/lib/annotate/annotate_models.rb index dc2901a3..c87cc4bc 100644 --- a/lib/annotate/annotate_models.rb +++ b/lib/annotate/annotate_models.rb @@ -107,7 +107,7 @@ def quote(value) when BigDecimal then value.to_s('F') when Array then value.map { |v| quote(v) } else - value.inspect + value.respond_to?(:to_s) ? value.to_s.inspect : value.inspect end end From 7edb9ab282a52e2c84688333d0a9de89dcf7221c Mon Sep 17 00:00:00 2001 From: Martin Mochetti Date: Wed, 7 May 2025 09:03:01 -0300 Subject: [PATCH 2/2] Add test --- spec/lib/annotate/annotate_models_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index 09647461..46d395ba 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -152,6 +152,20 @@ def mock_column(name, type, options = {}) is_expected.to eq(['1.2']) end end + + context 'when the argument is an object that responds to to_s' do + let(:value) do + obj = Object.new + def obj.to_s + "custom string representation" + end + obj + end + + it 'returns the result of to_s wrapped in quotes' do + is_expected.to eq('"custom string representation"') + end + end end describe '.parse_options' do