Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing multiplier option for number fields. #642

Merged
merged 1 commit into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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