Skip to content

Commit

Permalink
Skip redundant check for postfixed isntance currency name
Browse files Browse the repository at this point in the history
  • Loading branch information
antstorm committed Jul 24, 2016
1 parent 9afd399 commit 403b213
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 17 deletions.
9 changes: 0 additions & 9 deletions lib/money-rails/active_record/monetizable.rb
Expand Up @@ -277,10 +277,6 @@ def write_monetized(name, subunit_name, value, validation_enabled, instance_curr
end

def currency_for(name, instance_currency_name, field_currency_name)
if MoneyRails::Configuration.currency_column[:postfix].present?
instance_currency_name_with_postfix = "#{name}#{MoneyRails::Configuration.currency_column[:postfix]}"
end

if instance_currency_name.present? && respond_to?(instance_currency_name) &&
Money::Currency.find(public_send(instance_currency_name))

Expand All @@ -289,11 +285,6 @@ def currency_for(name, instance_currency_name, field_currency_name)
Money::Currency.find(field_currency_name.call(self))
elsif field_currency_name
Money::Currency.find(field_currency_name)
elsif instance_currency_name_with_postfix.present? &&
respond_to?(instance_currency_name_with_postfix) &&
Money::Currency.find(public_send(instance_currency_name_with_postfix))

Money::Currency.find(public_send(instance_currency_name_with_postfix))
elsif self.class.respond_to?(:currency)
self.class.currency
else
Expand Down
8 changes: 0 additions & 8 deletions spec/active_record/monetizable_spec.rb
Expand Up @@ -992,14 +992,6 @@ class SubProduct < Product
expect(currency.iso_code).to eq('CAD')
end

it "detects currency based on inferred currency field" do
product = Product.new(:reduced_price_currency => 'CAD')
currency = product.send(:currency_for, :reduced_price, nil, nil)

expect(currency).to be_an_instance_of(Money::Currency)
expect(currency.iso_code).to eq('CAD')
end

it "falls back to a registered currency" do
product = Product.new
currency = product.send(:currency_for, :amount, nil, nil)
Expand Down
1 change: 1 addition & 0 deletions spec/dummy/db/schema.rb
@@ -1,3 +1,4 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
Expand Down

0 comments on commit 403b213

Please sign in to comment.