Commit da233db6f1cc4bac72f918450abc70c7c90d8c76

Authored by Luciano Prestes
Committed by Gust
1 parent 11e22a9c

Add signup user with admin of new institution created in signup

(institution_fields)

Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com>
Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com>
controllers/mpog_software_plugin_controller.rb
@@ -77,8 +77,6 @@ class MpogSoftwarePluginController &lt; ApplicationController @@ -77,8 +77,6 @@ class MpogSoftwarePluginController &lt; ApplicationController
77 77
78 response_message = if verify_recaptcha(:model=> institution, :message => _('Please type the word correctly')) 78 response_message = if verify_recaptcha(:model=> institution, :message => _('Please type the word correctly'))
79 if institution.errors.full_messages.empty? and institution.valid? and institution.save 79 if institution.errors.full_messages.empty? and institution.valid? and institution.save
80 - institution.community.add_admin(environment.admins.first) unless environment.admins.empty?  
81 -  
82 {:success => true, :message => _("Institution successful created!"), :institution_data=>{:name=>institution.name, :id=>institution.id}} 80 {:success => true, :message => _("Institution successful created!"), :institution_data=>{:name=>institution.name, :id=>institution.id}}
83 else 81 else
84 {:success => false, :message => _("Institution could not be created!"), :errors => institution.errors.full_messages} 82 {:success => false, :message => _("Institution could not be created!"), :errors => institution.errors.full_messages}
features/step_definitions/mpog_steps.rb
@@ -37,9 +37,20 @@ end @@ -37,9 +37,20 @@ end
37 Given /^the following public institutions?$/ do |table| 37 Given /^the following public institutions?$/ do |table|
38 # table is a Cucumber::Ast::Table 38 # table is a Cucumber::Ast::Table
39 table.hashes.each do |item| 39 table.hashes.each do |item|
  40 + community = Community.new
  41 + community.name = item[:name]
  42 + community.country = item[:country]
  43 + community.state = item[:state]
  44 + community.city = item[:city]
  45 + community.save!
  46 +
40 governmental_power = GovernmentalPower.where(:name => item[:governmental_power]).first 47 governmental_power = GovernmentalPower.where(:name => item[:governmental_power]).first
41 governmental_sphere = GovernmentalSphere.where(:name => item[:governmental_sphere]).first 48 governmental_sphere = GovernmentalSphere.where(:name => item[:governmental_sphere]).first
42 - institution = PublicInstitution.create!(:name => item[:name], :type => "PublicInstitution", :acronym => item[:acronym], :cnpj => item[:cnpj], :governmental_power => governmental_power, :governmental_sphere => governmental_sphere) 49 +
  50 + juridical_nature = JuridicalNature.create(:name => item[:juridical_nature])
  51 +
  52 + institution = PublicInstitution.new(:name => item[:name], :type => "PublicInstitution", :acronym => item[:acronym], :cnpj => item[:cnpj], :juridical_nature => juridical_nature, :governmental_power => governmental_power, :governmental_sphere => governmental_sphere)
  53 + institution.community = community
43 institution.save! 54 institution.save!
44 end 55 end
45 end 56 end
features/user_profile_edition.feature
@@ -13,10 +13,10 @@ Feature: Institution Field @@ -13,10 +13,10 @@ Feature: Institution Field
13 And I go to /account/logout 13 And I go to /account/logout
14 And Institutions has initial default values on database 14 And Institutions has initial default values on database
15 And the following public institutions 15 And the following public institutions
16 - | name | acronym | cnpj | governmental_power | governmental_sphere |  
17 - | Ministerio das Cidades | MC | 58.745.189/0001-21 | Executivo | Federal |  
18 - | Governo do DF | GDF | 12.645.166/0001-44 | Legislativo | Federal |  
19 - | Ministerio do Planejamento | MP | 41.769.591/0001-43 | Judiciario | Federal | 16 + | name | acronym | country | state | city | cnpj | juridical_nature | governmental_power | governmental_sphere |
  17 + | Ministerio das Cidades | MC | BR | DF | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal |
  18 + | Governo do DF | GDF | BR | DF | Taguatinga | 12.645.166/0001-44 | Autarquia | Legislativo | Federal |
  19 + | Ministerio do Planejamento | MP | BR | DF | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal |
