Commit 5f9fa909 by John Gesimondo

Quote each value in default arrays

Previously, quoting an array fell back to `inspect`, which is ok for strings, but not good for BigDecimals, for instance.
parent 02ed4dae
...@@ -93,6 +93,7 @@ module AnnotateModels ...@@ -93,6 +93,7 @@ module AnnotateModels
when Float, Fixnum, Bignum then value.to_s when Float, Fixnum, Bignum then value.to_s
# BigDecimals need to be output in a non-normalized form and quoted. # BigDecimals need to be output in a non-normalized form and quoted.
when BigDecimal then value.to_s('F') when BigDecimal then value.to_s('F')
when Array then value.map {|v| quote(v)}
else else
value.inspect value.inspect
end end
......
...@@ -56,6 +56,8 @@ describe AnnotateModels do ...@@ -56,6 +56,8 @@ describe AnnotateModels do
it { expect(AnnotateModels.quote(25)).to eql("25") } it { expect(AnnotateModels.quote(25)).to eql("25") }
it { expect(AnnotateModels.quote(25.6)).to eql("25.6") } it { expect(AnnotateModels.quote(25.6)).to eql("25.6") }
it { expect(AnnotateModels.quote(1e-20)).to eql("1.0e-20") } it { expect(AnnotateModels.quote(1e-20)).to eql("1.0e-20") }
it { expect(AnnotateModels.quote(BigDecimal.new("1.2"))).to eql("1.2") }
it { expect(AnnotateModels.quote([BigDecimal.new("1.2")])).to eql(["1.2"]) }
it "should get schema info" do it "should get schema info" do
klass = mock_class(:users, :id, [ klass = mock_class(:users, :id, [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment