mirror of
https://github.com/we-promise/sure.git
synced 2026-04-18 19:44:09 +00:00
Update hard-coded currency UI with currency specific params (#488)
* Update hard-coded currency UI with currency specific params * Rename extension methods to match currency option names; Move cents extension to numeric class extension * Use currency's precision to show the cents part in accounts show page --------- Co-authored-by: Sriram Krishnan <sriram@seafoodsouq.com>
This commit is contained in:
28
test/initializers/numeric_extensions_test.rb
Normal file
28
test/initializers/numeric_extensions_test.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
# test/initializers/big_decimal_extensions_test.rb
|
||||
require "test_helper"
|
||||
|
||||
class NumericExtensionsTest < ActiveSupport::TestCase
|
||||
test "#cents returns the cents part with 2 precisions by default" do
|
||||
amount = 123.45
|
||||
assert_equal "45", amount.cents
|
||||
end
|
||||
|
||||
test "#cents returns empty when precision is 0" do
|
||||
amount = 123.45
|
||||
assert_equal "", amount.cents(precision: 0)
|
||||
end
|
||||
|
||||
test "#cents returns the cents part of the string with given precision" do
|
||||
amount = 123.4862
|
||||
assert_equal "4", amount.cents(precision: 1)
|
||||
assert_equal "486", amount.cents(precision: 3)
|
||||
end
|
||||
|
||||
test "#cents pads the cents part with zeros up to the specified precision" do
|
||||
amount_without_decimal = 123
|
||||
amount_with_decimal = 123.4
|
||||
|
||||
assert_equal "00", amount_without_decimal.cents
|
||||
assert_equal "40", amount_with_decimal.cents
|
||||
end
|
||||
end
|
||||
19
test/initializers/string_extensions_test.rb
Normal file
19
test/initializers/string_extensions_test.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
# test/string_extensions_test.rb
|
||||
require "test_helper"
|
||||
|
||||
class StringExtensionsTest < ActiveSupport::TestCase
|
||||
test "#unit returns the currency unit for a given currency code" do
|
||||
assert_equal "$", "USD".unit
|
||||
assert_equal "€", "EUR".unit
|
||||
end
|
||||
|
||||
test "#separator returns the currency separator for a given currency code" do
|
||||
assert_equal ".", "USD".separator
|
||||
assert_equal ",", "EUR".separator
|
||||
end
|
||||
|
||||
test "#precision returns the currency's precision for a given currency code" do
|
||||
assert_equal 2, "USD".precision
|
||||
assert_equal 0, "KRW".precision
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user