Skip to content

Commit

Permalink
Merge pull request #464 from RubyMoney/ruby-2-4-0
Browse files Browse the repository at this point in the history
Ruby 2.4.0 support
  • Loading branch information
antstorm committed Jan 23, 2017
2 parents 4ca2a63 + ef061e6 commit dbcfa0d
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 31 deletions.
17 changes: 13 additions & 4 deletions .travis.yml
Expand Up @@ -11,6 +11,7 @@ rvm:
- 2.1.8
- 2.2.4
- 2.3.0
- 2.4.0
# FIXME: failing native extensions
#- ruby-head
# TODO: investigate failure
Expand All @@ -29,16 +30,24 @@ gemfile:
- gemfiles/rails50.gemfile
matrix:
exclude:
- rvm: 1.9.2
gemfile: gemfiles/mongoid3.gemfile
- rvm: 1.9.2
gemfile: gemfiles/rails4.gemfile
- rvm: 1.9.3
gemfile: gemfiles/rails50.gemfile
- rvm: 2.0.0
gemfile: gemfiles/rails50.gemfile
- rvm: 2.1.8
gemfile: gemfiles/rails50.gemfile
- rvm: 2.4.0
gemfile: gemfiles/mongoid2.gemfile
- rvm: 2.4.0
gemfile: gemfiles/mongoid3.gemfile
- rvm: 2.4.0
gemfile: gemfiles/mongoid4.gemfile
- rvm: 2.4.0
gemfile: gemfiles/rails3.gemfile
- rvm: 2.4.0
gemfile: gemfiles/rails4.gemfile
- rvm: 2.4.0
gemfile: gemfiles/rails41.gemfile
notifications:
recipients:
- andreas@aloop.org
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog

## 1.8.0

- Ruby 2.4 support
- Upgrade Money dependency from 6.7 to 6.8.1
- Upgrade Monetize dependency from 1.4.0 to 1.6.0

## 1.7.0

- Rails 5 support
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/rails42.gemfile
@@ -1,6 +1,7 @@
source 'https://rubygems.org'

gem 'rails', '~> 4.2.0'
gem 'rails', github: 'rails/rails', branch: '4-2-stable'
gem 'nokogiri', '~> 1.6.8.1'

platforms :jruby do
gem "activerecord-jdbc-adapter"
Expand Down
1 change: 1 addition & 0 deletions lib/money-rails.rb
Expand Up @@ -5,6 +5,7 @@
require "money-rails/money"
require "money-rails/version"
require 'money-rails/hooks'
require 'money-rails/errors'

module MoneyRails
extend Configuration
Expand Down
9 changes: 3 additions & 6 deletions lib/money-rails/active_record/monetizable.rb
Expand Up @@ -5,7 +5,7 @@
module MoneyRails
module ActiveRecord
module Monetizable
class ReadOnlyCurrencyException < StandardError; end
class ReadOnlyCurrencyException < MoneyRails::Error; end
extend ActiveSupport::Concern

module ClassMethods
Expand Down Expand Up @@ -232,11 +232,8 @@ def write_monetized(name, subunit_name, value, validation_enabled, instance_curr
money = value.to_money(public_send("currency_for_#{name}"))
rescue NoMethodError
return nil
rescue ArgumentError
raise if MoneyRails.raise_error_on_money_parsing
return nil
rescue Money::Currency::UnknownCurrency
raise if MoneyRails.raise_error_on_money_parsing
rescue Money::Currency::UnknownCurrency, Monetize::ParseError => e
raise MoneyRails::Error, e.message if MoneyRails.raise_error_on_money_parsing
return nil
end
end
Expand Down
3 changes: 3 additions & 0 deletions lib/money-rails/errors.rb
@@ -0,0 +1,3 @@
module MoneyRails
class Error < StandardError; end
end
4 changes: 2 additions & 2 deletions lib/money-rails/mongoid/money.rb
Expand Up @@ -41,8 +41,8 @@ def mongoize(object)
when object.respond_to?(:to_money) then
begin
object.to_money.mongoize
rescue ArgumentError, Money::Currency::UnknownCurrency
raise if MoneyRails.raise_error_on_money_parsing
rescue Money::Currency::UnknownCurrency, Monetize::ParseError => e
raise MoneyRails::Error, e.message if MoneyRails.raise_error_on_money_parsing
nil
end
else object
Expand Down
4 changes: 2 additions & 2 deletions lib/money-rails/mongoid/two.rb
Expand Up @@ -25,8 +25,8 @@ def serialize(object)
when object.respond_to?(:to_money)
begin
serialize(object.to_money)
rescue ArgumentError
raise if MoneyRails.raise_error_on_money_parsing
rescue Monetize::ParseError => e
raise MoneyRails::Error, e.message if MoneyRails.raise_error_on_money_parsing
nil
end
else nil
Expand Down
2 changes: 1 addition & 1 deletion lib/money-rails/version.rb
@@ -1,3 +1,3 @@
module MoneyRails
VERSION = '1.7.0'
VERSION = '1.8.0'
end
4 changes: 2 additions & 2 deletions money-rails.gemspec
Expand Up @@ -26,8 +26,8 @@ Gem::Specification.new do |s|

s.require_path = "lib"

s.add_dependency "money", "~> 6.7"
s.add_dependency "monetize", "~> 1.4.0"
s.add_dependency "money", "~> 6.8.1"
s.add_dependency "monetize", "~> 1.6.0"
s.add_dependency "activesupport", ">= 3.0"
s.add_dependency "railties", ">= 3.0"
s.add_dependency "mime-types", "< 3" if RUBY_VERSION < '2.0' # mime-types > 3 depends on mime-types-data, which doesn't support ruby 1.9
Expand Down
12 changes: 6 additions & 6 deletions spec/active_record/monetizable_spec.rb
Expand Up @@ -154,7 +154,7 @@ class SubProduct < Product
after { MoneyRails.raise_error_on_money_parsing = false }

it "raises exception when a String value with hyphen is assigned" do
expect { product.accessor_price = "10-235" }.to raise_error ArgumentError
expect { product.accessor_price = "10-235" }.to raise_error MoneyRails::Error
end

it "raises an exception if it can't change currency" do
Expand Down Expand Up @@ -935,17 +935,17 @@ class SubProduct < Product
before { MoneyRails.raise_error_on_money_parsing = true }
after { MoneyRails.raise_error_on_money_parsing = false }

it "raises an ArgumentError when given an invalid value" do
it "raises a MoneyRails::Error when given an invalid value" do
expect {
product.write_monetized :price, :price_cents, '10-50', false, nil, {}
}.to raise_error(ArgumentError)
}.to raise_error(MoneyRails::Error)
end

