Commit 542135da6707c0055482a4c2f2bf54573a2a4967
Committed by
Antonio Terceiro
1 parent
fcc26970
Exists in
master
and in
29 other branches
Fixing the Enterprise Registering Process
* The registration has two validation type: region and admin. + Admin - There is no validator to choose. - The regions to choose are states (This might be changed in the future). - The admins of the environment recieves the task to approve the registration of this new enterprise. - The region field isn't displayed. + Region - If there isn't any validator, shows a message that it's not possible to register any enterprise and don't show the form. - Show only the regions where is registered at least one validator. - The region field is displayed. * The required fields are highlithed. * The fields that are active or required are set through the administration panel. * Only the fields name and identifier are always required. * After registering a new enterprise, the user is set as an admin of it. * The cancel button in the register form is working properly. * In the "Validator" step, the radio button is choosing a default option. * Cancel radio_button in the task validation has a "Rejection Explanation" field that is required. * Some navigation buttons added. * Changed some buttons to labelled buttons. * The "Register a new enterprise" button is an admin option. (ActionItem1482)
Showing
19 changed files
with
367 additions
and
77 deletions
Show diff stats
app/controllers/public/enterprise_registration_controller.rb
... | ... | @@ -9,15 +9,20 @@ class EnterpriseRegistrationController < ApplicationController |
9 | 9 | # FIXME: shouldn't this action present some sort of welcome message and point |
10 | 10 | # to the first step explicitly? |
11 | 11 | def index |
12 | + @validation = environment.organization_approval_method | |
12 | 13 | @create_enterprise = CreateEnterprise.new(params[:create_enterprise]) |
13 | - if params[:create_enterprise] && params[:create_enterprise][:target_id] | |
14 | - @create_enterprise.target = Profile.find(params[:create_enterprise][:target_id]) | |
14 | + if @validation == :region | |
15 | + if params[:create_enterprise] && params[:create_enterprise][:target_id] | |
16 | + @create_enterprise.target = Profile.find(params[:create_enterprise][:target_id]) | |
17 | + end | |
18 | + elsif @validation == :admin | |
19 | + @create_enterprise.target = @create_enterprise.environment | |
15 | 20 | end |
16 | 21 | @create_enterprise.requestor = current_user.person |
17 | 22 | the_action = |
18 | 23 | if request.post? |
19 | 24 | if @create_enterprise.valid_before_selecting_target? |
20 | - if @create_enterprise.valid? | |
25 | + if @create_enterprise.valid? || @validation == :admin | |
21 | 26 | :confirmation |
22 | 27 | else |
23 | 28 | :select_validator |
... | ... | @@ -38,7 +43,9 @@ class EnterpriseRegistrationController < ApplicationController |
38 | 43 | # |
39 | 44 | # Posts back. |
40 | 45 | def basic_information |
41 | - @regions = environment.regions.select{|i| i.has_validator?}.map {|item| [item.name, item.id]} | |
46 | + if @validation == :region | |
47 | + @regions = @create_enterprise.available_regions.map {|region| [region.name, region.id]} | |
48 | + end | |
42 | 49 | end |
43 | 50 | |
44 | 51 | # present information about validator organizations, and the user one to | ... | ... |
app/models/create_enterprise.rb
... | ... | @@ -11,7 +11,7 @@ class CreateEnterprise < Task |
11 | 11 | N_('Economic activity') |
12 | 12 | N_('Management information') |
13 | 13 | |
14 | - DATA_FIELDS = %w[ name identifier address contact_phone contact_person acronym foundation_year legal_form economic_activity management_information region_id reject_explanation ] | |
14 | + DATA_FIELDS = Enterprise.fields + %w[name identifier region_id reject_explanation] | |
15 | 15 | |
16 | 16 | serialize :data, Hash |
17 | 17 | attr_protected :data |
... | ... | @@ -31,20 +31,30 @@ class CreateEnterprise < Task |
31 | 31 | end |
32 | 32 | |
33 | 33 | # checks for virtual attributes |
34 | - validates_presence_of :name, :identifier, :address, :contact_phone, :contact_person, :legal_form, :economic_activity, :region_id | |
34 | + validates_presence_of :name, :identifier | |
35 | + | |
36 | + #checks if the validation method is region to validates | |
37 | + validates_presence_of :region_id, :if => lambda { |obj| obj.environment.organization_approval_method == :region } | |
38 | + | |
35 | 39 | validates_format_of :foundation_year, :with => /^\d*$/ |
36 | 40 | |
37 | 41 | # checks for actual attributes |
38 | 42 | validates_presence_of :requestor_id, :target_id |
39 | 43 | |
44 | + # checks for admins required attributes | |
45 | + DATA_FIELDS.each do |attribute| | |
46 | + validates_presence_of attribute, :if => lambda { |obj| obj.environment.required_enterprise_fields.include?(attribute) } | |
47 | + end | |
48 | + | |
40 | 49 | # check for explanation when rejecting |
41 | 50 | validates_presence_of :reject_explanation, :if => (lambda { |record| record.status == Task::Status::CANCELLED } ) |
42 | 51 | |
43 | 52 | xss_terminate :only => [ :acronym, :address, :contact_person, :contact_phone, :economic_activity, :legal_form, :management_information, :name ], :on => 'validation' |
44 | 53 | |
45 | 54 | def validate |
55 | + | |
46 | 56 | if self.region && self.target |
47 | - unless self.region.validators.include?(self.target) | |
57 | + unless self.region.validators.include?(self.target) || self.target_type == "Environment" | |
48 | 58 | self.errors.add(:target, '%{fn} is not a validator for the chosen region') |
49 | 59 | end |
50 | 60 | end |
... | ... | @@ -58,7 +68,7 @@ class CreateEnterprise < Task |
58 | 68 | if valid? |
59 | 69 | true |
60 | 70 | else |
61 | - self.errors.size == 1 and self.errors[:target_id] | |
71 | + self.errors.size == 1 && !self.errors[:target_id].nil? | |
62 | 72 | end |
63 | 73 | end |
64 | 74 | |
... | ... | @@ -81,7 +91,27 @@ class CreateEnterprise < Task |
81 | 91 | end |
82 | 92 | |
83 | 93 | def environment |
84 | - region ? region.environment : nil | |
94 | + region ? region.environment : self.requestor ? self.requestor.environment : Environment.default | |
95 | + end | |
96 | + | |
97 | + def available_regions | |
98 | + environment.regions.with_validators | |
99 | + end | |
100 | + | |
101 | + def active_fields | |
102 | + environment ? environment.active_enterprise_fields : [] | |
103 | + end | |
104 | + | |
105 | + def required_fields | |
106 | + environment ? environment.required_enterprise_fields : [] | |
107 | + end | |
108 | + | |
109 | + def community? | |
110 | + false | |
111 | + end | |
112 | + | |
113 | + def enterprise? | |
114 | + true | |
85 | 115 | end |
86 | 116 | |
87 | 117 | # Rejects the enterprise registration request. |
... | ... | @@ -107,21 +137,16 @@ class CreateEnterprise < Task |
107 | 137 | def perform |
108 | 138 | enterprise = Enterprise.new |
109 | 139 | |
110 | - profile_fields = %w[ name identifier contact_phone address region_id ] | |
111 | - profile_fields.each do |field| | |
140 | + DATA_FIELDS.reject{|field| field == "reject_explanation"}.each do |field| | |
112 | 141 | enterprise.send("#{field}=", self.send(field)) |
113 | 142 | end |
114 | 143 | |
115 | - organization_data = self.data.reject do |key,value| | |
116 | - profile_fields.include?(key.to_s) | |
117 | - end | |
118 | - | |
119 | 144 | enterprise.environment = environment |
120 | 145 | |
121 | 146 | enterprise.user = self.requestor.user |
122 | 147 | |
123 | - enterprise.update_attributes(organization_data) | |
124 | 148 | enterprise.save! |
149 | + enterprise.add_admin(enterprise.user.person) | |
125 | 150 | end |
126 | 151 | |
127 | 152 | def description | ... | ... |
app/models/enterprise.rb
... | ... | @@ -34,6 +34,8 @@ class Enterprise < Organization |
34 | 34 | organization_website |
35 | 35 | historic_and_current_context |
36 | 36 | activities_short_description |
37 | + acronym | |
38 | + foundation_year | |
37 | 39 | ] |
38 | 40 | |
39 | 41 | def self.fields |
... | ... | @@ -44,7 +46,7 @@ class Enterprise < Organization |
44 | 46 | super |
45 | 47 | self.required_fields.each do |field| |
46 | 48 | if self.send(field).blank? |
47 | - self.errors.add(field, _('%{fn} is mandatory')) | |
49 | + self.errors.add(field, _("%{fn} can't be blank")) | |
48 | 50 | end |
49 | 51 | end |
50 | 52 | end | ... | ... |
app/models/environment.rb
... | ... | @@ -89,6 +89,7 @@ class Environment < ActiveRecord::Base |
89 | 89 | 'disable_select_city_for_contact' => _('Disable state/city select for contact form'), |
90 | 90 | 'disable_contact_person' => _('Disable contact for people'), |
91 | 91 | 'disable_contact_community' => _('Disable contact for groups/communities'), |
92 | + 'disable_enterprise_registration' => _('Disable the enterprise registration'), | |
92 | 93 | 'join_community_popup' => _('Ask users to join a group/community with a popup'), |
93 | 94 | |
94 | 95 | 'enterprise_activation' => _('Enable activation of enterprises'), | ... | ... |
app/models/region.rb
... | ... | @@ -14,6 +14,10 @@ class Region < Category |
14 | 14 | def has_validator? |
15 | 15 | validators.count > 0 |
16 | 16 | end |
17 | + | |
18 | + def self.with_validators | |
19 | + Region.find(:all, :joins => 'INNER JOIN region_validators on (region_validators.region_id = categories.id)') | |
20 | + end | |
17 | 21 | |
18 | 22 | end |
19 | 23 | ... | ... |
app/views/enterprise_registration/basic_information.rhtml
... | ... | @@ -2,34 +2,34 @@ |
2 | 2 | |
3 | 3 | <h2><%= _('Register enterprise') %></h2> |
4 | 4 | |
5 | -<h3> <%= _('How to proceed') %> </h3> | |
6 | -<p> <%= _('Fill the form and hit the Register button then the enterprise will be submitted for evaluation at the validation entitiy of your choice (within your state), when the enterprise is aproved you will be able to activate its profile') %> </p> | |
7 | - | |
8 | -<% labelled_form_for(:create_enterprise, @create_enterprise) do |f| %> | |
9 | - <%= f.text_field 'identifier', 'size' => 20 %> | |
10 | - | |
11 | - <%= f.text_field 'name', 'size' => 20 %> | |
12 | - | |
13 | - <%= f.text_field 'address', 'size' => 50 %> | |
14 | - | |
15 | - <%= f.text_field 'contact_phone', 'size' => 20 %> | |
16 | - | |
17 | - <%= f.text_field 'contact_person', 'size' => 20 %> | |
18 | - | |
19 | - <%= f.text_field 'acronym', 'size' => 20 %> | |
20 | - | |
21 | - <%= f.text_field 'foundation_year', 'size' => 20 %> | |
22 | - | |
23 | - <%= f.text_field 'legal_form', 'size' => 20 %> | |
24 | - | |
25 | - <%= f.text_field 'economic_activity', 'size' => 20 %> | |
26 | - | |
27 | - <%= labelled_form_field(_('Management information'), text_editor('create_enterprise', 'management_information')) %> | |
28 | - | |
29 | - <%= labelled_form_field(_('Region'), f.select('region_id', @regions)) %> | |
5 | + | |
6 | +<% if @validation == :region && @regions.empty? %> | |
7 | + <div class='atention'> | |
8 | + <%= _('There are no validators to validate the registration of this new enterprise. Contact your administrator for instructions.') %> | |
9 | + </div> | |
30 | 10 | |
31 | 11 | <% button_bar do %> |
32 | - <%= submit_button('next', _('Next'), :cancel => {:action => 'index'}) %> | |
12 | + <%= button :back, _('Go back'), { :profile => current_user.person.identifier, :action=>"enterprises", :controller=>"profile" }%> | |
13 | + <% end %> | |
14 | +<% else %> | |
15 | + <div class='atention'> | |
16 | + <%= _('To register a new enterprise, fill in the form and hit the Register button. Then the enterprise will be submitted for evaluation at the validation entitiy of your choice (within your state) and when the enterprise is aproved you will be able to activate its profile.') %> | |
17 | + </div> | |
18 | + | |
19 | + <%= required_fields_message %> | |
20 | + | |
21 | + <% labelled_form_for(:create_enterprise, @create_enterprise) do |f| %> | |
22 | + <%= required f.text_field 'identifier'%> | |
23 | + <%= required f.text_field 'name'%> | |
24 | + <%= render :partial => 'shared/custom_fields', :locals => { :f => f, :object_name => :create_enterprise, :profile => @create_enterprise, :only_required => false } %> | |
25 | + <%= required labelled_form_field(_('Region'), f.select('region_id', @regions)) if @validation == :region %> | |
26 | + | |
27 | + <% if @validation == :admin %> | |
28 | + <%= hidden_field_tag 'create_enterprise[target_id]', environment.id %> | |
29 | + <% end %> | |
30 | + | |
31 | + <% button_bar do %> | |
32 | + <%= submit_button('next', _('Next'), :cancel => {:profile => current_user.person.identifier, :action=>"enterprises", :controller=>"profile"}) %> | |
33 | + <% end %> | |
33 | 34 | <% end %> |
34 | - | |
35 | 35 | <% end %> | ... | ... |
app/views/enterprise_registration/select_validator.rhtml
... | ... | @@ -9,8 +9,7 @@ |
9 | 9 | |
10 | 10 | <% for validator in @validators %> |
11 | 11 | <div> |
12 | - <%= radio_button_tag('create_enterprise[target_id]', validator.id) %> | |
13 | - <%= validator.name %> | |
12 | + <%= labelled_radio_button validator.name, 'create_enterprise[target_id]', validator.id, true %> | |
14 | 13 | |
15 | 14 | <%= labelled_form_field(_('Validation Methodology:'), validator.validation_methodology || _("(not informed)")) %> |
16 | 15 | <%= labelled_form_field(_('Restrictions (if any):'), validator.validation_restrictions || _("(not informed)")) %> | ... | ... |
app/views/memberships/index.rhtml
... | ... | @@ -4,6 +4,7 @@ |
4 | 4 | |
5 | 5 | <% button_bar do %> |
6 | 6 | <%= button(:add, __('Create a new community'), :controller => 'memberships', :action => 'new_community') %> |
7 | + <%= button :add, __('Register a new enterprise'), :controller => 'enterprise_registration' if !environment.enabled?('disable_enterprise_registration') %> | |
7 | 8 | <%= button :back, _('Go back'), :controller => 'profile_editor' %> |
8 | 9 | <% end %> |
9 | 10 | ... | ... |
app/views/profile/enterprises.rhtml
... | ... | @@ -12,8 +12,7 @@ |
12 | 12 | <% button_bar do %> |
13 | 13 | <%= button :back, _('Go back'), { :controller => 'profile' }, |
14 | 14 | :help => _('Back to the page where you come from.') %> |
15 | - <%= button :add, __('Register a new Enterprise'), | |
16 | - :controller => 'enterprise_registration' if logged_in? %> | |
15 | + <%= button :add, __('Register a new Enterprise'), :controller => 'enterprise_registration' if logged_in? && !environment.enabled?('disable_enterprise_registration') %> | |
17 | 16 | <% end %> |
18 | 17 | |
19 | 18 | </div><!-- fim class="common-profile-list-block" --> | ... | ... |
app/views/profile_editor/_organization.rhtml
1 | 1 | <h2><%= _('General information') %></h2> |
2 | 2 | |
3 | - <%= required_fields_message if @profile.required_fields.any? %> | |
3 | + <%= required_fields_message %> | |
4 | 4 | |
5 | 5 | <%= required f.text_field(:name) %> |
6 | 6 | |
... | ... | @@ -66,9 +66,6 @@ |
66 | 66 | </div> |
67 | 67 | <% end %> |
68 | 68 | |
69 | - <%= f.text_field(:acronym) %> | |
70 | - <%= f.text_field(:foundation_year) %> | |
71 | - | |
72 | 69 | <%= render :partial => 'shared/custom_fields', :locals => { :f => f, :object_name => 'profile_data', :profile => @profile, :only_required => false } %> |
73 | 70 | |
74 | 71 | <%= labelled_check_box(_('Enable "contact us"'), 'profile_data[enable_contact_us]', "1", @profile.enable_contact_us) if @profile.enterprise? %> | ... | ... |
app/views/shared/_custom_fields.rhtml
... | ... | @@ -12,6 +12,7 @@ |
12 | 12 | <%= optional_field(profile, 'address', labelled_form_field(_('Address (street and number)'), text_field(object_name, :address)), only_required) %> |
13 | 13 | |
14 | 14 | <% if profile.enterprise? %> |
15 | + <%= optional_field(profile, 'business_name', f.text_field(:business_name), only_required) %> | |
15 | 16 | <%= optional_field(profile, 'zip_code', labelled_form_field(_('ZIP code'), text_field(object_name, :zip_code)), only_required) %> |
16 | 17 | <%= optional_field(profile, 'city', f.text_field(:city), only_required) %> |
17 | 18 | <%= optional_field(profile, 'state', f.text_field(:state), only_required) %> |
... | ... | @@ -19,4 +20,6 @@ |
19 | 20 | <%= optional_field(profile, 'organization_website', f.text_field(:organization_website), only_required) %> |
20 | 21 | <%= optional_field(profile, 'historic_and_current_context', f.text_area(:historic_and_current_context, :rows => 5), only_required) %> |
21 | 22 | <%= optional_field(profile, 'activities_short_description', f.text_area(:activities_short_description, :rows => 5), only_required) %> |
23 | + <%= optional_field(profile, 'acronym', f.text_field(:acronym), only_required) %> | |
24 | + <%= optional_field(profile, 'foundation_year', f.text_field(:foundation_year), only_required) %> | |
22 | 25 | <% end %> | ... | ... |
app/views/tasks/_task.rhtml
... | ... | @@ -4,12 +4,14 @@ |
4 | 4 | <% form_for('task', task, :url => { :action => 'close', :id => task.id}) do |f| %> |
5 | 5 | |
6 | 6 | <div> |
7 | - <%= radio_button_tag(:decision, 'finish', true) %> | |
8 | - <%= _('OK') %> | |
7 | + <%= labelled_radio_button _('OK'), :decision, 'finish', true, :onclick => 'if(this.checked) $("rejection-field").style.display="none"' %> | |
9 | 8 | </div> |
10 | 9 | <div> |
11 | - <%= radio_button_tag(:decision, 'cancel', false) %> | |
12 | - <%= _('Cancel') %> | |
10 | + <%= labelled_radio_button _('Cancel'), :decision, 'cancel', false, :onclick => 'if(this.checked) $("rejection-field").style.display="block"' %> | |
11 | + </div> | |
12 | + | |
13 | + <div id="rejection-field" style='display: none'> | |
14 | + <%= required labelled_form_field(_('Rejection explanation'), text_area(:task, :reject_explanation, :rows => 5))%> | |
13 | 15 | </div> |
14 | 16 | |
15 | 17 | <% button_bar do %> | ... | ... |
features/location.feature
... | ... | @@ -10,7 +10,7 @@ Feature: Location |
10 | 10 | And I am logged in as "zezinho" |
11 | 11 | |
12 | 12 | Scenario: editing my address |
13 | - Given the following Person fields are enabled | |
13 | + Given the following Person fields are active | |
14 | 14 | | address | |
15 | 15 | | country | |
16 | 16 | | state | |
... | ... | @@ -29,7 +29,7 @@ Feature: Location |
29 | 29 | | Rua Marechal Floriano, 28 | BR | Bahia | Salvador | 40110010 | |
30 | 30 | |
31 | 31 | Scenario Outline: editing address of collectives |
32 | - Given the following <class> fields are enabled | |
32 | + Given the following <class> fields are active | |
33 | 33 | | address | |
34 | 34 | | country | |
35 | 35 | | state | | ... | ... |
... | ... | @@ -0,0 +1,191 @@ |
1 | +Feature: register enterprise | |
2 | + As a noosfero user | |
3 | + I want to register an enterprise | |
4 | + In order to interact in the web with my enterprise | |
5 | + | |
6 | + Background: | |
7 | + Given the following users | |
8 | + | login | name | | |
9 | + | joaosilva | Joao Silva | | |
10 | + | |
11 | + And I am logged in as "joaosilva" | |
12 | + And I am on Joao Silva's control panel | |
13 | + | |
14 | + Scenario: enterprise registration is disabled by admin | |
15 | + Given feature "disable_enterprise_registration" is enabled on environment | |
16 | + When I follow "Manage my groups" | |
17 | + Then I should not see "Register a new enterprise" | |
18 | + | |
19 | + Scenario: approval method is admin | |
20 | + Given organization_approval_method is "admin" on environment | |
21 | + And I follow "Manage my groups" | |
22 | + When I follow "Register a new enterprise" | |
23 | + Then I should not see "Region" | |
24 | + | |
25 | + Scenario: approval method is region | |
26 | + Given organization_approval_method is "region" on environment | |
27 | + And the following enterprise | |
28 | + | name | identifier | owner | | |
29 | + | Validator | validator | joaosilva | | |
30 | + And the following validation info | |
31 | + | validation_methodology | organization_name | | |
32 | + | "Sample methodology" | Validator | | |
33 | + And the following states | |
34 | + | name | validator_name | | |
35 | + | Sample State | Validator | | |
36 | + And I follow "Manage my groups" | |
37 | + When I follow "Register a new enterprise" | |
38 | + Then I should see "Region" | |
39 | + | |
40 | + Scenario: approval method is by region validator but there are no validators | |
41 | + Given organization_approval_method is "region" on environment | |
42 | + And I follow "Manage my groups" | |
43 | + When I follow "Register a new enterprise" | |
44 | + Then I should see "There are no validators to validate the registration of this new enterprise. Contact your administrator for instructions." | |
45 | + | |
46 | + Scenario: some active fields | |
47 | + Given the following enterprise fields are active | |
48 | + | foundation_year | | |
49 | + | contact_person | | |
50 | + | contact_email | | |
51 | + And I follow "Manage my groups" | |
52 | + When I follow "Register a new enterprise" | |
53 | + Then I should see "Foundation year" | |
54 | + Then I should see "Contact person" | |
55 | + Then I should see "Contact email" | |
56 | + | |
57 | + Scenario: some required fields | |
58 | + Given organization_approval_method is "admin" on environment | |
59 | + And I follow "Manage my groups" | |
60 | + And the following states | |
61 | + | name | | |
62 | + | Sample State | | |
63 | + And the following enterprise fields are required | |
64 | + | foundation_year | | |
65 | + | contact_person | | |
66 | + | contact_email | | |
67 | + And I follow "Register a new enterprise" | |
68 | + And I fill in the following: | |
69 | + | Identifier | my-enterprise | | |
70 | + | Name | My Enterprise | | |
71 | + | Foundation year | | | |
72 | + | Contact person | | | |
73 | + | Contact email | | | |
74 | + When I press "Next" | |
75 | + Then I should see "Foundation year can't be blank" | |
76 | + Then I should see "Contact person can't be blank" | |
77 | + Then I should see "Contact email can't be blank" | |
78 | + | |
79 | + Scenario: a user register an enterprise successfully through the admin | |
80 | + validator method and the admin accepts | |
81 | + Given organization_approval_method is "admin" on environment | |
82 | + And I follow "Manage my groups" | |
83 | + And the following states | |
84 | + | name | | |
85 | + | Sample State | | |
86 | + And I follow "Register a new enterprise" | |
87 | + And I fill in the following: | |
88 | + | Identifier | my-enterprise | | |
89 | + | Name | My Enterprise | | |
90 | + And I press "Next" | |
91 | + Then I should see "Enterprise Registration completed" | |
92 | + And I am logged in as admin | |
93 | + And I follow "Control panel" | |
94 | + When I follow "Tasks" | |
95 | + Then I should see /Processing task: Enterprise registration: "My Enterprise"/ | |
96 | + And I choose "Ok" | |
97 | + And I press "Ok" | |
98 | + And I am logged in as "joaosilva" | |
99 | + And I am on Joao Silva's control panel | |
100 | + When I follow "Manage my groups" | |
101 | + Then I should see "My Enterprise" | |
102 | + | |
103 | + Scenario: a user register an enterprise successfully through the admin | |
104 | + validator method and the admin rejects | |
105 | + Given organization_approval_method is "admin" on environment | |
106 | + And I follow "Manage my groups" | |
107 | + And the following states | |
108 | + | name | | |
109 | + | Sample State | | |
110 | + And I follow "Register a new enterprise" | |
111 | + And I fill in the following: | |
112 | + | Identifier | my-enterprise | | |
113 | + | Name | My Enterprise | | |
114 | + And I press "Next" | |
115 | + Then I should see "Enterprise Registration completed" | |
116 | + And I am logged in as admin | |
117 | + And I follow "Control panel" | |
118 | + When I follow "Tasks" | |
119 | + Then I should see /Processing task: Enterprise registration: "My Enterprise"/ | |
120 | + And I choose "Cancel" | |
121 | + And I fill in "Rejection explanation" with "This enterprise has some irregularities." | |
122 | + And I press "Ok" | |
123 | + And I am logged in as "joaosilva" | |
124 | + And I am on Joao Silva's control panel | |
125 | + When I follow "Manage my groups" | |
126 | + Then I should not see "My Enterprise" | |
127 | + | |
128 | + Scenario: a user register an enterprise successfully through the region | |
129 | + validator method and the validator accepts | |
130 | + Given organization_approval_method is "region" on environment | |
131 | + And I follow "Manage my groups" | |
132 | + And the following enterprise | |
133 | + | name | identifier | owner | | |
134 | + | Validator | validator | joaosilva | | |
135 | + And the following validation info | |
136 | + | validation_methodology | organization_name | | |
137 | + | "Sample methodology" | Validator | | |
138 | + And the following states | |
139 | + | name | validator_name | | |
140 | + | Sample State | Validator | | |
141 | + And I follow "Register a new enterprise" | |
142 | + And I fill in the following: | |
143 | + | Identifier | my-enterprise | | |
144 | + | Name | My Enterprise | | |
145 | + And I select "Sample State" from "Region" | |
146 | + And I press "Next" | |
147 | + Then I should see "Validator" | |
148 | + Then I should see "Sample methodology" | |
149 | + When I press "Confirm" | |
150 | + Then I should see "Enterprise Registration completed" | |
151 | + And I am on Validator's control panel | |
152 | + When I follow "Tasks" | |
153 | + Then I should see /Processing task: Enterprise registration: "My Enterprise"/ | |
154 | + And I choose "Ok" | |
155 | + And I press "Ok" | |
156 | + And I am on Joao Silva's control panel | |
157 | + When I follow "Manage my groups" | |
158 | + Then I should see "My Enterprise" | |
159 | + | |
160 | + Scenario: a user register an enterprise successfully through the region | |
161 | + validator method and the validator rejects | |
162 | + Given organization_approval_method is "region" on environment | |
163 | + And I follow "Manage my groups" | |
164 | + And the following enterprise | |
165 | + | name | identifier | owner | | |
166 | + | Validator | validator | joaosilva | | |
167 | + And the following validation info | |
168 | + | validation_methodology | organization_name | | |
169 | + | "Sample methodology" | Validator | | |
170 | + And the following states | |
171 | + | name | validator_name | | |
172 | + | Sample State | Validator | | |
173 | + And I follow "Register a new enterprise" | |
174 | + And I fill in the following: | |
175 | + | Identifier | my-enterprise | | |
176 | + | Name | My Enterprise | | |
177 | + And I select "Sample State" from "Region" | |
178 | + And I press "Next" | |
179 | + Then I should see "Validator" | |
180 | + Then I should see "Sample methodology" | |
181 | + When I press "Confirm" | |
182 | + Then I should see "Enterprise Registration completed" | |
183 | + And I am on Validator's control panel | |
184 | + When I follow "Tasks" | |
185 | + Then I should see /Processing task: Enterprise registration: "My Enterprise"/ | |
186 | + And I choose "Cancel" | |
187 | + And I fill in "Rejection explanation" with "This enterprise has some irregularities." | |
188 | + And I press "Ok" | |
189 | + And I am on Joao Silva's control panel | |
190 | + When I follow "Manage my groups" | |
191 | + Then I should not see "My Enterprise" | ... | ... |
features/step_definitions/noosfero_steps.rb
... | ... | @@ -65,7 +65,27 @@ Given /^the following products$/ do |table| |
65 | 65 | end |
66 | 66 | end |
67 | 67 | |
68 | +Given /^the following states$/ do |table| | |
69 | + table.hashes.each do |item| | |
70 | + data = item.dup | |
71 | + if validator = Enterprise.find_by_name(data.delete("validator_name")) | |
72 | + State.create!(data.merge(:environment => Environment.default, :validators => [validator])) | |
73 | + else | |
74 | + r = State.create!(data.merge(:environment => Environment.default)) | |
75 | + end | |
76 | + end | |
77 | +end | |
78 | + | |
79 | +Given /^the following validation info$/ do |table| | |
80 | + table.hashes.each do |item| | |
81 | + data = item.dup | |
82 | + organization = Organization.find_by_name(data.delete("organization_name")) | |
83 | + ValidationInfo.create!(data.merge(:organization => organization)) | |
84 | + end | |
85 | +end | |
86 | + | |
68 | 87 | Given /^I am logged in as "(.+)"$/ do |username| |
88 | + visit('/account/logout') | |
69 | 89 | visit('/account/login') |
70 | 90 | fill_in("Username", :with => username) |
71 | 91 | fill_in("Password", :with => '123456') |
... | ... | @@ -73,6 +93,7 @@ Given /^I am logged in as "(.+)"$/ do |username| |
73 | 93 | end |
74 | 94 | |
75 | 95 | Given /^I am logged in as admin$/ do |
96 | + visit('/account/logout') | |
76 | 97 | user = User.create!(:login => 'admin_user', :password => '123456', :password_confirmation => '123456', :email => 'admin_user@example.com') |
77 | 98 | e = Environment.default |
78 | 99 | e.add_admin(user.person) |
... | ... | @@ -86,15 +107,16 @@ Given /^I am not logged in$/ do |
86 | 107 | visit('/account/logout') |
87 | 108 | end |
88 | 109 | |
89 | -Given /^feature "(.+)" is enabled on environment$/ do |feature| | |
110 | +Given /^feature "(.+)" is (enabled|disabled) on environment$/ do |feature, status| | |
90 | 111 | e = Environment.default |
91 | - e.enable(feature) | |
112 | + status.chop! | |
113 | + e.send status, feature | |
92 | 114 | e.save |
93 | 115 | end |
94 | 116 | |
95 | -Given /^feature "(.+)" is disabled on environment$/ do |feature| | |
117 | +Given /^organization_approval_method is "(.+)" on environment$/ do |approval_method| | |
96 | 118 | e = Environment.default |
97 | - e.disable(feature) | |
119 | + e.organization_approval_method = approval_method | |
98 | 120 | e.save |
99 | 121 | end |
100 | 122 | |
... | ... | @@ -122,17 +144,18 @@ Given /^"([^\"]*)" has no articles$/ do |profile| |
122 | 144 | (Profile[profile] || Profile.find_by_name(profile)).articles.delete_all |
123 | 145 | end |
124 | 146 | |
125 | -Given /^the following (\w+) fields are enabled$/ do |klass, table| | |
147 | +Given /^the following (\w+) fields are (\w+)$/ do |klass, status, table| | |
126 | 148 | env = Environment.default |
127 | 149 | fields = table.raw.inject({}) do |hash, line| |
128 | 150 | hash[line.first] = { "active" => 'true' } |
151 | + hash[line.first].merge!({ "required" => 'true'}) if status == "required" | |
129 | 152 | hash |
130 | 153 | end |
131 | 154 | |
132 | 155 | env.send("custom_#{klass.downcase}_fields=", fields) |
133 | 156 | env.save! |
134 | - if fields.keys != env.send("active_#{klass.downcase}_fields") | |
135 | - raise "Not all fields enabled! Requested: %s; Enabled: %s" % [fields.keys.inspect, env.send("active_#{klass.downcase}_fields").inspect] | |
157 | + if fields.keys != env.send("#{status}_#{klass.downcase}_fields") | |
158 | + raise "Not all fields #{status}! Requested: %s; #{status.camelcase}: %s" % [fields.keys.inspect, env.send("#{status}_#{klass.downcase}_fields").inspect] | |
136 | 159 | end |
137 | 160 | end |
138 | 161 | ... | ... |
test/functional/enterprise_registration_controller_test.rb
... | ... | @@ -30,23 +30,29 @@ all_fixtures |
30 | 30 | assert_template 'basic_information' |
31 | 31 | end |
32 | 32 | |
33 | - should 'prompt for basic information' do | |
34 | - get :index | |
35 | - %w[ name identifier address contact_phone contact_person | |
36 | - acronym foundation_year legal_form economic_activity ].each do |item| | |
37 | - assert_tag :tag => 'input', :attributes => { :name => "create_enterprise[#{item}]" } | |
38 | - end | |
39 | - assert_tag :tag => 'textarea', :attributes => { :name => "create_enterprise[management_information]"} | |
40 | - assert_tag :tag => 'select', :attributes => { :name => "create_enterprise[region_id]"} | |
41 | - end | |
42 | - | |
43 | 33 | should 'get back to entering basic information if data is invalid' do |
44 | 34 | post :index, :create_enterprise => {} |
45 | 35 | assert_response :success |
46 | 36 | assert_template 'basic_information' |
47 | 37 | end |
48 | 38 | |
49 | - should 'prompt for selecting validator' do | |
39 | + should 'skip prompt for selection validator if approval method is admin' do | |
40 | + env = Environment.default | |
41 | + env.organization_approval_method = :admin | |
42 | + env.save | |
43 | + region = fast_create(Region) | |
44 | + | |
45 | + data = { :name => 'My new enterprise', :identifier => 'mynew', :region => region } | |
46 | + create_enterprise = CreateEnterprise.new(data) | |
47 | + | |
48 | + post :index, :create_enterprise => data | |
49 | + assert_template 'confirmation' | |
50 | + end | |
51 | + | |
52 | + should 'prompt for selecting validator if approval method is region' do | |
53 | + env = Environment.default | |
54 | + env.organization_approval_method = :region | |
55 | + env.save | |
50 | 56 | data = { 'name' => 'My new enterprise', 'identifier' => 'mynew' } |
51 | 57 | |
52 | 58 | create_enterprise = CreateEnterprise.new |
... | ... | @@ -135,8 +141,10 @@ all_fixtures |
135 | 141 | assert_sanitized assigns(:create_enterprise).management_information |
136 | 142 | end |
137 | 143 | |
138 | - should 'load only regions with validator organizations' do | |
144 | + should 'load only regions with validator organizations if approval method is region' do | |
139 | 145 | env = Environment.default |
146 | + env.organization_approval_method = :region | |
147 | + env.save | |
140 | 148 | |
141 | 149 | reg1 = env.regions.create!(:name => 'Region with validator') |
142 | 150 | reg1.validators.create!(:name => 'Validator one', :identifier => 'validator-one') | ... | ... |
test/integration/enterprise_registration_test.rb
... | ... | @@ -7,6 +7,8 @@ class EnterpriseRegistrationTest < ActionController::IntegrationTest |
7 | 7 | should 'be able to create an enterprise registration request' do |
8 | 8 | |
9 | 9 | environment = Environment.default |
10 | + environment.organization_approval_method = :region | |
11 | + environment.save | |
10 | 12 | region1 = environment.regions.build(:name => 'A region') |
11 | 13 | region1.save! |
12 | 14 | region2 = environment.regions.build(:name => 'Other region') | ... | ... |
test/unit/create_enterprise_test.rb
... | ... | @@ -219,6 +219,21 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
219 | 219 | assert request.errors.invalid?(:identifier) |
220 | 220 | end |
221 | 221 | |
222 | + should 'require the same fields as an enterprise does' do | |
223 | + environment = mock | |
224 | + request = CreateEnterprise.new | |
225 | + request.stubs(:environment).returns(environment) | |
226 | + environment.stubs(:organization_approval_method).returns(:region) | |
227 | + | |
228 | + environment.stubs(:required_enterprise_fields).returns([]) | |
229 | + request.valid? | |
230 | + assert_nil request.errors[:contact_person], 'should not require contact_person unless Enterprise requires it' | |
231 | + | |
232 | + environment.stubs(:required_enterprise_fields).returns(['contact_person']) | |
233 | + request.valid? | |
234 | + assert_not_nil request.errors[:contact_person], 'should require contact_person when Enterprise requires it' | |
235 | + end | |
236 | + | |
222 | 237 | should 'has permission to validate enterprise' do |
223 | 238 | t = CreateEnterprise.new |
224 | 239 | assert_equal :validate_enterprise, t.permission | ... | ... |
test/unit/region_test.rb
... | ... | @@ -53,4 +53,15 @@ class RegionTest < Test::Unit::TestCase |
53 | 53 | assert !region.has_validator? |
54 | 54 | end |
55 | 55 | |
56 | + should 'list regions with validators' do | |
57 | + bahia = fast_create(Region, :name => 'Bahia') | |
58 | + forum_ecosol_ba = fast_create(Enterprise, :name => 'Forum Baiano de Economia Solidaria', :identifier => 'ecosol-ba') | |
59 | + bahia.validators << forum_ecosol_ba | |
60 | + | |
61 | + sergipe = fast_create(Region, :name => 'Sergipe') | |
62 | + # Sergipe has no validators | |
63 | + | |
64 | + assert_equivalent Region.with_validators, [bahia] | |
65 | + end | |
66 | + | |
56 | 67 | end | ... | ... |