economy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +129 -0
- data/Rakefile +19 -0
- data/lib/economy.rb +43 -0
- data/lib/economy/builder.rb +81 -0
- data/lib/economy/cache.rb +26 -0
- data/lib/economy/configuration.rb +11 -0
- data/lib/economy/currencies.rb +34 -0
- data/lib/economy/currency.rb +28 -0
- data/lib/economy/exchange.rb +17 -0
- data/lib/economy/extensions/active_record/base.rb +18 -0
- data/lib/economy/money.rb +170 -0
- data/lib/economy/railtie.rb +18 -0
- data/lib/economy/rates/base.rb +27 -0
- data/lib/economy/rates/yahoo.rb +38 -0
- data/lib/economy/version.rb +5 -0
- data/lib/generators/economy/install_generator.rb +24 -0
- data/lib/generators/economy/templates/initializer.rb +13 -0
- data/lib/generators/economy/templates/migration.rb +14 -0
- data/lib/tasks/economy.rake +5 -0
- data/test/dummy/Rakefile +5 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/plan.rb +5 -0
- data/test/dummy/app/models/product.rb +5 -0
- data/test/dummy/app/views/layouts/application.html.erb +12 -0
- data/test/dummy/bin/bundle +4 -0
- data/test/dummy/bin/rails +5 -0
- data/test/dummy/bin/rake +5 -0
- data/test/dummy/bin/setup +30 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +25 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +7 -0
- data/test/dummy/config/database.yml.travis +3 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +45 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/economy.rb +19 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/db/migrate/20161115135521_create_exchanges.rb +14 -0
- data/test/dummy/db/migrate/20161115145905_create_products.rb +10 -0
- data/test/dummy/db/migrate/20161115150024_create_plans.rb +11 -0
- data/test/dummy/db/schema.rb +45 -0
- data/test/dummy/log/development.log +172 -0
- data/test/dummy/log/test.log +8574 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/fixtures/yahoo/multiple.json +29 -0
- data/test/fixtures/yahoo/single.json +18 -0
- data/test/fixtures/yahoo/unknown.json +18 -0
- data/test/generator_test.rb +19 -0
- data/test/money_test.rb +142 -0
- data/test/rates_test.rb +60 -0
- data/test/record_test.rb +60 -0
- data/test/support/money_helper.rb +30 -0
- data/test/support/rates_helper.rb +16 -0
- data/test/task_test.rb +22 -0
- data/test/test_helper.rb +14 -0
- metadata +234 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
{
|
2
|
+
"query": {
|
3
|
+
"count": 2,
|
4
|
+
"created": "2016-09-12T22: 16: 22Z",
|
5
|
+
"lang": "en-US",
|
6
|
+
"results": {
|
7
|
+
"rate": [
|
8
|
+
{
|
9
|
+
"id": "USDUYU",
|
10
|
+
"Name": "USD/UYU",
|
11
|
+
"Rate": "29.3200",
|
12
|
+
"Date": "9/12/2016",
|
13
|
+
"Time": "8: 51pm",
|
14
|
+
"Ask": "29.4200",
|
15
|
+
"Bid": "29.3200"
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"id": "UYUUSD",
|
19
|
+
"Name": "UYU/USD",
|
20
|
+
"Rate": "0.0341",
|
21
|
+
"Date": "9/12/2016",
|
22
|
+
"Time": "8: 51pm",
|
23
|
+
"Ask": "0.0341",
|
24
|
+
"Bid": "0.0341"
|
25
|
+
}
|
26
|
+
]
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"query": {
|
3
|
+
"count": 1,
|
4
|
+
"created": "2016-09-12T22: 12: 56Z",
|
5
|
+
"lang": "en-US",
|
6
|
+
"results": {
|
7
|
+
"rate": {
|
8
|
+
"id": "USDUYU",
|
9
|
+
"Name": "USD/UYU",
|
10
|
+
"Rate": "29.3200",
|
11
|
+
"Date": "9/12/2016",
|
12
|
+
"Time": "8: 51pm",
|
13
|
+
"Ask": "29.4200",
|
14
|
+
"Bid": "29.3200"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"query": {
|
3
|
+
"count": 1,
|
4
|
+
"created": "2016-09-12T22: 44: 50Z",
|
5
|
+
"lang": "en-US",
|
6
|
+
"results": {
|
7
|
+
"rate": {
|
8
|
+
"id": "KKKQQQ",
|
9
|
+
"Name": "N/A",
|
10
|
+
"Rate": "N/A",
|
11
|
+
"Date": "N/A",
|
12
|
+
"Time": "N/A",
|
13
|
+
"Ask": "N/A",
|
14
|
+
"Bid": "N/A"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'rails/generators'
|
3
|
+
require 'generators/economy/install_generator'
|
4
|
+
|
5
|
+
class GeneratorTest < Rails::Generators::TestCase
|
6
|
+
destination Rails.root.join('tmp')
|
7
|
+
|
8
|
+
teardown do
|
9
|
+
FileUtils.rm_rf destination_root
|
10
|
+
end
|
11
|
+
|
12
|
+
test 'install' do
|
13
|
+
self.class.tests Economy::Generators::InstallGenerator
|
14
|
+
run_generator
|
15
|
+
assert_file 'config/initializers/economy.rb'
|
16
|
+
assert_migration 'db/migrate/create_exchanges.rb'
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/test/money_test.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class MoneyTest < ActiveSupport::TestCase
|
4
|
+
include MoneyHelper
|
5
|
+
|
6
|
+
test 'abs and magnitude' do
|
7
|
+
%i(abs magnitude).each do |method|
|
8
|
+
assert_equal 10, money(-10, 'USD').send(method).amount
|
9
|
+
assert_equal 10, money(10, 'USD').send(method).amount
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
test '-@' do
|
14
|
+
assert_equal -10, (-money(10, 'USD')).amount
|
15
|
+
assert_equal 10, (-money(-10, 'USD')).amount
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'positive?' do
|
19
|
+
assert money(10, 'USD').positive?
|
20
|
+
assert_not money(-10, 'USD').positive?
|
21
|
+
assert_not money(0, 'USD').positive?
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'negative?' do
|
25
|
+
assert money(-10, 'USD').negative?
|
26
|
+
assert_not money(10, 'USD').negative?
|
27
|
+
assert_not money(0, 'USD').negative?
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'zero?' do
|
31
|
+
assert money(0, 'USD').zero?
|
32
|
+
assert_not money(4, 'USD').zero?
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'nonzero?' do
|
36
|
+
assert money(4, 'USD').nonzero?
|
37
|
+
assert_not money(0, 'USD').nonzero?
|
38
|
+
end
|
39
|
+
|
40
|
+
test '<' do
|
41
|
+
assert_operator money(2, 'USD'), :<, money(4, 'USD')
|
42
|
+
assert_not_operator money(2, 'USD'), :<, money(2, 'USD')
|
43
|
+
assert_not_operator money(2, 'USD'), :<, money(10, 'UYU')
|
44
|
+
assert_raises do
|
45
|
+
money(10, 'USD') < 4
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
test '===' do
|
50
|
+
assert_operator money(10, 'USD'), :===, money(10, 'USD')
|
51
|
+
assert_not_operator money(10, 'USD'), :===, money(10, 'UYU')
|
52
|
+
assert_raises do
|
53
|
+
money(10, 'USD') === 10
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
test '<=>' do
|
58
|
+
assert_equal -1, (money(5, 'USD') <=> money(10, 'USD'))
|
59
|
+
assert_equal 0, (money(10, 'USD') <=> money(10, 'USD'))
|
60
|
+
assert_equal 1, (money(10, 'USD') <=> money(5, 'UYU'))
|
61
|
+
assert_raises do
|
62
|
+
money(10, 'USD') <=> 4
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
test '+' do
|
67
|
+
assert_equal 17, (money(10, 'USD') + money(7, 'USD')).amount
|
68
|
+
assert_equal 20, (money(5, 'USD') + money(300, 'UYU')).amount
|
69
|
+
assert_raises do
|
70
|
+
money(10, 'USD') + 4
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
test '-' do
|
75
|
+
assert_equal 3, (money(10, 'USD') - money(7, 'USD')).amount
|
76
|
+
assert_equal 5, (money(10, 'USD') - money(100, 'UYU')).amount
|
77
|
+
assert_raises do
|
78
|
+
money(10, 'USD') - 5
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
test '*' do
|
83
|
+
assert_equal 30, (money(10, 'USD') * 3).amount
|
84
|
+
assert_raises do
|
85
|
+
money(10, 'USD') * money(3, 'USD')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
test '/ and div' do
|
90
|
+
%i(/ div).each do |operator|
|
91
|
+
assert_equal 5, (money(10, 'USD').send(operator, 2)).amount
|
92
|
+
assert_equal 5, (money(10, 'USD').send(operator, money(40, 'UYU')))
|
93
|
+
assert_raises do
|
94
|
+
money(10, 'USD').send operator, 'a'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
test 'divmod' do
|
100
|
+
assert_equal [money(3, 'USD'), money(1, 'USD')], money(13, 'USD').divmod(4)
|
101
|
+
assert_equal [3, money(1, 'USD')], money(13, 'USD').divmod(money(80, 'UYU'))
|
102
|
+
assert_raises do
|
103
|
+
money(10, 'USD').divmod 'a'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
test '% and modulo' do
|
108
|
+
%i(% modulo).each do |operator|
|
109
|
+
assert_equal money(1, 'USD'), money(13, 'USD').send(operator, 4)
|
110
|
+
assert_equal money(1, 'USD'), money(13, 'USD').send(operator, money(80, 'UYU'))
|
111
|
+
assert_raises do
|
112
|
+
money(10, 'USD').divmod 'a'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
test 'remainder' do
|
118
|
+
assert_equal money(1, 'USD'), money(13, 'USD').remainder(4)
|
119
|
+
assert_equal money(1, 'USD'), money(13, 'USD').remainder(money(80, 'UYU'))
|
120
|
+
end
|
121
|
+
|
122
|
+
test 'exchange_to' do
|
123
|
+
assert_raises do
|
124
|
+
money(10, 'USD').exchange_to 'EUR'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
test 'to_json and as_json' do
|
129
|
+
%i(to_json as_json).each do |method|
|
130
|
+
assert_equal '10.70', money(10.7, 'USD').send(method)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
test 'to_s' do
|
135
|
+
assert_equal 'U$S122,444.46', money(122444.45544, 'USD').to_s
|
136
|
+
end
|
137
|
+
|
138
|
+
test 'coerce' do
|
139
|
+
assert_equal money(4, 'USD'), (4 * money(1, 'USD'))
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
data/test/rates_test.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RatesTest < ActiveSupport::TestCase
|
4
|
+
include RatesHelper
|
5
|
+
|
6
|
+
test 'retries' do
|
7
|
+
base = Economy::Rates::Base.new
|
8
|
+
base.expects(:call).raises('Error').times(31)
|
9
|
+
base.expects(:sleep).with(60).times(30)
|
10
|
+
silence_stream(STDOUT) do
|
11
|
+
base.fetch
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
test 'yahoo' do
|
16
|
+
ids = Economy.currencies.map(&:iso_code).permutation(2).map(&:join).join(',')
|
17
|
+
uri = URI('https://query.yahooapis.com/v1/public/yql')
|
18
|
+
uri.query = URI.encode_www_form(
|
19
|
+
q: "select * from yahoo.finance.xchange where pair in ('#{ids}')",
|
20
|
+
env: 'store://datatables.org/alltableswithkeys',
|
21
|
+
format: 'json'
|
22
|
+
)
|
23
|
+
assert_response(
|
24
|
+
:yahoo,
|
25
|
+
uri,
|
26
|
+
[['USD','UYU',29.3200]],
|
27
|
+
'200',
|
28
|
+
:single
|
29
|
+
)
|
30
|
+
assert_response(
|
31
|
+
:yahoo,
|
32
|
+
uri,
|
33
|
+
[['USD','UYU',29.3200],['UYU','USD',0.0341]],
|
34
|
+
'200',
|
35
|
+
:multiple
|
36
|
+
)
|
37
|
+
assert_response(
|
38
|
+
:yahoo,
|
39
|
+
uri,
|
40
|
+
[],
|
41
|
+
'200',
|
42
|
+
:unknown
|
43
|
+
)
|
44
|
+
assert_response(
|
45
|
+
:yahoo,
|
46
|
+
uri,
|
47
|
+
[],
|
48
|
+
'500'
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def assert_response(service, uri, result, code, name=nil)
|
55
|
+
response = mock_response(service, code, name)
|
56
|
+
Net::HTTP.stubs(:get_response).with(uri).returns response
|
57
|
+
assert_equal result, Economy::Rates::Yahoo.new.fetch
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|