houdini/spec/lib/format/currency_spec.rb
Bradley M. Kuhn 6772312ea7 Relicense all .rb files under new project license.
The primary license of the project is changing to:
  AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later

with some specific files to be licensed under the one of two licenses:
   CC0-1.0
   LGPL-3.0-or-later

This commit is one of the many steps to relicense the entire codebase.

Documentation granting permission for this relicensing (from all past
contributors who hold copyrights) is on file with Software Freedom
Conservancy, Inc.
2018-03-25 15:10:40 -04:00

48 lines
1.3 KiB
Ruby

# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
require 'rails_helper'
describe Format::Currency do
symbol = Settings.intntl.currencies[0]
describe '.dollars_to_cents' do
context 'with dollar sign' do
it 'converts to a cents value as an integer' do
expect(Format::Currency.dollars_to_cents("#{symbol}11.11")).to eq(1111)
end
end
context 'without dollar sign' do
it 'converts to a cents value as an integer' do
expect(Format::Currency.dollars_to_cents("11.00")).to eq(1100)
end
end
context 'with large amount' do
it 'converts to a cents value as an integer' do
expect(Format::Currency.dollars_to_cents("#{symbol}111111111111.11")).to eq(11111111111111)
end
end
end
describe '.cents_to_dollars' do
context 'hundreth-precision (eg $1.11)' do
it 'converts to dollars with hundredth precision' do
expect(Format::Currency.cents_to_dollars(111)).to eq("1.11")
end
end
context 'tenth-precision (eg. $1.10)' do
it 'converts to dollars with a trailing zero' do
expect(Format::Currency.cents_to_dollars(110)).to eq("1.10")
end
end
context 'whole value (eg. $1)' do
it 'converts to dollars without decimals' do
expect(Format::Currency.cents_to_dollars(100)).to eq("1")
end
end
end
end