diff --git a/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb b/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb index d0f14dc..4454fc7 100644 --- a/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb +++ b/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb @@ -18,7 +18,6 @@ class GovUserPluginController < ApplicationController def create_institution create_institution_view_variables - if request.xhr? render :layout=>false else @@ -57,7 +56,7 @@ class GovUserPluginController < ApplicationController def institution_already_exists redirect_to "/" if !request.xhr? || params[:name].blank? - already_exists = !Institution.find_by_name(params[:name]).nil? + already_exists = !GovUserPlugin::Institution.find_by_name(params[:name]).nil? render :json=>already_exists.to_json end @@ -65,7 +64,7 @@ class GovUserPluginController < ApplicationController def get_institutions redirect_to "/" if !request.xhr? || params[:query].blank? - institutions = Institution.search_institution(params[:query]).select([:id, :name]) + institutions = GovUserPlugin::Institution.search_institution(params[:query]).select([:id, :name]) institutions_list = institutions.map { |institution| {:value=>institution.name, :id=>institution.id} } @@ -135,17 +134,17 @@ class GovUserPluginController < ApplicationController def get_governmental_spheres spheres = [[_("Select a Governmental Sphere"), 0]] - spheres.concat get_model_as_option_list(GovernmentalSphere) + spheres.concat get_model_as_option_list(GovUserPlugin::GovernmentalSphere) end def get_governmental_powers powers = [[_("Select a Governmental Power"), 0]] - powers.concat get_model_as_option_list(GovernmentalPower) + powers.concat get_model_as_option_list(GovUserPlugin::GovernmentalPower) end def get_juridical_natures natures = [[_("Select a Juridical Nature"), 0]] - natures.concat get_model_as_option_list(JuridicalNature) + natures.concat get_model_as_option_list(GovUserPlugin::JuridicalNature) end def get_model_as_option_list model @@ -157,10 +156,10 @@ class GovUserPluginController < ApplicationController :governmental_sphere, :juridical_nature ) - if params[:institutions][:type] == "PublicInstitution" - PublicInstitution::new institution_params + if params[:institutions][:type] == "GovUserPlugin::PublicInstitution" + GovUserPlugin::PublicInstitution::new institution_params else - PrivateInstitution::new institution_params + GovUserPlugin::PrivateInstitution::new institution_params end end @@ -168,9 +167,9 @@ class GovUserPluginController < ApplicationController inst_fields = params[:institutions] begin - gov_power = GovernmentalPower.find inst_fields[:governmental_power] - gov_sphere = GovernmentalSphere.find inst_fields[:governmental_sphere] - jur_nature = JuridicalNature.find inst_fields[:juridical_nature] + gov_power = GovUserPlugin::GovernmentalPower.find inst_fields[:governmental_power] + gov_sphere = GovUserPlugin::GovernmentalSphere.find inst_fields[:governmental_sphere] + jur_nature = GovUserPlugin::JuridicalNature.find inst_fields[:juridical_nature] institution.juridical_nature = jur_nature institution.governmental_power = gov_power @@ -191,7 +190,7 @@ class GovUserPluginController < ApplicationController institution.name = community[:name] institution.community = community - if institution.type == "PublicInstitution" + if institution.type == "GovUserPlugin::PublicInstitution" set_public_institution_fields institution end diff --git a/src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb b/src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb index 6b4d03e..eb5ac51 100644 --- a/src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb +++ b/src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb @@ -20,7 +20,7 @@ class GovUserPluginMyprofileController < MyProfileController def update_institution @institution.community.update_attributes(params[:community]) @institution.update_attributes(params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature)) - if @institution.type == "PublicInstitution" + if @institution.type == "GovUserPlugin::PublicInstitution" begin governmental_updates rescue @@ -36,15 +36,13 @@ class GovUserPluginMyprofileController < MyProfileController end def governmental_updates - gov_power = GovernmentalPower.find params[:institutions][:governmental_power] - gov_sphere = GovernmentalSphere.find params[:institutions][:governmental_sphere] - jur_nature = JuridicalNature.find params[:institutions][:juridical_nature] + gov_power = GovUserPlugin::GovernmentalPower.find params[:institutions][:governmental_power] + gov_sphere = GovUserPlugin::GovernmentalSphere.find params[:institutions][:governmental_sphere] + jur_nature = GovUserPlugin::JuridicalNature.find params[:institutions][:juridical_nature] @institution.juridical_nature = jur_nature @institution.governmental_power = gov_power @institution.governmental_sphere = gov_sphere @institution.save end - - end diff --git a/src/noosfero-spb/gov_user/db/migrate/20151019174219_rename_tables_with_plugin_namespace.rb b/src/noosfero-spb/gov_user/db/migrate/20151019174219_rename_tables_with_plugin_namespace.rb new file mode 100644 index 0000000..c2f9497 --- /dev/null +++ b/src/noosfero-spb/gov_user/db/migrate/20151019174219_rename_tables_with_plugin_namespace.rb @@ -0,0 +1,9 @@ +class RenameTablesWithPluginNamespace < ActiveRecord::Migration + def change + rename_table :institutions, :gov_user_plugin_institutions + rename_table :governmental_spheres, :gov_user_plugin_governmental_spheres + rename_table :governmental_powers, :gov_user_plugin_governmental_powers + rename_table :juridical_natures, :gov_user_plugin_juridical_natures + rename_table :institutions_users, :gov_user_plugin_institutions_users + end +end diff --git a/src/noosfero-spb/gov_user/features/institution_registration.feature b/src/noosfero-spb/gov_user/features/institution_registration.feature index c1fbb4e..0ce0a19 100644 --- a/src/noosfero-spb/gov_user/features/institution_registration.feature +++ b/src/noosfero-spb/gov_user/features/institution_registration.feature @@ -4,13 +4,9 @@ Feature: Institution Field So others users can use it Background: - Given "GovUserPlugin" plugin is enabled + Given plugin GovUser is enabled on environment And I am logged in as mpog_admin - And I go to /admin/plugins - And I check "GovUserPlugin" - 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 diff --git a/src/noosfero-spb/gov_user/features/step_definitions/gov_user_steps.rb b/src/noosfero-spb/gov_user/features/step_definitions/gov_user_steps.rb new file mode 100644 index 0000000..fd71abc --- /dev/null +++ b/src/noosfero-spb/gov_user/features/step_definitions/gov_user_steps.rb @@ -0,0 +1,90 @@ +Given /^Institutions has initial default values on database$/ do + GovUserPlugin::GovernmentalPower.create(:name => "Executivo") + GovUserPlugin::GovernmentalPower.create(:name => "Legislativo") + GovUserPlugin::GovernmentalPower.create(:name => "Judiciario") + + GovUserPlugin::GovernmentalSphere.create(:name => "Federal") + + GovUserPlugin::JuridicalNature.create(:name => "Autarquia") + GovUserPlugin::JuridicalNature.create(:name => "Administracao Direta") + GovUserPlugin::JuridicalNature.create(:name => "Empresa Publica") + GovUserPlugin::JuridicalNature.create(:name => "Fundacao") + GovUserPlugin::JuridicalNature.create(:name => "Orgao Autonomo") + GovUserPlugin::JuridicalNature.create(:name => "Sociedade") + GovUserPlugin::JuridicalNature.create(:name => "Sociedade Civil") + GovUserPlugin::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 /^I type in "([^"]*)" in autocomplete list "([^"]*)" and I choose "([^"]*)"$/ do |typed, input_field_selector, should_select| +# Wait the page javascript load +sleep 1 +# Basicaly it, search for the input field, type something, wait for ajax end select an item +page.driver.browser.execute_script %Q{ + var search_query = "#{input_field_selector}.ui-autocomplete-input"; + var input = jQuery(search_query).first(); + + input.trigger('click'); + input.val('#{typed}'); + input.trigger('keydown'); + + window.setTimeout(function(){ + search_query = ".ui-menu-item a:contains('#{should_select}')"; + var typed = jQuery(search_query).first(); + + typed.trigger('mouseenter').trigger('click'); + console.log(jQuery('#license_info_id')); + }, 1000); + } + sleep 1 +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 = GovUserPlugin::GovernmentalPower.where(:name => item[:governmental_power]).first + governmental_sphere = GovUserPlugin::GovernmentalSphere.where(:name => item[:governmental_sphere]).first + + juridical_nature = GovUserPlugin::JuridicalNature.create(:name => item[:juridical_nature]) + + institution = GovUserPlugin::PublicInstitution.new(:name => item[:name], :type => "GovUserPlugin::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 + +Given /^I sleep for (\d+) seconds$/ do |time| + sleep time.to_i +end + +Given /^I am logged in as mpog_admin$/ do + visit('/account/logout') + + user = User.new(:login => 'admin_user', :password => '123456', :password_confirmation => '123456', :email => 'admin_user@example.com') + person = Person.new :name=>"Mpog Admin", :identifier=>"mpog-admin" + user.person = person + user.save! + + user.activate + e = Environment.default + e.add_admin(user.person) + + visit('/account/login') + fill_in("Username", :with => user.login) + fill_in("Password", :with => '123456') + click_button("Log in") +end + diff --git a/src/noosfero-spb/gov_user/features/steps_definitions/gov_user_steps.rb b/src/noosfero-spb/gov_user/features/steps_definitions/gov_user_steps.rb deleted file mode 100644 index 97cf5e2..0000000 --- a/src/noosfero-spb/gov_user/features/steps_definitions/gov_user_steps.rb +++ /dev/null @@ -1,90 +0,0 @@ -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 /^I type in "([^"]*)" in autocomplete list "([^"]*)" and I choose "([^"]*)"$/ do |typed, input_field_selector, should_select| -# Wait the page javascript load -sleep 1 -# Basicaly it, search for the input field, type something, wait for ajax end select an item -page.driver.browser.execute_script %Q{ - var search_query = "#{input_field_selector}.ui-autocomplete-input"; - var input = jQuery(search_query).first(); - - input.trigger('click'); - input.val('#{typed}'); - input.trigger('keydown'); - - window.setTimeout(function(){ - search_query = ".ui-menu-item a:contains('#{should_select}')"; - var typed = jQuery(search_query).first(); - - typed.trigger('mouseenter').trigger('click'); - console.log(jQuery('#license_info_id')); - }, 1000); - } - sleep 1 -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 - -Given /^I sleep for (\d+) seconds$/ do |time| - sleep time.to_i -end - -Given /^I am logged in as mpog_admin$/ do - visit('/account/logout') - - user = User.new(:login => 'admin_user', :password => '123456', :password_confirmation => '123456', :email => 'admin_user@example.com') - person = Person.new :name=>"Mpog Admin", :identifier=>"mpog-admin" - user.person = person - user.save! - - user.activate - e = Environment.default - e.add_admin(user.person) - - visit('/account/login') - fill_in("Username", :with => user.login) - fill_in("Password", :with => '123456') - click_button("Log in") -end - diff --git a/src/noosfero-spb/gov_user/features/user_profile_edition.feature b/src/noosfero-spb/gov_user/features/user_profile_edition.feature index be7ecfa..f91a255 100644 --- a/src/noosfero-spb/gov_user/features/user_profile_edition.feature +++ b/src/noosfero-spb/gov_user/features/user_profile_edition.feature @@ -4,14 +4,11 @@ Feature: Institution Field So I can maintain my personal data updated Background: - Given "GovUserPlugin" plugin is enabled + Given plugin GovUser is enabled on environment And the following users | login | name | | joao | Joao Silva | And I am logged in as admin - And I go to /admin/plugins - And I check "GovUserPlugin" - And I press "Save changes" And feature "skip_new_user_email_confirmation" is enabled on environment And I go to /admin/features/manage_fields And I check "person_fields_country_active" @@ -44,11 +41,8 @@ Feature: Institution Field Given I am logged in as "joao" And I am on joao's control panel When 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" diff --git a/src/noosfero-spb/gov_user/lib/ext/community.rb b/src/noosfero-spb/gov_user/lib/ext/community.rb index d274660..e87a630 100644 --- a/src/noosfero-spb/gov_user/lib/ext/community.rb +++ b/src/noosfero-spb/gov_user/lib/ext/community.rb @@ -1,7 +1,7 @@ require_dependency 'community' class Community - has_one :institution, :dependent=>:destroy + has_one :institution, :class_name => 'GovUserPlugin::Institution', :dependent=>:destroy def institution? return !institution.nil? diff --git a/src/noosfero-spb/gov_user/lib/ext/organization_rating.rb b/src/noosfero-spb/gov_user/lib/ext/organization_rating.rb index fb2b59e..640a016 100644 --- a/src/noosfero-spb/gov_user/lib/ext/organization_rating.rb +++ b/src/noosfero-spb/gov_user/lib/ext/organization_rating.rb @@ -2,7 +2,7 @@ require_dependency "organization_rating" OrganizationRating.class_eval do - belongs_to :institution + belongs_to :institution, :class_name => 'GovUserPlugin::Institution' attr_accessible :institution, :institution_id @@ -12,7 +12,7 @@ OrganizationRating.class_eval do def verify_institution if self.institution != nil - institution = Institution.find_by_id self.institution.id + institution = GovUserPlugin::Institution.find_by_id self.institution.id self.errors.add :institution, _("not found") unless institution end end diff --git a/src/noosfero-spb/gov_user/lib/ext/search_controller.rb b/src/noosfero-spb/gov_user/lib/ext/search_controller.rb index 45a0523..7335fbc 100644 --- a/src/noosfero-spb/gov_user/lib/ext/search_controller.rb +++ b/src/noosfero-spb/gov_user/lib/ext/search_controller.rb @@ -14,7 +14,9 @@ class SearchController end def institutions - @titles[:institutions] = _("Institution Catalog") + @asset = "gov_user_plugin/institutions" + @assets = [@asset] + @titles["gov_user_plugin/institutions"] = _("Institution Catalog") results = filter_communities_list{|community| community.institution?} results = results.paginate(:per_page => 24, :page => params[:page]) @searches[@asset] = {:results => results} diff --git a/src/noosfero-spb/gov_user/lib/ext/search_helper.rb b/src/noosfero-spb/gov_user/lib/ext/search_helper.rb index aae5940..45f9aea 100644 --- a/src/noosfero-spb/gov_user/lib/ext/search_helper.rb +++ b/src/noosfero-spb/gov_user/lib/ext/search_helper.rb @@ -3,6 +3,6 @@ require_dependency 'search_helper' module SearchHelper COMMON_PROFILE_LIST_BLOCK ||= [] - COMMON_PROFILE_LIST_BLOCK << :institutions + COMMON_PROFILE_LIST_BLOCK << "gov_user_plugin/institution" end diff --git a/src/noosfero-spb/gov_user/lib/ext/user.rb b/src/noosfero-spb/gov_user/lib/ext/user.rb index ec5f7ce..f7c296f 100644 --- a/src/noosfero-spb/gov_user/lib/ext/user.rb +++ b/src/noosfero-spb/gov_user/lib/ext/user.rb @@ -4,7 +4,7 @@ class User GOV_SUFFIX = /^.*@[gov.br|jus.br|leg.br|mp.br]+$/ - has_and_belongs_to_many :institutions + has_and_belongs_to_many :institutions, :class_name => 'GovUserPlugin::Institution', :join_table => 'gov_user_plugin_institutions_users' validate :email_different_secondary?, :email_has_already_been_used?, :secondary_email_format diff --git a/src/noosfero-spb/gov_user/lib/gov_user_plugin.rb b/src/noosfero-spb/gov_user/lib/gov_user_plugin.rb index 5cd63dc..c441926 100644 --- a/src/noosfero-spb/gov_user/lib/gov_user_plugin.rb +++ b/src/noosfero-spb/gov_user/lib/gov_user_plugin.rb @@ -86,7 +86,7 @@ class GovUserPlugin < Noosfero::Plugin def self.extra_blocks { - InstitutionsBlock => { :type => [Environment, Person] } + GovUserPlugin::InstitutionsBlock => { :type => [Environment, Person] } } end @@ -223,7 +223,7 @@ class GovUserPlugin < Noosfero::Plugin end if context.params.has_key?(:institution) - Institution.transaction do + GovUserPlugin::Institution.transaction do context.profile. institution. update_attributes!(context.params[:institution]) @@ -277,7 +277,7 @@ class GovUserPlugin < Noosfero::Plugin context.params[:user][:institution_ids].delete('') context.params[:user][:institution_ids].each do |id| - new_communities << Institution.find(id).community + new_communities << GovUserPlugin::Institution.find(id).community end end @@ -320,7 +320,7 @@ class GovUserPlugin < Noosfero::Plugin def update_user_institutions(user) context.params[:user][:institution_ids].each do |institution_id| - institution = Institution.find institution_id + institution = GovUserPlugin::Institution.find institution_id user.institutions << institution if institution.community.admins.blank? diff --git a/src/noosfero-spb/gov_user/lib/gov_user_plugin/governmental_power.rb b/src/noosfero-spb/gov_user/lib/gov_user_plugin/governmental_power.rb new file mode 100644 index 0000000..9e2e909 --- /dev/null +++ b/src/noosfero-spb/gov_user/lib/gov_user_plugin/governmental_power.rb @@ -0,0 +1,6 @@ +class GovUserPlugin::GovernmentalPower < Noosfero::Plugin::ActiveRecord + attr_accessible :name + + validates :name, :presence=>true, :uniqueness=>true + has_many :institutions, :class_name => 'GovUserPlugin::Institution' +end diff --git a/src/noosfero-spb/gov_user/lib/gov_user_plugin/governmental_sphere.rb b/src/noosfero-spb/gov_user/lib/gov_user_plugin/governmental_sphere.rb new file mode 100644 index 0000000..5a16100 --- /dev/null +++ b/src/noosfero-spb/gov_user/lib/gov_user_plugin/governmental_sphere.rb @@ -0,0 +1,7 @@ +class GovUserPlugin::GovernmentalSphere < Noosfero::Plugin::ActiveRecord + attr_accessible :name + + validates :name, :presence=>true, :uniqueness=>true + + has_many :institutions, :class_name => 'GovUserPlugin::Institution' +end diff --git a/src/noosfero-spb/gov_user/lib/gov_user_plugin/institution.rb b/src/noosfero-spb/gov_user/lib/gov_user_plugin/institution.rb new file mode 100644 index 0000000..73bb1e9 --- /dev/null +++ b/src/noosfero-spb/gov_user/lib/gov_user_plugin/institution.rb @@ -0,0 +1,109 @@ +class GovUserPlugin::Institution < Noosfero::Plugin::ActiveRecord + has_many :comments + + SEARCH_FILTERS = { + :order => %w[], + :display => %w[compact] + } + + def self.default_search_display + 'compact' + end + + belongs_to :governmental_power, :class_name => 'GovUserPlugin::GovernmentalPower' + belongs_to :governmental_sphere, :class_name => 'GovUserPlugin::GovernmentalSphere' + belongs_to :juridical_nature, :class_name => 'GovUserPlugin::JuridicalNature' + + has_and_belongs_to_many :users, :join_table => 'gov_user_plugin_institutions_users' + + attr_accessible :name, :acronym, :unit_code, :parent_code, :unit_type, + :sub_juridical_nature, :normalization_level, + :version, :cnpj, :type, :governmental_power, + :governmental_sphere, :sisp, :juridical_nature, + :corporate_name, :siorg_code, :community + + validates :name, :presence=>true, :uniqueness=>true + + before_save :verify_institution_type + + belongs_to :community + + scope :public, :conditions => { :type => "GovUserPlugin::PublicInstitution" } + scope :private, :conditions => { :type => "GovUserPlugin::PrivateInstitution" } + scope :search_institution, lambda{ |value| + where("name ilike ? OR acronym ilike ?", "%#{value}%", "%#{value}%" ) + } + + validate :validate_country, :validate_state, :validate_city, + :verify_institution_type, :validate_format_cnpj + + + protected + + def verify_institution_type + valid_institutions_type = ["GovUserPlugin::PublicInstitution", "GovUserPlugin::PrivateInstitution"] + + unless valid_institutions_type.include? self.type + self.errors.add( + :type, + _("invalid, only public and private institutions are allowed.") + ) + + return false + end + + return true + end + + def validate_country + unless self.community.blank? + if self.community.country.blank? && self.errors[:country].blank? + self.errors.add(:country, _("can't be blank")) + return false + end + end + + return true + end + + def validate_state + unless self.community.blank? + if self.community.country == "BR" && + (self.community.state.blank? || self.community.state == "-1") && + self.errors[:state].blank? + + self.errors.add(:state, _("can't be blank")) + return false + end + end + + return true + end + + def validate_city + unless self.community.blank? + if self.community.country == "BR" && self.community.city.blank? && + self.errors[:city].blank? + + self.errors.add(:city, _("can't be blank")) + return false + end + end + + return true + end + + def validate_format_cnpj + return true if self.community.blank? && self.community.country != "BR" + return true if self.cnpj.blank? + + format = /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/ + + if !self.cnpj.blank? && format.match(self.cnpj) + return true + else + self.errors.add(:cnpj, _("invalid format")) + return false + end + end +end diff --git a/src/noosfero-spb/gov_user/lib/gov_user_plugin/institutions_block.rb b/src/noosfero-spb/gov_user/lib/gov_user_plugin/institutions_block.rb new file mode 100644 index 0000000..6c73dd3 --- /dev/null +++ b/src/noosfero-spb/gov_user/lib/gov_user_plugin/institutions_block.rb @@ -0,0 +1,70 @@ +class GovUserPlugin::InstitutionsBlock < CommunitiesBlock + def self.description + _('Institutions') + end + + def profile_count + profile_list.count + end + + def default_title + n_('{#} institution', '{#} institutions', profile_count) + end + + def help + _('This block displays the institutions in which the user is a member.') + end + + def footer + owner = self.owner + case owner + when Profile + lambda do |context| + link_to s_('institutions|View all'), :profile => owner.identifier, + :controller => 'profile', :action => 'communities', + :type => 'GovUserPlugin::Institution' + end + when Environment + lambda do |context| + link_to s_('institutions|View all'), :controller => 'search', + :action => 'communities', :type => 'GovUserPlugin::Institution' + end + else + '' + end + end + + def profile_list + result = get_visible_profiles + + result = result.select { |p| p.class == Community && p.institution? } + + result.slice(0..get_limit-1) + end + + def profiles + owner.communities + end + + private + + def get_visible_profiles + include_list = [:image,:domains,:preferred_domain,:environment] + visible_profiles = profiles.visible.includes(include_list) + + if !prioritize_profiles_with_image + visible_profiles.all(:limit => get_limit, + :order => 'profiles.updated_at DESC' + ).sort_by{ rand } + elsif profiles.visible.with_image.count >= get_limit + visible_profiles.with_image.all(:limit => get_limit * 5, + :order => 'profiles.updated_at DESC' + ).sort_by{ rand } + else + visible_profiles.with_image.sort_by{ rand } + + visible_profiles.without_image.all(:limit => get_limit * 5, + :order => 'profiles.updated_at DESC' + ).sort_by{ rand } + end + end +end diff --git a/src/noosfero-spb/gov_user/lib/gov_user_plugin/institutions_users.rb b/src/noosfero-spb/gov_user/lib/gov_user_plugin/institutions_users.rb new file mode 100644 index 0000000..055a754 --- /dev/null +++ b/src/noosfero-spb/gov_user/lib/gov_user_plugin/institutions_users.rb @@ -0,0 +1,4 @@ +class GovUserPlugin::InstitutionsUsers < Noosfero::Plugin::ActiveRecord + belongs_to :user + belongs_to :institution, :class_name => 'GovUserPlugin::Institution' +end diff --git a/src/noosfero-spb/gov_user/lib/gov_user_plugin/juridical_nature.rb b/src/noosfero-spb/gov_user/lib/gov_user_plugin/juridical_nature.rb new file mode 100644 index 0000000..4b2ae58 --- /dev/null +++ b/src/noosfero-spb/gov_user/lib/gov_user_plugin/juridical_nature.rb @@ -0,0 +1,10 @@ +class GovUserPlugin::JuridicalNature < Noosfero::Plugin::ActiveRecord + self.record_timestamps = false + + attr_accessible :name + + has_many :institutions, :class_name => 'GovUserPlugin::Institution' + + validates_presence_of :name + validates_uniqueness_of :name +end diff --git a/src/noosfero-spb/gov_user/lib/gov_user_plugin/private_institution.rb b/src/noosfero-spb/gov_user/lib/gov_user_plugin/private_institution.rb new file mode 100644 index 0000000..42ed38f --- /dev/null +++ b/src/noosfero-spb/gov_user/lib/gov_user_plugin/private_institution.rb @@ -0,0 +1,2 @@ +class GovUserPlugin::PrivateInstitution < GovUserPlugin::Institution +end diff --git a/src/noosfero-spb/gov_user/lib/gov_user_plugin/public_institution.rb b/src/noosfero-spb/gov_user/lib/gov_user_plugin/public_institution.rb new file mode 100644 index 0000000..846ef5b --- /dev/null +++ b/src/noosfero-spb/gov_user/lib/gov_user_plugin/public_institution.rb @@ -0,0 +1,13 @@ +class GovUserPlugin::PublicInstitution < GovUserPlugin::Institution + validates :governmental_power, :governmental_sphere, :juridical_nature, + :presence=>true + + validates :acronym, :allow_blank => true, :allow_nil => true, + :uniqueness=>true + + validates_format_of( + :cnpj, + :with => /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/, + :allow_nil => true, :allow_blank => true + ) +end diff --git a/src/noosfero-spb/gov_user/lib/governmental_power.rb b/src/noosfero-spb/gov_user/lib/governmental_power.rb deleted file mode 100644 index cb7ca36..0000000 --- a/src/noosfero-spb/gov_user/lib/governmental_power.rb +++ /dev/null @@ -1,13 +0,0 @@ -class GovernmentalPower < ActiveRecord::Base - attr_accessible :name - - validates :name, :presence=>true, :uniqueness=>true - has_many :institutions - - def public_institutions - Institution.where( - :type=>"PublicInstitution", - :governmental_power_id=>self.id - ) - end -end diff --git a/src/noosfero-spb/gov_user/lib/governmental_sphere.rb b/src/noosfero-spb/gov_user/lib/governmental_sphere.rb deleted file mode 100644 index aef8f8f..0000000 --- a/src/noosfero-spb/gov_user/lib/governmental_sphere.rb +++ /dev/null @@ -1,7 +0,0 @@ -class GovernmentalSphere < ActiveRecord::Base - attr_accessible :name - - validates :name, :presence=>true, :uniqueness=>true - - has_many :institutions -end diff --git a/src/noosfero-spb/gov_user/lib/institution.rb b/src/noosfero-spb/gov_user/lib/institution.rb deleted file mode 100644 index ee5e870..0000000 --- a/src/noosfero-spb/gov_user/lib/institution.rb +++ /dev/null @@ -1,107 +0,0 @@ -class Institution < ActiveRecord::Base - has_many :comments - - SEARCH_FILTERS = { - :order => %w[], - :display => %w[compact] - } - - def self.default_search_display - 'compact' - end - - belongs_to :governmental_power - belongs_to :governmental_sphere - belongs_to :juridical_nature - - has_and_belongs_to_many :users - - attr_accessible :name, :acronym, :unit_code, :parent_code, :unit_type, - :sub_juridical_nature, :normalization_level, - :version, :cnpj, :type, :governmental_power, - :governmental_sphere, :sisp, :juridical_nature, - :corporate_name, :siorg_code, :community - - validates :name, :presence=>true, :uniqueness=>true - - before_save :verify_institution_type - - belongs_to :community - - scope :search_institution, lambda{ |value| - where("name ilike ? OR acronym ilike ?", "%#{value}%", "%#{value}%" ) - } - - validate :validate_country, :validate_state, :validate_city, - :verify_institution_type, :validate_format_cnpj - - - protected - - def verify_institution_type - valid_institutions_type = ["PublicInstitution", "PrivateInstitution"] - - unless valid_institutions_type.include? self.type - self.errors.add( - :type, - _("invalid, only public and private institutions are allowed.") - ) - - return false - end - - return true - end - - def validate_country - unless self.community.blank? - if self.community.country.blank? && self.errors[:country].blank? - self.errors.add(:country, _("can't be blank")) - return false - end - end - - return true - end - - def validate_state - unless self.community.blank? - if self.community.country == "BR" && - (self.community.state.blank? || self.community.state == "-1") && - self.errors[:state].blank? - - self.errors.add(:state, _("can't be blank")) - return false - end - end - - return true - end - - def validate_city - unless self.community.blank? - if self.community.country == "BR" && self.community.city.blank? && - self.errors[:city].blank? - - self.errors.add(:city, _("can't be blank")) - return false - end - end - - return true - end - - def validate_format_cnpj - return true if self.community.blank? && self.community.country != "BR" - return true if self.cnpj.blank? - - format = /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/ - - if !self.cnpj.blank? && format.match(self.cnpj) - return true - else - self.errors.add(:cnpj, _("invalid format")) - return false - end - end -end diff --git a/src/noosfero-spb/gov_user/lib/institutions_block.rb b/src/noosfero-spb/gov_user/lib/institutions_block.rb deleted file mode 100644 index 8ef8f59..0000000 --- a/src/noosfero-spb/gov_user/lib/institutions_block.rb +++ /dev/null @@ -1,71 +0,0 @@ -class InstitutionsBlock < CommunitiesBlock - - def self.description - _('Institutions') - end - - def profile_count - profile_list.count - end - - def default_title - n_('{#} institution', '{#} institutions', profile_count) - end - - def help - _('This block displays the institutions in which the user is a member.') - end - - def footer - owner = self.owner - case owner - when Profile - lambda do |context| - link_to s_('institutions|View all'), :profile => owner.identifier, - :controller => 'profile', :action => 'communities', - :type => 'Institution' - end - when Environment - lambda do |context| - link_to s_('institutions|View all'), :controller => 'search', - :action => 'communities', :type => 'Institution' - end - else - '' - end - end - - def profile_list - result = get_visible_profiles - - result = result.select { |p| p.class == Community && p.institution? } - - result.slice(0..get_limit-1) - end - - def profiles - owner.communities - end - - private - - def get_visible_profiles - include_list = [:image,:domains,:preferred_domain,:environment] - visible_profiles = profiles.visible.includes(include_list) - - if !prioritize_profiles_with_image - visible_profiles.all(:limit => get_limit, - :order => 'profiles.updated_at DESC' - ).sort_by{ rand } - elsif profiles.visible.with_image.count >= get_limit - visible_profiles.with_image.all(:limit => get_limit * 5, - :order => 'profiles.updated_at DESC' - ).sort_by{ rand } - else - visible_profiles.with_image.sort_by{ rand } + - visible_profiles.without_image.all(:limit => get_limit * 5, - :order => 'profiles.updated_at DESC' - ).sort_by{ rand } - end - end -end diff --git a/src/noosfero-spb/gov_user/lib/institutions_users.rb b/src/noosfero-spb/gov_user/lib/institutions_users.rb deleted file mode 100644 index e47da86..0000000 --- a/src/noosfero-spb/gov_user/lib/institutions_users.rb +++ /dev/null @@ -1,4 +0,0 @@ -class InstitutionUser < ActiveRecord::Base - belongs_to :user - belongs_to :institution -end diff --git a/src/noosfero-spb/gov_user/lib/juridical_nature.rb b/src/noosfero-spb/gov_user/lib/juridical_nature.rb deleted file mode 100644 index 1bb17f8..0000000 --- a/src/noosfero-spb/gov_user/lib/juridical_nature.rb +++ /dev/null @@ -1,15 +0,0 @@ -class JuridicalNature < ActiveRecord::Base - attr_accessible :name - - has_many :institutions - - validates_presence_of :name - validates_uniqueness_of :name - - def public_institutions - Institution.where( - :type=>"PublicInstitution", - :juridical_nature_id=>self.id - ) - end -end diff --git a/src/noosfero-spb/gov_user/lib/private_institution.rb b/src/noosfero-spb/gov_user/lib/private_institution.rb deleted file mode 100644 index db490d2..0000000 --- a/src/noosfero-spb/gov_user/lib/private_institution.rb +++ /dev/null @@ -1,2 +0,0 @@ -class PrivateInstitution < Institution -end diff --git a/src/noosfero-spb/gov_user/lib/public_institution.rb b/src/noosfero-spb/gov_user/lib/public_institution.rb deleted file mode 100644 index 33d13eb..0000000 --- a/src/noosfero-spb/gov_user/lib/public_institution.rb +++ /dev/null @@ -1,13 +0,0 @@ -class PublicInstitution < Institution - validates :governmental_power, :governmental_sphere, :juridical_nature, - :presence=>true - - validates :acronym, :allow_blank => true, :allow_nil => true, - :uniqueness=>true - - validates_format_of( - :cnpj, - :with => /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/, - :allow_nil => true, :allow_blank => true - ) -end diff --git a/src/noosfero-spb/gov_user/public/views/create-institution.js b/src/noosfero-spb/gov_user/public/views/create-institution.js index 2da1926..2481f37 100644 --- a/src/noosfero-spb/gov_user/public/views/create-institution.js +++ b/src/noosfero-spb/gov_user/public/views/create-institution.js @@ -300,7 +300,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] function institution_type_actions(type) { var country = $("#community_country").val(); - if( type === "PublicInstitution" && country == "BR") { + if( type === "GovUserPlugin::PublicInstitution" && country == "BR") { show_public_institutions_fields(); } else { show_private_institutions_fields(); diff --git a/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_controller_test.rb b/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_controller_test.rb index 48b4fc4..f87dfc2 100644 --- a/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_controller_test.rb +++ b/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_controller_test.rb @@ -16,9 +16,9 @@ class GovUserPluginControllerTest < ActionController::TestCase @environment.add_admin(@admin) @environment.save - @gov_power = GovernmentalPower.create(:name=>"Some Gov Power") - @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") - @juridical_nature = JuridicalNature.create(:name => "Autarquia") + @gov_power = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power") + @gov_sphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere") + @juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia") @response = ActionController::TestResponse.new @institution_list = [] @@ -87,7 +87,7 @@ class GovUserPluginControllerTest < ActionController::TestCase "DF", "Brasilia", "12.234.567/8900-10", - "PublicInstitution" + "GovUserPlugin::PublicInstitution" ) fields[:institutions][:governmental_power] = @gov_power.id fields[:institutions][:governmental_sphere] = @gov_sphere.id @@ -109,7 +109,7 @@ class GovUserPluginControllerTest < ActionController::TestCase "DF", "Brasilia", "", - "PrivateInstitution" + "GovUserPlugin::PrivateInstitution" ) fields[:institutions][:acronym] = "SPI" @@ -147,7 +147,7 @@ class GovUserPluginControllerTest < ActionController::TestCase "DF", "Brasilia", "12.345.567/8900-10", - "PrivateInstitution" + "GovUserPlugin::PrivateInstitution" ) fields[:institutions][:acronym] = "SPI" @@ -165,7 +165,7 @@ class GovUserPluginControllerTest < ActionController::TestCase "DF", "Brasilia", "56.366.790/0001-88", - "PrivateInstitution" + "GovUserPlugin::PrivateInstitution" ) post :new_institution, fields @@ -182,7 +182,7 @@ class GovUserPluginControllerTest < ActionController::TestCase "", "", "", - "PrivateInstitution" + "GovUserPlugin::PrivateInstitution" ) fields[:institutions][:acronym] = "FI" @@ -200,7 +200,7 @@ class GovUserPluginControllerTest < ActionController::TestCase "", "", "", - "PrivateInstitution" + "GovUserPlugin::PrivateInstitution" ) fields[:institutions][:acronym] = "FI" @@ -224,13 +224,13 @@ class GovUserPluginControllerTest < ActionController::TestCase "DF", "Brasilia", "12.323.557/8900-10", - "PrivateInstitution" + "GovUserPlugin::PrivateInstitution" ) fields[:institutions][:acronym] = "PI" fields[:edit_institution_page] = false post :new_institution, fields - assert(Institution.last.community.admins.include?(admin2) ) + assert(GovUserPlugin::Institution.last.community.admins.include?(admin2) ) end end diff --git a/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb b/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb index 61c48b1..3fa2a21 100644 --- a/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb +++ b/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb @@ -24,9 +24,9 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase @environment.save! end should "user edit its community institution" do - govPower = GovernmentalPower.create(:name=>"Some Gov Power") - govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") - juridical_nature = JuridicalNature.create(:name => "Autarquia") + govPower = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power") + govSphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere") + juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia") institution = InstitutionTestHelper.create_public_institution( "Ministerio Publico da Uniao", @@ -48,7 +48,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase "DF", "Gama", "12.345.678/9012-45", - "PrivateInstitution" + "GovUserPlugin::PrivateInstitution" ) post( @@ -63,9 +63,9 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase end should "not user edit its community institution with wrong values" do - govPower = GovernmentalPower.create(:name=>"Some Gov Power") - govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") - juridical_nature = JuridicalNature.create(:name => "Autarquia") + govPower = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power") + govSphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere") + juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia") institution = InstitutionTestHelper.create_public_institution( "Ministerio Publico da Uniao", @@ -87,7 +87,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase "DF", "Gama", "6465465465", - "PrivateInstitution" + "GovUserPlugin::PrivateInstitution" ) post( diff --git a/src/noosfero-spb/gov_user/test/functional/profile_editor_controller_test.rb b/src/noosfero-spb/gov_user/test/functional/profile_editor_controller_test.rb index 52de533..dd944ca 100644 --- a/src/noosfero-spb/gov_user/test/functional/profile_editor_controller_test.rb +++ b/src/noosfero-spb/gov_user/test/functional/profile_editor_controller_test.rb @@ -29,9 +29,9 @@ class ProfileEditorControllerTest < ActionController::TestCase @environment.add_admin(admin) @environment.save - @govPower = GovernmentalPower.create(:name=>"Some Gov Power") - @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") - @juridical_nature = JuridicalNature.create(:name => "Autarquia") + @govPower = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power") + @govSphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere") + @juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia") @institution_list = [] @institution_list << InstitutionTestHelper.create_public_institution( diff --git a/src/noosfero-spb/gov_user/test/functional/search_controller_test.rb b/src/noosfero-spb/gov_user/test/functional/search_controller_test.rb index ab45f06..542b9a6 100644 --- a/src/noosfero-spb/gov_user/test/functional/search_controller_test.rb +++ b/src/noosfero-spb/gov_user/test/functional/search_controller_test.rb @@ -51,7 +51,7 @@ class SearchControllerTest < ActionController::TestCase get :institutions, :query => "New" - assert_includes assigns(:searches)[:institutions][:results], institution.community - assert_not_includes assigns(:searches)[:institutions][:results], community + assert_includes assigns(:searches)["gov_user_plugin/institutions"][:results], institution.community + assert_not_includes assigns(:searches)["gov_user_plugin/institutions"][:results], community end end diff --git a/src/noosfero-spb/gov_user/test/helpers/institution_test_helper.rb b/src/noosfero-spb/gov_user/test/helpers/institution_test_helper.rb index 1f4df2f..77a6260 100644 --- a/src/noosfero-spb/gov_user/test/helpers/institution_test_helper.rb +++ b/src/noosfero-spb/gov_user/test/helpers/institution_test_helper.rb @@ -22,7 +22,7 @@ module InstitutionTestHelper end def self.create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s, cnpj - institution = PublicInstitution.new + institution = GovUserPlugin::PublicInstitution.new institution.community = institution_community(name, country, state, city) institution.name = name institution.juridical_nature = juridical_nature @@ -36,7 +36,7 @@ module InstitutionTestHelper end def self.create_private_institution name, acronym, country, state, city, cnpj - institution = PrivateInstitution.new + institution = GovUserPlugin::PrivateInstitution.new institution.community = institution_community(name, country, state, city) institution.name = name institution.acronym = acronym @@ -56,4 +56,4 @@ module InstitutionTestHelper institution_community.save institution_community end -end \ No newline at end of file +end diff --git a/src/noosfero-spb/gov_user/test/unit/gov_user_person_test.rb b/src/noosfero-spb/gov_user/test/unit/gov_user_person_test.rb deleted file mode 100644 index 0c58478..0000000 --- a/src/noosfero-spb/gov_user/test/unit/gov_user_person_test.rb +++ /dev/null @@ -1,58 +0,0 @@ -# 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", - "user2@email.com", - "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/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/gov_user_person_test.rb b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/gov_user_person_test.rb new file mode 100644 index 0000000..e4f7c20 --- /dev/null +++ b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/gov_user_person_test.rb @@ -0,0 +1,58 @@ +# 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", + "user2@email.com", + "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/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/governmental_power_test.rb b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/governmental_power_test.rb new file mode 100644 index 0000000..2c6ba57 --- /dev/null +++ b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/governmental_power_test.rb @@ -0,0 +1,33 @@ +require File.dirname(__FILE__) + '/../../../../../test/test_helper' +require File.dirname(__FILE__) + '/../../helpers/institution_test_helper' + +class GovUserPlugin::GovernmentalPowerTest < ActiveSupport::TestCase + + def setup + @gov_sphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere") + @juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia") + end + + def teardown + GovUserPlugin::Institution.destroy_all + end + + should "get public institutions" do + inst_name = "Ministerio Publico da Uniao" + inst_cnpj = "12.345.678/9012-45" + gov_power = GovUserPlugin::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.institutions.public.count, GovUserPlugin::PublicInstitution.count + end +end diff --git a/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/institution_test.rb b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/institution_test.rb new file mode 100644 index 0000000..f06218e --- /dev/null +++ b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/institution_test.rb @@ -0,0 +1,63 @@ +require File.dirname(__FILE__) + '/../../../../../test/test_helper' +require File.dirname(__FILE__) + '/../../helpers/plugin_test_helper' + +class GovUserPlugin::InstitutionTest < ActiveSupport::TestCase + include PluginTestHelper + def setup + @gov_power = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power") + @gov_sphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere") + @juridical_nature = GovUserPlugin::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 + GovUserPlugin::GovernmentalPower.destroy_all + GovUserPlugin::GovernmentalSphere.destroy_all + GovUserPlugin::JuridicalNature.destroy_all + @institution = nil + end + should "not save institutions without name" do + @institution.name = nil + assert_equal false, @institution.save + assert_equal true, @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_equal false, @institution.save + assert_equal true, @institution.errors.full_messages.include?(invalid_msg) + end + + should "not save without country" do + @institution.community.country = nil + assert_equal false, @institution.save + assert_equal true, @institution.errors.full_messages.include?("Country can't be blank") + end + + should "not save without state" do + @institution.community.state = nil + + assert_equal false, @institution.save + assert_equal true, @institution.errors.full_messages.include?("State can't be blank") + end + + should "not save without city" do + @institution.community.city = nil + @institution.community.state = "DF" + + assert_equal false, @institution.save + assert_equal true, @institution.errors.full_messages.include?("City can't be blank") + end +end diff --git a/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/institutions_block_test.rb b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/institutions_block_test.rb new file mode 100644 index 0000000..d967147 --- /dev/null +++ b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/institutions_block_test.rb @@ -0,0 +1,51 @@ +require File.dirname(__FILE__) + '/../../../../../test/test_helper' +require File.dirname(__FILE__) + '/../../helpers/plugin_test_helper' + +class GovUserPlugin::InstitutionsBlockTest < ActiveSupport::TestCase + include PluginTestHelper + should 'inherit from Block' do + assert_kind_of Block, GovUserPlugin::InstitutionsBlock.new + end + + should 'declare its default title' do + GovUserPlugin::InstitutionsBlock.any_instance.stubs(:profile_count).returns(0) + assert_not_equal Block.new.default_title, GovUserPlugin::InstitutionsBlock.new.default_title + end + + should 'describe itself' do + assert_not_equal Block.description, GovUserPlugin::InstitutionsBlock.description + end + + should 'give empty footer on unsupported owner type' do + block = GovUserPlugin::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 = GovUserPlugin::InstitutionsBlock.new + block.expects(:owner).at_least_once.returns(user) + + assert_equivalent [institution.community], block.profiles + end + +end diff --git a/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/juridical_nature_test.rb b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/juridical_nature_test.rb new file mode 100644 index 0000000..6654665 --- /dev/null +++ b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/juridical_nature_test.rb @@ -0,0 +1,23 @@ +require File.dirname(__FILE__) + '/../../../../../test/test_helper' +require File.dirname(__FILE__) + '/../../helpers/plugin_test_helper' + +class GovUserPlugin::JuridicalNatureTest < ActiveSupport::TestCase + + include PluginTestHelper + + def setup + @govPower = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power") + @govSphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere") + end + + def teardown + GovUserPlugin::Institution.destroy_all + end + + should "get public institutions" do + juridical_nature = GovUserPlugin::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.institutions.public.count == GovUserPlugin::PublicInstitution.count + end +end diff --git a/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/organization_rating_test.rb b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/organization_rating_test.rb new file mode 100644 index 0000000..164291d --- /dev/null +++ b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/organization_rating_test.rb @@ -0,0 +1,44 @@ +require File.dirname(__FILE__) + '/../../../../../test/test_helper' +require File.dirname(__FILE__) + '/../../helpers/plugin_test_helper' + +class GovUserPlugin::OrganizationRatingTest < ActiveSupport::TestCase + include PluginTestHelper + + def setup + @environment = Environment.default + @environment.enabled_plugins = ['SoftwareCommunitiesPlugin'] + @environment.save + end + + should "validate institution if there is an institution_id" do + person = fast_create(Person) + community = fast_create(Community) + private_institution = build_private_institution "huehue", "hue", "11.222.333/4444-55" + + community_rating = OrganizationRating.new(:person => person, :value => 3, :organization => community, :institution => private_institution) + assert_equal false, community_rating.valid? + + assert_equal true, community_rating.errors[:institution].include?("not found") + + private_institution.save + community_rating.institution = private_institution + + assert_equal true, community_rating.valid? + assert_equal false, community_rating.errors[:institution].include?("not found") + end + + private + + def build_private_institution name, corporate_name, cnpj, country="AR" + community = Community.new :name => name + community.country = country + + institution = GovUserPlugin::PrivateInstitution.new :name=> name + institution.corporate_name = corporate_name + institution.cnpj = cnpj + institution.community = community + + institution + end +end + diff --git a/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/person_test.rb b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/person_test.rb new file mode 100644 index 0000000..82058a3 --- /dev/null +++ b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/person_test.rb @@ -0,0 +1,43 @@ +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", + "user@secondaryemail.com", + "Any State", + "Some City" + ) + end + + should 'calculate the percentege of person incomplete fields' do + @person.cell_phone = "76888919" + @person.contact_phone = "987654321" + + assert_equal(67, @plugin.calc_percentage_registration(@person)) + + @person.comercial_phone = "11223344" + @person.country = "I dont know" + @person.state = "I dont know" + @person.city = "I dont know" + @person.organization_website = "www.whatever.com" + @person.image = Image::new :uploaded_data=>fixture_file_upload('/files/rails.png', 'image/png') + @person.save + + assert_equal(100, @plugin.calc_percentage_registration(@person)) + end + + should 'return true when the email has not gov.br,jus.br,leg.br or mp.br' do + @user.secondary_email = "test_email@com.br" + @user.email = "test_email@net.br" + assert @user.save + end +end diff --git a/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/private_institution_test.rb b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/private_institution_test.rb new file mode 100644 index 0000000..125340e --- /dev/null +++ b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/private_institution_test.rb @@ -0,0 +1,34 @@ +require File.dirname(__FILE__) + '/../../../../../test/test_helper' +require File.dirname(__FILE__) + '/../../helpers/plugin_test_helper' + +class GovUserPlugin::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 + GovUserPlugin::Institution.destroy_all + end + + should "save without a cnpj" do + @institution.cnpj = nil + + assert @institution.save + end + + should "save without fantasy name" do + @institution.acronym = nil + @institution.community.save + + assert @institution.save + end +end diff --git a/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/public_institution_test.rb b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/public_institution_test.rb new file mode 100644 index 0000000..573f024 --- /dev/null +++ b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/public_institution_test.rb @@ -0,0 +1,68 @@ +require File.dirname(__FILE__) + '/../../../../../test/test_helper' +require File.dirname(__FILE__) + '/../../helpers/plugin_test_helper' + +class GovUserPlugin::PublicInstitutionTest < ActiveSupport::TestCase + include PluginTestHelper + def setup + @gov_power = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power") + @gov_sphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere") + @juridical_nature = GovUserPlugin::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 + GovUserPlugin::GovernmentalPower.destroy_all + GovUserPlugin::GovernmentalSphere.destroy_all + GovUserPlugin::JuridicalNature.destroy_all + GovUserPlugin::Institution.destroy_all + @gov_power = nil + @gov_sphere = nil + @juridical_nature = nil + @institution = nil + end + + should "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/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/user_test.rb b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/user_test.rb new file mode 100644 index 0000000..5424279 --- /dev/null +++ b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin/user_test.rb @@ -0,0 +1,99 @@ +require File.dirname(__FILE__) + '/../../../../../test/test_helper' +require File.dirname(__FILE__) + '/../../helpers/plugin_test_helper' + +class UserTest < ActiveSupport::TestCase + include PluginTestHelper + + should 'not save user whose both email and secondary email are the same' do + user = fast_create(User) + user.email = "test@email.com" + user.secondary_email = "test@email.com" + + assert !user.save + end + + should 'not save user whose email and secondary email have been taken' do + user1 = create_default_user + user2 = fast_create(User) + + user2.email = "primary@email.com" + user2.secondary_email = "secondary@email.com" + assert !user2.save + end + + should 'not save user whose email has already been used' do + user1 = create_default_user + user2 = fast_create(User) + + user2.email = "primary@email.com" + user2.secondary_email = "noosfero@email.com" + assert !user2.save + end + + should 'not save user whose email has been taken another in users secondary email' do + user1 = create_default_user + user2 = fast_create(User) + + user2.login = "another-login" + user2.email = "secondary@email.com" + user2.secondary_email = "noosfero@email.com" + assert !user2.save + end + + should 'not save user whose secondary email has been taken used in another users email' do + user1 = create_default_user + user2 = fast_create(User) + + user2.login = "another-login" + user2.email = "noosfero@email.com" + user2.secondary_email = "primary@email.com" + assert !user2.save + end + + should 'not save user whose secondary email has already been used in another users secondary email' do + user1 = create_default_user + user2 = fast_create(User) + + user2.login = "another-login" + user2.email = "noosfero@email.com" + user2.secondary_email = "secondary@email.com" + assert !user2.save + end + + should 'not save user whose secondary email is in the wrong format' do + user = fast_create(User) + user.email = "test@email.com" + user.secondary_email = "notarightformat.com" + + assert !user.save + + user.secondary_email = "not@arightformatcom" + + assert !user.save + end + + should 'save more than one user without secondary email' do + user = fast_create(User) + user.email = "test@email.com" + user.secondary_email = "" + user.save + + user2 = fast_create(User) + user2.email = "test2@email.com" + user2.secondary_email = "" + assert user2.save + end + + private + + def create_default_user + user = fast_create(User) + user.login = "a-login" + user.email = "primary@email.com" + user.secondary_email = "secondary@email.com" + user.save + + return user + end + +end diff --git a/src/noosfero-spb/gov_user/test/unit/governmental_power_test.rb b/src/noosfero-spb/gov_user/test/unit/governmental_power_test.rb deleted file mode 100644 index 5f777e6..0000000 --- a/src/noosfero-spb/gov_user/test/unit/governmental_power_test.rb +++ /dev/null @@ -1,33 +0,0 @@ -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/src/noosfero-spb/gov_user/test/unit/institution_test.rb b/src/noosfero-spb/gov_user/test/unit/institution_test.rb deleted file mode 100644 index c4c77e5..0000000 --- a/src/noosfero-spb/gov_user/test/unit/institution_test.rb +++ /dev/null @@ -1,63 +0,0 @@ -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_equal false, @institution.save - assert_equal true, @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_equal false, @institution.save - assert_equal true, @institution.errors.full_messages.include?(invalid_msg) - end - - should "not save without country" do - @institution.community.country = nil - assert_equal false, @institution.save - assert_equal true, @institution.errors.full_messages.include?("Country can't be blank") - end - - should "not save without state" do - @institution.community.state = nil - - assert_equal false, @institution.save - assert_equal true, @institution.errors.full_messages.include?("State can't be blank") - end - - should "not save without city" do - @institution.community.city = nil - @institution.community.state = "DF" - - assert_equal false, @institution.save - assert_equal true, @institution.errors.full_messages.include?("City can't be blank") - end -end diff --git a/src/noosfero-spb/gov_user/test/unit/institutions_block_test.rb b/src/noosfero-spb/gov_user/test/unit/institutions_block_test.rb deleted file mode 100644 index bcab723..0000000 --- a/src/noosfero-spb/gov_user/test/unit/institutions_block_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -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/src/noosfero-spb/gov_user/test/unit/juridical_nature_test.rb b/src/noosfero-spb/gov_user/test/unit/juridical_nature_test.rb deleted file mode 100644 index 80d34c6..0000000 --- a/src/noosfero-spb/gov_user/test/unit/juridical_nature_test.rb +++ /dev/null @@ -1,23 +0,0 @@ -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/src/noosfero-spb/gov_user/test/unit/organization_rating_test.rb b/src/noosfero-spb/gov_user/test/unit/organization_rating_test.rb deleted file mode 100644 index 748355f..0000000 --- a/src/noosfero-spb/gov_user/test/unit/organization_rating_test.rb +++ /dev/null @@ -1,44 +0,0 @@ -require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper' -require File.expand_path(File.dirname(__FILE__)) + '/../helpers/plugin_test_helper' - -class OrganizationRatingTest < ActiveSupport::TestCase - include PluginTestHelper - - def setup - @environment = Environment.default - @environment.enabled_plugins = ['SoftwareCommunitiesPlugin'] - @environment.save - end - - should "validate institution if there is an institution_id" do - person = fast_create(Person) - community = fast_create(Community) - private_institution = build_private_institution "huehue", "hue", "11.222.333/4444-55" - - community_rating = OrganizationRating.new(:person => person, :value => 3, :organization => community, :institution => private_institution) - assert_equal false, community_rating.valid? - - assert_equal true, community_rating.errors[:institution].include?("not found") - - private_institution.save - community_rating.institution = private_institution - - assert_equal true, community_rating.valid? - assert_equal false, community_rating.errors[:institution].include?("not found") - end - - private - - def build_private_institution name, corporate_name, cnpj, country="AR" - community = Community.new :name => name - community.country = country - - institution = PrivateInstitution.new :name=> name - institution.corporate_name = corporate_name - institution.cnpj = cnpj - institution.community = community - - institution - end -end - diff --git a/src/noosfero-spb/gov_user/test/unit/person_test.rb b/src/noosfero-spb/gov_user/test/unit/person_test.rb deleted file mode 100644 index dd6c628..0000000 --- a/src/noosfero-spb/gov_user/test/unit/person_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -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", - "user@secondaryemail.com", - "Any State", - "Some City" - ) - end - - should 'calculate the percentege of person incomplete fields' do - @person.cell_phone = "76888919" - @person.contact_phone = "987654321" - - assert_equal(67, @plugin.calc_percentage_registration(@person)) - - @person.comercial_phone = "11223344" - @person.country = "I dont know" - @person.state = "I dont know" - @person.city = "I dont know" - @person.organization_website = "www.whatever.com" - @person.image = Image::new :uploaded_data=>fixture_file_upload('/files/rails.png', 'image/png') - @person.save - - assert_equal(100, @plugin.calc_percentage_registration(@person)) - end - - should 'return true when the email has not gov.br,jus.br,leg.br or mp.br' do - @user.secondary_email = "test_email@com.br" - @user.email = "test_email@net.br" - assert @user.save - end -end diff --git a/src/noosfero-spb/gov_user/test/unit/private_institution_test.rb b/src/noosfero-spb/gov_user/test/unit/private_institution_test.rb deleted file mode 100644 index 8f01e95..0000000 --- a/src/noosfero-spb/gov_user/test/unit/private_institution_test.rb +++ /dev/null @@ -1,34 +0,0 @@ -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 "save without a cnpj" do - @institution.cnpj = nil - - assert @institution.save - end - - should "save without fantasy name" do - @institution.acronym = nil - @institution.community.save - - assert @institution.save - end -end diff --git a/src/noosfero-spb/gov_user/test/unit/public_institution_test.rb b/src/noosfero-spb/gov_user/test/unit/public_institution_test.rb deleted file mode 100644 index 9f37965..0000000 --- a/src/noosfero-spb/gov_user/test/unit/public_institution_test.rb +++ /dev/null @@ -1,68 +0,0 @@ -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 "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/src/noosfero-spb/gov_user/test/unit/user_test.rb b/src/noosfero-spb/gov_user/test/unit/user_test.rb deleted file mode 100644 index c2b15c6..0000000 --- a/src/noosfero-spb/gov_user/test/unit/user_test.rb +++ /dev/null @@ -1,99 +0,0 @@ -require File.dirname(__FILE__) + '/../../../../test/test_helper' -require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' - -class UserTest < ActiveSupport::TestCase - include PluginTestHelper - - should 'not save user whose both email and secondary email are the same' do - user = fast_create(User) - user.email = "test@email.com" - user.secondary_email = "test@email.com" - - assert !user.save - end - - should 'not save user whose email and secondary email have been taken' do - user1 = create_default_user - user2 = fast_create(User) - - user2.email = "primary@email.com" - user2.secondary_email = "secondary@email.com" - assert !user2.save - end - - should 'not save user whose email has already been used' do - user1 = create_default_user - user2 = fast_create(User) - - user2.email = "primary@email.com" - user2.secondary_email = "noosfero@email.com" - assert !user2.save - end - - should 'not save user whose email has been taken another in users secondary email' do - user1 = create_default_user - user2 = fast_create(User) - - user2.login = "another-login" - user2.email = "secondary@email.com" - user2.secondary_email = "noosfero@email.com" - assert !user2.save - end - - should 'not save user whose secondary email has been taken used in another users email' do - user1 = create_default_user - user2 = fast_create(User) - - user2.login = "another-login" - user2.email = "noosfero@email.com" - user2.secondary_email = "primary@email.com" - assert !user2.save - end - - should 'not save user whose secondary email has already been used in another users secondary email' do - user1 = create_default_user - user2 = fast_create(User) - - user2.login = "another-login" - user2.email = "noosfero@email.com" - user2.secondary_email = "secondary@email.com" - assert !user2.save - end - - should 'not save user whose secondary email is in the wrong format' do - user = fast_create(User) - user.email = "test@email.com" - user.secondary_email = "notarightformat.com" - - assert !user.save - - user.secondary_email = "not@arightformatcom" - - assert !user.save - end - - should 'save more than one user without secondary email' do - user = fast_create(User) - user.email = "test@email.com" - user.secondary_email = "" - user.save - - user2 = fast_create(User) - user2.email = "test2@email.com" - user2.secondary_email = "" - assert user2.save - end - - private - - def create_default_user - user = fast_create(User) - user.login = "a-login" - user.email = "primary@email.com" - user.secondary_email = "secondary@email.com" - user.save - - return user - end - -end diff --git a/src/noosfero-spb/gov_user/views/gov_user_plugin/_institution.html.erb b/src/noosfero-spb/gov_user/views/gov_user_plugin/_institution.html.erb index e2aa5b0..74b826c 100644 --- a/src/noosfero-spb/gov_user/views/gov_user_plugin/_institution.html.erb +++ b/src/noosfero-spb/gov_user/views/gov_user_plugin/_institution.html.erb @@ -31,11 +31,11 @@