money-rails 1.15.0 → 3.0.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.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -6
  3. data/LICENSE +1 -1
  4. data/README.md +182 -152
  5. data/config/locales/money.pt.yml +4 -0
  6. data/lib/money-rails/active_job/money_serializer.rb +23 -0
  7. data/lib/money-rails/active_record/monetizable.rb +39 -19
  8. data/lib/money-rails/configuration.rb +2 -2
  9. data/lib/money-rails/helpers/action_view_extension.rb +1 -1
  10. data/lib/money-rails/hooks.rb +16 -27
  11. data/lib/money-rails/mongoid/money.rb +4 -14
  12. data/lib/money-rails/test_helpers.rb +4 -4
  13. data/lib/money-rails/version.rb +3 -1
  14. data/lib/money-rails.rb +2 -0
  15. data/money-rails.gemspec +13 -26
  16. metadata +18 -228
  17. data/Rakefile +0 -84
  18. data/lib/money-rails/mongoid/two.rb +0 -35
  19. data/spec/active_record/migration_extensions/schema_statements_spec.rb +0 -101
  20. data/spec/active_record/migration_extensions/table_spec.rb +0 -104
  21. data/spec/active_record/monetizable_spec.rb +0 -1062
  22. data/spec/configuration_spec.rb +0 -147
  23. data/spec/dummy/README.rdoc +0 -261
  24. data/spec/dummy/Rakefile +0 -7
  25. data/spec/dummy/app/assets/config/manifest.js +0 -0
  26. data/spec/dummy/app/assets/javascripts/application.js +0 -15
  27. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  28. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  29. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  30. data/spec/dummy/app/models/dummy_product.rb +0 -8
  31. data/spec/dummy/app/models/priceable.rb +0 -8
  32. data/spec/dummy/app/models/product.rb +0 -59
  33. data/spec/dummy/app/models/service.rb +0 -5
  34. data/spec/dummy/app/models/transaction.rb +0 -13
  35. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  36. data/spec/dummy/config/application.rb +0 -66
  37. data/spec/dummy/config/boot.rb +0 -13
  38. data/spec/dummy/config/database.yml +0 -25
  39. data/spec/dummy/config/environment.rb +0 -5
  40. data/spec/dummy/config/environments/development.rb +0 -30
  41. data/spec/dummy/config/environments/production.rb +0 -69
  42. data/spec/dummy/config/environments/test.rb +0 -36
  43. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  44. data/spec/dummy/config/initializers/inflections.rb +0 -15
  45. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  46. data/spec/dummy/config/initializers/money.rb +0 -31
  47. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  48. data/spec/dummy/config/initializers/session_store.rb +0 -8
  49. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  50. data/spec/dummy/config/locales/en-GB.yml +0 -11
  51. data/spec/dummy/config/locales/en-US.yml +0 -5
  52. data/spec/dummy/config/locales/en.yml +0 -5
  53. data/spec/dummy/config/locales/it.yml +0 -11
  54. data/spec/dummy/config/mongoid.yml +0 -29
  55. data/spec/dummy/config/routes.rb +0 -3
  56. data/spec/dummy/config.ru +0 -4
  57. data/spec/dummy/db/migrate/20120331190108_create_products.rb +0 -10
  58. data/spec/dummy/db/migrate/20120402080348_add_bonus_cents_to_product.rb +0 -6
  59. data/spec/dummy/db/migrate/20120524052716_create_services.rb +0 -10
  60. data/spec/dummy/db/migrate/20120528181002_create_transactions.rb +0 -11
  61. data/spec/dummy/db/migrate/20120528210103_create_dummy_products.rb +0 -10
  62. data/spec/dummy/db/migrate/20120607210247_add_column_that_allows_nil.rb +0 -5
  63. data/spec/dummy/db/migrate/20120712202655_add_sale_price_cents_to_product.rb +0 -7
  64. data/spec/dummy/db/migrate/20130124023419_add_price_in_a_range_cents_to_products.rb +0 -5
  65. data/spec/dummy/db/migrate/20140110194016_add_validates_method_amount_cents_to_products.rb +0 -5
  66. data/spec/dummy/db/migrate/20141005075025_add_aliased_attr_to_products.rb +0 -5
  67. data/spec/dummy/db/migrate/20150107061030_add_delivery_fee_cents_and_restock_fee_cents_to_product.rb +0 -6
  68. data/spec/dummy/db/migrate/20150126231442_add_reduced_price_to_products.rb +0 -6
  69. data/spec/dummy/db/migrate/20150213234410_add_special_price_to_products.rb +0 -5
  70. data/spec/dummy/db/migrate/20150217222612_add_lambda_price_to_products.rb +0 -5
  71. data/spec/dummy/db/migrate/20150303222230_add_skip_validation_price_cents_to_products.rb +0 -5
  72. data/spec/dummy/db/migrate/20151026220420_add_optional_amount_to_transactions.rb +0 -5
  73. data/spec/dummy/db/schema.rb +0 -59
  74. data/spec/dummy/db/structure.sql +0 -21
  75. data/spec/dummy/public/404.html +0 -26
  76. data/spec/dummy/public/422.html +0 -26
  77. data/spec/dummy/public/500.html +0 -25
  78. data/spec/dummy/public/favicon.ico +0 -0
  79. data/spec/dummy/script/rails +0 -6
  80. data/spec/helpers/action_view_extension_spec.rb +0 -189
  81. data/spec/helpers/form_helper_spec.rb +0 -19
  82. data/spec/money_spec.rb +0 -40
  83. data/spec/mongoid/mongoid_spec.rb +0 -130
  84. data/spec/mongoid/two_spec.rb +0 -80
  85. data/spec/spec_helper.rb +0 -23
  86. data/spec/support/database_cleaner.rb +0 -14
  87. data/spec/test_helpers_spec.rb +0 -72
  88. /data/lib/money-rails/active_record/migration_extensions/{schema_statements_pg_rails4.rb → schema_statements_pg.rb} +0 -0
  89. /data/lib/money-rails/active_record/migration_extensions/{table_pg_rails4.rb → table_pg.rb} +0 -0
