diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 3191a2ab9..486759e03 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -57,10 +57,6 @@ module ApplicationHelper
SiteCustomization::ContentBlock.block_for(name, locale)
end
- def format_price(number)
- number_to_currency(number, precision: 0, locale: I18n.default_locale)
- end
-
def kaminari_path(url)
"#{root_url.chomp("\/")}#{url}"
end
diff --git a/app/models/budget.rb b/app/models/budget.rb
index 9b55dc4a6..6c80e7f1f 100644
--- a/app/models/budget.rb
+++ b/app/models/budget.rb
@@ -124,7 +124,7 @@ class Budget < ActiveRecord::Base
def formatted_amount(amount)
ActionController::Base.helpers.number_to_currency(amount,
precision: 0,
- locale: I18n.default_locale,
+ locale: I18n.locale,
unit: currency_symbol)
end
diff --git a/app/views/budgets/results/_results_table.html.erb b/app/views/budgets/results/_results_table.html.erb
index ebd3c2b15..48983a858 100644
--- a/app/views/budgets/results/_results_table.html.erb
+++ b/app/views/budgets/results/_results_table.html.erb
@@ -21,7 +21,7 @@
<% if results_type == :compatible %>
<%= t("budgets.results.amount_available") %>
- <%= format_price(heading_price) %>
+ <%= @budget.formatted_amount(heading_price) %>
|
<% end %>
@@ -53,12 +53,12 @@
<%= investment.ballot_lines_count %>
- <%= format_price investment.price %>
+ <%= @budget.formatted_amount(investment.price) %>
|
<% if results_type == :compatible %>
- <%= format_price amount_available - investment.price %>
+ title="<%= @budget.formatted_amount(amount_available) %> - <%= @budget.formatted_amount(investment.price) %>">
+ <%= @budget.formatted_amount(amount_available - investment.price) %>
<% amount_available -= investment.price if investment.winner? %>
|
<% end %>
diff --git a/spec/models/budget_spec.rb b/spec/models/budget_spec.rb
index 80f0a0c94..72b521861 100644
--- a/spec/models/budget_spec.rb
+++ b/spec/models/budget_spec.rb
@@ -228,4 +228,38 @@ describe Budget do
expect(finished_phase.prev_phase).to eq(reviewing_ballots_phase)
end
end
+
+ describe "#formatted_amount" do
+ after do
+ I18n.locale = :en
+ end
+
+ it "correctly formats Euros with Spanish" do
+ budget.update(currency_symbol: '€')
+ I18n.locale = :es
+
+ expect(budget.formatted_amount(1000.00)).to eq ('1.000 €')
+ end
+
+ it "correctly formats Dollars with Spanish" do
+ budget.update(currency_symbol: '$')
+ I18n.locale = :es
+
+ expect(budget.formatted_amount(1000.00)).to eq ('1.000 $')
+ end
+
+ it "correctly formats Dollars with English" do
+ budget.update(currency_symbol: '$')
+ I18n.locale = :en
+
+ expect(budget.formatted_amount(1000.00)).to eq ('$1,000')
+ end
+
+ it "correctly formats Euros with English" do
+ budget.update(currency_symbol: '€')
+ I18n.locale = :en
+
+ expect(budget.formatted_amount(1000.00)).to eq ('€1,000')
+ end
+ end
end