Permalink
Browse files

Add :currency_symbol_position config setting

This will address the issue brought up #1911, where the currency symbol was incorrectly being placed before the amount
  • Loading branch information...
radar committed Sep 4, 2012
1 parent d7082ee commit 575af696f39f9ea408fc9f4082bccff4e7fa4e05
Showing with 46 additions and 0 deletions.
  1. +1 −0 core/app/models/spree/app_configuration.rb
  2. +1 −0 core/lib/spree/money.rb
  3. +44 −0 core/spec/lib/money_spec.rb
@@ -42,6 +42,7 @@ class AppConfiguration < Preferences::Configuration
preference :company, :boolean, :default => false # Request company field for billing and shipping addr
preference :create_inventory_units, :boolean, :default => true # should only be false when track_inventory_levels is false, also disables RMA's
preference :currency, :string, :default => "USD"
preference :currency_symbol_position, :string, :default => "before"
preference :display_currency, :boolean, :default => false
preference :default_country_id, :integer, :default => 214
preference :default_locale, :string, :default => Rails.application.config.i18n.default_locale || :en
View
@@ -6,6 +6,7 @@ def initialize(amount, options={})
@money = ::Money.new(amount * 100, Spree::Config[:currency])
@options = {}
@options[:with_currency] = true if Spree::Config[:display_currency]
@options[:symbol_position] = Spree::Config[:currency_symbol_position].to_sym
@options.merge!(options)
end
@@ -0,0 +1,44 @@
require 'spec_helper'
module Spree
describe Money do
before do
reset_spree_preferences do |config|
config.currency = "USD"
config.currency_symbol_position = :before
config.display_currency = false
end
end
it "formats correctly" do
money = Spree::Money.new(10)
money.to_s.should == "$10.00"
end
context "with currency" do
it "passed in option" do
money = Spree::Money.new(10, :with_currency => true)
money.to_s.should == "$10.00 USD"
end
it "config option" do
Spree::Config[:display_currency] = true
money = Spree::Money.new(10)
money.to_s.should == "$10.00 USD"
end
end
context "symbol positioning" do
it "passed in option" do
money = Spree::Money.new(10, :symbol_position => :after)
money.to_s.should == "10.00 $"
end
it "config option" do
Spree::Config[:currency_symbol] = :after
money = Spree::Money.new(10)
money.to_s.should == "10.00 $"
end
end
end
end

0 comments on commit 575af69

Please sign in to comment.