diff --git a/app/controllers/public/enterprise_registration_controller.rb b/app/controllers/public/enterprise_registration_controller.rb index 7977982..1c14286 100644 --- a/app/controllers/public/enterprise_registration_controller.rb +++ b/app/controllers/public/enterprise_registration_controller.rb @@ -33,7 +33,7 @@ class EnterpriseRegistrationController < ApplicationController # # Posts back. def basic_information - @regions = environment.regions.map {|item| [item.name, item.id]} + @regions = environment.regions.select{|i| i.has_validator?}.map {|item| [item.name, item.id]} end # present information about validator organizations, and the user one to diff --git a/app/models/region.rb b/app/models/region.rb index 9bc654d..a8693c1 100644 --- a/app/models/region.rb +++ b/app/models/region.rb @@ -8,4 +8,9 @@ class Region < Category def search_possible_validators(search) Organization.find_by_contents(search).reject {|item| self.validator_ids.include?(item.id) } end + + def has_validator? + validators.count > 0 + end + end diff --git a/app/views/enterprise_registration/basic_information.rhtml b/app/views/enterprise_registration/basic_information.rhtml index e0eaee4..45f0be8 100644 --- a/app/views/enterprise_registration/basic_information.rhtml +++ b/app/views/enterprise_registration/basic_information.rhtml @@ -26,7 +26,7 @@ <%= labelled_form_field(_('Management information'), text_editor('create_enterprise', 'management_information')) %> - <%= f.select('region_id', @regions) %> + <%= labelled_form_field(_('Region'), f.select('region_id', @regions)) %> <% button_bar do %> <%= submit_button('next', _('Next'), :cancel => {:action => 'index'}) %> diff --git a/app/views/profile_editor/index.rhtml b/app/views/profile_editor/index.rhtml index 1e738bb..cc407d0 100644 --- a/app/views/profile_editor/index.rhtml +++ b/app/views/profile_editor/index.rhtml @@ -48,7 +48,7 @@ <% button_bar do %> <%= button(:add, _('Create a new community'), :controller => 'memberships', :action => 'new_community') %> - <%= button(:add, _('Register a new Enterprise'), :controller => 'enterprise_registration') %> + <%= button(:add, _('Register a new Enterprise'), :controller => 'enterprise_registration') if environment.regions.any?{|i| i.has_validator?} %> <% end %> <% file_manager do %> diff --git a/test/functional/enterprise_registration_controller_test.rb b/test/functional/enterprise_registration_controller_test.rb index 7db8a30..1e39bee 100644 --- a/test/functional/enterprise_registration_controller_test.rb +++ b/test/functional/enterprise_registration_controller_test.rb @@ -134,4 +134,18 @@ all_fixtures assert_sanitized assigns(:create_enterprise).management_information end + should 'load only regions with validator organizations' do + env = Environment.default + + reg1 = env.regions.create!(:name => 'Region with validator') + reg1.validators.create!(:name => 'Validator one', :identifier => 'validator-one') + reg2 = env.regions.create!(:name => 'Region without validator') + + get :index + + assert_includes assigns(:regions), [reg1.name, reg1.id] + assert_tag :tag => 'option', :content => "Region with validator" + assert_no_tag :tag => 'option', :content => "Region without validator" + end + end diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index 917926f..1448158 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -418,5 +418,19 @@ class ProfileEditorControllerTest < Test::Unit::TestCase get :index, :profile => profile.identifier assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/memberships/new_community" } end + + should 'not display link to register new enterprise if there is no validators' do + person = create_user('testuser').person + get :index, :profile => 'testuser' + assert_no_tag :tag => 'a', :content => 'Register a new Enterprise' + end + + should 'display link to register new enterprise' do + reg = Environment.default.regions.create!(:name => 'Region test') + reg.validators.create!(:name => 'Validator test', :identifier => 'validator-test') + person = create_user('testuser').person + get :index, :profile => 'testuser' + assert_tag :tag => 'a', :content => 'Register a new Enterprise' + end end diff --git a/test/unit/region_test.rb b/test/unit/region_test.rb index a9f4213..7ec7355 100644 --- a/test/unit/region_test.rb +++ b/test/unit/region_test.rb @@ -40,4 +40,17 @@ class RegionTest < Test::Unit::TestCase assert_not_includes possible, org1 end + should 'has validator' do + env = Environment.create!(:name => "my test environment") + region = Region.create!(:environment_id => env.id, :name => 'My Region') + region.validators.create!(:name => 'Validator entity', :identifier => 'validator-entity') + assert region.has_validator? + end + + should 'has no validator' do + env = Environment.create!(:name => "my test environment") + region = Region.create!(:environment_id => env.id, :name => 'My Region') + assert !region.has_validator? + end + end -- libgit2 0.21.2