Commit 7f3ef5c768d20a229dd98f46ab524cda71d10a39
1 parent
a51a5baa
Exists in
master
and in
28 other branches
ActionItem508: display only regions with validators on enterprise
registration git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2191 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
7 changed files
with
49 additions
and
3 deletions
Show diff stats
app/controllers/public/enterprise_registration_controller.rb
@@ -33,7 +33,7 @@ class EnterpriseRegistrationController < ApplicationController | @@ -33,7 +33,7 @@ class EnterpriseRegistrationController < ApplicationController | ||
33 | # | 33 | # |
34 | # Posts back. | 34 | # Posts back. |
35 | def basic_information | 35 | def basic_information |
36 | - @regions = environment.regions.map {|item| [item.name, item.id]} | 36 | + @regions = environment.regions.select{|i| i.has_validator?}.map {|item| [item.name, item.id]} |
37 | end | 37 | end |
38 | 38 | ||
39 | # present information about validator organizations, and the user one to | 39 | # present information about validator organizations, and the user one to |
app/models/region.rb
@@ -8,4 +8,9 @@ class Region < Category | @@ -8,4 +8,9 @@ class Region < Category | ||
8 | def search_possible_validators(search) | 8 | def search_possible_validators(search) |
9 | Organization.find_by_contents(search).reject {|item| self.validator_ids.include?(item.id) } | 9 | Organization.find_by_contents(search).reject {|item| self.validator_ids.include?(item.id) } |
10 | end | 10 | end |
11 | + | ||
12 | + def has_validator? | ||
13 | + validators.count > 0 | ||
14 | + end | ||
15 | + | ||
11 | end | 16 | end |
app/views/enterprise_registration/basic_information.rhtml
@@ -26,7 +26,7 @@ | @@ -26,7 +26,7 @@ | ||
26 | 26 | ||
27 | <%= labelled_form_field(_('Management information'), text_editor('create_enterprise', 'management_information')) %> | 27 | <%= labelled_form_field(_('Management information'), text_editor('create_enterprise', 'management_information')) %> |
28 | 28 | ||
29 | - <%= f.select('region_id', @regions) %> | 29 | + <%= labelled_form_field(_('Region'), f.select('region_id', @regions)) %> |
30 | 30 | ||
31 | <% button_bar do %> | 31 | <% button_bar do %> |
32 | <%= submit_button('next', _('Next'), :cancel => {:action => 'index'}) %> | 32 | <%= submit_button('next', _('Next'), :cancel => {:action => 'index'}) %> |
app/views/profile_editor/index.rhtml
@@ -48,7 +48,7 @@ | @@ -48,7 +48,7 @@ | ||
48 | 48 | ||
49 | <% button_bar do %> | 49 | <% button_bar do %> |
50 | <%= button(:add, _('Create a new community'), :controller => 'memberships', :action => 'new_community') %> | 50 | <%= button(:add, _('Create a new community'), :controller => 'memberships', :action => 'new_community') %> |
51 | - <%= button(:add, _('Register a new Enterprise'), :controller => 'enterprise_registration') %> | 51 | + <%= button(:add, _('Register a new Enterprise'), :controller => 'enterprise_registration') if environment.regions.any?{|i| i.has_validator?} %> |
52 | <% end %> | 52 | <% end %> |
53 | 53 | ||
54 | <% file_manager do %> | 54 | <% file_manager do %> |
test/functional/enterprise_registration_controller_test.rb
@@ -134,4 +134,18 @@ all_fixtures | @@ -134,4 +134,18 @@ all_fixtures | ||
134 | assert_sanitized assigns(:create_enterprise).management_information | 134 | assert_sanitized assigns(:create_enterprise).management_information |
135 | end | 135 | end |
136 | 136 | ||
137 | + should 'load only regions with validator organizations' do | ||
138 | + env = Environment.default | ||
139 | + | ||
140 | + reg1 = env.regions.create!(:name => 'Region with validator') | ||
141 | + reg1.validators.create!(:name => 'Validator one', :identifier => 'validator-one') | ||
142 | + reg2 = env.regions.create!(:name => 'Region without validator') | ||
143 | + | ||
144 | + get :index | ||
145 | + | ||
146 | + assert_includes assigns(:regions), [reg1.name, reg1.id] | ||
147 | + assert_tag :tag => 'option', :content => "Region with validator" | ||
148 | + assert_no_tag :tag => 'option', :content => "Region without validator" | ||
149 | + end | ||
150 | + | ||
137 | end | 151 | end |
test/functional/profile_editor_controller_test.rb
@@ -418,5 +418,19 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -418,5 +418,19 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
418 | get :index, :profile => profile.identifier | 418 | get :index, :profile => profile.identifier |
419 | assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/memberships/new_community" } | 419 | assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/memberships/new_community" } |
420 | end | 420 | end |
421 | + | ||
422 | + should 'not display link to register new enterprise if there is no validators' do | ||
423 | + person = create_user('testuser').person | ||
424 | + get :index, :profile => 'testuser' | ||
425 | + assert_no_tag :tag => 'a', :content => 'Register a new Enterprise' | ||
426 | + end | ||
427 | + | ||
428 | + should 'display link to register new enterprise' do | ||
429 | + reg = Environment.default.regions.create!(:name => 'Region test') | ||
430 | + reg.validators.create!(:name => 'Validator test', :identifier => 'validator-test') | ||
431 | + person = create_user('testuser').person | ||
432 | + get :index, :profile => 'testuser' | ||
433 | + assert_tag :tag => 'a', :content => 'Register a new Enterprise' | ||
434 | + end | ||
421 | 435 | ||
422 | end | 436 | end |
test/unit/region_test.rb
@@ -40,4 +40,17 @@ class RegionTest < Test::Unit::TestCase | @@ -40,4 +40,17 @@ class RegionTest < Test::Unit::TestCase | ||
40 | assert_not_includes possible, org1 | 40 | assert_not_includes possible, org1 |
41 | end | 41 | end |
42 | 42 | ||
43 | + should 'has validator' do | ||
44 | + env = Environment.create!(:name => "my test environment") | ||
45 | + region = Region.create!(:environment_id => env.id, :name => 'My Region') | ||
46 | + region.validators.create!(:name => 'Validator entity', :identifier => 'validator-entity') | ||
47 | + assert region.has_validator? | ||
48 | + end | ||
49 | + | ||
50 | + should 'has no validator' do | ||
51 | + env = Environment.create!(:name => "my test environment") | ||
52 | + region = Region.create!(:environment_id => env.id, :name => 'My Region') | ||
53 | + assert !region.has_validator? | ||
54 | + end | ||
55 | + | ||
43 | end | 56 | end |