From e9c7512728e01135dec05bebcb886ff0703214c6 Mon Sep 17 00:00:00 2001 From: Trevin Chow Date: Thu, 18 Jan 2024 19:48:02 -0800 Subject: [PATCH] chore: make it easier to add more currencies to test spec --- spec/integration/currency_locales_spec.rb | 474 +++------------------- 1 file changed, 51 insertions(+), 423 deletions(-) diff --git a/spec/integration/currency_locales_spec.rb b/spec/integration/currency_locales_spec.rb index 285d80b..25155f2 100755 --- a/spec/integration/currency_locales_spec.rb +++ b/spec/integration/currency_locales_spec.rb @@ -1,441 +1,69 @@ -# encoding: utf-8 - require 'spec_helper' -describe "CurrencyLocales" do - let(:small_amount) { 9.99 } - let(:small_currency) { number_to_currency(small_amount) } - let(:small_precision) { number_with_precision(small_amount) } - - let(:big_amount) { 9999.99 } - let(:big_currency) { number_to_currency(big_amount) } - let(:big_precision) { number_with_precision(big_amount) } - - def number_to_currency(number) - ActionController::Base.helpers.number_to_currency(number, :locale => locale) - end - - def number_with_precision(number) - ActionController::Base.helpers.number_with_precision(number, :locale => locale) - end - - describe "cs" do - let(:locale) { 'cs' } - - it "should translate the small amount to currency" do - small_currency.should == '9,99Kč' - end - - it "should translate the big amount to currency" do - big_currency.should == '9999,99Kč' - end - - it "should translate the small amount with precision" do - small_precision.should == '9,99' - end +shared_examples_for "locale" do |locale_code, small_currency, big_currency, small_precision, big_precision| + let(:locale) { locale_code } - it "should translate the big amount with precision" do - big_precision.should == '9999,99' - end + it "should translate the small amount to currency" do + expect(number_to_currency(small_amount)).to eq(small_currency) end - describe "da" do - let(:locale) { 'da' } - - it "should translate the small amount to currency" do - small_currency.should == 'kr9,99' - end - - it "should translate the big amount to currency" do - big_currency.should == 'kr9.999,99' - end - - it "should translate the small amount with precision" do - small_precision.should == '9,99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9.999,99' - end + it "should translate the big amount to currency" do + expect(number_to_currency(big_amount)).to eq(big_currency) end - describe "en-AU" do - let(:locale) { 'en-AU' } - - it "should translate the small amount to currency" do - small_currency.should == '$9.99' - end - - it "should translate the big amount to currency" do - big_currency.should == '$9,999.99' - end - - it "should translate the small amount with precision" do - small_precision.should == '9.99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9,999.99' - end + it "should translate the small amount with precision" do + expect(number_with_precision(small_amount)).to eq(small_precision) end - describe "en-GB" do - let(:locale) { 'en-GB' } - - it "should translate the small amount to currency" do - small_currency.should == '£9.99' - end - - it "should translate the big amount to currency" do - big_currency.should == '£9,999.99' - end - - it "should translate the small amount with precision" do - small_precision.should == '9.99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9,999.99' - end + it "should translate the big amount with precision" do + expect(number_with_precision(big_amount)).to eq(big_precision) end +end - describe "en-IN" do - let(:locale) { 'en-IN' } - - it "should translate the small amount to currency" do - small_currency.should == '₹9.99' - end - - it "should translate the big amount to currency" do - big_currency.should == '₹9,999.99' - end - - it "should translate the small amount with precision" do - small_precision.should == '9.99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9999.99' - end - end - - describe "en-PH" do - let(:locale) { 'en-PH' } - - it "should translate the small amount to currency" do - small_currency.should == '₱9.99' - end - - it "should translate the big amount to currency" do - big_currency.should == '₱9,999.99' - end - - it "should translate the small amount with precision" do - small_precision.should == '9.99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9,999.99' - end - end - - describe "es-MX" do - let(:locale) { 'es-MX' } - - it "should translate the small amount to currency" do - small_currency.should == '$9.99' - end - - it "should translate the big amount to currency" do - big_currency.should == '$9,999.99' - end - - it "should translate the small amount with precision" do - small_precision.should == '9.99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9,999.99' - end - end - - describe "en-US" do - let(:locale) { 'en-US' } - - it "should translate the small amount to currency" do - small_currency.should == '$9.99' - end - - it "should translate the big amount to currency" do - big_currency.should == '$9,999.99' - end - - it "should translate the small amount with precision" do - small_precision.should == '9.99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9,999.99' - end - end - - describe "eu" do - let(:locale) { 'eu' } - - it "should translate the small amount to currency" do - small_currency.should == '€9.99' - end - - it "should translate the big amount to currency" do - big_currency.should == '€9,999.99' - end - - it "should translate the small amount with precision" do - small_precision.should == '9.99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9,999.99' - end - end - - describe "gsw-CH" do - let(:locale) { 'gsw-CH' } - - it "should translate the small amount to currency" do - small_currency.should == 'CHF9.99' - end - - it "should translate the big amount to currency" do - big_currency.should == 'CHF9,999.99' - end - - it "should translate the small amount with precision" do - small_precision.should == '9.99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9,999.99' - end - end - - describe "hu" do - let(:locale) { 'hu' } - - it "should translate the small amount to currency" do - small_currency.should == '10Ft' - end - - it "should translate the big amount to currency" do - big_currency.should == '10000Ft' - end - - it "should translate the small amount with precision" do - small_precision.should == '9,99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9999,99' - end - end - - describe "il" do - let(:locale) { 'il' } - - it "should translate the small amount to currency" do - small_currency.should == '₪9.99' - end - - it "should translate the big amount to currency" do - big_currency.should == '₪9,999.99' - end - - it "should translate the small amount with precision" do - small_precision.should == '9.99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9,999.99' - end - end - - describe "ja" do - let(:locale) { 'ja' } - - it "should translate the small amount to currency" do - small_currency.should == '¥10' - end - - it "should translate the big amount to currency" do - big_currency.should == '¥10,000' - end - - it "should translate the small amount with precision" do - small_precision.should == '9.99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9,999.99' - end - end - - describe "ms-MY" do - let(:locale) { 'ms-MY' } - - it "should translate the small amount to currency" do - small_currency.should == 'RM9.99' - end - - it "should translate the big amount to currency" do - big_currency.should == 'RM9,999.99' - end - - it "should translate the small amount with precision" do - small_precision.should == '9.99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9,999.99' - end - end - - describe "nb" do - let(:locale) { 'nb' } - - it "should translate the small amount to currency" do - small_currency.should == '9,99kr' - end - - it "should translate the big amount to currency" do - big_currency.should == '9999,99kr' - end - - it "should translate the small amount with precision" do - small_precision.should == '9,99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9999,99' - end - end - - describe "pl" do - let(:locale) { 'pl' } - - it "should translate the small amount to currency" do - small_currency.should == '9,99zł' - end - - it "should translate the big amount to currency" do - big_currency.should == '9999,99zł' - end - - it "should translate the small amount with precision" do - small_precision.should == '9,99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9999,99' - end - end - - describe "pt-BR" do - let(:locale) { 'pt-BR' } - - it "should translate the small amount to currency" do - small_currency.should == 'R$9,99' - end - - it "should translate the big amount to currency" do - big_currency.should == 'R$9.999,99' - end - - it "should translate the small amount with precision" do - small_precision.should == '9,99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9.999,99' - end - end - - describe "sv-SE" do - let(:locale) { 'sv-SE' } - - it "should translate the small amount to currency" do - small_currency.should == '9,99kr' - end - - it "should translate the big amount to currency" do - big_currency.should == '9999,99kr' - end - - it "should translate the small amount with precision" do - small_precision.should == '9,99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9999,99' - end - end - - describe "th" do - let(:locale) { 'th' } - - it "should translate the small amount to currency" do - small_currency.should == '9.99฿' - end - - it "should translate the big amount to currency" do - big_currency.should == '9,999.99฿' - end - - it "should translate the small amount with precision" do - small_precision.should == '9.99' - end +describe "CurrencyLocales" do + let(:small_amount) { 9.99 } + let(:big_amount) { 9999.99 } - it "should translate the big amount with precision" do - big_precision.should == '9,999.99' - end + def number_to_currency(number) + ActionController::Base.helpers.number_to_currency(number, :locale => locale) end - describe "tr" do - let(:locale) { 'tr' } - - it "should translate the small amount to currency" do - small_currency.should == '9,99 ₺' - end - - it "should translate the big amount to currency" do - big_currency.should == '9.999,99 ₺' - end - - it "should translate the small amount with precision" do - small_precision.should == '9,99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9.999,99' - end + def number_with_precision(number) + ActionController::Base.helpers.number_with_precision(number, :locale => locale) end - describe "zh-TW" do - let(:locale) { 'zh-TW' } - - it "should translate the small amount to currency" do - small_currency.should == 'NT$9.99' - end - - it "should translate the big amount to currency" do - big_currency.should == 'NT$9,999.99' - end - - it "should translate the small amount with precision" do - small_precision.should == '9.99' - end - - it "should translate the big amount with precision" do - big_precision.should == '9,999.99' - end + locales = { + 'cs' => ['9,99Kč', '9999,99Kč', '9,99', '9999,99'], + 'da' => ['kr9,99', 'kr9.999,99', '9,99', '9.999,99'], + 'en-AU' => ['$9.99', '$9,999.99', '9.99', '9,999.99'], + 'en-GB' => ['£9.99', '£9,999.99', '9.99', '9,999.99'], + 'en-IN' => ['₹9.99', '₹9,999.99', '9.99', '9,999.99'], + 'en-PH' => ['₱9.99', '₱9,999.99', '9.99', '9,999.99'], + 'es-MX' => ['$9.99', '$9,999.99', '9.99', '9,999.99'], + 'en-US' => ['$9.99', '$9,999.99', '9.99', '9,999.99'], + 'eu' => ['€9.99', '€9,999.99', '9.99', '9,999.99'], + 'gsw-CH' => ['CHF9.99', 'CHF9,999.99', '9.99', '9,999.99'], + 'hu' => ['10Ft', '10000Ft', '9,99', '9999,99'], + 'id' => ['Rp9,99', 'Rp9.999,99', '9,99', '9.999,99'], + 'it' => ['€9,99', '€9.999,99', '9,99', '9.999,99'], + 'ko' => ['₩9.99', '₩9,999.99', '9.99', '9,999.99'], + 'nl' => ['€9,99', '€9.999,99', '9,99', '9.999,99'], + 'pt' => ['R$9,99', 'R$9.999,99', '9,99', '9.999,99'], + 'ro' => ['9,99Lei', '9.999,99Lei', '9,99', '9.999,99'], + 'ru' => ['9,99р.', '9.999,99р.', '9,99', '9.999,99'], + 'sk' => ['9,99€', '9.999,99€', '9,99', '9.999,99'], + 'th' => ['฿9.99', '฿9,999.99', '9.99', '9,999.99'], + 'tr' => ['9,99₺', '9.999,99₺', '9,99', '9.999,99'], + 'uk' => ['9,99₴', '9.999,99₴', '9,99', '9.999,99'], + 'vi' => ['9,99₫', '9.999,99₫', '9,99', '9.999,99'], + 'zh-CN' => ['¥9.99', '¥9,999.99', '9.99', '9,999.99'], + 'zh-HK' => ['HK$9.99', 'HK$9,999.99', '9.99', '9,999.99'], + 'zh-SG' => ['S$9.99', 'S$9,999.99', '9.99', '9,999.99'], + 'zh-TW' => ['NT$9.99', 'NT$9,999.99', '9.99', '9,999.99'], + } + + locales.each do |locale, values| + it_behaves_like "locale", locale, *values end end +