Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Use ISO codes as select values, not the IDs #24

Merged
merged 1 commit into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/currency_select.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tt>option</tt>
Expand Down
16 changes: 8 additions & 8 deletions spec/currency_select_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
"<option value=\"eur\" selected=\"selected\">Euro - EUR</option>"
'<option value="EUR" selected="selected">Euro - EUR</option>'
end
end

Expand All @@ -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 = "<option value=\"us\" selected=\"selected\">United States</option>".html_safe
user.currency_code = 'USD'
str = '<option value="USD" selected="selected">United States</option>'.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}<option value=\"eur")
expect(tag).to include("#{select_tag}<option value=\"EUR")
end

it "inserts a divider" do
expect(tag).to include("<option value=\"\" disabled=\"disabled\">-------------</option>")
expect(tag).to include('<option value="" disabled="disabled">-------------</option>')
end
end
end
Expand Down