data/Rakefile DELETED
@@ -1,84 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- require 'bundler/gem_tasks'
6
-
7
- begin
8
- Bundler.setup(:default, :development)
9
- rescue Bundler::BundlerError => e
10
- $stderr.puts e.message
11
- $stderr.puts "Run `bundle install` to install missing gems"
12
- exit e.status_code
13
- end
14
-
15
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
16
- GEMFILES_PATH = 'gemfiles/*.gemfile'.freeze
17
-
18
- load 'rails/tasks/engine.rake' if File.exist?(APP_RAKEFILE)
19
-
20
- require 'rake'
21
- require 'rspec/core/rake_task'
22
-
23
- RSpec::Core::RakeTask.new
24
-
25
- task default: "spec:all"
26
- task test: :spec
27
- task spec: :prepare_test_env
28
-
29
- desc "Prepare money-rails engine test environment"
30
- task :prepare_test_env do
31
- Rake.application['app:db:drop:all'].invoke
32
- Rake.application['app:db:create'].invoke if Rails::VERSION::MAJOR >= 5
33
- Rake.application['app:db:migrate'].invoke
34
- Rake.application['app:db:test:prepare'].invoke
35
- end
36
-
37
- def run_with_gemfile(gemfile)
38
- Bundler.with_clean_env do
39
- begin
40
- sh "BUNDLE_GEMFILE='#{gemfile}' bundle install --quiet"
41
- Rake.application['app:db:create'].invoke
42
- Rake.application['app:db:test:prepare'].invoke
43
- sh "BUNDLE_GEMFILE='#{gemfile}' bundle exec rake spec"
44
- ensure
45
- Rake.application['app:db:drop:all'].execute
46
- end
47
- end
48
- end
49
-
50
- namespace :spec do
51
- frameworks_versions = {}
52
-
53
- Dir[GEMFILES_PATH].each do |gemfile|
54
- file_name = File.basename(gemfile, '.gemfile')
55
- framework, version = file_name.split(/(\d+)/)
56
- major, minor = version.split(//)
57
-
58
- # Ruby 3 exclusions
59
- if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
60
- # Rails 5 does not support ruby-3.0.0 https://github.com/rails/rails/issues/40938#issuecomment-751569171
61
- # Mongoid gem does not yet support ruby-3.0.0 https://github.com/mongodb/mongoid#compatibility
62
- next if framework == 'mongoid' || (framework == 'rails' && version == "5")
63
- end
64
-
65
- frameworks_versions[framework] ||= []
66
- frameworks_versions[framework] << file_name
67
-
68
- desc "Run Tests against #{framework} #{[major, minor].compact.join('.')}"
69
- task(file_name) { run_with_gemfile gemfile }
70
- end
71
-
72
- frameworks_versions.each do |framework, versions|
73
- desc "Run Tests against all supported #{framework} versions"
74
- task framework => versions
75
- end
76
-
77
- desc 'Run Tests against all ORMs'
78
- task all: frameworks_versions.keys
79
- end
80
-
81
- desc "Update CONTRIBUTORS file"
82
- task :contributors do
83
- sh "git shortlog -s | awk '{ print $2 \" \" $3 }' > CONTRIBUTORS"
84
- end
@@ -1,35 +0,0 @@
1
- # Class name does not really matches the folder hierarchy, because
2
- # in order for (de)serialization to work, the class must be re-opened.
3
- # But this file brings mongoid 2.X compat., so...
4
-
5
- class Money
6
- include ::Mongoid::Fields::Serializable
7
-
8
- # Mongo friendly -> Money
9
- def deserialize(object)
10
- return nil if object.nil?
11
-
12
- object = object.with_indifferent_access
13
- ::Money.new object[:cents], object[:currency_iso]
14
- end
15
-
16
- # Money -> Mongo friendly
17
- def serialize(object)
18
- case
19
- when object.is_a?(Money)
20
- {
21
- cents: object.cents.is_a?(BigDecimal) ? object.cents.to_s : object.cents,
22
- currency_iso: object.currency.iso_code
23
- }
24
- when object.nil? then nil
25
- when object.respond_to?(:to_money)
26
- begin
27
- serialize(object.to_money)
28
- rescue Monetize::ParseError => e
29
- raise MoneyRails::Error, e.message if MoneyRails.raise_error_on_money_parsing
30
- nil
31
- end
32
- else nil
33
- end
34
- end
35
- end
@@ -1,101 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class Item < ActiveRecord::Base; end
4
-
5
- if defined? ActiveRecord
6
- describe MoneyRails::ActiveRecord::MigrationExtensions::SchemaStatements do
7
- before :all do
8
- @connection = ActiveRecord::Base.connection
9
- @connection.drop_table :items if @connection.table_exists? :items
10
- @connection.create_table :items
11
- @connection.send :extend, MoneyRails::ActiveRecord::MigrationExtensions::SchemaStatements
12
- end
13
-
14
- describe 'add_money' do
15
- before do
16
- @connection.add_money :items, :price
17
- @connection.add_money :items, :price_without_currency, currency: { present: false }
18
- @connection.add_money :items, :price_with_full_options, amount: {
19
- prefix: :prefix_,
20
- postfix: :_postfix,
21
- type: :decimal,
22
- precision: 4,
23
- scale: 2,
24
- default: 1,
25
- null: true
26
- }, currency: {
27
- prefix: :currency_prefix,
28
- postfix: :currency_postfix,
29
- column_name: :currency
30
- }
31
-
32
- Item.reset_column_information
33
- end
34
-
35
- context 'default options' do
36
- describe 'amount' do
37
- subject { Item.columns_hash['price_cents'] }
38
-
39
- it { expect(subject.default.to_i).to eq(0) }
40
- it { expect(Item.new.public_send(subject.name)).to eq(0) }
41
- it { expect(subject.null).to be(false) }
42
- it { expect(subject.type).to eq(:integer) }
43
- end
44
-
45
- describe 'currency' do
46
- subject { Item.columns_hash['price_currency'] }
47
-
48
- # set in spec/dummy/config/initializers/money.rb
49
- it { expect(subject.default).to eq('EUR') }
50
-
51
- it { expect(subject.null).to be(false) }
52
- it { expect(subject.type).to eq(:string) }
53
- end
54
- end
55
-
56
- context 'without currency column' do
57
- it { expect(Item.columns_hash['price_without_currency_cents']).not_to be nil }
58
- it { expect(Item.columns_hash['price_without_currency_currency']).to be nil }
59
- end
60
-
61
- context 'full options' do
62
- describe 'amount' do
63
- subject { Item.columns_hash['prefix_price_with_full_options_postfix'] }
64
-
65
- it { expect(subject.default.to_i).to eq(1) }
66
- it { expect(Item.new.public_send(subject.name)).to eq(1) }
67
- it { expect(subject.null).to be(true) }
68
- it { expect(subject.type).to eq(:decimal) }
69
- it { expect(subject.precision).to eq(4) }
70
- it { expect(subject.scale).to eq(2) }
71
- end
72
-
73
- describe 'currency' do
74
- it { expect(Item.columns_hash['currency']).not_to be nil }
75
- end
76
- end
77
- end
78
-
79
- describe 'remove_money' do
80
- before do
81
- @connection.add_money :items, :price
82
- @connection.add_money :items, :price_without_currency, currency: { present: false }
83
- @connection.add_money :items, :price_with_full_options, amount: { prefix: :prefix_, postfix: :_postfix }, currency: { column_name: :currency }
84
-
85
- @connection.remove_money :items, :price
86
- @connection.remove_money :items, :price_without_currency, currency: { present: false }
87
- @connection.remove_money :items, :price_with_full_options, amount: { prefix: :prefix_, postfix: :_postfix }, currency: { column_name: :currency }
88
-
89
- Item.reset_column_information
90
- end
91
-
92
- it { expect(Item.columns_hash['price_cents']).to be nil }
93
- it { expect(Item.columns_hash['price_currency']).to be nil }
94
-
95
- it { expect(Item.columns_hash['price_without_currency_cents']).to be nil }
96
-
97
- it { expect(Item.columns_hash['prefix_price_with_full_options_postfix']).to be nil }
98
- it { expect(Item.columns_hash['currency']).to be nil }
99
- end
100
- end
101
- end
@@ -1,104 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class Item < ActiveRecord::Base; end
4
-
5
- if defined? ActiveRecord
6
- describe MoneyRails::ActiveRecord::MigrationExtensions::SchemaStatements do
7
- before :all do
8
- @connection = ActiveRecord::Base.connection
9
- @connection.send :extend, MoneyRails::ActiveRecord::MigrationExtensions::SchemaStatements
10
- end
11
-
12
- describe 'money' do
13
- before do
14
- @connection.drop_table :items if @connection.table_exists? :items
15
- @connection.create_table :items do |t|
16
- t.money :price
17
- t.money :price_without_currency, currency: { present: false }
18
- t.money :price_with_full_options, amount: {
19
- prefix: :prefix_,
20
- postfix: :_postfix,
21
- type: :decimal,
22
- precision: 4,
23
- scale: 2,
24
- default: 1,
25
- null: true
26
- }, currency: {
27
- prefix: :currency_prefix,
28
- postfix: :currency_postfix,
29
- column_name: :currency
30
- }
31
- end
32
-
33
- Item.reset_column_information
34
- end
35
-
36
- context 'default options' do
37
- describe 'amount' do
38
- subject { Item.columns_hash['price_cents'] }
39
-
40
- it { expect(subject.default.to_i).to eq(0) }
41
- it { expect(Item.new.public_send(subject.name)).to eq(0) }
42
- it { expect(subject.null).to be(false) }
43
- it { expect(subject.type).to eq(:integer) }
44
- end
45
-
46
- describe 'currency' do
47
- subject { Item.columns_hash['price_currency'] }
48
-
49
- # set in spec/dummy/config/initializers/money.rb
50
- it { expect(subject.default).to eq('EUR') }
51
-
52
- it { expect(subject.null).to be(false) }
53
- it { expect(subject.type).to eq(:string) }
54
- end
55
- end
56
-
57
- context 'without currency column' do
58
- it { expect(Item.columns_hash['price_without_currency_cents']).not_to be nil }
59
- it { expect(Item.columns_hash['price_without_currency_currency']).to be nil }
60
- end
61
-
62
- context 'full options' do
63
- describe 'amount' do
64
- subject { Item.columns_hash['prefix_price_with_full_options_postfix'] }
65
-
66
- it { expect(subject.default.to_i).to eq(1) }
67
- it { expect(Item.new.public_send(subject.name)).to eq(1) }
68
- it { expect(subject.null).to be(true) }
69
- it { expect(subject.type).to eq(:decimal) }
70
- it { expect(subject.precision).to eq(4) }
71
- it { expect(subject.scale).to eq(2) }
72
- end
73
-
74
- describe 'currency' do
75
- it { expect(Item.columns_hash['currency']).not_to be nil }
76
- end
77
- end
78
- end
79
-
80
- describe 'remove_money' do
81
- before do
82
- @connection.change_table :items do |t|
83
- t.money :price
84
- t.money :price_without_currency, currency: { present: false }
85
- t.money :price_with_full_options, amount: { prefix: :prefix_, postfix: :_postfix }, currency: { column_name: :currency }
86
-
87
- t.remove_money :price
88
- t.remove_money :price_without_currency, currency: { present: false }
89
- t.remove_money :price_with_full_options, amount: { prefix: :prefix_, postfix: :_postfix }, currency: { column_name: :currency }
90
- end
91
-
92
- Item.reset_column_information
93
- end
94
-
95
- it { expect(Item.columns_hash['price_cents']).to be nil }
96
- it { expect(Item.columns_hash['price_currency']).to be nil }
97
-
98
- it { expect(Item.columns_hash['price_without_currency_cents']).to be nil }
99
-
100
- it { expect(Item.columns_hash['prefix_price_with_full_options_postfix']).to be nil }
101
- it { expect(Item.columns_hash['currency']).to be nil }
102
- end
103
- end
104
- end