From 3e8ee83802ad002b5cd21c6c69d9e382be9fa71c Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 27 Jun 2017 13:51:25 +0200 Subject: [PATCH] [BUGFIX] Use ISO codes as select values, not the IDs Fixes #11 --- CHANGELOG.md | 2 ++ lib/currency_select.rb | 2 +- spec/currency_select_spec.rb | 16 ++++++++-------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ee61e8..7645a2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +- Use ISO codes as select values, not the IDs + ([#24](https://github.com/braingourmets/currency_select/pull/24)) - Fix the the Gemfile ([#19](https://github.com/braingourmets/currency_select/pull/19)) - Fix the order of name attribute and ID in the specs diff --git a/lib/currency_select.rb b/lib/currency_select.rb index 2e76fb7..07cb6df 100644 --- a/lib/currency_select.rb +++ b/lib/currency_select.rb @@ -4,7 +4,7 @@ module CurrencySelect class << self CURRENCIES = Money::Currency::table.inject([]) do |array, (id, currency)| - array << [ "#{currency[:name]} - #{currency[:iso_code]}", id ] + array << [ "#{currency[:name]} - #{currency[:iso_code]}", currency[:iso_code] ] end.sort_by { |currency| currency.first } unless const_defined?("CURRENCIES") # Returns an array with ISO codes and currency names for option diff --git a/spec/currency_select_spec.rb b/spec/currency_select_spec.rb index 3fef859..3f09459 100644 --- a/spec/currency_select_spec.rb +++ b/spec/currency_select_spec.rb @@ -20,9 +20,9 @@ class User let(:selected_eur_option) do if defined?(Tags::Base) - content_tag(:option, 'Euro - EUR', selected: :selected, value: 'eur') + content_tag(:option, 'Euro - EUR', selected: :selected, value: 'EUR') else - "" + '' end end @@ -48,26 +48,26 @@ class User end it "selects the value of currency_code" do - user.currency_code = 'eur' + user.currency_code = 'EUR' t = builder.currency_select(:currency_code) expect(t).to include(selected_eur_option) end it "does not mark two currencies as selected" do - user.currency_code = "usd" - str = "".html_safe + user.currency_code = 'USD' + str = ''.html_safe expect(tag).to_not include(str) end describe "priority currencies" do - let(:tag) { builder.currency_select(:currency_code, ['eur']) } + let(:tag) { builder.currency_select(:currency_code, ['EUR']) } it "inserts the priority currencies at the top" do - expect(tag).to include("#{select_tag}") + expect(tag).to include('') end end end