Commit 5e076253c1d50b911ef2621c444c9322b64cf3c9
1 parent
6ead4aee
Exists in
gov-user-refactoring
gov-user: adequate models with proper namespacese
Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com> Signed-off-by: Thiago Ribeiro <thiagitosouza@hotmail.com> Signed-off-by: Tallys Martins <tallysmartins@yahoo.com.br> Closes #323
Showing
58 changed files
with
902 additions
and
915 deletions
Show diff stats
src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb
@@ -18,7 +18,6 @@ class GovUserPluginController < ApplicationController | @@ -18,7 +18,6 @@ class GovUserPluginController < ApplicationController | ||
18 | 18 | ||
19 | def create_institution | 19 | def create_institution |
20 | create_institution_view_variables | 20 | create_institution_view_variables |
21 | - | ||
22 | if request.xhr? | 21 | if request.xhr? |
23 | render :layout=>false | 22 | render :layout=>false |
24 | else | 23 | else |
@@ -57,7 +56,7 @@ class GovUserPluginController < ApplicationController | @@ -57,7 +56,7 @@ class GovUserPluginController < ApplicationController | ||
57 | def institution_already_exists | 56 | def institution_already_exists |
58 | redirect_to "/" if !request.xhr? || params[:name].blank? | 57 | redirect_to "/" if !request.xhr? || params[:name].blank? |
59 | 58 | ||
60 | - already_exists = !Institution.find_by_name(params[:name]).nil? | 59 | + already_exists = !GovUserPlugin::Institution.find_by_name(params[:name]).nil? |
61 | 60 | ||
62 | render :json=>already_exists.to_json | 61 | render :json=>already_exists.to_json |
63 | end | 62 | end |
@@ -65,7 +64,7 @@ class GovUserPluginController < ApplicationController | @@ -65,7 +64,7 @@ class GovUserPluginController < ApplicationController | ||
65 | def get_institutions | 64 | def get_institutions |
66 | redirect_to "/" if !request.xhr? || params[:query].blank? | 65 | redirect_to "/" if !request.xhr? || params[:query].blank? |
67 | 66 | ||
68 | - institutions = Institution.search_institution(params[:query]).select([:id, :name]) | 67 | + institutions = GovUserPlugin::Institution.search_institution(params[:query]).select([:id, :name]) |
69 | institutions_list = institutions.map { |institution| | 68 | institutions_list = institutions.map { |institution| |
70 | {:value=>institution.name, :id=>institution.id} | 69 | {:value=>institution.name, :id=>institution.id} |
71 | } | 70 | } |
@@ -135,17 +134,17 @@ class GovUserPluginController < ApplicationController | @@ -135,17 +134,17 @@ class GovUserPluginController < ApplicationController | ||
135 | 134 | ||
136 | def get_governmental_spheres | 135 | def get_governmental_spheres |
137 | spheres = [[_("Select a Governmental Sphere"), 0]] | 136 | spheres = [[_("Select a Governmental Sphere"), 0]] |
138 | - spheres.concat get_model_as_option_list(GovernmentalSphere) | 137 | + spheres.concat get_model_as_option_list(GovUserPlugin::GovernmentalSphere) |
139 | end | 138 | end |
140 | 139 | ||
141 | def get_governmental_powers | 140 | def get_governmental_powers |
142 | powers = [[_("Select a Governmental Power"), 0]] | 141 | powers = [[_("Select a Governmental Power"), 0]] |
143 | - powers.concat get_model_as_option_list(GovernmentalPower) | 142 | + powers.concat get_model_as_option_list(GovUserPlugin::GovernmentalPower) |
144 | end | 143 | end |
145 | 144 | ||
146 | def get_juridical_natures | 145 | def get_juridical_natures |
147 | natures = [[_("Select a Juridical Nature"), 0]] | 146 | natures = [[_("Select a Juridical Nature"), 0]] |
148 | - natures.concat get_model_as_option_list(JuridicalNature) | 147 | + natures.concat get_model_as_option_list(GovUserPlugin::JuridicalNature) |
149 | end | 148 | end |
150 | 149 | ||
151 | def get_model_as_option_list model | 150 | def get_model_as_option_list model |
@@ -157,10 +156,10 @@ class GovUserPluginController < ApplicationController | @@ -157,10 +156,10 @@ class GovUserPluginController < ApplicationController | ||
157 | :governmental_sphere, | 156 | :governmental_sphere, |
158 | :juridical_nature | 157 | :juridical_nature |
159 | ) | 158 | ) |
160 | - if params[:institutions][:type] == "PublicInstitution" | ||
161 | - PublicInstitution::new institution_params | 159 | + if params[:institutions][:type] == "GovUserPlugin::PublicInstitution" |
160 | + GovUserPlugin::PublicInstitution::new institution_params | ||
162 | else | 161 | else |
163 | - PrivateInstitution::new institution_params | 162 | + GovUserPlugin::PrivateInstitution::new institution_params |
164 | end | 163 | end |
165 | end | 164 | end |
166 | 165 | ||
@@ -168,9 +167,9 @@ class GovUserPluginController < ApplicationController | @@ -168,9 +167,9 @@ class GovUserPluginController < ApplicationController | ||
168 | inst_fields = params[:institutions] | 167 | inst_fields = params[:institutions] |
169 | 168 | ||
170 | begin | 169 | begin |
171 | - gov_power = GovernmentalPower.find inst_fields[:governmental_power] | ||
172 | - gov_sphere = GovernmentalSphere.find inst_fields[:governmental_sphere] | ||
173 | - jur_nature = JuridicalNature.find inst_fields[:juridical_nature] | 170 | + gov_power = GovUserPlugin::GovernmentalPower.find inst_fields[:governmental_power] |
171 | + gov_sphere = GovUserPlugin::GovernmentalSphere.find inst_fields[:governmental_sphere] | ||
172 | + jur_nature = GovUserPlugin::JuridicalNature.find inst_fields[:juridical_nature] | ||
174 | 173 | ||
175 | institution.juridical_nature = jur_nature | 174 | institution.juridical_nature = jur_nature |
176 | institution.governmental_power = gov_power | 175 | institution.governmental_power = gov_power |
@@ -191,7 +190,7 @@ class GovUserPluginController < ApplicationController | @@ -191,7 +190,7 @@ class GovUserPluginController < ApplicationController | ||
191 | institution.name = community[:name] | 190 | institution.name = community[:name] |
192 | institution.community = community | 191 | institution.community = community |
193 | 192 | ||
194 | - if institution.type == "PublicInstitution" | 193 | + if institution.type == "GovUserPlugin::PublicInstitution" |
195 | set_public_institution_fields institution | 194 | set_public_institution_fields institution |
196 | end | 195 | end |
197 | 196 |
src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb
@@ -20,7 +20,7 @@ class GovUserPluginMyprofileController < MyProfileController | @@ -20,7 +20,7 @@ class GovUserPluginMyprofileController < MyProfileController | ||
20 | def update_institution | 20 | def update_institution |
21 | @institution.community.update_attributes(params[:community]) | 21 | @institution.community.update_attributes(params[:community]) |
22 | @institution.update_attributes(params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature)) | 22 | @institution.update_attributes(params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature)) |
23 | - if @institution.type == "PublicInstitution" | 23 | + if @institution.type == "GovUserPlugin::PublicInstitution" |
24 | begin | 24 | begin |
25 | governmental_updates | 25 | governmental_updates |
26 | rescue | 26 | rescue |
@@ -36,15 +36,13 @@ class GovUserPluginMyprofileController < MyProfileController | @@ -36,15 +36,13 @@ class GovUserPluginMyprofileController < MyProfileController | ||
36 | end | 36 | end |
37 | 37 | ||
38 | def governmental_updates | 38 | def governmental_updates |
39 | - gov_power = GovernmentalPower.find params[:institutions][:governmental_power] | ||
40 | - gov_sphere = GovernmentalSphere.find params[:institutions][:governmental_sphere] | ||
41 | - jur_nature = JuridicalNature.find params[:institutions][:juridical_nature] | 39 | + gov_power = GovUserPlugin::GovernmentalPower.find params[:institutions][:governmental_power] |
40 | + gov_sphere = GovUserPlugin::GovernmentalSphere.find params[:institutions][:governmental_sphere] | ||
41 | + jur_nature = GovUserPlugin::JuridicalNature.find params[:institutions][:juridical_nature] | ||
42 | 42 | ||
43 | @institution.juridical_nature = jur_nature | 43 | @institution.juridical_nature = jur_nature |
44 | @institution.governmental_power = gov_power | 44 | @institution.governmental_power = gov_power |
45 | @institution.governmental_sphere = gov_sphere | 45 | @institution.governmental_sphere = gov_sphere |
46 | @institution.save | 46 | @institution.save |
47 | end | 47 | end |
48 | - | ||
49 | - | ||
50 | end | 48 | end |
src/noosfero-spb/gov_user/db/migrate/20151019174219_rename_tables_with_plugin_namespace.rb
0 → 100644
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +class RenameTablesWithPluginNamespace < ActiveRecord::Migration | ||
2 | + def change | ||
3 | + rename_table :institutions, :gov_user_plugin_institutions | ||
4 | + rename_table :governmental_spheres, :gov_user_plugin_governmental_spheres | ||
5 | + rename_table :governmental_powers, :gov_user_plugin_governmental_powers | ||
6 | + rename_table :juridical_natures, :gov_user_plugin_juridical_natures | ||
7 | + rename_table :institutions_users, :gov_user_plugin_institutions_users | ||
8 | + end | ||
9 | +end |
src/noosfero-spb/gov_user/features/institution_registration.feature
@@ -4,13 +4,9 @@ Feature: Institution Field | @@ -4,13 +4,9 @@ Feature: Institution Field | ||
4 | So others users can use it | 4 | So others users can use it |
5 | 5 | ||
6 | Background: | 6 | Background: |
7 | - Given "GovUserPlugin" plugin is enabled | 7 | + Given plugin GovUser is enabled on environment |
8 | And I am logged in as mpog_admin | 8 | And I am logged in as mpog_admin |
9 | - And I go to /admin/plugins | ||
10 | - And I check "GovUserPlugin" | ||
11 | - And I press "Save changes" | ||
12 | And Institutions has initial default values on database | 9 | And Institutions has initial default values on database |
13 | - And I am logged in as mpog_admin | ||
14 | 10 | ||
15 | @selenium | 11 | @selenium |
16 | Scenario: Show new institution fields when clicked in create new institution | 12 | Scenario: Show new institution fields when clicked in create new institution |
src/noosfero-spb/gov_user/features/step_definitions/gov_user_steps.rb
0 → 100644
@@ -0,0 +1,90 @@ | @@ -0,0 +1,90 @@ | ||
1 | +Given /^Institutions has initial default values on database$/ do | ||
2 | + GovUserPlugin::GovernmentalPower.create(:name => "Executivo") | ||
3 | + GovUserPlugin::GovernmentalPower.create(:name => "Legislativo") | ||
4 | + GovUserPlugin::GovernmentalPower.create(:name => "Judiciario") | ||
5 | + | ||
6 | + GovUserPlugin::GovernmentalSphere.create(:name => "Federal") | ||
7 | + | ||
8 | + GovUserPlugin::JuridicalNature.create(:name => "Autarquia") | ||
9 | + GovUserPlugin::JuridicalNature.create(:name => "Administracao Direta") | ||
10 | + GovUserPlugin::JuridicalNature.create(:name => "Empresa Publica") | ||
11 | + GovUserPlugin::JuridicalNature.create(:name => "Fundacao") | ||
12 | + GovUserPlugin::JuridicalNature.create(:name => "Orgao Autonomo") | ||
13 | + GovUserPlugin::JuridicalNature.create(:name => "Sociedade") | ||
14 | + GovUserPlugin::JuridicalNature.create(:name => "Sociedade Civil") | ||
15 | + GovUserPlugin::JuridicalNature.create(:name => "Sociedade de Economia Mista") | ||
16 | + | ||
17 | + national_region = NationalRegion.new | ||
18 | + national_region.name = "Distrito Federal" | ||
19 | + national_region.national_region_code = '35' | ||
20 | + national_region.national_region_type_id = NationalRegionType::STATE | ||
21 | + national_region.save | ||
22 | +end | ||
23 | + | ||
24 | +Given /^I type in "([^"]*)" in autocomplete list "([^"]*)" and I choose "([^"]*)"$/ do |typed, input_field_selector, should_select| | ||
25 | +# Wait the page javascript load | ||
26 | +sleep 1 | ||
27 | +# Basicaly it, search for the input field, type something, wait for ajax end select an item | ||
28 | +page.driver.browser.execute_script %Q{ | ||
29 | + var search_query = "#{input_field_selector}.ui-autocomplete-input"; | ||
30 | + var input = jQuery(search_query).first(); | ||
31 | + | ||
32 | + input.trigger('click'); | ||
33 | + input.val('#{typed}'); | ||
34 | + input.trigger('keydown'); | ||
35 | + | ||
36 | + window.setTimeout(function(){ | ||
37 | + search_query = ".ui-menu-item a:contains('#{should_select}')"; | ||
38 | + var typed = jQuery(search_query).first(); | ||
39 | + | ||
40 | + typed.trigger('mouseenter').trigger('click'); | ||
41 | + console.log(jQuery('#license_info_id')); | ||
42 | + }, 1000); | ||
43 | + } | ||
44 | + sleep 1 | ||
45 | +end | ||
46 | + | ||
47 | +Given /^the following public institutions?$/ do |table| | ||
48 | + # table is a Cucumber::Ast::Table | ||
49 | + table.hashes.each do |item| | ||
50 | + community = Community.new | ||
51 | + community.name = item[:name] | ||
52 | + community.country = item[:country] | ||
53 | + community.state = item[:state] | ||
54 | + community.city = item[:city] | ||
55 | + community.save! | ||
56 | + | ||
57 | + governmental_power = GovUserPlugin::GovernmentalPower.where(:name => item[:governmental_power]).first | ||
58 | + governmental_sphere = GovUserPlugin::GovernmentalSphere.where(:name => item[:governmental_sphere]).first | ||
59 | + | ||
60 | + juridical_nature = GovUserPlugin::JuridicalNature.create(:name => item[:juridical_nature]) | ||
61 | + | ||
62 | + 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) | ||
63 | + institution.community = community | ||
64 | + institution.corporate_name = item[:corporate_name] | ||
65 | + institution.save! | ||
66 | + end | ||
67 | +end | ||
68 | + | ||
69 | +Given /^I sleep for (\d+) seconds$/ do |time| | ||
70 | + sleep time.to_i | ||
71 | +end | ||
72 | + | ||
73 | +Given /^I am logged in as mpog_admin$/ do | ||
74 | + visit('/account/logout') | ||
75 | + | ||
76 | + user = User.new(:login => 'admin_user', :password => '123456', :password_confirmation => '123456', :email => 'admin_user@example.com') | ||
77 | + person = Person.new :name=>"Mpog Admin", :identifier=>"mpog-admin" | ||
78 | + user.person = person | ||
79 | + user.save! | ||
80 | + | ||
81 | + user.activate | ||
82 | + e = Environment.default | ||
83 | + e.add_admin(user.person) | ||
84 | + | ||
85 | + visit('/account/login') | ||
86 | + fill_in("Username", :with => user.login) | ||
87 | + fill_in("Password", :with => '123456') | ||
88 | + click_button("Log in") | ||
89 | +end | ||
90 | + |
src/noosfero-spb/gov_user/features/steps_definitions/gov_user_steps.rb
@@ -1,90 +0,0 @@ | @@ -1,90 +0,0 @@ | ||
1 | -Given /^Institutions has initial default values on database$/ do | ||
2 | - GovernmentalPower.create(:name => "Executivo") | ||
3 | - GovernmentalPower.create(:name => "Legislativo") | ||
4 | - GovernmentalPower.create(:name => "Judiciario") | ||
5 | - | ||
6 | - GovernmentalSphere.create(:name => "Federal") | ||
7 | - | ||
8 | - JuridicalNature.create(:name => "Autarquia") | ||
9 | - JuridicalNature.create(:name => "Administracao Direta") | ||
10 | - JuridicalNature.create(:name => "Empresa Publica") | ||
11 | - JuridicalNature.create(:name => "Fundacao") | ||
12 | - JuridicalNature.create(:name => "Orgao Autonomo") | ||
13 | - JuridicalNature.create(:name => "Sociedade") | ||
14 | - JuridicalNature.create(:name => "Sociedade Civil") | ||
15 | - JuridicalNature.create(:name => "Sociedade de Economia Mista") | ||
16 | - | ||
17 | - national_region = NationalRegion.new | ||
18 | - national_region.name = "Distrito Federal" | ||
19 | - national_region.national_region_code = '35' | ||
20 | - national_region.national_region_type_id = NationalRegionType::STATE | ||
21 | - national_region.save | ||
22 | -end | ||
23 | - | ||
24 | -Given /^I type in "([^"]*)" in autocomplete list "([^"]*)" and I choose "([^"]*)"$/ do |typed, input_field_selector, should_select| | ||
25 | -# Wait the page javascript load | ||
26 | -sleep 1 | ||
27 | -# Basicaly it, search for the input field, type something, wait for ajax end select an item | ||
28 | -page.driver.browser.execute_script %Q{ | ||
29 | - var search_query = "#{input_field_selector}.ui-autocomplete-input"; | ||
30 | - var input = jQuery(search_query).first(); | ||
31 | - | ||
32 | - input.trigger('click'); | ||
33 | - input.val('#{typed}'); | ||
34 | - input.trigger('keydown'); | ||
35 | - | ||
36 | - window.setTimeout(function(){ | ||
37 | - search_query = ".ui-menu-item a:contains('#{should_select}')"; | ||
38 | - var typed = jQuery(search_query).first(); | ||
39 | - | ||
40 | - typed.trigger('mouseenter').trigger('click'); | ||
41 | - console.log(jQuery('#license_info_id')); | ||
42 | - }, 1000); | ||
43 | - } | ||
44 | - sleep 1 | ||
45 | -end | ||
46 | - | ||
47 | -Given /^the following public institutions?$/ do |table| | ||
48 | - # table is a Cucumber::Ast::Table | ||
49 | - table.hashes.each do |item| | ||
50 | - community = Community.new | ||
51 | - community.name = item[:name] | ||
52 | - community.country = item[:country] | ||
53 | - community.state = item[:state] | ||
54 | - community.city = item[:city] | ||
55 | - community.save! | ||
56 | - | ||
57 | - governmental_power = GovernmentalPower.where(:name => item[:governmental_power]).first | ||
58 | - governmental_sphere = GovernmentalSphere.where(:name => item[:governmental_sphere]).first | ||
59 | - | ||
60 | - juridical_nature = JuridicalNature.create(:name => item[:juridical_nature]) | ||
61 | - | ||
62 | - 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) | ||
63 | - institution.community = community | ||
64 | - institution.corporate_name = item[:corporate_name] | ||
65 | - institution.save! | ||
66 | - end | ||
67 | -end | ||
68 | - | ||
69 | -Given /^I sleep for (\d+) seconds$/ do |time| | ||
70 | - sleep time.to_i | ||
71 | -end | ||
72 | - | ||
73 | -Given /^I am logged in as mpog_admin$/ do | ||
74 | - visit('/account/logout') | ||
75 | - | ||
76 | - user = User.new(:login => 'admin_user', :password => '123456', :password_confirmation => '123456', :email => 'admin_user@example.com') | ||
77 | - person = Person.new :name=>"Mpog Admin", :identifier=>"mpog-admin" | ||
78 | - user.person = person | ||
79 | - user.save! | ||
80 | - | ||
81 | - user.activate | ||
82 | - e = Environment.default | ||
83 | - e.add_admin(user.person) | ||
84 | - | ||
85 | - visit('/account/login') | ||
86 | - fill_in("Username", :with => user.login) | ||
87 | - fill_in("Password", :with => '123456') | ||
88 | - click_button("Log in") | ||
89 | -end | ||
90 | - |
src/noosfero-spb/gov_user/features/user_profile_edition.feature
@@ -4,14 +4,11 @@ Feature: Institution Field | @@ -4,14 +4,11 @@ Feature: Institution Field | ||
4 | So I can maintain my personal data updated | 4 | So I can maintain my personal data updated |
5 | 5 | ||
6 | Background: | 6 | Background: |
7 | - Given "GovUserPlugin" plugin is enabled | 7 | + Given plugin GovUser is enabled on environment |
8 | And the following users | 8 | And the following users |
9 | | login | name | | 9 | | login | name | |
10 | | joao | Joao Silva | | 10 | | joao | Joao Silva | |
11 | And I am logged in as admin | 11 | And I am logged in as admin |
12 | - And I go to /admin/plugins | ||
13 | - And I check "GovUserPlugin" | ||
14 | - And I press "Save changes" | ||
15 | And feature "skip_new_user_email_confirmation" is enabled on environment | 12 | And feature "skip_new_user_email_confirmation" is enabled on environment |
16 | And I go to /admin/features/manage_fields | 13 | And I go to /admin/features/manage_fields |
17 | And I check "person_fields_country_active" | 14 | And I check "person_fields_country_active" |
@@ -44,11 +41,8 @@ Feature: Institution Field | @@ -44,11 +41,8 @@ Feature: Institution Field | ||
44 | Given I am logged in as "joao" | 41 | Given I am logged in as "joao" |
45 | And I am on joao's control panel | 42 | And I am on joao's control panel |
46 | When I follow "Edit Profile" | 43 | When I follow "Edit Profile" |
47 | - And I follow "Add new institution" | ||
48 | And I type in "Minis" in autocomplete list "#input_institution" and I choose "Ministerio do Planejamento" | 44 | And I type in "Minis" in autocomplete list "#input_institution" and I choose "Ministerio do Planejamento" |
49 | - And I follow "Add new institution" | ||
50 | And I type in "Gover" in autocomplete list "#input_institution" and I choose "Governo do DF" | 45 | And I type in "Gover" in autocomplete list "#input_institution" and I choose "Governo do DF" |
51 | - And I follow "Add new institution" | ||
52 | Then I should see "Ministerio do Planejamento" within ".institutions_added" | 46 | Then I should see "Ministerio do Planejamento" within ".institutions_added" |
53 | And I should see "Governo do DF" within ".institutions_added" | 47 | And I should see "Governo do DF" within ".institutions_added" |
54 | 48 |
src/noosfero-spb/gov_user/lib/ext/community.rb
1 | require_dependency 'community' | 1 | require_dependency 'community' |
2 | 2 | ||
3 | class Community | 3 | class Community |
4 | - has_one :institution, :dependent=>:destroy | 4 | + has_one :institution, :class_name => 'GovUserPlugin::Institution', :dependent=>:destroy |
5 | 5 | ||
6 | def institution? | 6 | def institution? |
7 | return !institution.nil? | 7 | return !institution.nil? |
src/noosfero-spb/gov_user/lib/ext/organization_rating.rb
@@ -2,7 +2,7 @@ require_dependency "organization_rating" | @@ -2,7 +2,7 @@ require_dependency "organization_rating" | ||
2 | 2 | ||
3 | OrganizationRating.class_eval do | 3 | OrganizationRating.class_eval do |
4 | 4 | ||
5 | - belongs_to :institution | 5 | + belongs_to :institution, :class_name => 'GovUserPlugin::Institution' |
6 | 6 | ||
7 | attr_accessible :institution, :institution_id | 7 | attr_accessible :institution, :institution_id |
8 | 8 | ||
@@ -12,7 +12,7 @@ OrganizationRating.class_eval do | @@ -12,7 +12,7 @@ OrganizationRating.class_eval do | ||
12 | 12 | ||
13 | def verify_institution | 13 | def verify_institution |
14 | if self.institution != nil | 14 | if self.institution != nil |
15 | - institution = Institution.find_by_id self.institution.id | 15 | + institution = GovUserPlugin::Institution.find_by_id self.institution.id |
16 | self.errors.add :institution, _("not found") unless institution | 16 | self.errors.add :institution, _("not found") unless institution |
17 | end | 17 | end |
18 | end | 18 | end |
src/noosfero-spb/gov_user/lib/ext/search_controller.rb
@@ -14,7 +14,9 @@ class SearchController | @@ -14,7 +14,9 @@ class SearchController | ||
14 | end | 14 | end |
15 | 15 | ||
16 | def institutions | 16 | def institutions |
17 | - @titles[:institutions] = _("Institution Catalog") | 17 | + @asset = "gov_user_plugin/institutions" |
18 | + @assets = [@asset] | ||
19 | + @titles["gov_user_plugin/institutions"] = _("Institution Catalog") | ||
18 | results = filter_communities_list{|community| community.institution?} | 20 | results = filter_communities_list{|community| community.institution?} |
19 | results = results.paginate(:per_page => 24, :page => params[:page]) | 21 | results = results.paginate(:per_page => 24, :page => params[:page]) |
20 | @searches[@asset] = {:results => results} | 22 | @searches[@asset] = {:results => results} |
src/noosfero-spb/gov_user/lib/ext/search_helper.rb
@@ -3,6 +3,6 @@ require_dependency 'search_helper' | @@ -3,6 +3,6 @@ require_dependency 'search_helper' | ||
3 | module SearchHelper | 3 | module SearchHelper |
4 | 4 | ||
5 | COMMON_PROFILE_LIST_BLOCK ||= [] | 5 | COMMON_PROFILE_LIST_BLOCK ||= [] |
6 | - COMMON_PROFILE_LIST_BLOCK << :institutions | 6 | + COMMON_PROFILE_LIST_BLOCK << "gov_user_plugin/institution" |
7 | 7 | ||
8 | end | 8 | end |
src/noosfero-spb/gov_user/lib/ext/user.rb
@@ -4,7 +4,7 @@ class User | @@ -4,7 +4,7 @@ class User | ||
4 | 4 | ||
5 | GOV_SUFFIX = /^.*@[gov.br|jus.br|leg.br|mp.br]+$/ | 5 | GOV_SUFFIX = /^.*@[gov.br|jus.br|leg.br|mp.br]+$/ |
6 | 6 | ||
7 | - has_and_belongs_to_many :institutions | 7 | + has_and_belongs_to_many :institutions, :class_name => 'GovUserPlugin::Institution', :join_table => 'gov_user_plugin_institutions_users' |
8 | 8 | ||
9 | validate :email_different_secondary?, :email_has_already_been_used?, | 9 | validate :email_different_secondary?, :email_has_already_been_used?, |
10 | :secondary_email_format | 10 | :secondary_email_format |
src/noosfero-spb/gov_user/lib/gov_user_plugin.rb
@@ -86,7 +86,7 @@ class GovUserPlugin < Noosfero::Plugin | @@ -86,7 +86,7 @@ class GovUserPlugin < Noosfero::Plugin | ||
86 | 86 | ||
87 | def self.extra_blocks | 87 | def self.extra_blocks |
88 | { | 88 | { |
89 | - InstitutionsBlock => { :type => [Environment, Person] } | 89 | + GovUserPlugin::InstitutionsBlock => { :type => [Environment, Person] } |
90 | } | 90 | } |
91 | end | 91 | end |
92 | 92 | ||
@@ -223,7 +223,7 @@ class GovUserPlugin < Noosfero::Plugin | @@ -223,7 +223,7 @@ class GovUserPlugin < Noosfero::Plugin | ||
223 | end | 223 | end |
224 | 224 | ||
225 | if context.params.has_key?(:institution) | 225 | if context.params.has_key?(:institution) |
226 | - Institution.transaction do | 226 | + GovUserPlugin::Institution.transaction do |
227 | context.profile. | 227 | context.profile. |
228 | institution. | 228 | institution. |
229 | update_attributes!(context.params[:institution]) | 229 | update_attributes!(context.params[:institution]) |
@@ -277,7 +277,7 @@ class GovUserPlugin < Noosfero::Plugin | @@ -277,7 +277,7 @@ class GovUserPlugin < Noosfero::Plugin | ||
277 | context.params[:user][:institution_ids].delete('') | 277 | context.params[:user][:institution_ids].delete('') |
278 | 278 | ||
279 | context.params[:user][:institution_ids].each do |id| | 279 | context.params[:user][:institution_ids].each do |id| |
280 | - new_communities << Institution.find(id).community | 280 | + new_communities << GovUserPlugin::Institution.find(id).community |
281 | end | 281 | end |
282 | end | 282 | end |
283 | 283 | ||
@@ -320,7 +320,7 @@ class GovUserPlugin < Noosfero::Plugin | @@ -320,7 +320,7 @@ class GovUserPlugin < Noosfero::Plugin | ||
320 | 320 | ||
321 | def update_user_institutions(user) | 321 | def update_user_institutions(user) |
322 | context.params[:user][:institution_ids].each do |institution_id| | 322 | context.params[:user][:institution_ids].each do |institution_id| |
323 | - institution = Institution.find institution_id | 323 | + institution = GovUserPlugin::Institution.find institution_id |
324 | user.institutions << institution | 324 | user.institutions << institution |
325 | 325 | ||
326 | if institution.community.admins.blank? | 326 | if institution.community.admins.blank? |
src/noosfero-spb/gov_user/lib/gov_user_plugin/governmental_power.rb
0 → 100644
src/noosfero-spb/gov_user/lib/gov_user_plugin/governmental_sphere.rb
0 → 100644
src/noosfero-spb/gov_user/lib/gov_user_plugin/institution.rb
0 → 100644
@@ -0,0 +1,109 @@ | @@ -0,0 +1,109 @@ | ||
1 | +class GovUserPlugin::Institution < Noosfero::Plugin::ActiveRecord | ||
2 | + has_many :comments | ||
3 | + | ||
4 | + SEARCH_FILTERS = { | ||
5 | + :order => %w[], | ||
6 | + :display => %w[compact] | ||
7 | + } | ||
8 | + | ||
9 | + def self.default_search_display | ||
10 | + 'compact' | ||
11 | + end | ||
12 | + | ||
13 | + belongs_to :governmental_power, :class_name => 'GovUserPlugin::GovernmentalPower' | ||
14 | + belongs_to :governmental_sphere, :class_name => 'GovUserPlugin::GovernmentalSphere' | ||
15 | + belongs_to :juridical_nature, :class_name => 'GovUserPlugin::JuridicalNature' | ||
16 | + | ||
17 | + has_and_belongs_to_many :users, :join_table => 'gov_user_plugin_institutions_users' | ||
18 | + | ||
19 | + attr_accessible :name, :acronym, :unit_code, :parent_code, :unit_type, | ||
20 | + :sub_juridical_nature, :normalization_level, | ||
21 | + :version, :cnpj, :type, :governmental_power, | ||
22 | + :governmental_sphere, :sisp, :juridical_nature, | ||
23 | + :corporate_name, :siorg_code, :community | ||
24 | + | ||
25 | + validates :name, :presence=>true, :uniqueness=>true | ||
26 | + | ||
27 | + before_save :verify_institution_type | ||
28 | + | ||
29 | + belongs_to :community | ||
30 | + | ||
31 | + scope :public, :conditions => { :type => "GovUserPlugin::PublicInstitution" } | ||
32 | + scope :private, :conditions => { :type => "GovUserPlugin::PrivateInstitution" } | ||
33 | + scope :search_institution, lambda{ |value| | ||
34 | + where("name ilike ? OR acronym ilike ?", "%#{value}%", "%#{value}%" ) | ||
35 | + } | ||
36 | + | ||
37 | + validate :validate_country, :validate_state, :validate_city, | ||
38 | + :verify_institution_type, :validate_format_cnpj | ||
39 | + | ||
40 | + | ||
41 | + protected | ||
42 | + | ||
43 | + def verify_institution_type | ||
44 | + valid_institutions_type = ["GovUserPlugin::PublicInstitution", "GovUserPlugin::PrivateInstitution"] | ||
45 | + | ||
46 | + unless valid_institutions_type.include? self.type | ||
47 | + self.errors.add( | ||
48 | + :type, | ||
49 | + _("invalid, only public and private institutions are allowed.") | ||
50 | + ) | ||
51 | + | ||
52 | + return false | ||
53 | + end | ||
54 | + | ||
55 | + return true | ||
56 | + end | ||
57 | + | ||
58 | + def validate_country | ||
59 | + unless self.community.blank? | ||
60 | + if self.community.country.blank? && self.errors[:country].blank? | ||
61 | + self.errors.add(:country, _("can't be blank")) | ||
62 | + return false | ||
63 | + end | ||
64 | + end | ||
65 | + | ||
66 | + return true | ||
67 | + end | ||
68 | + | ||
69 | + def validate_state | ||
70 | + unless self.community.blank? | ||
71 | + if self.community.country == "BR" && | ||
72 | + (self.community.state.blank? || self.community.state == "-1") && | ||
73 | + self.errors[:state].blank? | ||
74 | + | ||
75 | + self.errors.add(:state, _("can't be blank")) | ||
76 | + return false | ||
77 | + end | ||
78 | + end | ||
79 | + | ||
80 | + return true | ||
81 | + end | ||
82 | + | ||
83 | + def validate_city | ||
84 | + unless self.community.blank? | ||
85 | + if self.community.country == "BR" && self.community.city.blank? && | ||
86 | + self.errors[:city].blank? | ||
87 | + | ||
88 | + self.errors.add(:city, _("can't be blank")) | ||
89 | + return false | ||
90 | + end | ||
91 | + end | ||
92 | + | ||
93 | + return true | ||
94 | + end | ||
95 | + | ||
96 | + def validate_format_cnpj | ||
97 | + return true if self.community.blank? && self.community.country != "BR" | ||
98 | + return true if self.cnpj.blank? | ||
99 | + | ||
100 | + format = /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/ | ||
101 | + | ||
102 | + if !self.cnpj.blank? && format.match(self.cnpj) | ||
103 | + return true | ||
104 | + else | ||
105 | + self.errors.add(:cnpj, _("invalid format")) | ||
106 | + return false | ||
107 | + end | ||
108 | + end | ||
109 | +end |
src/noosfero-spb/gov_user/lib/gov_user_plugin/institutions_block.rb
0 → 100644
@@ -0,0 +1,70 @@ | @@ -0,0 +1,70 @@ | ||
1 | +class GovUserPlugin::InstitutionsBlock < CommunitiesBlock | ||
2 | + def self.description | ||
3 | + _('Institutions') | ||
4 | + end | ||
5 | + | ||
6 | + def profile_count | ||
7 | + profile_list.count | ||
8 | + end | ||
9 | + | ||
10 | + def default_title | ||
11 | + n_('{#} institution', '{#} institutions', profile_count) | ||
12 | + end | ||
13 | + | ||
14 | + def help | ||
15 | + _('This block displays the institutions in which the user is a member.') | ||
16 | + end | ||
17 | + | ||
18 | + def footer | ||
19 | + owner = self.owner | ||
20 | + case owner | ||
21 | + when Profile | ||
22 | + lambda do |context| | ||
23 | + link_to s_('institutions|View all'), :profile => owner.identifier, | ||
24 | + :controller => 'profile', :action => 'communities', | ||
25 | + :type => 'GovUserPlugin::Institution' | ||
26 | + end | ||
27 | + when Environment | ||
28 | + lambda do |context| | ||
29 | + link_to s_('institutions|View all'), :controller => 'search', | ||
30 | + :action => 'communities', :type => 'GovUserPlugin::Institution' | ||
31 | + end | ||
32 | + else | ||
33 | + '' | ||
34 | + end | ||
35 | + end | ||
36 | + | ||
37 | + def profile_list | ||
38 | + result = get_visible_profiles | ||
39 | + | ||
40 | + result = result.select { |p| p.class == Community && p.institution? } | ||
41 | + | ||
42 | + result.slice(0..get_limit-1) | ||
43 | + end | ||
44 | + | ||
45 | + def profiles | ||
46 | + owner.communities | ||
47 | + end | ||
48 | + | ||
49 | + private | ||
50 | + | ||
51 | + def get_visible_profiles | ||
52 | + include_list = [:image,:domains,:preferred_domain,:environment] | ||
53 | + visible_profiles = profiles.visible.includes(include_list) | ||
54 | + | ||
55 | + if !prioritize_profiles_with_image | ||
56 | + visible_profiles.all(:limit => get_limit, | ||
57 | + :order => 'profiles.updated_at DESC' | ||
58 | + ).sort_by{ rand } | ||
59 | + elsif profiles.visible.with_image.count >= get_limit | ||
60 | + visible_profiles.with_image.all(:limit => get_limit * 5, | ||
61 | + :order => 'profiles.updated_at DESC' | ||
62 | + ).sort_by{ rand } | ||
63 | + else | ||
64 | + visible_profiles.with_image.sort_by{ rand } + | ||
65 | + visible_profiles.without_image.all(:limit => get_limit * 5, | ||
66 | + :order => 'profiles.updated_at DESC' | ||
67 | + ).sort_by{ rand } | ||
68 | + end | ||
69 | + end | ||
70 | +end |
src/noosfero-spb/gov_user/lib/gov_user_plugin/institutions_users.rb
0 → 100644
src/noosfero-spb/gov_user/lib/gov_user_plugin/juridical_nature.rb
0 → 100644
@@ -0,0 +1,10 @@ | @@ -0,0 +1,10 @@ | ||
1 | +class GovUserPlugin::JuridicalNature < Noosfero::Plugin::ActiveRecord | ||
2 | + self.record_timestamps = false | ||
3 | + | ||
4 | + attr_accessible :name | ||
5 | + | ||
6 | + has_many :institutions, :class_name => 'GovUserPlugin::Institution' | ||
7 | + | ||
8 | + validates_presence_of :name | ||
9 | + validates_uniqueness_of :name | ||
10 | +end |
src/noosfero-spb/gov_user/lib/gov_user_plugin/private_institution.rb
0 → 100644
src/noosfero-spb/gov_user/lib/gov_user_plugin/public_institution.rb
0 → 100644
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +class GovUserPlugin::PublicInstitution < GovUserPlugin::Institution | ||
2 | + validates :governmental_power, :governmental_sphere, :juridical_nature, | ||
3 | + :presence=>true | ||
4 | + | ||
5 | + validates :acronym, :allow_blank => true, :allow_nil => true, | ||
6 | + :uniqueness=>true | ||
7 | + | ||
8 | + validates_format_of( | ||
9 | + :cnpj, | ||
10 | + :with => /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/, | ||
11 | + :allow_nil => true, :allow_blank => true | ||
12 | + ) | ||
13 | +end |
src/noosfero-spb/gov_user/lib/governmental_power.rb
@@ -1,13 +0,0 @@ | @@ -1,13 +0,0 @@ | ||
1 | -class GovernmentalPower < ActiveRecord::Base | ||
2 | - attr_accessible :name | ||
3 | - | ||
4 | - validates :name, :presence=>true, :uniqueness=>true | ||
5 | - has_many :institutions | ||
6 | - | ||
7 | - def public_institutions | ||
8 | - Institution.where( | ||
9 | - :type=>"PublicInstitution", | ||
10 | - :governmental_power_id=>self.id | ||
11 | - ) | ||
12 | - end | ||
13 | -end |
src/noosfero-spb/gov_user/lib/governmental_sphere.rb
src/noosfero-spb/gov_user/lib/institution.rb
@@ -1,107 +0,0 @@ | @@ -1,107 +0,0 @@ | ||
1 | -class Institution < ActiveRecord::Base | ||
2 | - has_many :comments | ||
3 | - | ||
4 | - SEARCH_FILTERS = { | ||
5 | - :order => %w[], | ||
6 | - :display => %w[compact] | ||
7 | - } | ||
8 | - | ||
9 | - def self.default_search_display | ||
10 | - 'compact' | ||
11 | - end | ||
12 | - | ||
13 | - belongs_to :governmental_power | ||
14 | - belongs_to :governmental_sphere | ||
15 | - belongs_to :juridical_nature | ||
16 | - | ||
17 | - has_and_belongs_to_many :users | ||
18 | - | ||
19 | - attr_accessible :name, :acronym, :unit_code, :parent_code, :unit_type, | ||
20 | - :sub_juridical_nature, :normalization_level, | ||
21 | - :version, :cnpj, :type, :governmental_power, | ||
22 | - :governmental_sphere, :sisp, :juridical_nature, | ||
23 | - :corporate_name, :siorg_code, :community | ||
24 | - | ||
25 | - validates :name, :presence=>true, :uniqueness=>true | ||
26 | - | ||
27 | - before_save :verify_institution_type | ||
28 | - | ||
29 | - belongs_to :community | ||
30 | - | ||
31 | - scope :search_institution, lambda{ |value| | ||
32 | - where("name ilike ? OR acronym ilike ?", "%#{value}%", "%#{value}%" ) | ||
33 | - } | ||
34 | - | ||
35 | - validate :validate_country, :validate_state, :validate_city, | ||
36 | - :verify_institution_type, :validate_format_cnpj | ||
37 | - | ||
38 | - | ||
39 | - protected | ||
40 | - | ||
41 | - def verify_institution_type | ||
42 | - valid_institutions_type = ["PublicInstitution", "PrivateInstitution"] | ||
43 | - | ||
44 | - unless valid_institutions_type.include? self.type | ||
45 | - self.errors.add( | ||
46 | - :type, | ||
47 | - _("invalid, only public and private institutions are allowed.") | ||
48 | - ) | ||
49 | - | ||
50 | - return false | ||
51 | - end | ||
52 | - | ||
53 | - return true | ||
54 | - end | ||
55 | - | ||
56 | - def validate_country | ||
57 | - unless self.community.blank? | ||
58 | - if self.community.country.blank? && self.errors[:country].blank? | ||
59 | - self.errors.add(:country, _("can't be blank")) | ||
60 | - return false | ||
61 | - end | ||
62 | - end | ||
63 | - | ||
64 | - return true | ||
65 | - end | ||
66 | - | ||
67 | - def validate_state | ||
68 | - unless self.community.blank? | ||
69 | - if self.community.country == "BR" && | ||
70 | - (self.community.state.blank? || self.community.state == "-1") && | ||
71 | - self.errors[:state].blank? | ||
72 | - | ||
73 | - self.errors.add(:state, _("can't be blank")) | ||
74 | - return false | ||
75 | - end | ||
76 | - end | ||
77 | - | ||
78 | - return true | ||
79 | - end | ||
80 | - | ||
81 | - def validate_city | ||
82 | - unless self.community.blank? | ||
83 | - if self.community.country == "BR" && self.community.city.blank? && | ||
84 | - self.errors[:city].blank? | ||
85 | - | ||
86 | - self.errors.add(:city, _("can't be blank")) | ||
87 | - return false | ||
88 | - end | ||
89 | - end | ||
90 | - | ||
91 | - return true | ||
92 | - end | ||
93 | - | ||
94 | - def validate_format_cnpj | ||
95 | - return true if self.community.blank? && self.community.country != "BR" | ||
96 | - return true if self.cnpj.blank? | ||
97 | - | ||
98 | - format = /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/ | ||
99 | - | ||
100 | - if !self.cnpj.blank? && format.match(self.cnpj) | ||
101 | - return true | ||
102 | - else | ||
103 | - self.errors.add(:cnpj, _("invalid format")) | ||
104 | - return false | ||
105 | - end | ||
106 | - end | ||
107 | -end |
src/noosfero-spb/gov_user/lib/institutions_block.rb
@@ -1,71 +0,0 @@ | @@ -1,71 +0,0 @@ | ||
1 | -class InstitutionsBlock < CommunitiesBlock | ||
2 | - | ||
3 | - def self.description | ||
4 | - _('Institutions') | ||
5 | - end | ||
6 | - | ||
7 | - def profile_count | ||
8 | - profile_list.count | ||
9 | - end | ||
10 | - | ||
11 | - def default_title | ||
12 | - n_('{#} institution', '{#} institutions', profile_count) | ||
13 | - end | ||
14 | - | ||
15 | - def help | ||
16 | - _('This block displays the institutions in which the user is a member.') | ||
17 | - end | ||
18 | - | ||
19 | - def footer | ||
20 | - owner = self.owner | ||
21 | - case owner | ||
22 | - when Profile | ||
23 | - lambda do |context| | ||
24 | - link_to s_('institutions|View all'), :profile => owner.identifier, | ||
25 | - :controller => 'profile', :action => 'communities', | ||
26 | - :type => 'Institution' | ||
27 | - end | ||
28 | - when Environment | ||
29 | - lambda do |context| | ||
30 | - link_to s_('institutions|View all'), :controller => 'search', | ||
31 | - :action => 'communities', :type => 'Institution' | ||
32 | - end | ||
33 | - else | ||
34 | - '' | ||
35 | - end | ||
36 | - end | ||
37 | - | ||
38 | - def profile_list | ||
39 | - result = get_visible_profiles | ||
40 | - | ||
41 | - result = result.select { |p| p.class == Community && p.institution? } | ||
42 | - | ||
43 | - result.slice(0..get_limit-1) | ||
44 | - end | ||
45 | - | ||
46 | - def profiles | ||
47 | - owner.communities | ||
48 | - end | ||
49 | - | ||
50 | - private | ||
51 | - | ||
52 | - def get_visible_profiles | ||
53 | - include_list = [:image,:domains,:preferred_domain,:environment] | ||
54 | - visible_profiles = profiles.visible.includes(include_list) | ||
55 | - | ||
56 | - if !prioritize_profiles_with_image | ||
57 | - visible_profiles.all(:limit => get_limit, | ||
58 | - :order => 'profiles.updated_at DESC' | ||
59 | - ).sort_by{ rand } | ||
60 | - elsif profiles.visible.with_image.count >= get_limit | ||
61 | - visible_profiles.with_image.all(:limit => get_limit * 5, | ||
62 | - :order => 'profiles.updated_at DESC' | ||
63 | - ).sort_by{ rand } | ||
64 | - else | ||
65 | - visible_profiles.with_image.sort_by{ rand } + | ||
66 | - visible_profiles.without_image.all(:limit => get_limit * 5, | ||
67 | - :order => 'profiles.updated_at DESC' | ||
68 | - ).sort_by{ rand } | ||
69 | - end | ||
70 | - end | ||
71 | -end |
src/noosfero-spb/gov_user/lib/institutions_users.rb
src/noosfero-spb/gov_user/lib/juridical_nature.rb
@@ -1,15 +0,0 @@ | @@ -1,15 +0,0 @@ | ||
1 | -class JuridicalNature < ActiveRecord::Base | ||
2 | - attr_accessible :name | ||
3 | - | ||
4 | - has_many :institutions | ||
5 | - | ||
6 | - validates_presence_of :name | ||
7 | - validates_uniqueness_of :name | ||
8 | - | ||
9 | - def public_institutions | ||
10 | - Institution.where( | ||
11 | - :type=>"PublicInstitution", | ||
12 | - :juridical_nature_id=>self.id | ||
13 | - ) | ||
14 | - end | ||
15 | -end |
src/noosfero-spb/gov_user/lib/private_institution.rb
src/noosfero-spb/gov_user/lib/public_institution.rb
@@ -1,13 +0,0 @@ | @@ -1,13 +0,0 @@ | ||
1 | -class PublicInstitution < Institution | ||
2 | - validates :governmental_power, :governmental_sphere, :juridical_nature, | ||
3 | - :presence=>true | ||
4 | - | ||
5 | - validates :acronym, :allow_blank => true, :allow_nil => true, | ||
6 | - :uniqueness=>true | ||
7 | - | ||
8 | - validates_format_of( | ||
9 | - :cnpj, | ||
10 | - :with => /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/, | ||
11 | - :allow_nil => true, :allow_blank => true | ||
12 | - ) | ||
13 | -end |
src/noosfero-spb/gov_user/public/views/create-institution.js
@@ -300,7 +300,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | @@ -300,7 +300,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | ||
300 | 300 | ||
301 | function institution_type_actions(type) { | 301 | function institution_type_actions(type) { |
302 | var country = $("#community_country").val(); | 302 | var country = $("#community_country").val(); |
303 | - if( type === "PublicInstitution" && country == "BR") { | 303 | + if( type === "GovUserPlugin::PublicInstitution" && country == "BR") { |
304 | show_public_institutions_fields(); | 304 | show_public_institutions_fields(); |
305 | } else { | 305 | } else { |
306 | show_private_institutions_fields(); | 306 | show_private_institutions_fields(); |
src/noosfero-spb/gov_user/test/functional/gov_user_plugin_controller_test.rb
@@ -16,9 +16,9 @@ class GovUserPluginControllerTest < ActionController::TestCase | @@ -16,9 +16,9 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
16 | @environment.add_admin(@admin) | 16 | @environment.add_admin(@admin) |
17 | @environment.save | 17 | @environment.save |
18 | 18 | ||
19 | - @gov_power = GovernmentalPower.create(:name=>"Some Gov Power") | ||
20 | - @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
21 | - @juridical_nature = JuridicalNature.create(:name => "Autarquia") | 19 | + @gov_power = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power") |
20 | + @gov_sphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
21 | + @juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia") | ||
22 | @response = ActionController::TestResponse.new | 22 | @response = ActionController::TestResponse.new |
23 | 23 | ||
24 | @institution_list = [] | 24 | @institution_list = [] |
@@ -87,7 +87,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | @@ -87,7 +87,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
87 | "DF", | 87 | "DF", |
88 | "Brasilia", | 88 | "Brasilia", |
89 | "12.234.567/8900-10", | 89 | "12.234.567/8900-10", |
90 | - "PublicInstitution" | 90 | + "GovUserPlugin::PublicInstitution" |
91 | ) | 91 | ) |
92 | fields[:institutions][:governmental_power] = @gov_power.id | 92 | fields[:institutions][:governmental_power] = @gov_power.id |
93 | fields[:institutions][:governmental_sphere] = @gov_sphere.id | 93 | fields[:institutions][:governmental_sphere] = @gov_sphere.id |
@@ -109,7 +109,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | @@ -109,7 +109,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
109 | "DF", | 109 | "DF", |
110 | "Brasilia", | 110 | "Brasilia", |
111 | "", | 111 | "", |
112 | - "PrivateInstitution" | 112 | + "GovUserPlugin::PrivateInstitution" |
113 | ) | 113 | ) |
114 | fields[:institutions][:acronym] = "SPI" | 114 | fields[:institutions][:acronym] = "SPI" |
115 | 115 | ||
@@ -147,7 +147,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | @@ -147,7 +147,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
147 | "DF", | 147 | "DF", |
148 | "Brasilia", | 148 | "Brasilia", |
149 | "12.345.567/8900-10", | 149 | "12.345.567/8900-10", |
150 | - "PrivateInstitution" | 150 | + "GovUserPlugin::PrivateInstitution" |
151 | ) | 151 | ) |
152 | fields[:institutions][:acronym] = "SPI" | 152 | fields[:institutions][:acronym] = "SPI" |
153 | 153 | ||
@@ -165,7 +165,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | @@ -165,7 +165,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
165 | "DF", | 165 | "DF", |
166 | "Brasilia", | 166 | "Brasilia", |
167 | "56.366.790/0001-88", | 167 | "56.366.790/0001-88", |
168 | - "PrivateInstitution" | 168 | + "GovUserPlugin::PrivateInstitution" |
169 | ) | 169 | ) |
170 | 170 | ||
171 | post :new_institution, fields | 171 | post :new_institution, fields |
@@ -182,7 +182,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | @@ -182,7 +182,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
182 | "", | 182 | "", |
183 | "", | 183 | "", |
184 | "", | 184 | "", |
185 | - "PrivateInstitution" | 185 | + "GovUserPlugin::PrivateInstitution" |
186 | ) | 186 | ) |
187 | fields[:institutions][:acronym] = "FI" | 187 | fields[:institutions][:acronym] = "FI" |
188 | 188 | ||
@@ -200,7 +200,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | @@ -200,7 +200,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
200 | "", | 200 | "", |
201 | "", | 201 | "", |
202 | "", | 202 | "", |
203 | - "PrivateInstitution" | 203 | + "GovUserPlugin::PrivateInstitution" |
204 | ) | 204 | ) |
205 | fields[:institutions][:acronym] = "FI" | 205 | fields[:institutions][:acronym] = "FI" |
206 | 206 | ||
@@ -224,13 +224,13 @@ class GovUserPluginControllerTest < ActionController::TestCase | @@ -224,13 +224,13 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
224 | "DF", | 224 | "DF", |
225 | "Brasilia", | 225 | "Brasilia", |
226 | "12.323.557/8900-10", | 226 | "12.323.557/8900-10", |
227 | - "PrivateInstitution" | 227 | + "GovUserPlugin::PrivateInstitution" |
228 | ) | 228 | ) |
229 | fields[:institutions][:acronym] = "PI" | 229 | fields[:institutions][:acronym] = "PI" |
230 | fields[:edit_institution_page] = false | 230 | fields[:edit_institution_page] = false |
231 | post :new_institution, fields | 231 | post :new_institution, fields |
232 | 232 | ||
233 | - assert(Institution.last.community.admins.include?(admin2) ) | 233 | + assert(GovUserPlugin::Institution.last.community.admins.include?(admin2) ) |
234 | end | 234 | end |
235 | 235 | ||
236 | end | 236 | end |
src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb
@@ -24,9 +24,9 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase | @@ -24,9 +24,9 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase | ||
24 | @environment.save! | 24 | @environment.save! |
25 | end | 25 | end |
26 | should "user edit its community institution" do | 26 | should "user edit its community institution" do |
27 | - govPower = GovernmentalPower.create(:name=>"Some Gov Power") | ||
28 | - govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
29 | - juridical_nature = JuridicalNature.create(:name => "Autarquia") | 27 | + govPower = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power") |
28 | + govSphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
29 | + juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia") | ||
30 | 30 | ||
31 | institution = InstitutionTestHelper.create_public_institution( | 31 | institution = InstitutionTestHelper.create_public_institution( |
32 | "Ministerio Publico da Uniao", | 32 | "Ministerio Publico da Uniao", |
@@ -48,7 +48,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase | @@ -48,7 +48,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase | ||
48 | "DF", | 48 | "DF", |
49 | "Gama", | 49 | "Gama", |
50 | "12.345.678/9012-45", | 50 | "12.345.678/9012-45", |
51 | - "PrivateInstitution" | 51 | + "GovUserPlugin::PrivateInstitution" |
52 | ) | 52 | ) |
53 | 53 | ||
54 | post( | 54 | post( |
@@ -63,9 +63,9 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase | @@ -63,9 +63,9 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase | ||
63 | end | 63 | end |
64 | 64 | ||
65 | should "not user edit its community institution with wrong values" do | 65 | should "not user edit its community institution with wrong values" do |
66 | - govPower = GovernmentalPower.create(:name=>"Some Gov Power") | ||
67 | - govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
68 | - juridical_nature = JuridicalNature.create(:name => "Autarquia") | 66 | + govPower = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power") |
67 | + govSphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
68 | + juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia") | ||
69 | 69 | ||
70 | institution = InstitutionTestHelper.create_public_institution( | 70 | institution = InstitutionTestHelper.create_public_institution( |
71 | "Ministerio Publico da Uniao", | 71 | "Ministerio Publico da Uniao", |
@@ -87,7 +87,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase | @@ -87,7 +87,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase | ||
87 | "DF", | 87 | "DF", |
88 | "Gama", | 88 | "Gama", |
89 | "6465465465", | 89 | "6465465465", |
90 | - "PrivateInstitution" | 90 | + "GovUserPlugin::PrivateInstitution" |
91 | ) | 91 | ) |
92 | 92 | ||
93 | post( | 93 | post( |
src/noosfero-spb/gov_user/test/functional/profile_editor_controller_test.rb
@@ -29,9 +29,9 @@ class ProfileEditorControllerTest < ActionController::TestCase | @@ -29,9 +29,9 @@ class ProfileEditorControllerTest < ActionController::TestCase | ||
29 | @environment.add_admin(admin) | 29 | @environment.add_admin(admin) |
30 | @environment.save | 30 | @environment.save |
31 | 31 | ||
32 | - @govPower = GovernmentalPower.create(:name=>"Some Gov Power") | ||
33 | - @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
34 | - @juridical_nature = JuridicalNature.create(:name => "Autarquia") | 32 | + @govPower = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power") |
33 | + @govSphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
34 | + @juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia") | ||
35 | 35 | ||
36 | @institution_list = [] | 36 | @institution_list = [] |
37 | @institution_list << InstitutionTestHelper.create_public_institution( | 37 | @institution_list << InstitutionTestHelper.create_public_institution( |
src/noosfero-spb/gov_user/test/functional/search_controller_test.rb
@@ -51,7 +51,7 @@ class SearchControllerTest < ActionController::TestCase | @@ -51,7 +51,7 @@ class SearchControllerTest < ActionController::TestCase | ||
51 | 51 | ||
52 | get :institutions, :query => "New" | 52 | get :institutions, :query => "New" |
53 | 53 | ||
54 | - assert_includes assigns(:searches)[:institutions][:results], institution.community | ||
55 | - assert_not_includes assigns(:searches)[:institutions][:results], community | 54 | + assert_includes assigns(:searches)["gov_user_plugin/institutions"][:results], institution.community |
55 | + assert_not_includes assigns(:searches)["gov_user_plugin/institutions"][:results], community | ||
56 | end | 56 | end |
57 | end | 57 | end |
src/noosfero-spb/gov_user/test/helpers/institution_test_helper.rb
@@ -22,7 +22,7 @@ module InstitutionTestHelper | @@ -22,7 +22,7 @@ module InstitutionTestHelper | ||
22 | end | 22 | end |
23 | 23 | ||
24 | def self.create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s, cnpj | 24 | def self.create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s, cnpj |
25 | - institution = PublicInstitution.new | 25 | + institution = GovUserPlugin::PublicInstitution.new |
26 | institution.community = institution_community(name, country, state, city) | 26 | institution.community = institution_community(name, country, state, city) |
27 | institution.name = name | 27 | institution.name = name |
28 | institution.juridical_nature = juridical_nature | 28 | institution.juridical_nature = juridical_nature |
@@ -36,7 +36,7 @@ module InstitutionTestHelper | @@ -36,7 +36,7 @@ module InstitutionTestHelper | ||
36 | end | 36 | end |
37 | 37 | ||
38 | def self.create_private_institution name, acronym, country, state, city, cnpj | 38 | def self.create_private_institution name, acronym, country, state, city, cnpj |
39 | - institution = PrivateInstitution.new | 39 | + institution = GovUserPlugin::PrivateInstitution.new |
40 | institution.community = institution_community(name, country, state, city) | 40 | institution.community = institution_community(name, country, state, city) |
41 | institution.name = name | 41 | institution.name = name |
42 | institution.acronym = acronym | 42 | institution.acronym = acronym |
@@ -56,4 +56,4 @@ module InstitutionTestHelper | @@ -56,4 +56,4 @@ module InstitutionTestHelper | ||
56 | institution_community.save | 56 | institution_community.save |
57 | institution_community | 57 | institution_community |
58 | end | 58 | end |
59 | -end | ||
60 | \ No newline at end of file | 59 | \ No newline at end of file |
60 | +end |
src/noosfero-spb/gov_user/test/unit/gov_user_person_test.rb
@@ -1,58 +0,0 @@ | @@ -1,58 +0,0 @@ | ||
1 | -# encoding: utf-8 | ||
2 | - | ||
3 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
4 | -require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' | ||
5 | - | ||
6 | -class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase | ||
7 | - include PluginTestHelper | ||
8 | - | ||
9 | - def setup | ||
10 | - @plugin = GovUserPlugin.new | ||
11 | - | ||
12 | - @user = fast_create(User) | ||
13 | - @person = create_person( | ||
14 | - "My Name", | ||
15 | - "user@email.com", | ||
16 | - "123456", | ||
17 | - "123456", | ||
18 | - "user2@email.com", | ||
19 | - "Any State", | ||
20 | - "Some City" | ||
21 | - ) | ||
22 | - end | ||
23 | - | ||
24 | - def teardown | ||
25 | - @plugin = nil | ||
26 | - end | ||
27 | - | ||
28 | - should 'be a noosfero plugin' do | ||
29 | - assert_kind_of Noosfero::Plugin, @plugin | ||
30 | - end | ||
31 | - | ||
32 | - should 'save person with a valid full name' do | ||
33 | - p = Person::new :name=>"S1mpl3 0f N4m3", :identifier=>"simple-name" | ||
34 | - p.user = fast_create(:user) | ||
35 | - | ||
36 | - assert_equal true, p.save | ||
37 | - end | ||
38 | - | ||
39 | - should 'save person with a valid full name with accents' do | ||
40 | - name = 'Jônatàs dâ Sîlvã Jösé' | ||
41 | - identifier = "jonatas-jose-da-silva" | ||
42 | - p = Person::new :name=>name, :identifier=>identifier | ||
43 | - p.user = fast_create(:user) | ||
44 | - | ||
45 | - assert_equal true, p.save | ||
46 | - end | ||
47 | - | ||
48 | - should 'not save person whose name has not capital letter' do | ||
49 | - p = Person::new :name=>"simple name" | ||
50 | - assert !p.save, _("Name Should begin with a capital letter and no special characters") | ||
51 | - end | ||
52 | - | ||
53 | - should 'not save person whose name has special characters' do | ||
54 | - p = Person::new :name=>"Simple N@me" | ||
55 | - | ||
56 | - assert !p.save , _("Name Should begin with a capital letter and no special characters") | ||
57 | - end | ||
58 | -end |
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/gov_user_person_test.rb
0 → 100644
@@ -0,0 +1,58 @@ | @@ -0,0 +1,58 @@ | ||
1 | +# encoding: utf-8 | ||
2 | + | ||
3 | +require File.dirname(__FILE__) + '/../../../../../test/test_helper' | ||
4 | +require File.dirname(__FILE__) + '/../../helpers/plugin_test_helper' | ||
5 | + | ||
6 | +class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase | ||
7 | + include PluginTestHelper | ||
8 | + | ||
9 | + def setup | ||
10 | + @plugin = GovUserPlugin.new | ||
11 | + | ||
12 | + @user = fast_create(User) | ||
13 | + @person = create_person( | ||
14 | + "My Name", | ||
15 | + "user@email.com", | ||
16 | + "123456", | ||
17 | + "123456", | ||
18 | + "user2@email.com", | ||
19 | + "Any State", | ||
20 | + "Some City" | ||
21 | + ) | ||
22 | + end | ||
23 | + | ||
24 | + def teardown | ||
25 | + @plugin = nil | ||
26 | + end | ||
27 | + | ||
28 | + should 'be a noosfero plugin' do | ||
29 | + assert_kind_of Noosfero::Plugin, @plugin | ||
30 | + end | ||
31 | + | ||
32 | + should 'save person with a valid full name' do | ||
33 | + p = Person::new :name=>"S1mpl3 0f N4m3", :identifier=>"simple-name" | ||
34 | + p.user = fast_create(:user) | ||
35 | + | ||
36 | + assert_equal true, p.save | ||
37 | + end | ||
38 | + | ||
39 | + should 'save person with a valid full name with accents' do | ||
40 | + name = 'Jônatàs dâ Sîlvã Jösé' | ||
41 | + identifier = "jonatas-jose-da-silva" | ||
42 | + p = Person::new :name=>name, :identifier=>identifier | ||
43 | + p.user = fast_create(:user) | ||
44 | + | ||
45 | + assert_equal true, p.save | ||
46 | + end | ||
47 | + | ||
48 | + should 'not save person whose name has not capital letter' do | ||
49 | + p = Person::new :name=>"simple name" | ||
50 | + assert !p.save, _("Name Should begin with a capital letter and no special characters") | ||
51 | + end | ||
52 | + | ||
53 | + should 'not save person whose name has special characters' do | ||
54 | + p = Person::new :name=>"Simple N@me" | ||
55 | + | ||
56 | + assert !p.save , _("Name Should begin with a capital letter and no special characters") | ||
57 | + end | ||
58 | +end |
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/governmental_power_test.rb
0 → 100644
@@ -0,0 +1,33 @@ | @@ -0,0 +1,33 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../../../test/test_helper' | ||
2 | +require File.dirname(__FILE__) + '/../../helpers/institution_test_helper' | ||
3 | + | ||
4 | +class GovUserPlugin::GovernmentalPowerTest < ActiveSupport::TestCase | ||
5 | + | ||
6 | + def setup | ||
7 | + @gov_sphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
8 | + @juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia") | ||
9 | + end | ||
10 | + | ||
11 | + def teardown | ||
12 | + GovUserPlugin::Institution.destroy_all | ||
13 | + end | ||
14 | + | ||
15 | + should "get public institutions" do | ||
16 | + inst_name = "Ministerio Publico da Uniao" | ||
17 | + inst_cnpj = "12.345.678/9012-45" | ||
18 | + gov_power = GovUserPlugin::GovernmentalPower.create(:name=>"Some gov power") | ||
19 | + InstitutionTestHelper.create_public_institution( | ||
20 | + inst_name, | ||
21 | + "MPU", | ||
22 | + "BR", | ||
23 | + "DF", | ||
24 | + "Gama", | ||
25 | + @juridical_nature, | ||
26 | + gov_power, | ||
27 | + @gov_sphere, | ||
28 | + inst_cnpj | ||
29 | + ) | ||
30 | + | ||
31 | + assert_equal gov_power.institutions.public.count, GovUserPlugin::PublicInstitution.count | ||
32 | + end | ||
33 | +end |
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/institution_test.rb
0 → 100644
@@ -0,0 +1,63 @@ | @@ -0,0 +1,63 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../../../test/test_helper' | ||
2 | +require File.dirname(__FILE__) + '/../../helpers/plugin_test_helper' | ||
3 | + | ||
4 | +class GovUserPlugin::InstitutionTest < ActiveSupport::TestCase | ||
5 | + include PluginTestHelper | ||
6 | + def setup | ||
7 | + @gov_power = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power") | ||
8 | + @gov_sphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
9 | + @juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia") | ||
10 | + | ||
11 | + @institution = create_public_institution( | ||
12 | + "Ministerio Publico da Uniao", | ||
13 | + "MPU", | ||
14 | + "BR", | ||
15 | + "DF", | ||
16 | + "Gama", | ||
17 | + @juridical_nature, | ||
18 | + @gov_power, | ||
19 | + @gov_sphere, | ||
20 | + "11.222.333/4444-55" | ||
21 | + ) | ||
22 | + end | ||
23 | + | ||
24 | + def teardown | ||
25 | + GovUserPlugin::GovernmentalPower.destroy_all | ||
26 | + GovUserPlugin::GovernmentalSphere.destroy_all | ||
27 | + GovUserPlugin::JuridicalNature.destroy_all | ||
28 | + @institution = nil | ||
29 | + end | ||
30 | + should "not save institutions without name" do | ||
31 | + @institution.name = nil | ||
32 | + assert_equal false, @institution.save | ||
33 | + assert_equal true, @institution.errors.full_messages.include?("Name can't be blank") | ||
34 | + end | ||
35 | + | ||
36 | + should "not save if institution has invalid type" do | ||
37 | + invalid_msg = "Type invalid, only public and private institutions are allowed." | ||
38 | + @institution.type = "Other type" | ||
39 | + assert_equal false, @institution.save | ||
40 | + assert_equal true, @institution.errors.full_messages.include?(invalid_msg) | ||
41 | + end | ||
42 | + | ||
43 | + should "not save without country" do | ||
44 | + @institution.community.country = nil | ||
45 | + assert_equal false, @institution.save | ||
46 | + assert_equal true, @institution.errors.full_messages.include?("Country can't be blank") | ||
47 | + end | ||
48 | + | ||
49 | + should "not save without state" do | ||
50 | + @institution.community.state = nil | ||
51 | + | ||
52 | + assert_equal false, @institution.save | ||
53 | + assert_equal true, @institution.errors.full_messages.include?("State can't be blank") | ||
54 | + end | ||
55 | + | ||
56 | + should "not save without city" do | ||
57 | + @institution.community.city = nil | ||
58 | + @institution.community.state = "DF" | ||
59 | + | ||
60 | + assert_equal false, @institution.save | ||
61 | + assert_equal true, @institution.errors.full_messages.include?("City can't be blank") | ||
62 | + end | ||
63 | +end |
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/institutions_block_test.rb
0 → 100644
@@ -0,0 +1,51 @@ | @@ -0,0 +1,51 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../../../test/test_helper' | ||
2 | +require File.dirname(__FILE__) + '/../../helpers/plugin_test_helper' | ||
3 | + | ||
4 | +class GovUserPlugin::InstitutionsBlockTest < ActiveSupport::TestCase | ||
5 | + include PluginTestHelper | ||
6 | + should 'inherit from Block' do | ||
7 | + assert_kind_of Block, GovUserPlugin::InstitutionsBlock.new | ||
8 | + end | ||
9 | + | ||
10 | + should 'declare its default title' do | ||
11 | + GovUserPlugin::InstitutionsBlock.any_instance.stubs(:profile_count).returns(0) | ||
12 | + assert_not_equal Block.new.default_title, GovUserPlugin::InstitutionsBlock.new.default_title | ||
13 | + end | ||
14 | + | ||
15 | + should 'describe itself' do | ||
16 | + assert_not_equal Block.description, GovUserPlugin::InstitutionsBlock.description | ||
17 | + end | ||
18 | + | ||
19 | + should 'give empty footer on unsupported owner type' do | ||
20 | + block = GovUserPlugin::InstitutionsBlock.new | ||
21 | + block.expects(:owner).returns(1) | ||
22 | + assert_equal '', block.footer | ||
23 | + end | ||
24 | + | ||
25 | + should 'list institutions' do | ||
26 | + user = create_person("Jose_Augusto", | ||
27 | + "jose_augusto@email.com", | ||
28 | + "aaaaaaa", | ||
29 | + "aaaaaaa", | ||
30 | + 'jose@secondary.com', | ||
31 | + "DF", | ||
32 | + "Gama" | ||
33 | + ) | ||
34 | + | ||
35 | + institution = create_private_institution( | ||
36 | + "inst name", | ||
37 | + "IN", | ||
38 | + "country", | ||
39 | + "state", | ||
40 | + "city", | ||
41 | + "00.111.222/3333-44" | ||
42 | + ) | ||
43 | + institution.community.add_member(user) | ||
44 | + | ||
45 | + block = GovUserPlugin::InstitutionsBlock.new | ||
46 | + block.expects(:owner).at_least_once.returns(user) | ||
47 | + | ||
48 | + assert_equivalent [institution.community], block.profiles | ||
49 | + end | ||
50 | + | ||
51 | +end |
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/juridical_nature_test.rb
0 → 100644
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../../../test/test_helper' | ||
2 | +require File.dirname(__FILE__) + '/../../helpers/plugin_test_helper' | ||
3 | + | ||
4 | +class GovUserPlugin::JuridicalNatureTest < ActiveSupport::TestCase | ||
5 | + | ||
6 | + include PluginTestHelper | ||
7 | + | ||
8 | + def setup | ||
9 | + @govPower = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power") | ||
10 | + @govSphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
11 | + end | ||
12 | + | ||
13 | + def teardown | ||
14 | + GovUserPlugin::Institution.destroy_all | ||
15 | + end | ||
16 | + | ||
17 | + should "get public institutions" do | ||
18 | + juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia") | ||
19 | + create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", juridical_nature, @govPower, @govSphere, "22.333.444/5555-66") | ||
20 | + create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", juridical_nature, @govPower, @govSphere, "22.333.444/5555-77") | ||
21 | + assert juridical_nature.institutions.public.count == GovUserPlugin::PublicInstitution.count | ||
22 | + end | ||
23 | +end |
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/organization_rating_test.rb
0 → 100644
@@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../../../test/test_helper' | ||
2 | +require File.dirname(__FILE__) + '/../../helpers/plugin_test_helper' | ||
3 | + | ||
4 | +class GovUserPlugin::OrganizationRatingTest < ActiveSupport::TestCase | ||
5 | + include PluginTestHelper | ||
6 | + | ||
7 | + def setup | ||
8 | + @environment = Environment.default | ||
9 | + @environment.enabled_plugins = ['SoftwareCommunitiesPlugin'] | ||
10 | + @environment.save | ||
11 | + end | ||
12 | + | ||
13 | + should "validate institution if there is an institution_id" do | ||
14 | + person = fast_create(Person) | ||
15 | + community = fast_create(Community) | ||
16 | + private_institution = build_private_institution "huehue", "hue", "11.222.333/4444-55" | ||
17 | + | ||
18 | + community_rating = OrganizationRating.new(:person => person, :value => 3, :organization => community, :institution => private_institution) | ||
19 | + assert_equal false, community_rating.valid? | ||
20 | + | ||
21 | + assert_equal true, community_rating.errors[:institution].include?("not found") | ||
22 | + | ||
23 | + private_institution.save | ||
24 | + community_rating.institution = private_institution | ||
25 | + | ||
26 | + assert_equal true, community_rating.valid? | ||
27 | + assert_equal false, community_rating.errors[:institution].include?("not found") | ||
28 | + end | ||
29 | + | ||
30 | + private | ||
31 | + | ||
32 | + def build_private_institution name, corporate_name, cnpj, country="AR" | ||
33 | + community = Community.new :name => name | ||
34 | + community.country = country | ||
35 | + | ||
36 | + institution = GovUserPlugin::PrivateInstitution.new :name=> name | ||
37 | + institution.corporate_name = corporate_name | ||
38 | + institution.cnpj = cnpj | ||
39 | + institution.community = community | ||
40 | + | ||
41 | + institution | ||
42 | + end | ||
43 | +end | ||
44 | + |
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/person_test.rb
0 → 100644
@@ -0,0 +1,43 @@ | @@ -0,0 +1,43 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../../../test/test_helper' | ||
2 | +require File.dirname(__FILE__) + '/../../helpers/plugin_test_helper' | ||
3 | + | ||
4 | +class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase | ||
5 | + include PluginTestHelper | ||
6 | + def setup | ||
7 | + @plugin = GovUserPlugin.new | ||
8 | + | ||
9 | + @user = fast_create(User) | ||
10 | + @person = create_person( | ||
11 | + "My Name", | ||
12 | + "user@email.com", | ||
13 | + "123456", | ||
14 | + "123456", | ||
15 | + "user@secondaryemail.com", | ||
16 | + "Any State", | ||
17 | + "Some City" | ||
18 | + ) | ||
19 | + end | ||
20 | + | ||
21 | + should 'calculate the percentege of person incomplete fields' do | ||
22 | + @person.cell_phone = "76888919" | ||
23 | + @person.contact_phone = "987654321" | ||
24 | + | ||
25 | + assert_equal(67, @plugin.calc_percentage_registration(@person)) | ||
26 | + | ||
27 | + @person.comercial_phone = "11223344" | ||
28 | + @person.country = "I dont know" | ||
29 | + @person.state = "I dont know" | ||
30 | + @person.city = "I dont know" | ||
31 | + @person.organization_website = "www.whatever.com" | ||
32 | + @person.image = Image::new :uploaded_data=>fixture_file_upload('/files/rails.png', 'image/png') | ||
33 | + @person.save | ||
34 | + | ||
35 | + assert_equal(100, @plugin.calc_percentage_registration(@person)) | ||
36 | + end | ||
37 | + | ||
38 | + should 'return true when the email has not gov.br,jus.br,leg.br or mp.br' do | ||
39 | + @user.secondary_email = "test_email@com.br" | ||
40 | + @user.email = "test_email@net.br" | ||
41 | + assert @user.save | ||
42 | + end | ||
43 | +end |
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/private_institution_test.rb
0 → 100644
@@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../../../test/test_helper' | ||
2 | +require File.dirname(__FILE__) + '/../../helpers/plugin_test_helper' | ||
3 | + | ||
4 | +class GovUserPlugin::PrivateInstitutionTest < ActiveSupport::TestCase | ||
5 | + include PluginTestHelper | ||
6 | + def setup | ||
7 | + @institution = create_private_institution( | ||
8 | + "Simple Private Institution", | ||
9 | + "SPI", | ||
10 | + "BR", | ||
11 | + "DF", | ||
12 | + "Gama", | ||
13 | + "00.000.000/0001-00" | ||
14 | + ) | ||
15 | + end | ||
16 | + | ||
17 | + def teardown | ||
18 | + @institution = nil | ||
19 | + GovUserPlugin::Institution.destroy_all | ||
20 | + end | ||
21 | + | ||
22 | + should "save without a cnpj" do | ||
23 | + @institution.cnpj = nil | ||
24 | + | ||
25 | + assert @institution.save | ||
26 | + end | ||
27 | + | ||
28 | + should "save without fantasy name" do | ||
29 | + @institution.acronym = nil | ||
30 | + @institution.community.save | ||
31 | + | ||
32 | + assert @institution.save | ||
33 | + end | ||
34 | +end |
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/public_institution_test.rb
0 → 100644
@@ -0,0 +1,68 @@ | @@ -0,0 +1,68 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../../../test/test_helper' | ||
2 | +require File.dirname(__FILE__) + '/../../helpers/plugin_test_helper' | ||
3 | + | ||
4 | +class GovUserPlugin::PublicInstitutionTest < ActiveSupport::TestCase | ||
5 | + include PluginTestHelper | ||
6 | + def setup | ||
7 | + @gov_power = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power") | ||
8 | + @gov_sphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
9 | + @juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia") | ||
10 | + | ||
11 | + @institution = create_public_institution( | ||
12 | + "Ministerio Publico da Uniao", | ||
13 | + "MPU", | ||
14 | + "BR", | ||
15 | + "DF", | ||
16 | + "Gama", | ||
17 | + @juridical_nature, | ||
18 | + @gov_power, | ||
19 | + @gov_sphere, | ||
20 | + "11.222.333/4444-55" | ||
21 | + ) | ||
22 | + end | ||
23 | + | ||
24 | + def teardown | ||
25 | + GovUserPlugin::GovernmentalPower.destroy_all | ||
26 | + GovUserPlugin::GovernmentalSphere.destroy_all | ||
27 | + GovUserPlugin::JuridicalNature.destroy_all | ||
28 | + GovUserPlugin::Institution.destroy_all | ||
29 | + @gov_power = nil | ||
30 | + @gov_sphere = nil | ||
31 | + @juridical_nature = nil | ||
32 | + @institution = nil | ||
33 | + end | ||
34 | + | ||
35 | + should "save without a cnpj" do | ||
36 | + @institution.cnpj = nil | ||
37 | + assert @institution.save | ||
38 | + end | ||
39 | + | ||
40 | + should "save institution without an acronym" do | ||
41 | + @institution.acronym = nil | ||
42 | + assert @institution.save | ||
43 | + end | ||
44 | + | ||
45 | + should "Not save institution without a governmental_power" do | ||
46 | + invalid_msg = "Governmental power can't be blank" | ||
47 | + @institution.governmental_power = nil | ||
48 | + | ||
49 | + assert !@institution.save | ||
50 | + assert @institution.errors.full_messages.include? invalid_msg | ||
51 | + end | ||
52 | + | ||
53 | + should "Not save institution without a governmental_sphere" do | ||
54 | + invalid_msg = "Governmental sphere can't be blank" | ||
55 | + @institution.governmental_sphere = nil | ||
56 | + | ||
57 | + assert !@institution.save | ||
58 | + assert @institution.errors.full_messages.include? invalid_msg | ||
59 | + end | ||
60 | + | ||
61 | + should "not save institution without juridical nature" do | ||
62 | + invalid_msg = "Juridical nature can't be blank" | ||
63 | + @institution.juridical_nature = nil | ||
64 | + | ||
65 | + assert !@institution.save | ||
66 | + assert @institution.errors.full_messages.include? invalid_msg | ||
67 | + end | ||
68 | +end |
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/user_test.rb
0 → 100644
@@ -0,0 +1,99 @@ | @@ -0,0 +1,99 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../../../test/test_helper' | ||
2 | +require File.dirname(__FILE__) + '/../../helpers/plugin_test_helper' | ||
3 | + | ||
4 | +class UserTest < ActiveSupport::TestCase | ||
5 | + include PluginTestHelper | ||
6 | + | ||
7 | + should 'not save user whose both email and secondary email are the same' do | ||
8 | + user = fast_create(User) | ||
9 | + user.email = "test@email.com" | ||
10 | + user.secondary_email = "test@email.com" | ||
11 | + | ||
12 | + assert !user.save | ||
13 | + end | ||
14 | + | ||
15 | + should 'not save user whose email and secondary email have been taken' do | ||
16 | + user1 = create_default_user | ||
17 | + user2 = fast_create(User) | ||
18 | + | ||
19 | + user2.email = "primary@email.com" | ||
20 | + user2.secondary_email = "secondary@email.com" | ||
21 | + assert !user2.save | ||
22 | + end | ||
23 | + | ||
24 | + should 'not save user whose email has already been used' do | ||
25 | + user1 = create_default_user | ||
26 | + user2 = fast_create(User) | ||
27 | + | ||
28 | + user2.email = "primary@email.com" | ||
29 | + user2.secondary_email = "noosfero@email.com" | ||
30 | + assert !user2.save | ||
31 | + end | ||
32 | + | ||
33 | + should 'not save user whose email has been taken another in users secondary email' do | ||
34 | + user1 = create_default_user | ||
35 | + user2 = fast_create(User) | ||
36 | + | ||
37 | + user2.login = "another-login" | ||
38 | + user2.email = "secondary@email.com" | ||
39 | + user2.secondary_email = "noosfero@email.com" | ||
40 | + assert !user2.save | ||
41 | + end | ||
42 | + | ||
43 | + should 'not save user whose secondary email has been taken used in another users email' do | ||
44 | + user1 = create_default_user | ||
45 | + user2 = fast_create(User) | ||
46 | + | ||
47 | + user2.login = "another-login" | ||
48 | + user2.email = "noosfero@email.com" | ||
49 | + user2.secondary_email = "primary@email.com" | ||
50 | + assert !user2.save | ||
51 | + end | ||
52 | + | ||
53 | + should 'not save user whose secondary email has already been used in another users secondary email' do | ||
54 | + user1 = create_default_user | ||
55 | + user2 = fast_create(User) | ||
56 | + | ||
57 | + user2.login = "another-login" | ||
58 | + user2.email = "noosfero@email.com" | ||
59 | + user2.secondary_email = "secondary@email.com" | ||
60 | + assert !user2.save | ||
61 | + end | ||
62 | + | ||
63 | + should 'not save user whose secondary email is in the wrong format' do | ||
64 | + user = fast_create(User) | ||
65 | + user.email = "test@email.com" | ||
66 | + user.secondary_email = "notarightformat.com" | ||
67 | + | ||
68 | + assert !user.save | ||
69 | + | ||
70 | + user.secondary_email = "not@arightformatcom" | ||
71 | + | ||
72 | + assert !user.save | ||
73 | + end | ||
74 | + | ||
75 | + should 'save more than one user without secondary email' do | ||
76 | + user = fast_create(User) | ||
77 | + user.email = "test@email.com" | ||
78 | + user.secondary_email = "" | ||
79 | + user.save | ||
80 | + | ||
81 | + user2 = fast_create(User) | ||
82 | + user2.email = "test2@email.com" | ||
83 | + user2.secondary_email = "" | ||
84 | + assert user2.save | ||
85 | + end | ||
86 | + | ||
87 | + private | ||
88 | + | ||
89 | + def create_default_user | ||
90 | + user = fast_create(User) | ||
91 | + user.login = "a-login" | ||
92 | + user.email = "primary@email.com" | ||
93 | + user.secondary_email = "secondary@email.com" | ||
94 | + user.save | ||
95 | + | ||
96 | + return user | ||
97 | + end | ||
98 | + | ||
99 | +end |
src/noosfero-spb/gov_user/test/unit/governmental_power_test.rb
@@ -1,33 +0,0 @@ | @@ -1,33 +0,0 @@ | ||
1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
2 | -require File.dirname(__FILE__) + '/../helpers/institution_test_helper' | ||
3 | - | ||
4 | -class GovernmentalPowerTest < ActiveSupport::TestCase | ||
5 | - | ||
6 | - def setup | ||
7 | - @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
8 | - @juridical_nature = JuridicalNature.create(:name => "Autarquia") | ||
9 | - end | ||
10 | - | ||
11 | - def teardown | ||
12 | - Institution.destroy_all | ||
13 | - end | ||
14 | - | ||
15 | - should "get public institutions" do | ||
16 | - inst_name = "Ministerio Publico da Uniao" | ||
17 | - inst_cnpj = "12.345.678/9012-45" | ||
18 | - gov_power = GovernmentalPower.create(:name=>"Some gov power") | ||
19 | - InstitutionTestHelper.create_public_institution( | ||
20 | - inst_name, | ||
21 | - "MPU", | ||
22 | - "BR", | ||
23 | - "DF", | ||
24 | - "Gama", | ||
25 | - @juridical_nature, | ||
26 | - gov_power, | ||
27 | - @gov_sphere, | ||
28 | - inst_cnpj | ||
29 | - ) | ||
30 | - | ||
31 | - assert_equal gov_power.public_institutions.count, PublicInstitution.count | ||
32 | - end | ||
33 | -end | ||
34 | \ No newline at end of file | 0 | \ No newline at end of file |
src/noosfero-spb/gov_user/test/unit/institution_test.rb
@@ -1,63 +0,0 @@ | @@ -1,63 +0,0 @@ | ||
1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
2 | -require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' | ||
3 | - | ||
4 | -class InstitutionTest < ActiveSupport::TestCase | ||
5 | - include PluginTestHelper | ||
6 | - def setup | ||
7 | - @gov_power = GovernmentalPower.create(:name=>"Some Gov Power") | ||
8 | - @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
9 | - @juridical_nature = JuridicalNature.create(:name => "Autarquia") | ||
10 | - | ||
11 | - @institution = create_public_institution( | ||
12 | - "Ministerio Publico da Uniao", | ||
13 | - "MPU", | ||
14 | - "BR", | ||
15 | - "DF", | ||
16 | - "Gama", | ||
17 | - @juridical_nature, | ||
18 | - @gov_power, | ||
19 | - @gov_sphere, | ||
20 | - "11.222.333/4444-55" | ||
21 | - ) | ||
22 | - end | ||
23 | - | ||
24 | - def teardown | ||
25 | - GovernmentalPower.destroy_all | ||
26 | - GovernmentalSphere.destroy_all | ||
27 | - JuridicalNature.destroy_all | ||
28 | - @institution = nil | ||
29 | - end | ||
30 | - should "not save institutions without name" do | ||
31 | - @institution.name = nil | ||
32 | - assert_equal false, @institution.save | ||
33 | - assert_equal true, @institution.errors.full_messages.include?("Name can't be blank") | ||
34 | - end | ||
35 | - | ||
36 | - should "not save if institution has invalid type" do | ||
37 | - invalid_msg = "Type invalid, only public and private institutions are allowed." | ||
38 | - @institution.type = "Other type" | ||
39 | - assert_equal false, @institution.save | ||
40 | - assert_equal true, @institution.errors.full_messages.include?(invalid_msg) | ||
41 | - end | ||
42 | - | ||
43 | - should "not save without country" do | ||
44 | - @institution.community.country = nil | ||
45 | - assert_equal false, @institution.save | ||
46 | - assert_equal true, @institution.errors.full_messages.include?("Country can't be blank") | ||
47 | - end | ||
48 | - | ||
49 | - should "not save without state" do | ||
50 | - @institution.community.state = nil | ||
51 | - | ||
52 | - assert_equal false, @institution.save | ||
53 | - assert_equal true, @institution.errors.full_messages.include?("State can't be blank") | ||
54 | - end | ||
55 | - | ||
56 | - should "not save without city" do | ||
57 | - @institution.community.city = nil | ||
58 | - @institution.community.state = "DF" | ||
59 | - | ||
60 | - assert_equal false, @institution.save | ||
61 | - assert_equal true, @institution.errors.full_messages.include?("City can't be blank") | ||
62 | - end | ||
63 | -end |
src/noosfero-spb/gov_user/test/unit/institutions_block_test.rb
@@ -1,51 +0,0 @@ | @@ -1,51 +0,0 @@ | ||
1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
2 | -require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' | ||
3 | - | ||
4 | -class InstitutionsBlockTest < ActiveSupport::TestCase | ||
5 | - include PluginTestHelper | ||
6 | - should 'inherit from Block' do | ||
7 | - assert_kind_of Block, InstitutionsBlock.new | ||
8 | - end | ||
9 | - | ||
10 | - should 'declare its default title' do | ||
11 | - InstitutionsBlock.any_instance.stubs(:profile_count).returns(0) | ||
12 | - assert_not_equal Block.new.default_title, InstitutionsBlock.new.default_title | ||
13 | - end | ||
14 | - | ||
15 | - should 'describe itself' do | ||
16 | - assert_not_equal Block.description, InstitutionsBlock.description | ||
17 | - end | ||
18 | - | ||
19 | - should 'give empty footer on unsupported owner type' do | ||
20 | - block = InstitutionsBlock.new | ||
21 | - block.expects(:owner).returns(1) | ||
22 | - assert_equal '', block.footer | ||
23 | - end | ||
24 | - | ||
25 | - should 'list institutions' do | ||
26 | - user = create_person("Jose_Augusto", | ||
27 | - "jose_augusto@email.com", | ||
28 | - "aaaaaaa", | ||
29 | - "aaaaaaa", | ||
30 | - 'jose@secondary.com', | ||
31 | - "DF", | ||
32 | - "Gama" | ||
33 | - ) | ||
34 | - | ||
35 | - institution = create_private_institution( | ||
36 | - "inst name", | ||
37 | - "IN", | ||
38 | - "country", | ||
39 | - "state", | ||
40 | - "city", | ||
41 | - "00.111.222/3333-44" | ||
42 | - ) | ||
43 | - institution.community.add_member(user) | ||
44 | - | ||
45 | - block = InstitutionsBlock.new | ||
46 | - block.expects(:owner).at_least_once.returns(user) | ||
47 | - | ||
48 | - assert_equivalent [institution.community], block.profiles | ||
49 | - end | ||
50 | - | ||
51 | -end |
src/noosfero-spb/gov_user/test/unit/juridical_nature_test.rb
@@ -1,23 +0,0 @@ | @@ -1,23 +0,0 @@ | ||
1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
2 | -require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' | ||
3 | - | ||
4 | -class JuridicalNatureTest < ActiveSupport::TestCase | ||
5 | - | ||
6 | - include PluginTestHelper | ||
7 | - | ||
8 | - def setup | ||
9 | - @govPower = GovernmentalPower.create(:name=>"Some Gov Power") | ||
10 | - @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
11 | - end | ||
12 | - | ||
13 | - def teardown | ||
14 | - Institution.destroy_all | ||
15 | - end | ||
16 | - | ||
17 | - should "get public institutions" do | ||
18 | - juridical_nature = JuridicalNature.create(:name => "Autarquia") | ||
19 | - create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", juridical_nature, @govPower, @govSphere, "22.333.444/5555-66") | ||
20 | - create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", juridical_nature, @govPower, @govSphere, "22.333.444/5555-77") | ||
21 | - assert juridical_nature.public_institutions.count == PublicInstitution.count | ||
22 | - end | ||
23 | -end |
src/noosfero-spb/gov_user/test/unit/organization_rating_test.rb
@@ -1,44 +0,0 @@ | @@ -1,44 +0,0 @@ | ||
1 | -require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper' | ||
2 | -require File.expand_path(File.dirname(__FILE__)) + '/../helpers/plugin_test_helper' | ||
3 | - | ||
4 | -class OrganizationRatingTest < ActiveSupport::TestCase | ||
5 | - include PluginTestHelper | ||
6 | - | ||
7 | - def setup | ||
8 | - @environment = Environment.default | ||
9 | - @environment.enabled_plugins = ['SoftwareCommunitiesPlugin'] | ||
10 | - @environment.save | ||
11 | - end | ||
12 | - | ||
13 | - should "validate institution if there is an institution_id" do | ||
14 | - person = fast_create(Person) | ||
15 | - community = fast_create(Community) | ||
16 | - private_institution = build_private_institution "huehue", "hue", "11.222.333/4444-55" | ||
17 | - | ||
18 | - community_rating = OrganizationRating.new(:person => person, :value => 3, :organization => community, :institution => private_institution) | ||
19 | - assert_equal false, community_rating.valid? | ||
20 | - | ||
21 | - assert_equal true, community_rating.errors[:institution].include?("not found") | ||
22 | - | ||
23 | - private_institution.save | ||
24 | - community_rating.institution = private_institution | ||
25 | - | ||
26 | - assert_equal true, community_rating.valid? | ||
27 | - assert_equal false, community_rating.errors[:institution].include?("not found") | ||
28 | - end | ||
29 | - | ||
30 | - private | ||
31 | - | ||
32 | - def build_private_institution name, corporate_name, cnpj, country="AR" | ||
33 | - community = Community.new :name => name | ||
34 | - community.country = country | ||
35 | - | ||
36 | - institution = PrivateInstitution.new :name=> name | ||
37 | - institution.corporate_name = corporate_name | ||
38 | - institution.cnpj = cnpj | ||
39 | - institution.community = community | ||
40 | - | ||
41 | - institution | ||
42 | - end | ||
43 | -end | ||
44 | - |
src/noosfero-spb/gov_user/test/unit/person_test.rb
@@ -1,43 +0,0 @@ | @@ -1,43 +0,0 @@ | ||
1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
2 | -require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' | ||
3 | - | ||
4 | -class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase | ||
5 | - include PluginTestHelper | ||
6 | - def setup | ||
7 | - @plugin = GovUserPlugin.new | ||
8 | - | ||
9 | - @user = fast_create(User) | ||
10 | - @person = create_person( | ||
11 | - "My Name", | ||
12 | - "user@email.com", | ||
13 | - "123456", | ||
14 | - "123456", | ||
15 | - "user@secondaryemail.com", | ||
16 | - "Any State", | ||
17 | - "Some City" | ||
18 | - ) | ||
19 | - end | ||
20 | - | ||
21 | - should 'calculate the percentege of person incomplete fields' do | ||
22 | - @person.cell_phone = "76888919" | ||
23 | - @person.contact_phone = "987654321" | ||
24 | - | ||
25 | - assert_equal(67, @plugin.calc_percentage_registration(@person)) | ||
26 | - | ||
27 | - @person.comercial_phone = "11223344" | ||
28 | - @person.country = "I dont know" | ||
29 | - @person.state = "I dont know" | ||
30 | - @person.city = "I dont know" | ||
31 | - @person.organization_website = "www.whatever.com" | ||
32 | - @person.image = Image::new :uploaded_data=>fixture_file_upload('/files/rails.png', 'image/png') | ||
33 | - @person.save | ||
34 | - | ||
35 | - assert_equal(100, @plugin.calc_percentage_registration(@person)) | ||
36 | - end | ||
37 | - | ||
38 | - should 'return true when the email has not gov.br,jus.br,leg.br or mp.br' do | ||
39 | - @user.secondary_email = "test_email@com.br" | ||
40 | - @user.email = "test_email@net.br" | ||
41 | - assert @user.save | ||
42 | - end | ||
43 | -end |
src/noosfero-spb/gov_user/test/unit/private_institution_test.rb
@@ -1,34 +0,0 @@ | @@ -1,34 +0,0 @@ | ||
1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
2 | -require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' | ||
3 | - | ||
4 | -class PrivateInstitutionTest < ActiveSupport::TestCase | ||
5 | - include PluginTestHelper | ||
6 | - def setup | ||
7 | - @institution = create_private_institution( | ||
8 | - "Simple Private Institution", | ||
9 | - "SPI", | ||
10 | - "BR", | ||
11 | - "DF", | ||
12 | - "Gama", | ||
13 | - "00.000.000/0001-00" | ||
14 | - ) | ||
15 | - end | ||
16 | - | ||
17 | - def teardown | ||
18 | - @institution = nil | ||
19 | - Institution.destroy_all | ||
20 | - end | ||
21 | - | ||
22 | - should "save without a cnpj" do | ||
23 | - @institution.cnpj = nil | ||
24 | - | ||
25 | - assert @institution.save | ||
26 | - end | ||
27 | - | ||
28 | - should "save without fantasy name" do | ||
29 | - @institution.acronym = nil | ||
30 | - @institution.community.save | ||
31 | - | ||
32 | - assert @institution.save | ||
33 | - end | ||
34 | -end |
src/noosfero-spb/gov_user/test/unit/public_institution_test.rb
@@ -1,68 +0,0 @@ | @@ -1,68 +0,0 @@ | ||
1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
2 | -require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' | ||
3 | - | ||
4 | -class PublicInstitutionTest < ActiveSupport::TestCase | ||
5 | - include PluginTestHelper | ||
6 | - def setup | ||
7 | - @gov_power = GovernmentalPower.create(:name=>"Some Gov Power") | ||
8 | - @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
9 | - @juridical_nature = JuridicalNature.create(:name => "Autarquia") | ||
10 | - | ||
11 | - @institution = create_public_institution( | ||
12 | - "Ministerio Publico da Uniao", | ||
13 | - "MPU", | ||
14 | - "BR", | ||
15 | - "DF", | ||
16 | - "Gama", | ||
17 | - @juridical_nature, | ||
18 | - @gov_power, | ||
19 | - @gov_sphere, | ||
20 | - "11.222.333/4444-55" | ||
21 | - ) | ||
22 | - end | ||
23 | - | ||
24 | - def teardown | ||
25 | - GovernmentalPower.destroy_all | ||
26 | - GovernmentalSphere.destroy_all | ||
27 | - JuridicalNature.destroy_all | ||
28 | - Institution.destroy_all | ||
29 | - @gov_power = nil | ||
30 | - @gov_sphere = nil | ||
31 | - @juridical_nature = nil | ||
32 | - @institution = nil | ||
33 | - end | ||
34 | - | ||
35 | - should "save without a cnpj" do | ||
36 | - @institution.cnpj = nil | ||
37 | - assert @institution.save | ||
38 | - end | ||
39 | - | ||
40 | - should "save institution without an acronym" do | ||
41 | - @institution.acronym = nil | ||
42 | - assert @institution.save | ||
43 | - end | ||
44 | - | ||
45 | - should "Not save institution without a governmental_power" do | ||
46 | - invalid_msg = "Governmental power can't be blank" | ||
47 | - @institution.governmental_power = nil | ||
48 | - | ||
49 | - assert !@institution.save | ||
50 | - assert @institution.errors.full_messages.include? invalid_msg | ||
51 | - end | ||
52 | - | ||
53 | - should "Not save institution without a governmental_sphere" do | ||
54 | - invalid_msg = "Governmental sphere can't be blank" | ||
55 | - @institution.governmental_sphere = nil | ||
56 | - | ||
57 | - assert !@institution.save | ||
58 | - assert @institution.errors.full_messages.include? invalid_msg | ||
59 | - end | ||
60 | - | ||
61 | - should "not save institution without juridical nature" do | ||
62 | - invalid_msg = "Juridical nature can't be blank" | ||
63 | - @institution.juridical_nature = nil | ||
64 | - | ||
65 | - assert !@institution.save | ||
66 | - assert @institution.errors.full_messages.include? invalid_msg | ||
67 | - end | ||
68 | -end |
src/noosfero-spb/gov_user/test/unit/user_test.rb
@@ -1,99 +0,0 @@ | @@ -1,99 +0,0 @@ | ||
1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
2 | -require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' | ||
3 | - | ||
4 | -class UserTest < ActiveSupport::TestCase | ||
5 | - include PluginTestHelper | ||
6 | - | ||
7 | - should 'not save user whose both email and secondary email are the same' do | ||
8 | - user = fast_create(User) | ||
9 | - user.email = "test@email.com" | ||
10 | - user.secondary_email = "test@email.com" | ||
11 | - | ||
12 | - assert !user.save | ||
13 | - end | ||
14 | - | ||
15 | - should 'not save user whose email and secondary email have been taken' do | ||
16 | - user1 = create_default_user | ||
17 | - user2 = fast_create(User) | ||
18 | - | ||
19 | - user2.email = "primary@email.com" | ||
20 | - user2.secondary_email = "secondary@email.com" | ||
21 | - assert !user2.save | ||
22 | - end | ||
23 | - | ||
24 | - should 'not save user whose email has already been used' do | ||
25 | - user1 = create_default_user | ||
26 | - user2 = fast_create(User) | ||
27 | - | ||
28 | - user2.email = "primary@email.com" | ||
29 | - user2.secondary_email = "noosfero@email.com" | ||
30 | - assert !user2.save | ||
31 | - end | ||
32 | - | ||
33 | - should 'not save user whose email has been taken another in users secondary email' do | ||
34 | - user1 = create_default_user | ||
35 | - user2 = fast_create(User) | ||
36 | - | ||
37 | - user2.login = "another-login" | ||
38 | - user2.email = "secondary@email.com" | ||
39 | - user2.secondary_email = "noosfero@email.com" | ||
40 | - assert !user2.save | ||
41 | - end | ||
42 | - | ||
43 | - should 'not save user whose secondary email has been taken used in another users email' do | ||
44 | - user1 = create_default_user | ||
45 | - user2 = fast_create(User) | ||
46 | - | ||
47 | - user2.login = "another-login" | ||
48 | - user2.email = "noosfero@email.com" | ||
49 | - user2.secondary_email = "primary@email.com" | ||
50 | - assert !user2.save | ||
51 | - end | ||
52 | - | ||
53 | - should 'not save user whose secondary email has already been used in another users secondary email' do | ||
54 | - user1 = create_default_user | ||
55 | - user2 = fast_create(User) | ||
56 | - | ||
57 | - user2.login = "another-login" | ||
58 | - user2.email = "noosfero@email.com" | ||
59 | - user2.secondary_email = "secondary@email.com" | ||
60 | - assert !user2.save | ||
61 | - end | ||
62 | - | ||
63 | - should 'not save user whose secondary email is in the wrong format' do | ||
64 | - user = fast_create(User) | ||
65 | - user.email = "test@email.com" | ||
66 | - user.secondary_email = "notarightformat.com" | ||
67 | - | ||
68 | - assert !user.save | ||
69 | - | ||
70 | - user.secondary_email = "not@arightformatcom" | ||
71 | - | ||
72 | - assert !user.save | ||
73 | - end | ||
74 | - | ||
75 | - should 'save more than one user without secondary email' do | ||
76 | - user = fast_create(User) | ||
77 | - user.email = "test@email.com" | ||
78 | - user.secondary_email = "" | ||
79 | - user.save | ||
80 | - | ||
81 | - user2 = fast_create(User) | ||
82 | - user2.email = "test2@email.com" | ||
83 | - user2.secondary_email = "" | ||
84 | - assert user2.save | ||
85 | - end | ||
86 | - | ||
87 | - private | ||
88 | - | ||
89 | - def create_default_user | ||
90 | - user = fast_create(User) | ||
91 | - user.login = "a-login" | ||
92 | - user.email = "primary@email.com" | ||
93 | - user.secondary_email = "secondary@email.com" | ||
94 | - user.save | ||
95 | - | ||
96 | - return user | ||
97 | - end | ||
98 | - | ||
99 | -end |
src/noosfero-spb/gov_user/views/gov_user_plugin/_institution.html.erb
@@ -31,11 +31,11 @@ | @@ -31,11 +31,11 @@ | ||
31 | <div class='formfield type-radio'> | 31 | <div class='formfield type-radio'> |
32 | <label> | 32 | <label> |
33 | <%= _("Private Institution") %> | 33 | <%= _("Private Institution") %> |
34 | - <%= radio_button_tag("institutions[type]" ,"PrivateInstitution", true)%> | 34 | + <%= radio_button_tag("institutions[type]" ,"GovUserPlugin::PrivateInstitution", true)%> |
35 | </label> | 35 | </label> |
36 | 36 | ||
37 | <label> <%= _("Public Institution") %> | 37 | <label> <%= _("Public Institution") %> |
38 | - <%= radio_button_tag("institutions[type]", "PublicInstitution") %> | 38 | + <%= radio_button_tag("institutions[type]", "GovUserPlugin::PublicInstitution") %> |
39 | </label> | 39 | </label> |
40 | </div> | 40 | </div> |
41 | </span> | 41 | </span> |
src/noosfero-spb/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb
@@ -26,12 +26,12 @@ | @@ -26,12 +26,12 @@ | ||
26 | <span class=''> | 26 | <span class=''> |
27 | <div class='formfield type-radio'> | 27 | <div class='formfield type-radio'> |
28 | <label> <%= _("Public Institution") %> | 28 | <label> <%= _("Public Institution") %> |
29 | - <%= radio_button_tag("institutions[type]", "PublicInstitution", (@institution.type == "PublicInstitution" ? true : false)) %> | 29 | + <%= radio_button_tag("institutions[type]", "GovUserPlugin::PublicInstitution", (@institution.type == "GovUserPlugin::PublicInstitution" ? true : false)) %> |
30 | </label> | 30 | </label> |
31 | 31 | ||
32 | <label> | 32 | <label> |
33 | <%= _("Private Institution") %> | 33 | <%= _("Private Institution") %> |
34 | - <%= radio_button_tag("institutions[type]" ,"PrivateInstitution", (@institution.type == "PrivateInstitution" ? true : false))%> | 34 | + <%= radio_button_tag("institutions[type]" ,"GovUserPlugin::PrivateInstitution", (@institution.type == "GovUserPlugin::PrivateInstitution" ? true : false))%> |
35 | </label> | 35 | </label> |
36 | </div> | 36 | </div> |
37 | </span> | 37 | </span> |
@@ -77,20 +77,20 @@ | @@ -77,20 +77,20 @@ | ||
77 | <span class='required-field public-institutions-fields'> | 77 | <span class='required-field public-institutions-fields'> |
78 | <div class="formfield type-text"> | 78 | <div class="formfield type-text"> |
79 | <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %> | 79 | <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %> |
80 | - <%= inst.select(:governmental_sphere, [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}, {:selected=>@institution.governmental_power_id})%> | 80 | + <%= inst.select(:governmental_sphere, [[_("Select a Governmental Sphere"), 0]]|GovUserPlugin::GovernmentalSphere.all.map {|s| [s.name, s.id]}, {:selected=>@institution.governmental_power_id})%> |
81 | </div> | 81 | </div> |
82 | </span> | 82 | </span> |
83 | 83 | ||
84 | <span class='required-field public-institutions-fields'> | 84 | <span class='required-field public-institutions-fields'> |
85 | <div class="formfield type-text"> | 85 | <div class="formfield type-text"> |
86 | <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %> | 86 | <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %> |
87 | - <%= inst.select(:governmental_power, [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}, {:selected=> @institution.governmental_sphere_id})%> | 87 | + <%= inst.select(:governmental_power, [[_("Select a Governmental Power"), 0]]|GovUserPlugin::GovernmentalPower.all.map {|g| [g.name, g.id]}, {:selected=> @institution.governmental_sphere_id})%> |
88 | </div> | 88 | </div> |
89 | </span> | 89 | </span> |
90 | <span class='required-field public-institutions-fields'> | 90 | <span class='required-field public-institutions-fields'> |
91 | <div class="formfield type-text"> | 91 | <div class="formfield type-text"> |
92 | <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %> | 92 | <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %> |
93 | - <%= inst.select(:juridical_nature, [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}, {:selected=> @institution.juridical_nature_id})%> | 93 | + <%= inst.select(:juridical_nature, [[_("Select a Juridical Nature"), 0]]|GovUserPlugin::JuridicalNature.all.map {|j| [j.name, j.id]}, {:selected=> @institution.juridical_nature_id})%> |
94 | </div> | 94 | </div> |
95 | </span> | 95 | </span> |
96 | 96 |
src/noosfero-spb/gov_user/views/profile/_institution_tab.html.erb
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | <%= display_mpog_field(_('Country:'), profile.institution.community, :country, true) %> | 9 | <%= display_mpog_field(_('Country:'), profile.institution.community, :country, true) %> |
10 | <%= display_mpog_field(_('State:'), profile.institution.community, :state, true) %> | 10 | <%= display_mpog_field(_('State:'), profile.institution.community, :state, true) %> |
11 | <%= display_mpog_field(_('City:'), profile.institution.community, :city, true) %> | 11 | <%= display_mpog_field(_('City:'), profile.institution.community, :city, true) %> |
12 | - <% if profile.institution.type == "PrivateInstitution"%> | 12 | + <% if profile.institution.type == "GovUserPlugin::PrivateInstitution"%> |
13 | <%= display_mpog_field(_('Fantasy Name:'), profile.institution, :acronym, true) %> | 13 | <%= display_mpog_field(_('Fantasy Name:'), profile.institution, :acronym, true) %> |
14 | <% else %> | 14 | <% else %> |
15 | <%= display_mpog_field(_('Acronym:'), profile.institution, :acronym, true) %> | 15 | <%= display_mpog_field(_('Acronym:'), profile.institution, :acronym, true) %> |