Skip to content

Commit

Permalink
Add missing multiplier option for number fields. (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
tristandunn authored and nickcharlton committed Mar 7, 2017
1 parent 4ba6e31 commit d296c98
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/administrate/field/number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def to_s
if data.nil?
"-"
else
format_string % data
format_string % value
end
end

Expand All @@ -24,6 +24,10 @@ def prefix
def decimals
options.fetch(:decimals, 0)
end

def value
data * options.fetch(:multiplier, 1)
end
end
end
end
10 changes: 10 additions & 0 deletions spec/lib/fields/number_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d296c98

Please sign in to comment.