it "raises a Money::Currency::UnknownCurrency error when trying to set invalid currency" do
it "raises a MoneyRails::Error error when trying to set invalid currency" do
allow(product).to receive(:currency_for_price).and_return('INVALID_CURRENCY')
expect {
product.write_monetized :price, :price_cents, 10, false, nil, {}
}.to raise_error(Money::Currency::UnknownCurrency)
}.to raise_error(MoneyRails::Error)
end
end

Expand All @@ -956,7 +956,7 @@ class SubProduct < Product
expect(product.price).to eq(old_price_value)
end

it "raises a Money::Currency::UnknownCurrency error when trying to set invalid currency" do
it "raises a MoneyRails::Error error when trying to set invalid currency" do
allow(product).to receive(:currency_for_price).and_return('INVALID_CURRENCY')
product.write_monetized :price, :price_cents, 10, false, nil, {}

Expand Down
4 changes: 2 additions & 2 deletions spec/mongoid/five_spec.rb
Expand Up @@ -41,11 +41,11 @@
after { MoneyRails.raise_error_on_money_parsing = false }

it "raises exception if the mongoized value is a String with a hyphen" do
expect { priceable_from_string_with_hyphen }.to raise_error ArgumentError
expect { priceable_from_string_with_hyphen }.to raise_error MoneyRails::Error
end

it "raises exception if the mongoized value is a String with an unknown currency" do
expect { priceable_from_string_with_unknown_currency }.to raise_error ArgumentError
expect { priceable_from_string_with_unknown_currency }.to raise_error MoneyRails::Error
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/mongoid/four_spec.rb
Expand Up @@ -46,11 +46,11 @@
after { MoneyRails.raise_error_on_money_parsing = false }

it "raises exception if the mongoized value is a String with a hyphen" do
expect { priceable_from_string_with_hyphen }.to raise_error ArgumentError
expect { priceable_from_string_with_hyphen }.to raise_error MoneyRails::Error
end

it "raises exception if the mongoized value is a String with an unknown currency" do
expect { priceable_from_string_with_unknown_currency }.to raise_error ArgumentError
expect { priceable_from_string_with_unknown_currency }.to raise_error MoneyRails::Error
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/mongoid/three_spec.rb
Expand Up @@ -46,11 +46,11 @@
after { MoneyRails.raise_error_on_money_parsing = false }

it "raises exception if the mongoized value is a String with a hyphen" do
expect { priceable_from_string_with_hyphen }.to raise_error ArgumentError
expect { priceable_from_string_with_hyphen }.to raise_error MoneyRails::Error
end

it "raises exception if the mongoized value is a String with an unknown currency" do
expect { priceable_from_string_with_unknown_currency }.to raise_error ArgumentError
expect { priceable_from_string_with_unknown_currency }.to raise_error MoneyRails::Error
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/mongoid/two_spec.rb
Expand Up @@ -50,7 +50,7 @@
after { MoneyRails.raise_error_on_money_parsing = false }

it "raises exception if the mongoized value is a String with a hyphen" do
expect { priceable_from_string_with_hyphen }.to raise_error ArgumentError
expect { priceable_from_string_with_hyphen }.to raise_error MoneyRails::Error
end
end

Expand Down

0 comments on commit dbcfa0d

Please sign in to comment.