money-rails 1.14.0 → 2.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 (85) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -5
  3. data/LICENSE +1 -1
  4. data/README.md +121 -102
  5. data/config/locales/money.en.yml +1 -2
  6. data/config/locales/money.pt.yml +4 -0
  7. data/config/locales/money.ru.yml +4 -0
  8. data/lib/money-rails/active_job/money_serializer.rb +19 -0
  9. data/lib/money-rails/active_record/monetizable.rb +17 -7
  10. data/lib/money-rails/configuration.rb +2 -2
  11. data/lib/money-rails/helpers/action_view_extension.rb +1 -1
  12. data/lib/money-rails/hooks.rb +11 -0
  13. data/lib/money-rails/version.rb +3 -1
  14. data/money-rails.gemspec +13 -26
  15. metadata +17 -225
  16. data/Rakefile +0 -84
  17. data/spec/active_record/migration_extensions/schema_statements_spec.rb +0 -101
  18. data/spec/active_record/migration_extensions/table_spec.rb +0 -104
  19. data/spec/active_record/monetizable_spec.rb +0 -1062
  20. data/spec/configuration_spec.rb +0 -147
  21. data/spec/dummy/README.rdoc +0 -261
  22. data/spec/dummy/Rakefile +0 -7
  23. data/spec/dummy/app/assets/config/manifest.js +0 -0
  24. data/spec/dummy/app/assets/javascripts/application.js +0 -15
  25. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  26. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  27. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  28. data/spec/dummy/app/models/dummy_product.rb +0 -8
  29. data/spec/dummy/app/models/priceable.rb +0 -8
  30. data/spec/dummy/app/models/product.rb +0 -59
  31. data/spec/dummy/app/models/service.rb +0 -5
  32. data/spec/dummy/app/models/transaction.rb +0 -13
  33. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  34. data/spec/dummy/config/application.rb +0 -66
  35. data/spec/dummy/config/boot.rb +0 -13
  36. data/spec/dummy/config/database.yml +0 -25
  37. data/spec/dummy/config/environment.rb +0 -5
  38. data/spec/dummy/config/environments/development.rb +0 -30
  39. data/spec/dummy/config/environments/production.rb +0 -69
  40. data/spec/dummy/config/environments/test.rb +0 -36
  41. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  42. data/spec/dummy/config/initializers/inflections.rb +0 -15
  43. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  44. data/spec/dummy/config/initializers/money.rb +0 -31
  45. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  46. data/spec/dummy/config/initializers/session_store.rb +0 -8
  47. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  48. data/spec/dummy/config/locales/en-GB.yml +0 -11
  49. data/spec/dummy/config/locales/en-US.yml +0 -5
  50. data/spec/dummy/config/locales/en.yml +0 -5
  51. data/spec/dummy/config/locales/it.yml +0 -11
  52. data/spec/dummy/config/mongoid.yml +0 -29
  53. data/spec/dummy/config/routes.rb +0 -3
  54. data/spec/dummy/config.ru +0 -4
  55. data/spec/dummy/db/migrate/20120331190108_create_products.rb +0 -10
  56. data/spec/dummy/db/migrate/20120402080348_add_bonus_cents_to_product.rb +0 -6
  57. data/spec/dummy/db/migrate/20120524052716_create_services.rb +0 -10
  58. data/spec/dummy/db/migrate/20120528181002_create_transactions.rb +0 -11
  59. data/spec/dummy/db/migrate/20120528210103_create_dummy_products.rb +0 -10
  60. data/spec/dummy/db/migrate/20120607210247_add_column_that_allows_nil.rb +0 -5
  61. data/spec/dummy/db/migrate/20120712202655_add_sale_price_cents_to_product.rb +0 -7
  62. data/spec/dummy/db/migrate/20130124023419_add_price_in_a_range_cents_to_products.rb +0 -5
  63. data/spec/dummy/db/migrate/20140110194016_add_validates_method_amount_cents_to_products.rb +0 -5
  64. data/spec/dummy/db/migrate/20141005075025_add_aliased_attr_to_products.rb +0 -5
  65. data/spec/dummy/db/migrate/20150107061030_add_delivery_fee_cents_and_restock_fee_cents_to_product.rb +0 -6
  66. data/spec/dummy/db/migrate/20150126231442_add_reduced_price_to_products.rb +0 -6
  67. data/spec/dummy/db/migrate/20150213234410_add_special_price_to_products.rb +0 -5
  68. data/spec/dummy/db/migrate/20150217222612_add_lambda_price_to_products.rb +0 -5
  69. data/spec/dummy/db/migrate/20150303222230_add_skip_validation_price_cents_to_products.rb +0 -5
  70. data/spec/dummy/db/migrate/20151026220420_add_optional_amount_to_transactions.rb +0 -5
  71. data/spec/dummy/db/schema.rb +0 -59
  72. data/spec/dummy/db/structure.sql +0 -21
  73. data/spec/dummy/public/404.html +0 -26
  74. data/spec/dummy/public/422.html +0 -26
  75. data/spec/dummy/public/500.html +0 -25
  76. data/spec/dummy/public/favicon.ico +0 -0
  77. data/spec/dummy/script/rails +0 -6
  78. data/spec/helpers/action_view_extension_spec.rb +0 -189
  79. data/spec/helpers/form_helper_spec.rb +0 -19
  80. data/spec/money_spec.rb +0 -40
  81. data/spec/mongoid/mongoid_spec.rb +0 -130
  82. data/spec/mongoid/two_spec.rb +0 -80
  83. data/spec/spec_helper.rb +0 -23
  84. data/spec/support/database_cleaner.rb +0 -14
  85. data/spec/test_helpers_spec.rb +0 -72
@@ -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