diff --git a/features/institution_registration.feature b/features/institution_registration.feature
new file mode 100644
index 0000000..086b14e
--- /dev/null
+++ b/features/institution_registration.feature
@@ -0,0 +1,32 @@
+Feature: Institution Field
+ As a user
+ I want to sign up resgistring my institution
+ So others users can use it
+
+ Background:
+ Given "SoftwareCommunitiesPlugin" plugin is enabled
+ And I am logged in as mpog_admin
+ And I go to /admin/plugins
+ And I check "SoftwareCommunitiesPlugin"
+ And I press "Save changes"
+ And Institutions has initial default values on database
+ And I am logged in as mpog_admin
+
+ @selenium
+ Scenario: Show new institution fields when clicked in create new institution
+ Given I follow "Edit Profile"
+ When I follow "Create new institution"
+ And I should see "New Institution"
+ And I should see "Public Institution"
+ And I should see "Private Institution"
+ And I should see "Corporate Name"
+ And I should see "Name"
+ And I should see "State"
+ And I should see "City"
+ And I should see "Country"
+ And I should see "CNPJ"
+ And I should see "Acronym"
+ And I choose "Public Institution"
+ Then I should see "Governmental Sphere:"
+ And I should see "Governmental Power:"
+ And I should see "Juridical Nature:"
\ No newline at end of file
diff --git a/features/steps_definitions/gov_user_steps.rb b/features/steps_definitions/gov_user_steps.rb
new file mode 100644
index 0000000..6609f8d
--- /dev/null
+++ b/features/steps_definitions/gov_user_steps.rb
@@ -0,0 +1,45 @@
+Given /^Institutions has initial default values on database$/ do
+ GovernmentalPower.create(:name => "Executivo")
+ GovernmentalPower.create(:name => "Legislativo")
+ GovernmentalPower.create(:name => "Judiciario")
+
+ GovernmentalSphere.create(:name => "Federal")
+
+ JuridicalNature.create(:name => "Autarquia")
+ JuridicalNature.create(:name => "Administracao Direta")
+ JuridicalNature.create(:name => "Empresa Publica")
+ JuridicalNature.create(:name => "Fundacao")
+ JuridicalNature.create(:name => "Orgao Autonomo")
+ JuridicalNature.create(:name => "Sociedade")
+ JuridicalNature.create(:name => "Sociedade Civil")
+ JuridicalNature.create(:name => "Sociedade de Economia Mista")
+
+ national_region = NationalRegion.new
+ national_region.name = "Distrito Federal"
+ national_region.national_region_code = '35'
+ national_region.national_region_type_id = NationalRegionType::STATE
+ national_region.save
+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
+
+ 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.corporate_name = item[:corporate_name]
+ institution.save!
+ end
+end
diff --git a/features/user_profile_edition.feature b/features/user_profile_edition.feature
index 0c21c72..3d9f060 100644
--- a/features/user_profile_edition.feature
+++ b/features/user_profile_edition.feature
@@ -26,3 +26,32 @@ Feature: Institution Field
Scenario: Verify text information to use governmental e-mail
Given I follow "Edit Profile"
Then I should see "If you work in a public agency use your government e-Mail"
+
+ @selenium
+ Scenario: Add more then one instituion on profile editor
+ Given I follow "Edit Profile"
+ And I follow "Add new institution"
+ And I type in "Minis" in autocomplete list "#input_institution" and I choose "Ministerio do Planejamento"
+ And I follow "Add new institution"
+ And I type in "Gover" in autocomplete list "#input_institution" and I choose "Governo do DF"
+ And I follow "Add new institution"
+ Then I should see "Ministerio do Planejamento" within ".institutions_added"
+ And I should see "Governo do DF" within ".institutions_added"
+
+ @selenium
+ Scenario: Verify if field 'city' is shown when Brazil is selected
+ Given I follow "Edit Profile"
+ Then I should see "City"
+
+ @selenium
+ Scenario: Verify if field 'city' does not appear when Brazil is not selected as country
+ Given I follow "Edit Profile"
+ When I select "United States" from "profile_data_country"
+ Then I should not see "City" within ".type-text"
+
+ @selenium
+ Scenario: Show message of institution not found
+ Given I follow "Edit Profile"
+ And I fill in "input_institution" with "Some Nonexistent Institution"
+ And I sleep for 1 seconds
+ Then I should see "No institution found"
diff --git a/lib/ext/person.rb b/lib/ext/person.rb
index 08e9614..32a42b0 100644
--- a/lib/ext/person.rb
+++ b/lib/ext/person.rb
@@ -10,6 +10,9 @@ class Person
delegate :login, :to => :user, :prefix => true
+ def institution?
+ false
+ end
def secondary_email
self.user.secondary_email unless self.user.nil?
end
diff --git a/lib/gov_user_plugin.rb b/lib/gov_user_plugin.rb
index d6e5302..1dc5bbb 100644
--- a/lib/gov_user_plugin.rb
+++ b/lib/gov_user_plugin.rb
@@ -128,6 +128,10 @@ class GovUserPlugin < Noosfero::Plugin
views/complete-registration.js
initializer.js
app.js
+ views/control-panel.js
+ views/create-institution.js
+ views/new-community.js
+ views/user-edit-profile.js
)
end
diff --git a/public/initializer.js b/public/initializer.js
index 44751b5..0bbc0d2 100644
--- a/public/initializer.js
+++ b/public/initializer.js
@@ -3,6 +3,8 @@
var dependencies = [
'CompleteRegistration',
+ 'UserEditProfile',
+ 'CreateInstitution'
];
diff --git a/public/lib/select-element.js b/public/lib/select-element.js
new file mode 100644
index 0000000..26880ae
--- /dev/null
+++ b/public/lib/select-element.js
@@ -0,0 +1,35 @@
+modulejs.define('SelectElement', function() {
+ 'use strict';
+
+
+ function SelectElement(name, id) {
+ this.select = document.createElement("select");
+ }
+
+
+ SelectElement.prototype.setAttr = function(attr, value) {
+ return this.select.setAttribute(attr, value);
+ };
+
+
+ SelectElement.prototype.addOption = function(option) {
+ return this.select.add(option);
+ };
+
+
+ SelectElement.prototype.getSelect = function() {
+ return this.select;
+ };
+
+
+ SelectElement.generateOption = function(value, text) {
+ var option;
+ option = document.createElement("option");
+ option.setAttribute("value", value);
+ option.text = text;
+ return option;
+ };
+
+
+ return SelectElement;
+});
diff --git a/public/lib/select-field-choices.js b/public/lib/select-field-choices.js
new file mode 100644
index 0000000..095d4e1
--- /dev/null
+++ b/public/lib/select-field-choices.js
@@ -0,0 +1,81 @@
+modulejs.define('SelectFieldChoices', ['jquery', 'SelectElement'], function($, SelectElement) {
+ 'use strict';
+
+
+ function SelectFieldChoices(state_id, city_id, state_url) {
+ this.state_id = state_id;
+ this.input_html = $(state_id).parent().html();
+ this.old_value = $(state_id).val();
+ this.city_parent_div = $(city_id).parent().parent().parent();
+ this.state_url = state_url;
+ }
+
+
+ SelectFieldChoices.prototype.getCurrentStateElement = function() {
+ return $(this.state_id);
+ };
+
+
+ SelectFieldChoices.prototype.replaceWith = function(html) {
+ var parent_div = this.getCurrentStateElement().parent();
+ parent_div.html(html);
+ };
+
+
+ SelectFieldChoices.prototype.generateSelect = function(state_list) {
+ var select_element, option;
+
+ select_element = new SelectElement();
+ select_element.setAttr("name", "profile_data[state]");
+ select_element.setAttr("id", "state_field");
+ select_element.setAttr("class", "type-select valid");
+
+ state_list.forEach(function(state) {
+ option = SelectElement.generateOption(state, state);
+ select_element.addOption(option);
+ });
+
+ return select_element.getSelect();
+ };
+
+
+ SelectFieldChoices.prototype.replaceStateWithSelectElement = function() {
+ var klass = this;
+
+ $.get(this.state_url, function(response) {
+ var select_html;
+
+ if (response.length > 0) {
+ select_html = klass.generateSelect(response);
+ klass.replaceWith(select_html);
+
+ if (klass.old_value.length !== 0 && response.include(klass.old_value)) {
+ klass.getCurrentStateElement().val(klass.old_value);
+ }
+ }
+ });
+ };
+
+
+ SelectFieldChoices.prototype.replaceStateWithInputElement = function() {
+ this.replaceWith(this.input_html);
+ };
+
+
+ SelectFieldChoices.prototype.hideCity = function() {
+ this.city_parent_div.addClass("mpog_hidden_field");
+ };
+
+
+ SelectFieldChoices.prototype.showCity = function() {
+ this.city_parent_div.removeClass("mpog_hidden_field");
+ };
+
+
+ SelectFieldChoices.prototype.actualFieldIsInput = function() {
+ return this.getCurrentStateElement().attr("type") === "text";
+ };
+
+
+ return SelectFieldChoices;
+});
diff --git a/public/static/governmental_powers.txt b/public/static/governmental_powers.txt
new file mode 100644
index 0000000..6fffa27
--- /dev/null
+++ b/public/static/governmental_powers.txt
@@ -0,0 +1,4 @@
+Executivo
+Legislativo
+Judiciario
+Nao se aplica
diff --git a/public/static/governmental_sphere.txt b/public/static/governmental_sphere.txt
new file mode 100644
index 0000000..ffaa31e
--- /dev/null
+++ b/public/static/governmental_sphere.txt
@@ -0,0 +1,4 @@
+Federal
+Estadual
+Distrital
+Municipal
\ No newline at end of file
diff --git a/public/static/juridical_nature.txt b/public/static/juridical_nature.txt
new file mode 100644
index 0000000..517bbd6
--- /dev/null
+++ b/public/static/juridical_nature.txt
@@ -0,0 +1,8 @@
+Administracao Direta
+Autarquia
+Empresa Publica
+Fundacao
+Orgao Autonomo
+Sociedade
+Sociedade Civil
+Sociedade de Economia Mista
diff --git a/public/views/control-panel.js b/public/views/control-panel.js
new file mode 100644
index 0000000..b746fc7
--- /dev/null
+++ b/public/views/control-panel.js
@@ -0,0 +1,32 @@
+modulejs.define('ControlPanel', ['jquery'], function($) {
+ 'use strict';
+
+ function add_institution_on_control_panel(control_panel) {
+ var institution_link = $(".control-panel-instituton-link").remove();
+
+ if( institution_link.size() > 0 ) {
+ control_panel.prepend(institution_link);
+ }
+ }
+
+
+ function add_itens_on_controla_panel() {
+ var control_panel = $(".control-panel");
+
+ if( control_panel.size() > 0 ) {
+ add_institution_on_control_panel(control_panel);
+ }
+ }
+
+
+ return {
+ isCurrentPage: function() {
+ return $("#profile-editor-index").length === 1;
+ },
+
+
+ init: function() {
+ add_itens_on_controla_panel();
+ }
+ }
+});
diff --git a/public/views/create-institution.js b/public/views/create-institution.js
new file mode 100644
index 0000000..f909bc4
--- /dev/null
+++ b/public/views/create-institution.js
@@ -0,0 +1,312 @@
+modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'], function($, NoosferoRoot, SelectElement) {
+ 'use strict';
+
+ var AJAX_URL = {
+ create_institution_modal:
+ NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/create_institution"),
+ new_institution:
+ NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/new_institution"),
+ institution_already_exists:
+ NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/institution_already_exists"),
+ get_institutions:
+ NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/get_institutions")
+ };
+
+
+ function open_create_institution_modal(evt) {
+ evt.preventDefault();
+
+ $.get(AJAX_URL.create_institution_modal, function(response){
+ $("#institution_dialog").html(response);
+
+ set_form_count_custom_data();
+ set_events();
+
+ $("#institution_dialog").dialog({
+ modal: true,
+ width: 500,
+ height: 530,
+ position: 'center',
+ close: function() {
+ $("#institution_dialog").html("");
+ $('#institution_empty_ajax_message').switchClass("show-field", "hide-field");
+ }
+ });
+ });
+ }
+
+
+ function show_public_institutions_fields() {
+ $(".public-institutions-fields").show();
+ }
+
+
+ function show_private_institutions_fields() {
+ $(".public-institutions-fields").hide();
+
+ $("#institutions_governmental_power option").selected(0);
+ $("#institutions_governmental_sphere option").selected(0);
+ }
+
+
+ function get_comunity_post_data() {
+ return {
+ name : $("#community_name").val(),
+ country : $("#community_country").val(),
+ state : $("#community_state").val(),
+ city : $("#community_city").val()
+ }
+ }
+
+
+ function get_institution_post_data() {
+ return {
+ cnpj: $("#institutions_cnpj").val(),
+ type: $("input[name='institutions[type]']:checked").val(),
+ acronym : $("#institutions_acronym").val(),
+ governmental_power: $("#institutions_governmental_power").selected().val(),
+ governmental_sphere: $("#institutions_governmental_sphere").selected().val(),
+ juridical_nature: $("#institutions_juridical_nature").selected().val(),
+ corporate_name: $("#institutions_corporate_name").val()
+ }
+ }
+
+
+ function get_post_data() {
+ var post_data = {};
+
+ post_data.community = get_comunity_post_data();
+ post_data.institutions = get_institution_post_data();
+
+ return post_data;
+ }
+
+
+ function success_ajax_response(response) {
+ close_loading();
+
+ if(response.success){
+ var institution_name = response.institution_data.name;
+ var institution_id = response.institution_data.id;
+
+ $("#institution_dialog").html("
"+message+"");
+ } else {
+ $("." + hidden_message_id).show();
+ }
+ }
+
+
+ function hide_plugin_error_message(field_selector, hidden_message_id) {
+ $(field_selector).removeClass("invalid").addClass("validated");
+ $("." + hidden_message_id).hide();
+ }
+
+
+ function add_blur_fields(field_selector, hidden_message_id, validation_function, allow_blank) {
+ $(field_selector).blur(function(){
+ $(this).attr("class", "");
+
+ if( validation_function(this.value, !!allow_blank) ) {
+ show_plugin_error_message(field_selector, hidden_message_id);
+ } else {
+ hide_plugin_error_message(field_selector, hidden_message_id);
+ }
+ });
+ }
+
+
+ function invalid_email_validation(value, allow_blank) {
+ if( allow_blank && value.trim().length === 0 ) {
+ return false;
+ }
+
+ var correct_format_regex = new RegExp(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/);
+
+ return !correct_format_regex.test(value);
+ }
+
+
+ function invalid_site_validation(value) {
+ var correct_format_regex = new RegExp(/(^|)(http[s]{0,1})\:\/\/(\w+[.])\w+/g);
+
+ return !correct_format_regex.test(value);
+ }
+
+
+ function get_privacy_selector_parent_div(field_id, actual) {
+ if( actual === undefined ) actual = $(field_id);
+
+ if( actual.is("form") || actual.length === 0 ) return null; // Not allow recursion over form
+
+ if( actual.hasClass("field-with-privacy-selector") ) {
+ return actual;
+ } else {
+ return get_privacy_selector_parent_div(field_id, actual.parent());
+ }
+ }
+
+
+ function try_to_remove(list, field) {
+ try {
+ list.push(field.remove());
+ } catch(e) {
+ console.log("Cound not remove field");
+ }
+ }
+
+
+ function get_edit_fields_in_insertion_order() {
+ var containers = [];
+
+ try_to_remove(containers, get_privacy_selector_parent_div("#city_field"));
+ try_to_remove(containers, get_privacy_selector_parent_div("#state_field"));
+ try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_country"));
+ try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_birth_date"));
+ try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_organization_website"));
+ try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_personal_website"));
+ try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_comercial_phone"));
+ try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_contact_phone"));
+ try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_cell_phone"));
+ try_to_remove(containers, $("#select_institution"));
+ try_to_remove(containers, $("#user_secondary_email").parent().parent());
+ try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_email"));
+ try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_name"));
+ try_to_remove(containers, $(".pseudoformlabel").parent().parent());
+ try_to_remove(containers, $("h2")[0]);
+
+ return containers;
+ }
+
+
+ function change_edit_fields_order() {
+ var form = $("#profile-data");
+
+ if( form.length !== 0 ) {
+ var containers = get_edit_fields_in_insertion_order();
+
+ containers.forEach(function(container){
+ form.prepend(container);
+ });
+ }
+ }
+
+
+ function set_fields_validations() {
+ $("#profile_data_country").blur(show_or_hide_phone_mask);
+
+ $("#profile_data_birth_date").mask("99/99/9999");
+
+ fix_phone_mask_format("#profile_data_cell_phone");
+ fix_phone_mask_format("#profile_data_comercial_phone");
+ fix_phone_mask_format("#profile_data_contact_phone");
+
+ add_blur_fields("#profile_data_email", "email_error", invalid_email_validation);
+ add_blur_fields("#user_secondary_email", "email_error", invalid_email_validation, true);
+ add_blur_fields("#profile_data_personal_website", "site_error", invalid_site_validation);
+ add_blur_fields("#profile_data_organization_website", "site_error", invalid_site_validation);
+ }
+
+
+ return {
+ isCurrentPage: function() {
+ return $('#profile_data_email').length === 1;
+ },
+
+
+ init: function() {
+ change_edit_fields_order(); // To change the fields order, it MUST be the first function executed
+
+ show_state_if_country_is_brazil();
+
+ show_or_hide_phone_mask();
+
+ set_fields_validations();
+
+ CreateInstitution.init();
+ }
+ }
+});
diff --git a/test/unit/gov_user_person_test.rb b/test/unit/gov_user_person_test.rb
new file mode 100644
index 0000000..b959c97
--- /dev/null
+++ b/test/unit/gov_user_person_test.rb
@@ -0,0 +1,57 @@
+# encoding: utf-8
+
+require File.dirname(__FILE__) + '/../../../../test/test_helper'
+require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
+
+class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase
+ include PluginTestHelper
+
+ def setup
+ @plugin = GovUserPlugin.new
+
+ @user = fast_create(User)
+ @person = create_person(
+ "My Name",
+ "user@email.com",
+ "123456",
+ "123456",
+ "Any State",
+ "Some City"
+ )
+ end
+
+ def teardown
+ @plugin = nil
+ end
+
+ should 'be a noosfero plugin' do
+ assert_kind_of Noosfero::Plugin, @plugin
+ end
+
+ should 'save person with a valid full name' do
+ p = Person::new :name=>"S1mpl3 0f N4m3", :identifier=>"simple-name"
+ p.user = fast_create(:user)
+
+ assert_equal true, p.save
+ end
+
+ should 'save person with a valid full name with accents' do
+ name = 'Jônatàs dâ Sîlvã Jösé'
+ identifier = "jonatas-jose-da-silva"
+ p = Person::new :name=>name, :identifier=>identifier
+ p.user = fast_create(:user)
+
+ assert_equal true, p.save
+ end
+
+ should 'not save person whose name has not capital letter' do
+ p = Person::new :name=>"simple name"
+ assert !p.save, _("Name Should begin with a capital letter and no special characters")
+ end
+
+ should 'not save person whose name has special characters' do
+ p = Person::new :name=>"Simple N@me"
+
+ assert !p.save , _("Name Should begin with a capital letter and no special characters")
+ end
+end
diff --git a/test/unit/governmental_power_test.rb b/test/unit/governmental_power_test.rb
new file mode 100644
index 0000000..5f777e6
--- /dev/null
+++ b/test/unit/governmental_power_test.rb
@@ -0,0 +1,33 @@
+require File.dirname(__FILE__) + '/../../../../test/test_helper'
+require File.dirname(__FILE__) + '/../helpers/institution_test_helper'
+
+class GovernmentalPowerTest < ActiveSupport::TestCase
+
+ def setup
+ @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
+ @juridical_nature = JuridicalNature.create(:name => "Autarquia")
+ end
+
+ def teardown
+ Institution.destroy_all
+ end
+
+ should "get public institutions" do
+ inst_name = "Ministerio Publico da Uniao"
+ inst_cnpj = "12.345.678/9012-45"
+ gov_power = GovernmentalPower.create(:name=>"Some gov power")
+ InstitutionTestHelper.create_public_institution(
+ inst_name,
+ "MPU",
+ "BR",
+ "DF",
+ "Gama",
+ @juridical_nature,
+ gov_power,
+ @gov_sphere,
+ inst_cnpj
+ )
+
+ assert_equal gov_power.public_institutions.count, PublicInstitution.count
+ end
+end
\ No newline at end of file
diff --git a/test/unit/institution_test.rb b/test/unit/institution_test.rb
new file mode 100644
index 0000000..cda237c
--- /dev/null
+++ b/test/unit/institution_test.rb
@@ -0,0 +1,62 @@
+require File.dirname(__FILE__) + '/../../../../test/test_helper'
+require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
+
+class InstitutionTest < ActiveSupport::TestCase
+ include PluginTestHelper
+ def setup
+ @gov_power = GovernmentalPower.create(:name=>"Some Gov Power")
+ @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
+ @juridical_nature = JuridicalNature.create(:name => "Autarquia")
+
+ @institution = create_public_institution(
+ "Ministerio Publico da Uniao",
+ "MPU",
+ "BR",
+ "DF",
+ "Gama",
+ @juridical_nature,
+ @gov_power,
+ @gov_sphere,
+ "11.222.333/4444-55"
+ )
+ end
+
+ def teardown
+ GovernmentalPower.destroy_all
+ GovernmentalSphere.destroy_all
+ JuridicalNature.destroy_all
+ @institution = nil
+ end
+ should "not save institutions without name" do
+ @institution.name = nil
+ assert !@institution.save
+ assert @institution.errors.full_messages.include? "Name can't be blank"
+ end
+
+ should "not save if institution has invalid type" do
+ invalid_msg = "Type invalid, only public and private institutions are allowed."
+ @institution.type = "Other type"
+ assert !@institution.save, 'Invalid type'
+ assert @institution.errors.full_messages.include? invalid_msg
+ end
+
+ should "not save without country" do
+ @institution.community.country = nil
+ assert !@institution.save, "Country can't be blank"
+ assert @institution.errors.full_messages.include? "Country can't be blank"
+ end
+
+ should "not save without state" do
+ @institution.community.state = nil
+
+ assert !@institution.save, "State can't be blank"
+ assert @institution.errors.full_messages.include? "State can't be blank"
+ end
+
+ should "not save without city" do
+ @institution.community.city = nil
+
+ assert !@institution.save, "City can't be blank"
+ assert @institution.errors.full_messages.include? "City can't be blank"
+ end
+end
diff --git a/test/unit/institutions_block_test.rb b/test/unit/institutions_block_test.rb
new file mode 100644
index 0000000..bcab723
--- /dev/null
+++ b/test/unit/institutions_block_test.rb
@@ -0,0 +1,51 @@
+require File.dirname(__FILE__) + '/../../../../test/test_helper'
+require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
+
+class InstitutionsBlockTest < ActiveSupport::TestCase
+ include PluginTestHelper
+ should 'inherit from Block' do
+ assert_kind_of Block, InstitutionsBlock.new
+ end
+
+ should 'declare its default title' do
+ InstitutionsBlock.any_instance.stubs(:profile_count).returns(0)
+ assert_not_equal Block.new.default_title, InstitutionsBlock.new.default_title
+ end
+
+ should 'describe itself' do
+ assert_not_equal Block.description, InstitutionsBlock.description
+ end
+
+ should 'give empty footer on unsupported owner type' do
+ block = InstitutionsBlock.new
+ block.expects(:owner).returns(1)
+ assert_equal '', block.footer
+ end
+
+ should 'list institutions' do
+ user = create_person("Jose_Augusto",
+ "jose_augusto@email.com",
+ "aaaaaaa",
+ "aaaaaaa",
+ 'jose@secondary.com',
+ "DF",
+ "Gama"
+ )
+
+ institution = create_private_institution(
+ "inst name",
+ "IN",
+ "country",
+ "state",
+ "city",
+ "00.111.222/3333-44"
+ )
+ institution.community.add_member(user)
+
+ block = InstitutionsBlock.new
+ block.expects(:owner).at_least_once.returns(user)
+
+ assert_equivalent [institution.community], block.profiles
+ end
+
+end
diff --git a/test/unit/juridical_nature_test.rb b/test/unit/juridical_nature_test.rb
new file mode 100644
index 0000000..80d34c6
--- /dev/null
+++ b/test/unit/juridical_nature_test.rb
@@ -0,0 +1,23 @@
+require File.dirname(__FILE__) + '/../../../../test/test_helper'
+require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
+
+class JuridicalNatureTest < ActiveSupport::TestCase
+
+ include PluginTestHelper
+
+ def setup
+ @govPower = GovernmentalPower.create(:name=>"Some Gov Power")
+ @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
+ end
+
+ def teardown
+ Institution.destroy_all
+ end
+
+ should "get public institutions" do
+ juridical_nature = JuridicalNature.create(:name => "Autarquia")
+ create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", juridical_nature, @govPower, @govSphere, "22.333.444/5555-66")
+ create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", juridical_nature, @govPower, @govSphere, "22.333.444/5555-77")
+ assert juridical_nature.public_institutions.count == PublicInstitution.count
+ end
+end
diff --git a/test/unit/private_institution_test.rb b/test/unit/private_institution_test.rb
new file mode 100644
index 0000000..e0fad37
--- /dev/null
+++ b/test/unit/private_institution_test.rb
@@ -0,0 +1,50 @@
+require File.dirname(__FILE__) + '/../../../../test/test_helper'
+require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
+
+class PrivateInstitutionTest < ActiveSupport::TestCase
+ include PluginTestHelper
+ def setup
+ @institution = create_private_institution(
+ "Simple Private Institution",
+ "SPI",
+ "BR",
+ "DF",
+ "Gama",
+ "00.000.000/0001-00"
+ )
+ end
+
+ def teardown
+ @institution = nil
+ Institution.destroy_all
+ end
+
+ should "not save without a cnpj" do
+ @institution.cnpj = nil
+
+ assert !@institution.save
+ assert @institution.errors.full_messages.include? "Cnpj can't be blank"
+ end
+
+ should "not save with a repeated cnpj" do
+ msg = "Cnpj has already been taken"
+ assert @institution.save
+ sec_institution = create_private_institution(
+ "Another Private Institution",
+ "API",
+ "BR",
+ "DF",
+ "Gama",
+ "00.000.000/0001-00"
+ )
+
+ assert sec_institution.errors.full_messages.include? msg
+ end
+
+ should "save without fantasy name" do
+ @institution.acronym = nil
+ @institution.community.save
+
+ assert @institution.save
+ end
+end
diff --git a/test/unit/public_institution_test.rb b/test/unit/public_institution_test.rb
new file mode 100644
index 0000000..1976d0f
--- /dev/null
+++ b/test/unit/public_institution_test.rb
@@ -0,0 +1,68 @@
+require File.dirname(__FILE__) + '/../../../../test/test_helper'
+require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
+
+class PublicInstitutionTest < ActiveSupport::TestCase
+ include PluginTestHelper
+ def setup
+ @gov_power = GovernmentalPower.create(:name=>"Some Gov Power")
+ @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
+ @juridical_nature = JuridicalNature.create(:name => "Autarquia")
+
+ @institution = create_public_institution(
+ "Ministerio Publico da Uniao",
+ "MPU",
+ "BR",
+ "DF",
+ "Gama",
+ @juridical_nature,
+ @gov_power,
+ @gov_sphere,
+ "11.222.333/4444-55"
+ )
+ end
+
+ def teardown
+ GovernmentalPower.destroy_all
+ GovernmentalSphere.destroy_all
+ JuridicalNature.destroy_all
+ Institution.destroy_all
+ @gov_power = nil
+ @gov_sphere = nil
+ @juridical_nature = nil
+ @institution = nil
+ end
+
+ should "not save without a cnpj" do
+ @institution.cnpj = nil
+ assert !@institution.save
+ end
+
+ should "save institution without an acronym" do
+ @institution.acronym = nil
+ assert @institution.save
+ end
+
+ should "Not save institution without a governmental_power" do
+ invalid_msg = "Governmental power can't be blank"
+ @institution.governmental_power = nil
+
+ assert !@institution.save
+ assert @institution.errors.full_messages.include? invalid_msg
+ end
+
+ should "Not save institution without a governmental_sphere" do
+ invalid_msg = "Governmental sphere can't be blank"
+ @institution.governmental_sphere = nil
+
+ assert !@institution.save
+ assert @institution.errors.full_messages.include? invalid_msg
+ end
+
+ should "not save institution without juridical nature" do
+ invalid_msg = "Juridical nature can't be blank"
+ @institution.juridical_nature = nil
+
+ assert !@institution.save
+ assert @institution.errors.full_messages.include? invalid_msg
+ end
+end
diff --git a/views/gov_user_plugin_myprofile/_public_software_info.html.erb b/views/gov_user_plugin_myprofile/_public_software_info.html.erb
deleted file mode 100644
index 1f3466c..0000000
--- a/views/gov_user_plugin_myprofile/_public_software_info.html.erb
+++ /dev/null
@@ -1,102 +0,0 @@
-
- <% if @disabled_public_software_field == true %>
- <%= check_box_tag("software[public_software]", "true", @software_info.public_software?, :disabled => "disabled") %>
- <%= label_tag _("Public Software"), _("Public software"), :class => "public_software_disabled" %>
- <% else %>
- <%= check_box_tag("software[public_software]", "true", @software_info.public_software?) %>
- <%= label_tag _("Public Software"), _("Public software"), :class => "public_software_enabled" %>
- <% end %>
-
-
<%= _("Public Software") %>
-
- <%= label_tag _("Adherent to e-PING ?") %>
-
- <%= label_tag "e_ping_true", "Yes" %>
- <%= radio_button_tag("software[e_ping]", true, @software_info.e_ping)%>
- <%= label_tag "e_ping_false", "No"%>
- <%= radio_button_tag("software[e_ping]", false, !@software_info.e_ping)%>
-
-
-
- <%= label_tag _("Adherent to e-MAG ?") %>
-
- <%= label_tag "e_mag_true", "Yes"%>
- <%= radio_button_tag("software[e_mag]", true, @software_info.e_mag)%>
- <%= label_tag "e_mag_false", "No"%>
- <%= radio_button_tag("software[e_mag]", false, !@software_info.e_mag)%>
-
-
-
- <%= label_tag _("Adherent to ICP-Brasil ?") %>
-
- <%= label_tag "icp_brasil_true", "Yes"%>
- <%= radio_button_tag("software[icp_brasil]", true, @software_info.icp_brasil)%>
- <%= label_tag "icp_brasil_false", "No"%>
- <%= radio_button_tag("software[icp_brasil]", false, !@software_info.icp_brasil)%>
-
-
-
- <%= label_tag _("Adherent to e-ARQ ?") %>
-
- <%= label_tag "e_arq_true", "Yes"%>
- <%= radio_button_tag("software[e_arq]", true, @software_info.e_arq)%>
- <%= label_tag "e_arq_false", "No"%>
- <%= radio_button_tag("software[e_arq]", false, !@software_info.e_arq)%>
-
-
-
- <%= label_tag _("Internacionalizable ?") %>
-
- <%= label_tag "intern_true", "Yes" %>
- <%= radio_button_tag("software[intern]", true, @software_info.intern)%>
- <%= label_tag "intern_false", "No"%>
- <%= radio_button_tag("software[intern]", false, !@software_info.intern)%>
-
-
-
-
-
-
<%= _("Operating Platform") %>
- <%= text_area_tag "software[operating_platform]", @software_info.operating_platform, :cols => 40, :rows => 5%>
-
-
-
-
<%= _("Features") %>
- <%= text_area_tag "software[features]", @software_info.features, :maxlength=>"4000", :cols => 40, :rows => 5%>
-
-
-
-
<%= _("Demonstration url") %>
- <%= text_field_tag("software[demonstration_url]", @software_info.demonstration_url) %>
-
-
-
-
<%= _("Libraries") %>
-
- <%= render :partial => 'library_fields', :locals => {:object_name => 'community', :profile => @community, :libraries => @list_libraries } %>
-
-
-
-
-
-
<%= _("Operating Systems") %>
-
- <%= render :partial => 'operating_system_fields', :locals => {:object_name => 'community', :profile => @community, :operating_systems_fields => @list_operating_systems} %>
-
-
-
-
-
-
<%= _("Programming languages") %>
-
- <%= render :partial => 'language_fields', :locals => { :object_name => 'community', :profile => @community, :languages => @list_languages } %>
-
-
-
-
-
<%= _("Databases") %>
-
- <%= render :partial => 'database_fields', :locals => {:object_name => 'community', :profile => @community, :database => @list_databases } %>
-
-
-
diff --git a/views/person_editor_extras.html.erb b/views/person_editor_extras.html.erb
index a0a58ca..a3a11fc 100644
--- a/views/person_editor_extras.html.erb
+++ b/views/person_editor_extras.html.erb
@@ -6,6 +6,36 @@
+
+