diff --git a/controllers/mpog_software_plugin_controller.rb b/controllers/mpog_software_plugin_controller.rb index f58c589..38baff3 100644 --- a/controllers/mpog_software_plugin_controller.rb +++ b/controllers/mpog_software_plugin_controller.rb @@ -77,8 +77,6 @@ class MpogSoftwarePluginController < ApplicationController response_message = if verify_recaptcha(:model=> institution, :message => _('Please type the word correctly')) if institution.errors.full_messages.empty? and institution.valid? and institution.save - institution.community.add_admin(environment.admins.first) unless environment.admins.empty? - {:success => true, :message => _("Institution successful created!"), :institution_data=>{:name=>institution.name, :id=>institution.id}} else {:success => false, :message => _("Institution could not be created!"), :errors => institution.errors.full_messages} diff --git a/features/step_definitions/mpog_steps.rb b/features/step_definitions/mpog_steps.rb index f033267..f6976fb 100644 --- a/features/step_definitions/mpog_steps.rb +++ b/features/step_definitions/mpog_steps.rb @@ -37,9 +37,20 @@ end Given /^the following public institutions?$/ do |table| # table is a Cucumber::Ast::Table table.hashes.each do |item| + community = Community.new + community.name = item[:name] + community.country = item[:country] + community.state = item[:state] + community.city = item[:city] + community.save! + governmental_power = GovernmentalPower.where(:name => item[:governmental_power]).first governmental_sphere = GovernmentalSphere.where(:name => item[:governmental_sphere]).first - institution = PublicInstitution.create!(:name => item[:name], :type => "PublicInstitution", :acronym => item[:acronym], :cnpj => item[:cnpj], :governmental_power => governmental_power, :governmental_sphere => governmental_sphere) + + juridical_nature = JuridicalNature.create(:name => item[:juridical_nature]) + + 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) + institution.community = community institution.save! end end diff --git a/features/user_profile_edition.feature b/features/user_profile_edition.feature index 59f923f..85e166d 100644 --- a/features/user_profile_edition.feature +++ b/features/user_profile_edition.feature @@ -13,10 +13,10 @@ Feature: Institution Field And I go to /account/logout And Institutions has initial default values on database And the following public institutions - | name | acronym | cnpj | governmental_power | governmental_sphere | - | Ministerio das Cidades | MC | 58.745.189/0001-21 | Executivo | Federal | - | Governo do DF | GDF | 12.645.166/0001-44 | Legislativo | Federal | - | Ministerio do Planejamento | MP | 41.769.591/0001-43 | Judiciario | Federal | + | name | acronym | country | state | city | cnpj | juridical_nature | governmental_power | governmental_sphere | + | Ministerio das Cidades | MC | BR | DF | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal | + | Governo do DF | GDF | BR | DF | Taguatinga | 12.645.166/0001-44 | Autarquia | Legislativo | Federal | + | Ministerio do Planejamento | MP | BR | DF | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal | And I go to /account/signup And Institutions has initial default values on database And I fill in the following within ".no-boxes": diff --git a/features/user_registration.feature b/features/user_registration.feature index 58ec523..4231417 100644 --- a/features/user_registration.feature +++ b/features/user_registration.feature @@ -48,10 +48,10 @@ Feature: User Registration Given I go to /account/signup And Institutions has initial default values on database And the following public institutions - | name | acronym | cnpj | governmental_power | governmental_sphere | - | Ministerio das Cidades | MC | 58.745.189/0001-21 | Executivo | Federal | - | Governo do DF | GDF | 12.645.166/0001-44 | Legislativo | Federal | - | Ministerio do Planejamento | MP | 41.769.591/0001-43 | Judiciario | Federal | + | name | acronym | country | state | city | cnpj | juridical_nature | governmental_power | governmental_sphere | + | Ministerio das Cidades | MC | BR | DF | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal | + | Governo do DF | GDF | BR | DF | Taguatinga | 12.645.166/0001-44 | Autarquia | Legislativo | Federal | + | Ministerio do Planejamento | MP | BR | DF | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal | And I fill in the following within ".no-boxes": | e-Mail | josesilva@serpro.gov.br| | Username | josesilva | @@ -78,10 +78,10 @@ Feature: User Registration Given I go to /account/signup And Institutions has initial default values on database And the following public institutions - | name | acronym | cnpj | governmental_power | governmental_sphere | - | Ministerio das Cidades | MC | 58.745.189/0001-21 | Executivo | Federal | - | Governo do DF | GDF | 12.645.166/0001-44 | Legislativo | Federal | - | Ministerio do Planejamento | MP | 41.769.591/0001-43 | Judiciario | Federal | + | name | acronym | country | state | city | cnpj | juridical_nature | governmental_power | governmental_sphere | + | Ministerio das Cidades | MC | BR | DF | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal | + | Governo do DF | GDF | BR | DF | Taguatinga | 12.645.166/0001-44 | Autarquia | Legislativo | Federal | + | Ministerio do Planejamento | MP | BR | DF | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal | And I fill in the following within ".no-boxes": | e-Mail | josesilva@serpro.gov.br| | Username | josesilva | @@ -94,6 +94,7 @@ Feature: User Registration And I select "Brazil" from "profile_data[country]" And I type in "MP" into autocomplete list "input_institution" and I choose "Ministerio do Planejamento" And wait for the captcha signup time + And I follow "Add new institution" And I press "Create my account" When José da Silva's account is activated And I go to login page diff --git a/lib/mpog_software_plugin.rb b/lib/mpog_software_plugin.rb index ceb2f0f..ef2856a 100644 --- a/lib/mpog_software_plugin.rb +++ b/lib/mpog_software_plugin.rb @@ -196,6 +196,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin context.params[:user][:institution_ids].each do |institution_id| institution = Institution.find institution_id user.institutions << institution + institution.community.add_admin(user.person) if institution.community.admins.blank? end end user.save unless user.institution_ids.empty? diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index 4afe285..3d83f10 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -76,7 +76,7 @@ class ProfileEditorControllerTest < ActionController::TestCase private - def create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s + def create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s institution_community = fast_create(Community) institution_community.name = name institution_community.country = country -- libgit2 0.21.2