bd_money 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12
1
+ 0.0.13
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bd_money}
8
- s.version = "0.0.12"
8
+ s.version = "0.0.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Adrian Madrid"]
12
- s.date = %q{2012-04-05}
12
+ s.date = %q{2012-06-18}
13
13
  s.description = %q{This library makes it easier to deal with Money values, storing them as BigDecimal to avoid floating-point math errors.}
14
14
  s.email = %q{aemadrid@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -190,6 +190,10 @@ class Money
190
190
 
191
191
  alias :inspect :to_s
192
192
 
193
+ def to_json
194
+ to_s
195
+ end
196
+
193
197
  def formatted(*args)
194
198
  defaults = args.first.is_a?(::Symbol) ? FORMATS[args.shift] : FORMATS[:default]
195
199
  options = args.last.is_a?(::Hash) ? args.pop : { }
@@ -313,6 +313,40 @@ describe Money do
313
313
  end
314
314
  end
315
315
 
316
+ describe "to_json" do
317
+ describe "no decimals" do
318
+ let(:amt) { '3' }
319
+ it { subject.to_json.should == "#{amt}.00" }
320
+ end
321
+ describe "one decimal" do
322
+ let(:amt) { '3.5' }
323
+ it { subject.to_json.should == "#{amt}0" }
324
+ end
325
+ describe "two decimals" do
326
+ let(:amt) { '3.53' }
327
+ it { subject.to_json.should == amt }
328
+ end
329
+ describe "three decimals" do
330
+ let(:amt) { '3.534' }
331
+ it { subject.to_json.should == amt[0, 4] }
332
+ end
333
+ describe "four decimals" do
334
+ let(:amt) { '3.5343' }
335
+ it { subject.to_json.should == amt[0, 4] }
336
+ end
337
+ describe "five decimals" do
338
+ let(:amt) { '3.53434' }
339
+ it { subject.to_json.should == amt[0, 4] }
340
+ end
341
+ describe "six decimals" do
342
+ let(:amt) { '3.534343' }
343
+ it { subject.to_json.should == amt[0, 4] }
344
+ end
345
+ describe "not a number" do
346
+ it { nan_subject.to_json.should == "NaN" }
347
+ end
348
+ end
349
+
316
350
  describe "to_big_decimal" do
317
351
  let(:bd_amt) { BigDecimal.new(amt) }
318
352
  it { bd_amt.should == subject.to_big_decimal }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bd_money
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 12
10
- version: 0.0.12
9
+ - 13
10
+ version: 0.0.13
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adrian Madrid
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-04-05 00:00:00 -06:00
18
+ date: 2012-06-18 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency