acvwilson-acvwilson-currency 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/currency.gemspec +5 -5
- data/lib/currency.rb +2 -2
- data/lib/currency/config.rb +26 -24
- data/lib/currency/core_extensions.rb +0 -15
- data/lib/currency/currency.rb +3 -6
- data/lib/currency/currency/factory.rb +14 -4
- data/lib/currency/exchange.rb +0 -2
- data/lib/currency/exchange/rate/source/base.rb +2 -2
- data/lib/currency/exchange/rate/source/federal_reserve.rb +3 -12
- data/lib/currency/exchange/rate/source/provider.rb +7 -10
- data/lib/currency/formatter.rb +9 -1
- data/lib/currency/money.rb +4 -7
- data/spec/ar_column_spec.rb +36 -49
- data/spec/ar_simple_spec.rb +9 -17
- data/spec/ar_spec_helper.rb +127 -0
- data/spec/config_spec.rb +44 -3
- data/spec/federal_reserve_spec.rb +55 -59
- data/spec/historical_writer_spec.rb +74 -140
- data/spec/macro_spec.rb +8 -8
- data/spec/money_spec.rb +1 -1
- data/spec/new_york_fed_spec.rb +11 -11
- data/spec/parser_spec.rb +14 -14
- data/spec/spec_helper.rb +6 -6
- data/spec/timed_cache_spec.rb +23 -23
- metadata +4 -5
- data/spec/ar_base_spec.rb +0 -140
- data/spec/ar_core_spec.rb +0 -64
data/spec/timed_cache_spec.rb
CHANGED
@@ -28,12 +28,12 @@ class TimedCacheTest < TestBase
|
|
28
28
|
|
29
29
|
|
30
30
|
it "timed cache usd cad" do
|
31
|
-
rates = @source.raw_rates.
|
32
|
-
rates[:USD].
|
33
|
-
usd_cad = rates[:USD][:CAD].
|
31
|
+
rates = @source.raw_rates.should_not == nil
|
32
|
+
rates[:USD].should_not == nil
|
33
|
+
usd_cad = rates[:USD][:CAD].should_not == nil
|
34
34
|
|
35
|
-
usd = Money.new(123.45, :USD).
|
36
|
-
cad = usd.convert(:CAD).
|
35
|
+
usd = Money.new(123.45, :USD).should_not == nil
|
36
|
+
cad = usd.convert(:CAD).should_not == nil
|
37
37
|
|
38
38
|
assert_kind_of Numeric, m = (cad.to_f / usd.to_f)
|
39
39
|
# $stderr.puts "m = #{m}"
|
@@ -42,13 +42,13 @@ class TimedCacheTest < TestBase
|
|
42
42
|
|
43
43
|
|
44
44
|
it "timed cache cad eur" do
|
45
|
-
rates = @source.raw_rates.
|
46
|
-
rates[:USD].
|
47
|
-
usd_cad = rates[:USD][:CAD].
|
48
|
-
usd_eur = rates[:USD][:EUR].
|
45
|
+
rates = @source.raw_rates.should_not == nil
|
46
|
+
rates[:USD].should_not == nil
|
47
|
+
usd_cad = rates[:USD][:CAD].should_not == nil
|
48
|
+
usd_eur = rates[:USD][:EUR].should_not == nil
|
49
49
|
|
50
|
-
cad = Money.new(123.45, :CAD).
|
51
|
-
eur = cad.convert(:EUR).
|
50
|
+
cad = Money.new(123.45, :CAD).should_not == nil
|
51
|
+
eur = cad.convert(:EUR).should_not == nil
|
52
52
|
|
53
53
|
assert_kind_of Numeric, m = (eur.to_f / cad.to_f)
|
54
54
|
# $stderr.puts "m = #{m}"
|
@@ -61,32 +61,32 @@ class TimedCacheTest < TestBase
|
|
61
61
|
|
62
62
|
test_timed_cache_cad_eur
|
63
63
|
|
64
|
-
rates = @source.raw_rates.
|
65
|
-
rates[:USD].
|
66
|
-
usd_cad_1 = rates[:USD][:CAD].
|
64
|
+
rates = @source.raw_rates.should_not == nil
|
65
|
+
rates[:USD].should_not == nil
|
66
|
+
usd_cad_1 = rates[:USD][:CAD].should_not == nil
|
67
67
|
|
68
|
-
t1 = @cache.rate_load_time.
|
69
|
-
t1_reload = @cache.rate_reload_time.
|
68
|
+
t1 = @cache.rate_load_time.should_not == nil
|
69
|
+
t1_reload = @cache.rate_reload_time.should_not == nil
|
70
70
|
t1_reload.to_i.should > t1.to_i
|
71
71
|
|
72
72
|
@cache.time_to_live = 5
|
73
73
|
@cache.time_to_live_fudge = 0
|
74
74
|
|
75
75
|
# puts @cache.rate_reload_time.to_i - @cache.rate_load_time.to_i
|
76
|
-
@cache.rate_reload_time.to_i - @cache.rate_load_time.to_i == @cache.time_to_live.
|
76
|
+
@cache.rate_reload_time.to_i - @cache.rate_load_time.to_i == @cache.time_to_live.should_not == nil
|
77
77
|
|
78
78
|
sleep 10
|
79
79
|
|
80
80
|
test_timed_cache_cad_eur
|
81
81
|
|
82
|
-
t2 = @cache.rate_load_time.
|
83
|
-
t1.to_i != t2.to_i.
|
82
|
+
t2 = @cache.rate_load_time.should_not == nil
|
83
|
+
t1.to_i != t2.to_i.should_not == nil
|
84
84
|
|
85
|
-
rates = @source.raw_rates.
|
86
|
-
rates[:USD].
|
87
|
-
usd_cad_2 = rates[:USD][:CAD].
|
85
|
+
rates = @source.raw_rates.should_not == nil
|
86
|
+
rates[:USD].should_not == nil
|
87
|
+
usd_cad_2 = rates[:USD][:CAD].should_not == nil
|
88
88
|
|
89
|
-
usd_cad_1.object_id != usd_cad_2.object_id.
|
89
|
+
usd_cad_1.object_id != usd_cad_2.object_id.should_not == nil
|
90
90
|
end
|
91
91
|
|
92
92
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acvwilson-acvwilson-currency
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Asa Wilson
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-11-
|
12
|
+
date: 2008-11-17 13:55:30.797497 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -68,9 +68,8 @@ files:
|
|
68
68
|
- Manifest.txt
|
69
69
|
- README.txt
|
70
70
|
- Releases.txt
|
71
|
-
- spec/
|
71
|
+
- spec/ar_spec_helper.rb
|
72
72
|
- spec/ar_column_spec.rb
|
73
|
-
- spec/ar_core_spec.rb
|
74
73
|
- spec/ar_simple_spec.rb
|
75
74
|
- spec/config_spec.rb
|
76
75
|
- spec/federal_reserve_spec.rb
|
@@ -112,6 +111,6 @@ rubyforge_project:
|
|
112
111
|
rubygems_version: 1.2.0
|
113
112
|
signing_key:
|
114
113
|
specification_version: 2
|
115
|
-
summary:
|
114
|
+
summary: "#{s.name} #{s.version}"
|
116
115
|
test_files: []
|
117
116
|
|
data/spec/ar_base_spec.rb
DELETED
@@ -1,140 +0,0 @@
|
|
1
|
-
# Copyright (C) 2006-2007 Kurt Stephens <ruby-currency(at)umleta.com>
|
2
|
-
# See LICENSE.txt for details.
|
3
|
-
|
4
|
-
require 'test/test_base'
|
5
|
-
require 'currency'
|
6
|
-
|
7
|
-
require 'rubygems'
|
8
|
-
require 'active_record'
|
9
|
-
require 'active_record/migration'
|
10
|
-
require 'currency/active_record'
|
11
|
-
|
12
|
-
AR_M = ActiveRecord::Migration
|
13
|
-
AR_B = ActiveRecord::Base
|
14
|
-
|
15
|
-
module Currency
|
16
|
-
|
17
|
-
class ArTestBase < TestBase
|
18
|
-
|
19
|
-
##################################################
|
20
|
-
|
21
|
-
before do
|
22
|
-
super
|
23
|
-
AR_B.establish_connection(database_spec)
|
24
|
-
|
25
|
-
# Subclasses can override this.
|
26
|
-
@currency_test_migration ||= nil
|
27
|
-
@currency_test ||= nil
|
28
|
-
|
29
|
-
# schema_down
|
30
|
-
|
31
|
-
schema_up
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
def teardown
|
36
|
-
super
|
37
|
-
# schema_down
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
def database_spec
|
42
|
-
# TODO: Get from ../config/database.yml:test
|
43
|
-
# Create test database on:
|
44
|
-
|
45
|
-
# MYSQL:
|
46
|
-
#
|
47
|
-
# sudo mysqladmin create test;
|
48
|
-
# sudo mysql
|
49
|
-
# grant all on test.* to test@localhost identified by 'test';
|
50
|
-
# flush privileges;
|
51
|
-
|
52
|
-
# POSTGRES:
|
53
|
-
#
|
54
|
-
# CREATE USER test PASSWORD 'test';
|
55
|
-
# CREATE DATABASE test WITH OWNER = test;
|
56
|
-
#
|
57
|
-
|
58
|
-
@database_spec = {
|
59
|
-
:adapter => ENV['TEST_DB_ADAPTER'] || 'mysql',
|
60
|
-
:host => ENV['TEST_DB_HOST'] || 'localhost',
|
61
|
-
:username => ENV['TEST_DB_USER'] || 'test',
|
62
|
-
:password => ENV['TEST_DB_PASS'] || 'test',
|
63
|
-
:database => ENV['TEST_DB_TEST'] || 'test'
|
64
|
-
}
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
def schema_up
|
69
|
-
return unless @currency_test_migration
|
70
|
-
begin
|
71
|
-
@currency_test_migration.migrate(:up)
|
72
|
-
rescue Object =>e
|
73
|
-
$stderr.puts "Warning: #{e}"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
|
78
|
-
def schema_down
|
79
|
-
return unless @currency_test_migration
|
80
|
-
begin
|
81
|
-
@currency_test_migration.migrate(:down)
|
82
|
-
rescue Object => e
|
83
|
-
$stderr.puts "Warning: #{e}"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
|
88
|
-
##################################################
|
89
|
-
# Scaffold
|
90
|
-
#
|
91
|
-
|
92
|
-
def insert_records
|
93
|
-
delete_records
|
94
|
-
|
95
|
-
@currency_test.reset_column_information
|
96
|
-
|
97
|
-
@usd = @currency_test.new(:name => '#1: USD', :amount => Money.new("12.34", :USD))
|
98
|
-
@usd.save
|
99
|
-
|
100
|
-
@cad = @currency_test.new(:name => '#2: CAD', :amount => Money.new("56.78", :CAD))
|
101
|
-
@cad.save
|
102
|
-
end
|
103
|
-
|
104
|
-
|
105
|
-
def delete_records
|
106
|
-
@currency_test.destroy_all
|
107
|
-
end
|
108
|
-
|
109
|
-
|
110
|
-
##################################################
|
111
|
-
|
112
|
-
|
113
|
-
def assert_equal_money(a,b)
|
114
|
-
a.should_not be_nil
|
115
|
-
b.should_not be_nil
|
116
|
-
# Make sure a and b are not the same object.
|
117
|
-
b.object_id.should_not == a.object_id
|
118
|
-
b.id.should == a.id
|
119
|
-
a.amount.should.not == nil
|
120
|
-
a.amount.should be_kind_of(Money)
|
121
|
-
b.amount.should.not == nil
|
122
|
-
b.amount.should be_kind_of(Money)
|
123
|
-
# Make sure that what gets stored in the database comes back out
|
124
|
-
# when converted back to the original currency.
|
125
|
-
b.amount.rep.should == a.amount.convert(b.amount.currency).rep
|
126
|
-
end
|
127
|
-
|
128
|
-
|
129
|
-
def assert_equal_currency(a,b)
|
130
|
-
assert_equal_money a, b
|
131
|
-
|
132
|
-
b.amount.rep.should == a.amount.rep
|
133
|
-
b.amount.currency.should == a.amount.currency
|
134
|
-
b.amount.currency.code.should == a.amount.currency.code
|
135
|
-
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
end # module
|
140
|
-
|
data/spec/ar_core_spec.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
# Copyright (C) 2006-2007 Kurt Stephens <ruby-currency(at)umleta.com>
|
2
|
-
# See LICENSE.txt for details.
|
3
|
-
|
4
|
-
require 'test/ar_test_base'
|
5
|
-
|
6
|
-
module Currency
|
7
|
-
|
8
|
-
class ArTestCore < ArTestBase
|
9
|
-
|
10
|
-
##################################################
|
11
|
-
# Basic CurrenyTest AR::B class
|
12
|
-
#
|
13
|
-
|
14
|
-
TABLE_NAME = 'currency_test'
|
15
|
-
|
16
|
-
class CurrencyTestMigration < AR_M
|
17
|
-
def self.up
|
18
|
-
create_table TABLE_NAME.intern do |t|
|
19
|
-
t.column :name, :string
|
20
|
-
t.column :amount, :integer # Money
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.down
|
25
|
-
drop_table TABLE_NAME.intern
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
class CurrencyTest < AR_B
|
31
|
-
set_table_name TABLE_NAME
|
32
|
-
attr_money :amount
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
##################################################
|
37
|
-
|
38
|
-
|
39
|
-
before do
|
40
|
-
@currency_test_migration ||= CurrencyTestMigration
|
41
|
-
@currency_test ||= CurrencyTest
|
42
|
-
super
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
def teardown
|
47
|
-
super
|
48
|
-
# schema_down
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
##################################################
|
53
|
-
#
|
54
|
-
#
|
55
|
-
|
56
|
-
|
57
|
-
it "insert" do
|
58
|
-
insert_records
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
end # module
|
64
|
-
|