diff --git a/lib/administrate/field/number.rb b/lib/administrate/field/number.rb index c366c1a13e..cb6f9abb48 100644 --- a/lib/administrate/field/number.rb +++ b/lib/administrate/field/number.rb @@ -7,7 +7,7 @@ def to_s if data.nil? "-" else - format_string % data + format_string % value end end @@ -24,6 +24,10 @@ def prefix def decimals options.fetch(:decimals, 0) end + + def value + data * options.fetch(:multiplier, 1) + end end end end diff --git a/spec/lib/fields/number_spec.rb b/spec/lib/fields/number_spec.rb index 095f12750a..6c07bd9b54 100644 --- a/spec/lib/fields/number_spec.rb +++ b/spec/lib/fields/number_spec.rb @@ -53,6 +53,16 @@ end end + context "with `multiplier` option" do + it "multiples the number by the given multiplier" do + hundredth = number_with_options(100, multiplier: 0.01) + ten = number_with_options(100, multiplier: 10) + + expect(hundredth.to_s).to eq("1") + expect(ten.to_s).to eq("1000") + end + end + context "when data is nil" do it "returns a dash" do number = Administrate::Field::Number.new(:number, nil, :page)