more_money 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,117 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ include MoreMoney
4
+ class MoreMoneyTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ Money.load_std_currencies
8
+ Money.default_currency = 'USD'
9
+ end
10
+
11
+ def test_create
12
+ a = Money.new(100)
13
+ assert_equal 100, a.cents
14
+ b = Money.new(1000)
15
+ assert_equal 1000, b.cents
16
+ Money.default_currency = 'JPY'
17
+ c = Money.new(1000)
18
+ assert_equal 1000, c.cents
19
+ assert_equal 'JPY', c.currency
20
+ assert_equal 'USD', a.currency
21
+ assert_equal 'USD', b.currency
22
+ end
23
+
24
+ def test_generated_creator
25
+ a = Money.us_dollar(100)
26
+ assert_equal 100, a.cents
27
+ assert_equal 'USD', a.currency
28
+ b = Money.jp_yen(100)
29
+ assert_equal 100, b.cents
30
+ assert_equal 'JPY', b.currency
31
+ end
32
+
33
+ def test_format
34
+ a = Money.us_dollar(100)
35
+ b = Money.jp_yen(100)
36
+ c = Money.gb_pound(100)
37
+ assert_equal "$ 1.00", a.format
38
+ assert_equal "¥ 1.00", b.format
39
+ assert_equal "£ 1.00", c.format
40
+ assert_equal "$ 1.00 USD", a.format(:with_currency)
41
+ assert_equal "¥ 1.00 JPY", b.format(:with_currency)
42
+ assert_equal "£ 1.00 GBP", c.format(:with_currency)
43
+ test_format = lambda do |cents, code, symbol, rules|
44
+ if rules.include?(:no_cents)
45
+ formatted = sprintf("test %d", cents.to_f / 100 )
46
+ else
47
+ formatted = sprintf("test %.2f", cents.to_f / 100 )
48
+ end
49
+ formatted = "#{formatted} #{symbol}"
50
+ if rules.include?(:with_currency)
51
+ formatted << " "
52
+ formatted << '<span class="currency">' if rules.include?(:html)
53
+ formatted << code
54
+ formatted << '</span>' if rules.include?(:html)
55
+ end
56
+ formatted
57
+ end
58
+ Money.add_currency(:code => 'TST', :description => 'test_currency', :symbol => '!', :format => test_format)
59
+ d = Money.test_currency(1000)
60
+ assert_equal "test 10.00 !", d.format
61
+ assert_equal "test 10.00 ! TST", d.format(:with_currency)
62
+ assert_equal "$ 0.00", Money.us_dollar(0).format
63
+ Money.add_currency({:code => 'USD', :symbol => '$', :description => 'us_dollar', :format_defaults => { 0 => 'free' }})
64
+ assert_equal "free", Money.us_dollar(0).format
65
+ assert_equal "£ 0.00", Money.gb_pound(0).format
66
+ Money.set_default_format(0, 'free as in a beer')
67
+ assert_equal "free", Money.us_dollar(0).format
68
+ assert_equal "free as in a beer", Money.gb_pound(0).format
69
+ end
70
+
71
+ def test_nil
72
+ a = Money.new(nil)
73
+ assert_equal nil, a.cents
74
+ assert_equal 'USD', a.currency
75
+ assert_equal nil, (a * 2).cents
76
+ assert_equal nil, (a / 2).cents
77
+ b = Money.new(100)
78
+ assert(b > a)
79
+ assert_equal 100, (a + b).cents
80
+ assert_equal(-100, (a - b).cents)
81
+ assert_equal 100, (b + a).cents
82
+ assert_equal 100, (b - a).cents
83
+ c = nil.to_money
84
+ assert_equal nil, c.cents
85
+ assert_equal 'USD', c.currency
86
+ end
87
+
88
+ def test_thousands
89
+ a = Money.us_dollar(100)
90
+ assert_equal "$ 1.00", a.format(:with_thousands)
91
+ a = Money.us_dollar(10000)
92
+ assert_equal "$ 100.00", a.format(:with_thousands)
93
+ a = Money.us_dollar(100000)
94
+ assert_equal "$ 1,000.00", a.format(:with_thousands)
95
+ a = Money.us_dollar(1000000)
96
+ assert_equal "$ 10,000.00", a.format(:with_thousands)
97
+ a = Money.us_dollar(10000000)
98
+ assert_equal "$ 100,000.00", a.format(:with_thousands)
99
+ a = Money.us_dollar(100000000)
100
+ assert_equal "$ 1,000,000.00", a.format(:with_thousands)
101
+ assert_equal "$ 1,000,000", a.format(:with_thousands, :no_cents)
102
+ end
103
+
104
+ def test_exchange
105
+ a = Money.us_dollar(100)
106
+ b = Money.jp_yen(10000)
107
+ c = Money.gb_pound(100)
108
+ d = Money.au_dollar(100)
109
+ Money.set_exchange_rate('USD', 'GBP', 0.51)
110
+ Money.set_exchange_rate('JPY', 'GBP', 0.0043)
111
+ Money.set_exchange_rate('JPY', 'GBP', 0.0043)
112
+ assert_equal [ 51, 'GBP'], a.exchange_to('GBP').instance_eval("[cents, currency]")
113
+ assert_equal [ 43, 'GBP'], b.exchange_to('GBP').instance_eval("[cents, currency]")
114
+ assert_equal [ 100, 'GBP'], c.exchange_to('GBP').instance_eval("[cents, currency]")
115
+ assert_raise(MoreMoney::MoneyMissingExchangeRate) { d.exchange_to('GBP') }
116
+ end
117
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/more_money'
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: more_money
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.5
7
+ date: 2007-01-08 00:00:00 +00:00
8
+ summary: handles money objects using just integer as backend
9
+ require_paths:
10
+ - lib
11
+ email: your contact email for bug fixes and info
12
+ homepage: http://more_money.rubyforge.org
13
+ rubyforge_project: more_money
14
+ description: handles money objects using just integer as backend
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - blank
31
+ files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ - Rakefile
36
+ - setup.rb
37
+ - lib/more_money.rb
38
+ - lib/more_money/version.rb
39
+ - lib/more_money/core_extensions.rb
40
+ - lib/more_money/more_money.rb
41
+ - test/test_helper.rb
42
+ - test/more_money_test.rb
43
+ test_files:
44
+ - test/more_money_test.rb
45
+ rdoc_options: []
46
+
47
+ extra_rdoc_files: []
48
+
49
+ executables: []
50
+
51
+ extensions: []
52
+
53
+ requirements: []
54
+
55
+ dependencies:
56
+ - !ruby/object:Gem::Dependency
57
+ name: hoe
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Version::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 1.1.6
64
+ version: