From d296c9842307443d7f5f594a58aacf8593717335 Mon Sep 17 00:00:00 2001 From: Tristan Dunn Date: Tue, 7 Mar 2017 15:24:56 -0500 Subject: [PATCH] Add missing multiplier option for number fields. (#642) --- lib/administrate/field/number.rb | 6 +++++- spec/lib/fields/number_spec.rb | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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)