Skip to content

Commit

Permalink
Merge branch 'mcrowe-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jim committed Mar 6, 2014
2 parents 282223f + 81006ab commit b97db31
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/carmen/rails/action_view/form_helper.rb
Expand Up @@ -94,6 +94,11 @@ def region_options_for_select(regions, selected=nil, options={})
unless priority_regions.empty?
region_options += options_for_select(priority_regions, selected)
region_options += "<option disabled>-------------</option>"

# If a priority region is selected, don't select it again in the main list.
# This prevents some browsers from selecting the second occurance of this region,
# which makes it difficult to select an alternative priority region.
selected = nil if priority_region_codes.include?(selected)
end
end

Expand Down
17 changes: 17 additions & 0 deletions test/carmen/action_view/helpers/form_helper_test.rb
Expand Up @@ -101,6 +101,23 @@ def test_priority_country_select_deprecated_api
assert_equal_markup(expected, html)
end

def test_country_select_selected_priority_region_not_selected_twice
@object.country_code = 'ES'

html = country_select(@object, :country_code, :priority => ['ES'])
expected = <<-HTML
<select id="object_country_code" name="object[country_code]">
<option value="ES" selected="selected">Eastasia</option>
<option disabled>-------------</option>
<option value="ES">Eastasia</option>
<option value="EU">Eurasia</option>
<option value="OC">Oceania</option>
</select>
HTML

assert_equal_markup(expected, html)
end

def test_basic_subregion_select
oceania = Carmen::Country.coded('OC')
expected = <<-HTML
Expand Down
6 changes: 6 additions & 0 deletions test/test_helper.rb
Expand Up @@ -30,6 +30,12 @@ def assert_equal_markup(expected, actual, message=nil)
private

def clean_markup(markup)
clean_whitespace(markup).gsub(/( [a-zA-Z_]*="[^"]*")+/) do |match|
' ' + match.strip!.split(' ').sort.join(' ')
end
end

def clean_whitespace(markup)
markup.
gsub(/\s+/, ' '). # cleanup whitespace
gsub(/>\s/, '>'). # kill space after tags
Expand Down

0 comments on commit b97db31

Please sign in to comment.