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 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