Commit abbd3c4292374bf4154ca8487419ad160f387d5a

Authored by Rodrigo Souto
Committed by Antonio Terceiro
1 parent 46cedcbe

City and state fields are displayed only if there is any state

(ActionItem1645)
app/helpers/forms_helper.rb
... ... @@ -60,6 +60,10 @@ module FormsHelper
60 60  
61 61 state_id = 'state-' + FormsHelper.next_id_number
62 62 city_id = 'city-' + FormsHelper.next_id_number
  63 +
  64 + if states.length < 1
  65 + return
  66 + end
63 67  
64 68 if simple
65 69 states = [State.new(:name => _('Select the State'))] + states
... ...
app/views/contact/new.rhtml
... ... @@ -9,8 +9,10 @@
9 9  
10 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 16 <% end %>
15 17 <%= required f.text_field(:subject) %>
16 18 <%= required f.text_area(:message, :rows => 10, :cols => 60) %>
... ...
features/contact.feature 0 → 100644
... ... @@ -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 &lt; Test::Unit::TestCase
64 64 end
65 65  
66 66 should 'not display select/city select when disable it in environment' do
  67 + state = State.create!(:name => "Bahia", :environment => Environment.default)
67 68 get :new, :profile => profile.identifier
68 69 assert_tag :tag => 'select', :attributes => {:name => 'state'}
69 70 env = Environment.default
... ...
test/functional/search_controller_test.rb
... ... @@ -365,6 +365,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
365 365 end
366 366  
367 367 should 'display option to search within a given point and distance' do
  368 + state = State.create!(:name => "Bahia", :environment => Environment.default)
368 369 get :popup
369 370  
370 371 assert_tag :tag => 'select', :attributes => {:name => 'radius'}
... ...