diff --git a/.travis.yml b/.travis.yml index 8496a44d2c..e56a0c8281 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 763f429a48..c169c15fba 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/gemfiles/rails42.gemfile b/gemfiles/rails42.gemfile index d2c04f4bb0..051f8e856e 100644 --- a/gemfiles/rails42.gemfile +++ b/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" diff --git a/lib/money-rails.rb b/lib/money-rails.rb index 0d7424c3ea..be0715a6cd 100644 --- a/lib/money-rails.rb +++ b/lib/money-rails.rb @@ -5,6 +5,7 @@ require "money-rails/money" require "money-rails/version" require 'money-rails/hooks' +require 'money-rails/errors' module MoneyRails extend Configuration diff --git a/lib/money-rails/active_record/monetizable.rb b/lib/money-rails/active_record/monetizable.rb index 3735950f86..826493255f 100644 --- a/lib/money-rails/active_record/monetizable.rb +++ b/lib/money-rails/active_record/monetizable.rb @@ -5,7 +5,7 @@ module MoneyRails module ActiveRecord module Monetizable - class ReadOnlyCurrencyException < StandardError; end + class ReadOnlyCurrencyException < MoneyRails::Error; end extend ActiveSupport::Concern module ClassMethods @@ -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 diff --git a/lib/money-rails/errors.rb b/lib/money-rails/errors.rb new file mode 100644 index 0000000000..f973794b4e --- /dev/null +++ b/lib/money-rails/errors.rb @@ -0,0 +1,3 @@ +module MoneyRails + class Error < StandardError; end +end diff --git a/lib/money-rails/mongoid/money.rb b/lib/money-rails/mongoid/money.rb index f218cd7053..3d02da899a 100644 --- a/lib/money-rails/mongoid/money.rb +++ b/lib/money-rails/mongoid/money.rb @@ -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 diff --git a/lib/money-rails/mongoid/two.rb b/lib/money-rails/mongoid/two.rb index 0157b6b06d..cdbdc3eca8 100644 --- a/lib/money-rails/mongoid/two.rb +++ b/lib/money-rails/mongoid/two.rb @@ -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 diff --git a/lib/money-rails/version.rb b/lib/money-rails/version.rb index 2ebdf5d8e9..5275335a1b 100644 --- a/lib/money-rails/version.rb +++ b/lib/money-rails/version.rb @@ -1,3 +1,3 @@ module MoneyRails - VERSION = '1.7.0' + VERSION = '1.8.0' end diff --git a/money-rails.gemspec b/money-rails.gemspec index e7b2207b8f..fa467ef262 100644 --- a/money-rails.gemspec +++ b/money-rails.gemspec @@ -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 diff --git a/spec/active_record/monetizable_spec.rb b/spec/active_record/monetizable_spec.rb index 3552f465a8..5729ebf308 100644 --- a/spec/active_record/monetizable_spec.rb +++ b/spec/active_record/monetizable_spec.rb @@ -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 @@ -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 @@ -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, {} diff --git a/spec/mongoid/five_spec.rb b/spec/mongoid/five_spec.rb index 543f32bff0..9bf5411098 100644 --- a/spec/mongoid/five_spec.rb +++ b/spec/mongoid/five_spec.rb @@ -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 diff --git a/spec/mongoid/four_spec.rb b/spec/mongoid/four_spec.rb index e628da2fcf..a6a9764aa4 100644 --- a/spec/mongoid/four_spec.rb +++ b/spec/mongoid/four_spec.rb @@ -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 diff --git a/spec/mongoid/three_spec.rb b/spec/mongoid/three_spec.rb index 4cd42809e9..777f4a27be 100644 --- a/spec/mongoid/three_spec.rb +++ b/spec/mongoid/three_spec.rb @@ -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 diff --git a/spec/mongoid/two_spec.rb b/spec/mongoid/two_spec.rb index 499f2b8eec..e4efa966f6 100644 --- a/spec/mongoid/two_spec.rb +++ b/spec/mongoid/two_spec.rb @@ -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