20 And I go to /account/signup 20 And I go to /account/signup
21 And Institutions has initial default values on database 21 And Institutions has initial default values on database
22 And I fill in the following within ".no-boxes": 22 And I fill in the following within ".no-boxes":
features/user_registration.feature
@@ -48,10 +48,10 @@ Feature: User Registration @@ -48,10 +48,10 @@ Feature: User Registration
48 Given I go to /account/signup 48 Given I go to /account/signup
49 And Institutions has initial default values on database 49 And Institutions has initial default values on database
50 And the following public institutions 50 And the following public institutions
51 - | name | acronym | cnpj | governmental_power | governmental_sphere |  
52 - | Ministerio das Cidades | MC | 58.745.189/0001-21 | Executivo | Federal |  
53 - | Governo do DF | GDF | 12.645.166/0001-44 | Legislativo | Federal |  
54 - | Ministerio do Planejamento | MP | 41.769.591/0001-43 | Judiciario | Federal | 51 + | name | acronym | country | state | city | cnpj | juridical_nature | governmental_power | governmental_sphere |
  52 + | Ministerio das Cidades | MC | BR | DF | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal |
  53 + | Governo do DF | GDF | BR | DF | Taguatinga | 12.645.166/0001-44 | Autarquia | Legislativo | Federal |
  54 + | Ministerio do Planejamento | MP | BR | DF | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal |
55 And I fill in the following within ".no-boxes": 55 And I fill in the following within ".no-boxes":
56 | e-Mail | josesilva@serpro.gov.br| 56 | e-Mail | josesilva@serpro.gov.br|
57 | Username | josesilva | 57 | Username | josesilva |
@@ -78,10 +78,10 @@ Feature: User Registration @@ -78,10 +78,10 @@ Feature: User Registration
78 Given I go to /account/signup 78 Given I go to /account/signup
79 And Institutions has initial default values on database 79 And Institutions has initial default values on database
80 And the following public institutions 80 And the following public institutions
81 - | name | acronym | cnpj | governmental_power | governmental_sphere |  
82 - | Ministerio das Cidades | MC | 58.745.189/0001-21 | Executivo | Federal |  
83 - | Governo do DF | GDF | 12.645.166/0001-44 | Legislativo | Federal |  
84 - | Ministerio do Planejamento | MP | 41.769.591/0001-43 | Judiciario | Federal | 81 + | name | acronym | country | state | city | cnpj | juridical_nature | governmental_power | governmental_sphere |
  82 + | Ministerio das Cidades | MC | BR | DF | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal |
  83 + | Governo do DF | GDF | BR | DF | Taguatinga | 12.645.166/0001-44 | Autarquia | Legislativo | Federal |
  84 + | Ministerio do Planejamento | MP | BR | DF | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal |
85 And I fill in the following within ".no-boxes": 85 And I fill in the following within ".no-boxes":
86 | e-Mail | josesilva@serpro.gov.br| 86 | e-Mail | josesilva@serpro.gov.br|
87 | Username | josesilva | 87 | Username | josesilva |
@@ -94,6 +94,7 @@ Feature: User Registration @@ -94,6 +94,7 @@ Feature: User Registration
94 And I select "Brazil" from "profile_data[country]" 94 And I select "Brazil" from "profile_data[country]"
95 And I type in "MP" into autocomplete list "input_institution" and I choose "Ministerio do Planejamento" 95 And I type in "MP" into autocomplete list "input_institution" and I choose "Ministerio do Planejamento"
96 And wait for the captcha signup time 96 And wait for the captcha signup time
  97 + And I follow "Add new institution"
97 And I press "Create my account" 98 And I press "Create my account"
98 When José da Silva's account is activated 99 When José da Silva's account is activated
99 And I go to login page 100 And I go to login page
lib/mpog_software_plugin.rb
@@ -196,6 +196,7 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin @@ -196,6 +196,7 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
196 context.params[:user][:institution_ids].each do |institution_id| 196 context.params[:user][:institution_ids].each do |institution_id|
197 institution = Institution.find institution_id 197 institution = Institution.find institution_id
198 user.institutions << institution 198 user.institutions << institution
  199 + institution.community.add_admin(user.person) if institution.community.admins.blank?
199 end 200 end
200 end 201 end
201 user.save unless user.institution_ids.empty? 202 user.save unless user.institution_ids.empty?
test/functional/profile_editor_controller_test.rb
@@ -76,7 +76,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase @@ -76,7 +76,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
76 76
77 private 77 private
78 78
79 - def create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s 79 + def create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s
80 institution_community = fast_create(Community) 80 institution_community = fast_create(Community)
81 institution_community.name = name 81 institution_community.name = name
82 institution_community.country = country 82 institution_community.country = country