economy 4.0.2.2 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +5 -5
- data/Rakefile +1 -3
- data/lib/economy.rb +2 -0
- data/lib/economy/cache.rb +3 -3
- data/lib/economy/configuration.rb +1 -1
- data/lib/economy/money.rb +6 -3
- data/lib/economy/version.rb +1 -1
- data/lib/generators/economy/install/install_generator.rb +6 -6
- data/lib/generators/economy/install/templates/{migration.rb → create_exchanges.rb} +0 -0
- data/lib/generators/economy/install/templates/{initializer.rb → economy.rb} +0 -0
- data/lib/generators/economy/install/templates/{configuration.yml → redis.yml} +0 -0
- metadata +20 -136
- data/test/dummy/Rakefile +0 -5
- data/test/dummy/app/assets/javascripts/application.js +0 -13
- data/test/dummy/app/assets/stylesheets/application.css +0 -15
- data/test/dummy/app/controllers/application_controller.rb +0 -5
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/models/plan.rb +0 -5
- data/test/dummy/app/models/product.rb +0 -5
- data/test/dummy/app/views/layouts/application.html.erb +0 -12
- data/test/dummy/bin/bundle +0 -4
- data/test/dummy/bin/rails +0 -5
- data/test/dummy/bin/rake +0 -5
- data/test/dummy/bin/setup +0 -30
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -25
- data/test/dummy/config/boot.rb +0 -5
- data/test/dummy/config/database.yml +0 -10
- data/test/dummy/config/database.yml.travis +0 -3
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -41
- data/test/dummy/config/environments/production.rb +0 -79
- data/test/dummy/config/environments/test.rb +0 -42
- data/test/dummy/config/initializers/assets.rb +0 -11
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/test/dummy/config/initializers/economy.rb +0 -19
- data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/test/dummy/config/initializers/inflections.rb +0 -16
- data/test/dummy/config/initializers/mime_types.rb +0 -4
- data/test/dummy/config/initializers/session_store.rb +0 -3
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -23
- data/test/dummy/config/redis.yml +0 -9
- data/test/dummy/config/routes.rb +0 -56
- data/test/dummy/config/secrets.yml +0 -22
- data/test/dummy/db/migrate/20161115135521_create_exchanges.rb +0 -14
- data/test/dummy/db/migrate/20161115145905_create_products.rb +0 -10
- data/test/dummy/db/migrate/20161115150024_create_plans.rb +0 -11
- data/test/dummy/db/schema.rb +0 -45
- data/test/dummy/log/development.log +0 -224
- data/test/dummy/log/test.log +0 -4988
- data/test/dummy/public/404.html +0 -61
- data/test/dummy/public/422.html +0 -61
- data/test/dummy/public/500.html +0 -60
- data/test/dummy/public/favicon.ico +0 -0
- data/test/fixtures/yahoo/multiple.json +0 -29
- data/test/fixtures/yahoo/single.json +0 -18
- data/test/fixtures/yahoo/unknown.json +0 -18
- data/test/generator_test.rb +0 -20
- data/test/money_test.rb +0 -142
- data/test/rate_test.rb +0 -60
- data/test/record_test.rb +0 -60
- data/test/support/money_helper.rb +0 -30
- data/test/support/rate_helper.rb +0 -16
- data/test/task_test.rb +0 -22
- data/test/test_helper.rb +0 -14
data/test/record_test.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class RecordTest < ActiveSupport::TestCase
|
4
|
-
include MoneyHelper
|
5
|
-
|
6
|
-
test 'default currency' do
|
7
|
-
product = Product.new
|
8
|
-
assert_equal 0, product.price
|
9
|
-
assert_equal 'USD', product.price.currency.iso_code
|
10
|
-
assert_nil product.price_currency
|
11
|
-
end
|
12
|
-
|
13
|
-
test 'persistent' do
|
14
|
-
plan = Plan.create(monthly_price: 20, annually_price: 200, currency: 'UYU')
|
15
|
-
assert_equal 20, plan.monthly_price.amount
|
16
|
-
assert_equal 'UYU', plan.monthly_price.currency.iso_code
|
17
|
-
assert_equal 200, plan.annually_price.amount
|
18
|
-
assert_equal 'UYU', plan.annually_price.currency.iso_code
|
19
|
-
assert_equal 'UYU', plan.currency
|
20
|
-
|
21
|
-
plan.update monthly_price: money(5, 'USD')
|
22
|
-
assert_equal 100, plan.monthly_price.amount
|
23
|
-
assert_equal 200, plan.annually_price.amount
|
24
|
-
assert_equal 'UYU', plan.currency
|
25
|
-
|
26
|
-
product = Product.create(price: 15, price_currency: 'UYU')
|
27
|
-
assert_equal 15, product.price.amount
|
28
|
-
assert_equal 'UYU', product.price.currency.iso_code
|
29
|
-
assert_equal 'UYU', product.price_currency
|
30
|
-
|
31
|
-
product.update price: money(5, 'USD')
|
32
|
-
assert_equal 5, product.price.amount
|
33
|
-
assert_equal 'USD', product.price.currency.iso_code
|
34
|
-
assert_equal 'USD', product.price_currency
|
35
|
-
end
|
36
|
-
|
37
|
-
test 'validators' do
|
38
|
-
product = Product.new
|
39
|
-
assert product.valid?
|
40
|
-
|
41
|
-
product.price = 20
|
42
|
-
assert product.invalid?
|
43
|
-
|
44
|
-
product.price_currency = 'IO'
|
45
|
-
assert product.invalid?
|
46
|
-
|
47
|
-
product.price_currency = 'UYU'
|
48
|
-
assert product.valid?
|
49
|
-
|
50
|
-
product.price = 0
|
51
|
-
assert product.valid?
|
52
|
-
end
|
53
|
-
|
54
|
-
test 'helpers' do
|
55
|
-
product = Product.new(price: 10000)
|
56
|
-
assert product.price_came_from_user?
|
57
|
-
assert_equal '10000.00', product.price_before_type_cast
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module MoneyHelper
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
included do
|
5
|
-
setup do
|
6
|
-
Economy.cache.clear
|
7
|
-
usd_to_uyu = Economy::Exchange.create(
|
8
|
-
service: 'Yahoo',
|
9
|
-
from: 'USD',
|
10
|
-
to: 'UYU',
|
11
|
-
rate: 20
|
12
|
-
)
|
13
|
-
usd_to_uyu.run_callbacks :commit
|
14
|
-
uyu_to_usd = Economy::Exchange.create(
|
15
|
-
service: 'Yahoo',
|
16
|
-
from: 'UYU',
|
17
|
-
to: 'USD',
|
18
|
-
rate: 0.05
|
19
|
-
)
|
20
|
-
uyu_to_usd.run_callbacks :commit
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def money(amount, currency)
|
27
|
-
Economy::Money.new amount, currency
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
data/test/support/rate_helper.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module RateHelper
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
private
|
5
|
-
|
6
|
-
def mock_response(service, code, name)
|
7
|
-
response = mock
|
8
|
-
response.expects(:code).returns code
|
9
|
-
if name
|
10
|
-
body = File.read(File.dirname(__FILE__) + "/../fixtures/#{service}/#{name}.json")
|
11
|
-
response.expects(:body).returns body
|
12
|
-
end
|
13
|
-
response
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
data/test/task_test.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class TaskTest < ActiveSupport::TestCase
|
4
|
-
include RateHelper
|
5
|
-
|
6
|
-
setup do
|
7
|
-
Dummy::Application.load_tasks
|
8
|
-
end
|
9
|
-
|
10
|
-
test 'update rates' do
|
11
|
-
response = mock_response(:yahoo, '200', :multiple)
|
12
|
-
Net::HTTP.stubs(:get_response).returns response
|
13
|
-
silence_stream(STDOUT) do
|
14
|
-
Rake::Task['economy:update_rates'].invoke
|
15
|
-
end
|
16
|
-
|
17
|
-
assert_equal 2, Economy::Exchange.count
|
18
|
-
assert Economy::Exchange.exists?(service: 'Yahoo', from: 'USD', to: 'UYU', rate: 29.3200)
|
19
|
-
assert Economy::Exchange.exists?(service: 'Yahoo', from: 'UYU', to: 'USD', rate: 0.0341)
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# Configure Rails Environment
|
2
|
-
ENV['RAILS_ENV'] = 'test'
|
3
|
-
|
4
|
-
require File.expand_path('../../test/dummy/config/environment.rb', __FILE__)
|
5
|
-
ActiveRecord::Migrator.migrations_paths = [File.expand_path('../../test/dummy/db/migrate', __FILE__)]
|
6
|
-
require 'rails/test_help'
|
7
|
-
require 'mocha/mini_test'
|
8
|
-
|
9
|
-
# Filter out Minitest backtrace while allowing backtrace from other libraries
|
10
|
-
# to be shown.
|
11
|
-
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
12
|
-
|
13
|
-
# Load support files
|
14
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|