Commit abbd3c4292374bf4154ca8487419ad160f387d5a
Committed by
Antonio Terceiro
1 parent
46cedcbe
Exists in
master
and in
23 other branches
City and state fields are displayed only if there is any state
(ActionItem1645)
Showing
5 changed files
with
34 additions
and
2 deletions
Show diff stats
app/helpers/forms_helper.rb
| @@ -60,6 +60,10 @@ module FormsHelper | @@ -60,6 +60,10 @@ module FormsHelper | ||
| 60 | 60 | ||
| 61 | state_id = 'state-' + FormsHelper.next_id_number | 61 | state_id = 'state-' + FormsHelper.next_id_number |
| 62 | city_id = 'city-' + FormsHelper.next_id_number | 62 | city_id = 'city-' + FormsHelper.next_id_number |
| 63 | + | ||
| 64 | + if states.length < 1 | ||
| 65 | + return | ||
| 66 | + end | ||
| 63 | 67 | ||
| 64 | if simple | 68 | if simple |
| 65 | states = [State.new(:name => _('Select the State'))] + states | 69 | states = [State.new(:name => _('Select the State'))] + states |
app/views/contact/new.rhtml
| @@ -9,8 +9,10 @@ | @@ -9,8 +9,10 @@ | ||
| 9 | 9 | ||
| 10 | <%= required_fields_message %> | 10 | <%= required_fields_message %> |
| 11 | 11 | ||
| 12 | - <% unless environment.enabled?('disable_select_city_for_contact') %> | ||
| 13 | - <%= labelled_form_field _('City and state'), select_city(true) %> | 12 | + <% location_fields = select_city(true) %> |
| 13 | + | ||
| 14 | + <% unless environment.enabled?('disable_select_city_for_contact') || location_fields.blank? %> | ||
| 15 | + <%= labelled_form_field _('City and state'), location_fields %> | ||
| 14 | <% end %> | 16 | <% end %> |
| 15 | <%= required f.text_field(:subject) %> | 17 | <%= required f.text_field(:subject) %> |
| 16 | <%= required f.text_area(:message, :rows => 10, :cols => 60) %> | 18 | <%= required f.text_area(:message, :rows => 10, :cols => 60) %> |
| @@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
| 1 | +Feature: contact organization | ||
| 2 | +As a user | ||
| 3 | +I want to contact an organization | ||
| 4 | +In order to ask questions and solve problems | ||
| 5 | + | ||
| 6 | + Background: | ||
| 7 | + Given the following users | ||
| 8 | + | login | name | | ||
| 9 | + | joaosilva | Joao Silva | | ||
| 10 | + And the following communities | ||
| 11 | + | identifier | name | | ||
| 12 | + | sample-community | Sample Community | | ||
| 13 | + And I am logged in as "joaosilva" | ||
| 14 | + | ||
| 15 | + Scenario: contact us show state field only if there is any state | ||
| 16 | + Given I am on Sample Community's homepage | ||
| 17 | + When I follow "Contact us" | ||
| 18 | + Then I should not see "City and state" | ||
| 19 | + Given the following states | ||
| 20 | + | name | | ||
| 21 | + | Bahia | | ||
| 22 | + When I follow "Contact us" | ||
| 23 | + Then I should see "City and state" | ||
| 24 | + |
test/functional/contact_controller_test.rb
| @@ -64,6 +64,7 @@ class ContactControllerTest < Test::Unit::TestCase | @@ -64,6 +64,7 @@ class ContactControllerTest < Test::Unit::TestCase | ||
| 64 | end | 64 | end |
| 65 | 65 | ||
| 66 | should 'not display select/city select when disable it in environment' do | 66 | should 'not display select/city select when disable it in environment' do |
| 67 | + state = State.create!(:name => "Bahia", :environment => Environment.default) | ||
| 67 | get :new, :profile => profile.identifier | 68 | get :new, :profile => profile.identifier |
| 68 | assert_tag :tag => 'select', :attributes => {:name => 'state'} | 69 | assert_tag :tag => 'select', :attributes => {:name => 'state'} |
| 69 | env = Environment.default | 70 | env = Environment.default |
test/functional/search_controller_test.rb
| @@ -365,6 +365,7 @@ class SearchControllerTest < Test::Unit::TestCase | @@ -365,6 +365,7 @@ class SearchControllerTest < Test::Unit::TestCase | ||
| 365 | end | 365 | end |
| 366 | 366 | ||
| 367 | should 'display option to search within a given point and distance' do | 367 | should 'display option to search within a given point and distance' do |
| 368 | + state = State.create!(:name => "Bahia", :environment => Environment.default) | ||
| 368 | get :popup | 369 | get :popup |
| 369 | 370 | ||
| 370 | assert_tag :tag => 'select', :attributes => {:name => 'radius'} | 371 | assert_tag :tag => 'select', :attributes => {:name => 'radius'} |