Commit a014bdb712478c9809d997519df72a6e583eabf6

Authored by Gabriela Navarro
Committed by Arthur Esposte
1 parent f4efbd44

Remove institution from software communites.

Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Signed-off-by: Thiago Ribeiro <thiagitosouza@hotmail.com>
controllers/software_communities_plugin_controller.rb
@@ -20,6 +20,27 @@ class SoftwareCommunitiesPluginController &lt; ApplicationController @@ -20,6 +20,27 @@ class SoftwareCommunitiesPluginController &lt; ApplicationController
20 render 'box_organizer/_download_list_template', :layout => false 20 render 'box_organizer/_download_list_template', :layout => false
21 end 21 end
22 22
  23 + def get_field_data
  24 + condition = !request.xhr? || params[:query].nil? || params[:field].nil?
  25 + return render :json=>{} if condition
  26 +
  27 + model = get_model_by_params_field
  28 +
  29 + data = model.where("name ILIKE ?", "%#{params[:query]}%").select("id, name")
  30 + .collect { |db|
  31 + {:id=>db.id, :label=>db.name}
  32 + }
  33 +
  34 + other = [model.select("id, name").last].collect { |db|
  35 + {:id=>db.id, :label=>db.name}
  36 + }
  37 +
  38 + # Always has other in the list
  39 + data |= other
  40 +
  41 + render :json=> data
  42 + end
  43 +
23 protected 44 protected
24 45
25 def get_model_by_params_field 46 def get_model_by_params_field
features/institution_registration.feature
@@ -1,32 +0,0 @@ @@ -1,32 +0,0 @@
1 -Feature: Institution Field  
2 - As a user  
3 - I want to sign up resgistring my institution  
4 - So others users can use it  
5 -  
6 - Background:  
7 - Given "SoftwareCommunitiesPlugin" plugin is enabled  
8 - And I am logged in as mpog_admin  
9 - And I go to /admin/plugins  
10 - And I check "SoftwareCommunitiesPlugin"  
11 - And I press "Save changes"  
12 - And Institutions has initial default values on database  
13 - And I am logged in as mpog_admin  
14 -  
15 - @selenium  
16 - Scenario: Show new institution fields when clicked in create new institution  
17 - Given I follow "Edit Profile"  
18 - When I follow "Create new institution"  
19 - And I should see "New Institution"  
20 - And I should see "Public Institution"  
21 - And I should see "Private Institution"  
22 - And I should see "Corporate Name"  
23 - And I should see "Name"  
24 - And I should see "State"  
25 - And I should see "City"  
26 - And I should see "Country"  
27 - And I should see "CNPJ"  
28 - And I should see "Acronym"  
29 - And I choose "Public Institution"  
30 - Then I should see "Governmental Sphere:"  
31 - And I should see "Governmental Power:"  
32 - And I should see "Juridical Nature:"  
33 \ No newline at end of file 0 \ No newline at end of file
features/public_software_validation.feature
@@ -47,6 +47,3 @@ Feature: edit adherent fields @@ -47,6 +47,3 @@ Feature: edit adherent fields
47 And I check "software[public_software]" 47 And I check "software[public_software]"
48 And I uncheck "software[public_software]" 48 And I uncheck "software[public_software]"
49 Then I should not see "Adherent to e-ping ?" 49 Then I should not see "Adherent to e-ping ?"
50 -  
51 -  
52 -  
features/step_definitions/software_communities_steps.rb
@@ -18,28 +18,6 @@ Given /^SoftwareInfo has initial default values on database$/ do @@ -18,28 +18,6 @@ Given /^SoftwareInfo has initial default values on database$/ do
18 OperatingSystemName.create(:name=>"CentOS") 18 OperatingSystemName.create(:name=>"CentOS")
19 end 19 end
20 20
21 -Given /^Institutions has initial default values on database$/ do  
22 - GovernmentalPower.create(:name => "Executivo")  
23 - GovernmentalPower.create(:name => "Legislativo")  
24 - GovernmentalPower.create(:name => "Judiciario")  
25 -  
26 - GovernmentalSphere.create(:name => "Federal")  
27 -  
28 - JuridicalNature.create(:name => "Autarquia")  
29 - JuridicalNature.create(:name => "Administracao Direta")  
30 - JuridicalNature.create(:name => "Empresa Publica")  
31 - JuridicalNature.create(:name => "Fundacao")  
32 - JuridicalNature.create(:name => "Orgao Autonomo")  
33 - JuridicalNature.create(:name => "Sociedade")  
34 - JuridicalNature.create(:name => "Sociedade Civil")  
35 - JuridicalNature.create(:name => "Sociedade de Economia Mista")  
36 -  
37 - national_region = NationalRegion.new  
38 - national_region.name = "Distrito Federal"  
39 - national_region.national_region_code = '35'  
40 - national_region.national_region_type_id = NationalRegionType::STATE  
41 - national_region.save  
42 -end  
43 21
44 Given /^I type in "([^"]*)" in autocomplete list "([^"]*)" and I choose "([^"]*)"$/ do |typed, input_field_selector, should_select| 22 Given /^I type in "([^"]*)" in autocomplete list "([^"]*)" and I choose "([^"]*)"$/ do |typed, input_field_selector, should_select|
45 # Wait the page javascript load 23 # Wait the page javascript load
@@ -64,27 +42,6 @@ Given /^I type in &quot;([^&quot;]*)&quot; in autocomplete list &quot;([^&quot;]*)&quot; and I choose &quot;([^&quot;]*) @@ -64,27 +42,6 @@ Given /^I type in &quot;([^&quot;]*)&quot; in autocomplete list &quot;([^&quot;]*)&quot; and I choose &quot;([^&quot;]*)
64 sleep 1 42 sleep 1
65 end 43 end
66 44
67 -Given /^the following public institutions?$/ do |table|  
68 - # table is a Cucumber::Ast::Table  
69 - table.hashes.each do |item|  
70 - community = Community.new  
71 - community.name = item[:name]  
72 - community.country = item[:country]  
73 - community.state = item[:state]  
74 - community.city = item[:city]  
75 - community.save!  
76 -  
77 - governmental_power = GovernmentalPower.where(:name => item[:governmental_power]).first  
78 - governmental_sphere = GovernmentalSphere.where(:name => item[:governmental_sphere]).first  
79 -  
80 - juridical_nature = JuridicalNature.create(:name => item[:juridical_nature])  
81 -  
82 - 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)  
83 - institution.community = community  
84 - institution.corporate_name = item[:corporate_name]  
85 - institution.save!  
86 - end  
87 -end  
88 45
89 Given /^the following software language$/ do |table| 46 Given /^the following software language$/ do |table|
90 table.hashes.each do |item| 47 table.hashes.each do |item|
features/user_profile_edition.feature
@@ -1,53 +0,0 @@ @@ -1,53 +0,0 @@
1 -Feature: Institution Field  
2 - As a user  
3 - I want to update my update my user data  
4 - So I can maintain my personal data updated  
5 -  
6 - Background:  
7 - Given "SoftwareCommunitiesPlugin" plugin is enabled  
8 - And I am logged in as mpog_admin  
9 - And I go to /admin/plugins  
10 - And I check "SoftwareCommunitiesPlugin"  
11 - And I press "Save changes"  
12 - And feature "skip_new_user_email_confirmation" is enabled on environment  
13 - And I go to /admin/features/manage_fields  
14 - And I check "person_fields_country_active"  
15 - And I check "person_fields_state_active"  
16 - And I check "person_fields_city_active"  
17 - And I press "Save changes"  
18 - And Institutions has initial default values on database  
19 - And the following public institutions  
20 - | name | acronym | country | state | city | cnpj | juridical_nature | governmental_power | governmental_sphere | corporate_name |  
21 - | Ministerio das Cidades | MC | BR | DF | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal | Ministerio das Cidades |  
22 - | Governo do DF | GDF | BR | DF | Taguatinga | 12.645.166/0001-44 | Autarquia | Legislativo | Federal | Governo do DF |  
23 - | Ministerio do Planejamento | MP | BR | DF | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal | Ministerio do Planejamento |  
24 - And I am logged in as mpog_admin  
25 -  
26 - @selenium  
27 - Scenario: Add more then one instituion on profile editor  
28 - Given I follow "Edit Profile"  
29 - And I follow "Add new institution"  
30 - And I type in "Minis" in autocomplete list "#input_institution" and I choose "Ministerio do Planejamento"  
31 - And I follow "Add new institution"  
32 - And I type in "Gover" in autocomplete list "#input_institution" and I choose "Governo do DF"  
33 - And I follow "Add new institution"  
34 - Then I should see "Ministerio do Planejamento" within ".institutions_added"  
35 - And I should see "Governo do DF" within ".institutions_added"  
36 -  
37 - @selenium  
38 - Scenario: Verify if field 'city' is shown when Brazil is selected  
39 - Given I follow "Edit Profile"  
40 - Then I should see "City"  
41 -  
42 - @selenium  
43 - Scenario: Verify if field 'city' does not appear when Brazil is not selected as country  
44 - Given I follow "Edit Profile"  
45 - When I select "United States" from "profile_data_country"  
46 - Then I should not see "City" within ".type-text"  
47 -  
48 - @selenium  
49 - Scenario: Show message of institution not found  
50 - Given I follow "Edit Profile"  
51 - And I fill in "input_institution" with "Some Nonexistent Institution"  
52 - And I sleep for 1 seconds  
53 - Then I should see "No institution found"  
lib/software_communities_plugin.rb
@@ -73,14 +73,12 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin @@ -73,14 +73,12 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin
73 vendor/jquery.js 73 vendor/jquery.js
74 lib/noosfero-root.js 74 lib/noosfero-root.js
75 lib/select-element.js 75 lib/select-element.js
76 - lib/select-field-choices 76 + lib/select-field-choices.js
77 lib/auto-complete.js 77 lib/auto-complete.js
78 lib/software-catalog-component.js 78 lib/software-catalog-component.js
79 views/control-panel.js 79 views/control-panel.js
80 views/edit-software.js 80 views/edit-software.js
81 views/new-software.js 81 views/new-software.js
82 - views/user-edit-profile.js  
83 - views/create-institution.js  
84 views/search-software-catalog.js 82 views/search-software-catalog.js
85 views/profile-tabs-software.js 83 views/profile-tabs-software.js
86 views/new-community.js 84 views/new-community.js
public/initializer.js
@@ -5,8 +5,6 @@ @@ -5,8 +5,6 @@
5 'ControlPanel', 5 'ControlPanel',
6 'EditSoftware', 6 'EditSoftware',
7 'NewSoftware', 7 'NewSoftware',
8 - 'UserEditProfile',  
9 - 'CreateInstitution',  
10 'SearchSoftwareCatalog', 8 'SearchSoftwareCatalog',
11 'SoftwareDownload', 9 'SoftwareDownload',
12 'ProfileTabsSoftware', 10 'ProfileTabsSoftware',
public/static/governmental_powers.txt
@@ -1,4 +0,0 @@ @@ -1,4 +0,0 @@
1 -Executivo  
2 -Legislativo  
3 -Judiciario  
4 -Nao se aplica  
public/static/governmental_sphere.txt
@@ -1,4 +0,0 @@ @@ -1,4 +0,0 @@
1 -Federal  
2 -Estadual  
3 -Distrital  
4 -Municipal  
5 \ No newline at end of file 0 \ No newline at end of file
public/static/juridical_nature.txt
@@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
1 -Administracao Direta  
2 -Autarquia  
3 -Empresa Publica  
4 -Fundacao  
5 -Orgao Autonomo  
6 -Sociedade  
7 -Sociedade Civil  
8 -Sociedade de Economia Mista  
public/views/control-panel.js
@@ -9,22 +9,11 @@ modulejs.define(&#39;ControlPanel&#39;, [&#39;jquery&#39;], function($) { @@ -9,22 +9,11 @@ modulejs.define(&#39;ControlPanel&#39;, [&#39;jquery&#39;], function($) {
9 } 9 }
10 } 10 }
11 11
12 -  
13 - function add_institution_on_control_panel(control_panel) {  
14 - var institution_link = $(".control-panel-instituton-link").remove();  
15 -  
16 - if( institution_link.size() > 0 ) {  
17 - control_panel.prepend(institution_link);  
18 - }  
19 - }  
20 -  
21 -  
22 function add_itens_on_controla_panel() { 12 function add_itens_on_controla_panel() {
23 var control_panel = $(".control-panel"); 13 var control_panel = $(".control-panel");
24 14
25 if( control_panel.size() > 0 ) { 15 if( control_panel.size() > 0 ) {
26 add_software_on_control_panel(control_panel); 16 add_software_on_control_panel(control_panel);
27 - add_institution_on_control_panel(control_panel);  
28 } 17 }
29 } 18 }
30 19
public/views/create-institution.js
@@ -1,312 +0,0 @@ @@ -1,312 +0,0 @@
1 -modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'], function($, NoosferoRoot, SelectElement) {  
2 - 'use strict';  
3 -  
4 - var AJAX_URL = {  
5 - create_institution_modal:  
6 - NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/create_institution"),  
7 - new_institution:  
8 - NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/new_institution"),  
9 - institution_already_exists:  
10 - NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/institution_already_exists"),  
11 - get_institutions:  
12 - NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/get_institutions")  
13 - };  
14 -  
15 -  
16 - function open_create_institution_modal(evt) {  
17 - evt.preventDefault();  
18 -  
19 - $.get(AJAX_URL.create_institution_modal, function(response){  
20 - $("#institution_dialog").html(response);  
21 -  
22 - set_form_count_custom_data();  
23 - set_events();  
24 -  
25 - $("#institution_dialog").dialog({  
26 - modal: true,  
27 - width: 500,  
28 - height: 530,  
29 - position: 'center',  
30 - close: function() {  
31 - $("#institution_dialog").html("");  
32 - $('#institution_empty_ajax_message').switchClass("show-field", "hide-field");  
33 - }  
34 - });  
35 - });  
36 - }  
37 -  
38 -  
39 - function show_public_institutions_fields() {  
40 - $(".public-institutions-fields").show();  
41 - }  
42 -  
43 -  
44 - function show_private_institutions_fields() {  
45 - $(".public-institutions-fields").hide();  
46 -  
47 - $("#institutions_governmental_power option").selected(0);  
48 - $("#institutions_governmental_sphere option").selected(0);  
49 - }  
50 -  
51 -  
52 - function get_comunity_post_data() {  
53 - return {  
54 - name : $("#community_name").val(),  
55 - country : $("#community_country").val(),  
56 - state : $("#community_state").val(),  
57 - city : $("#community_city").val()  
58 - }  
59 - }  
60 -  
61 -  
62 - function get_institution_post_data() {  
63 - return {  
64 - cnpj: $("#institutions_cnpj").val(),  
65 - type: $("input[name='institutions[type]']:checked").val(),  
66 - acronym : $("#institutions_acronym").val(),  
67 - governmental_power: $("#institutions_governmental_power").selected().val(),  
68 - governmental_sphere: $("#institutions_governmental_sphere").selected().val(),  
69 - juridical_nature: $("#institutions_juridical_nature").selected().val(),  
70 - corporate_name: $("#institutions_corporate_name").val()  
71 - }  
72 - }  
73 -  
74 -  
75 - function get_post_data() {  
76 - var post_data = {};  
77 -  
78 - post_data.community = get_comunity_post_data();  
79 - post_data.institutions = get_institution_post_data();  
80 -  
81 - return post_data;  
82 - }  
83 -  
84 -  
85 - function success_ajax_response(response) {  
86 - close_loading();  
87 -  
88 - if(response.success){  
89 - var institution_name = response.institution_data.name;  
90 - var institution_id = response.institution_data.id;  
91 -  
92 - $("#institution_dialog").html("<div class='errorExplanation'><h2>"+response.message+"</h2></div>");  
93 - $("#create_institution_errors").switchClass("show-field", "hide-field");  
94 -  
95 - $(".institution_container").append(get_clone_institution_data(institution_id));  
96 - add_selected_institution_to_list(institution_id, institution_name);  
97 -  
98 - $(".remove-institution").click(remove_institution);  
99 - } else {  
100 - var errors = "<ul>";  
101 -  
102 - for(var i = 0; i < response.errors.length; i++) {  
103 - errors += "<li>"+response.errors[i]+"</li>";  
104 - }  
105 - errors += "</ul>";  
106 -  
107 - $("#create_institution_errors").switchClass("hide-field", "show-field").html("<h2>"+response.message+"</h2>"+errors);  
108 - }  
109 - }  
110 -  
111 -  
112 - function save_institution(evt) {  
113 - evt.preventDefault();  
114 -  
115 - open_loading($("#loading_message").val());  
116 - $.ajax({  
117 - url: AJAX_URL.new_institution,  
118 - data : get_post_data(),  
119 - type: "POST",  
120 - success: success_ajax_response,  
121 - error: function() {  
122 - close_loading();  
123 - var error_message = $("#institution_error_message").val();  
124 - $("#create_institution_errors").switchClass("hide-field", "show-field").html("<h2>"+error_message+"</h2>");  
125 - }  
126 - });  
127 - }  
128 -  
129 -  
130 - function institution_already_exists(){  
131 - if( this.value.length >= 3 ) {  
132 - $.get(AJAX_URL.institution_already_exists, {name:this.value}, function(response){  
133 - if( response === true ) {  
134 - $("#already_exists_text").switchClass("hide-field", "show-field");  
135 - } else {  
136 - $("#already_exists_text").switchClass("show-field", "hide-field");  
137 - }  
138 - });  
139 - }  
140 - }  
141 -  
142 -  
143 - function get_clone_institution_data(value) {  
144 - var user_institutions = $(".user_institutions").first().clone();  
145 - user_institutions.val(value);  
146 -  
147 - return user_institutions;  
148 - }  
149 -  
150 -  
151 - function institution_autocomplete() {  
152 - $("#input_institution").autocomplete({  
153 - source : function(request, response){  
154 - $.ajax({  
155 - type: "GET",  
156 - url: AJAX_URL.get_institutions,  
157 - data: {query: request.term},  
158 - success: function(result){  
159 - response(result);  
160 -  
161 - if( result.length === 0 ) {  
162 - $('#institution_empty_ajax_message').switchClass("hide-field", "show-field");  
163 - } else {  
164 - $('#institution_empty_ajax_message').switchClass("show-field", "hide-field");  
165 - }  
166 - },  
167 - error: function(ajax, stat, errorThrown) {  
168 - console.log('Link not found : ' + errorThrown);  
169 - }  
170 - });  
171 - },  
172 -  
173 - minLength: 2,  
174 -  
175 - select : function (event, selected) {  
176 - $("#institution_selected").val(selected.item.id).attr("data-name", selected.item.label);  
177 - }  
178 - });  
179 - }  
180 -  
181 -  
182 - function add_selected_institution_to_list(id, name) {  
183 - var selected_institution = "<li data-institution='"+id+"'>"+name;  
184 - selected_institution += "<a href='#' class='button without-text icon-remove remove-institution'></a></li>";  
185 -  
186 - $(".institutions_added").append(selected_institution);  
187 - }  
188 -  
189 -  
190 - function add_new_institution(evt) {  
191 - evt.preventDefault();  
192 - var selected = $("#institution_selected");  
193 - var institution_already_added = $(".institutions_added li[data-institution='"+selected.val()+"']").length;  
194 -  
195 - if(selected.val().length > 0 && institution_already_added === 0) {  
196 - //field that send the institutions to the server  
197 - $(".institution_container").append(get_clone_institution_data(selected.val()));  
198 -  
199 - // Visualy add the selected institution to the list  
200 - add_selected_institution_to_list(selected.val(), selected.attr("data-name"));  
201 -  
202 - // clean the institution flag  
203 - selected.val("").attr("data-name", "");  
204 - $("#input_institution").val("");  
205 -  
206 - $(".remove-institution").click(remove_institution);  
207 - }  
208 - }  
209 -  
210 -  
211 - function remove_institution(evt) {  
212 - evt.preventDefault();  
213 - var code = $(this).parent().attr("data-institution");  
214 -  
215 - $(".user_institutions[value="+code+"]").remove();  
216 - $(this).parent().remove();  
217 - }  
218 -  
219 -  
220 - function add_mask_to_form_items() {  
221 - $(".intitution_cnpj_field").mask("99.999.999/9999-99");  
222 - }  
223 -  
224 -  
225 - function show_hide_cnpj_city(country) {  
226 - var cnpj = $("#institutions_cnpj").parent().parent();  
227 - var city = $("#community_city").parent().parent();  
228 - var state = $("#community_state").parent().parent();  
229 -  
230 - if( country === "-1" ) $("#community_country").val("BR");  
231 -  
232 - if( country !== "BR" ) {  
233 - cnpj.hide();  
234 - city.hide();  
235 - state.hide();  
236 - } else {  
237 - cnpj.show();  
238 - city.show();  
239 - state.show();  
240 - }  
241 - }  
242 -  
243 -  
244 - function institution_type_actions(type) {  
245 - if( type === "PublicInstitution" ) {  
246 - show_public_institutions_fields();  
247 - } else {  
248 - show_private_institutions_fields();  
249 - }  
250 - }  
251 -  
252 -  
253 - function set_form_count_custom_data() {  
254 - var divisor_option = SelectElement.generateOption("-1", "--------------------------------");  
255 - var default_option = SelectElement.generateOption("BR", "Brazil");  
256 -  
257 - var inst_type = $("input[name='institutions[type]']:checked").val();  
258 - var country = $("#community_country").val();  
259 -  
260 - institution_type_actions(inst_type);  
261 - show_hide_cnpj_city(country);  
262 -  
263 - if( $('#community_country').find("option[value='']").length === 1 ) {  
264 - $('#community_country').find("option[value='']").remove();  
265 - $('#community_country').prepend(divisor_option);  
266 - $('#community_country').prepend(default_option);  
267 -  
268 - if($("#edit_institution_page").val() === "false") {  
269 - $('#community_country').val("BR");  
270 - show_hide_cnpj_city($('#community_country').val());  
271 - }  
272 - }  
273 - }  
274 -  
275 -  
276 - function set_events() {  
277 - $("#create_institution_link").click(open_create_institution_modal);  
278 -  
279 - $("input[name='institutions[type]']").click(function(){  
280 - institution_type_actions(this.value);  
281 - });  
282 -  
283 - $('#save_institution_button').click(save_institution);  
284 -  
285 - $("#community_name").keyup(institution_already_exists);  
286 -  
287 - $("#add_new_institution").click(add_new_institution);  
288 -  
289 - $(".remove-institution").click(remove_institution);  
290 -  
291 - $("#community_country").change(function(){  
292 - show_hide_cnpj_city(this.value);  
293 - });  
294 -  
295 - add_mask_to_form_items();  
296 -  
297 - institution_autocomplete();  
298 - }  
299 -  
300 -  
301 - return {  
302 - isCurrentPage: function() {  
303 - return $("#institution_form").length === 1;  
304 - },  
305 -  
306 -  
307 - init: function() {  
308 - set_form_count_custom_data();  
309 - set_events();  
310 - }  
311 - }  
312 -});  
public/views/user-edit-profile.js
@@ -1,216 +0,0 @@ @@ -1,216 +0,0 @@
1 -modulejs.define('UserEditProfile', ['jquery', 'SelectElement', 'SelectFieldChoices', 'CreateInstitution'], function($, SelectElement, SelectFieldChoices, CreateInstitution) {  
2 - 'use strict';  
3 -  
4 - function set_form_count_custom_data() {  
5 - var divisor_option = SelectElement.generateOption("-1", "--------------------------------");  
6 - var default_option = SelectElement.generateOption("BR", "Brazil");  
7 -  
8 - $('#profile_data_country').find("option[value='']").remove();  
9 - $('#profile_data_country').prepend(divisor_option);  
10 - $('#profile_data_country').prepend(default_option);  
11 - $('#profile_data_country').val("BR");  
12 - }  
13 -  
14 -  
15 - function set_initial_form_custom_data(selectFieldChoices) {  
16 - set_form_count_custom_data();  
17 -  
18 - $("#password-balloon").html($("#user_password_menssage").val());  
19 - $("#profile_data_email").parent().append($("#email_public_message").remove());  
20 -  
21 - if( $("#state_field").length !== 0 ) selectFieldChoices.replaceStateWithSelectElement();  
22 - }  
23 -  
24 -  
25 - function show_state_if_country_is_brazil() {  
26 - var selectFieldChoices = new SelectFieldChoices("#state_field", "#city_field", "/plugin/software_communities/get_brazil_states");  
27 - set_initial_form_custom_data(selectFieldChoices);  
28 -  
29 - $("#profile_data_country").change(function(){  
30 - if( this.value === "-1" ) $(this).val("BR");  
31 -  
32 - if( this.value === "BR" && selectFieldChoices.actualFieldIsInput() ) {  
33 - selectFieldChoices.replaceStateWithSelectElement();  
34 - selectFieldChoices.showCity();  
35 - } else if( this.value !== "BR" && !selectFieldChoices.actualFieldIsInput() ) {  
36 - selectFieldChoices.replaceStateWithInputElement();  
37 - selectFieldChoices.hideCity();  
38 - }  
39 - });  
40 - }  
41 -  
42 -  
43 - function show_or_hide_phone_mask() {  
44 - if($("#profile_data_country").val() === "BR") {  
45 - if( (typeof $("#profile_data_cell_phone").data("rawMaskFn") === 'undefined') ) {  
46 - $("#profile_data_cell_phone").mask("(99) 9999?9-9999");  
47 - $("#profile_data_comercial_phone").mask("(99) 9999?9-9999");  
48 - $("#profile_data_contact_phone").mask("(99) 9999?9-9999");  
49 - }  
50 - } else {  
51 - $("#profile_data_cell_phone").unmask();  
52 - $("#profile_data_comercial_phone").unmask();  
53 - $("#profile_data_contact_phone").unmask();  
54 - }  
55 - }  
56 -  
57 -  
58 - function fix_phone_mask_format(id) {  
59 - $(id).blur(function() {  
60 - var last = $(this).val().substr( $(this).val().indexOf("-") + 1 );  
61 -  
62 - if( last.length === 3 ) {  
63 - var move = $(this).val().substr( $(this).val().indexOf("-") - 1, 1 );  
64 - var lastfour = move + last;  
65 - var first = $(this).val().substr( 0, 9 );  
66 -  
67 - $(this).val( first + '-' + lastfour );  
68 - }  
69 - });  
70 - }  
71 -  
72 -  
73 - function show_plugin_error_message(field_selector, hidden_message_id ) {  
74 - var field = $(field_selector);  
75 -  
76 - field.removeClass("validated").addClass("invalid");  
77 -  
78 - if(!$("." + hidden_message_id)[0]) {  
79 - var message = $("#" + hidden_message_id).val();  
80 - field.parent().append("<div class='" + hidden_message_id + " errorExplanation'>"+message+"</span>");  
81 - } else {  
82 - $("." + hidden_message_id).show();  
83 - }  
84 - }  
85 -  
86 -  
87 - function hide_plugin_error_message(field_selector, hidden_message_id) {  
88 - $(field_selector).removeClass("invalid").addClass("validated");  
89 - $("." + hidden_message_id).hide();  
90 - }  
91 -  
92 -  
93 - function add_blur_fields(field_selector, hidden_message_id, validation_function, allow_blank) {  
94 - $(field_selector).blur(function(){  
95 - $(this).attr("class", "");  
96 -  
97 - if( validation_function(this.value, !!allow_blank) ) {  
98 - show_plugin_error_message(field_selector, hidden_message_id);  
99 - } else {  
100 - hide_plugin_error_message(field_selector, hidden_message_id);  
101 - }  
102 - });  
103 - }  
104 -  
105 -  
106 - function invalid_email_validation(value, allow_blank) {  
107 - if( allow_blank && value.trim().length === 0 ) {  
108 - return false;  
109 - }  
110 -  
111 - var correct_format_regex = new RegExp(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/);  
112 -  
113 - return !correct_format_regex.test(value);  
114 - }  
115 -  
116 -  
117 - function invalid_site_validation(value) {  
118 - var correct_format_regex = new RegExp(/(^|)(http[s]{0,1})\:\/\/(\w+[.])\w+/g);  
119 -  
120 - return !correct_format_regex.test(value);  
121 - }  
122 -  
123 -  
124 - function get_privacy_selector_parent_div(field_id, actual) {  
125 - if( actual === undefined ) actual = $(field_id);  
126 -  
127 - if( actual.is("form") || actual.length === 0 ) return null; // Not allow recursion over form  
128 -  
129 - if( actual.hasClass("field-with-privacy-selector") ) {  
130 - return actual;  
131 - } else {  
132 - return get_privacy_selector_parent_div(field_id, actual.parent());  
133 - }  
134 - }  
135 -  
136 -  
137 - function try_to_remove(list, field) {  
138 - try {  
139 - list.push(field.remove());  
140 - } catch(e) {  
141 - console.log("Cound not remove field");  
142 - }  
143 - }  
144 -  
145 -  
146 - function get_edit_fields_in_insertion_order() {  
147 - var containers = [];  
148 -  
149 - try_to_remove(containers, get_privacy_selector_parent_div("#city_field"));  
150 - try_to_remove(containers, get_privacy_selector_parent_div("#state_field"));  
151 - try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_country"));  
152 - try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_birth_date"));  
153 - try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_organization_website"));  
154 - try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_personal_website"));  
155 - try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_comercial_phone"));  
156 - try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_contact_phone"));  
157 - try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_cell_phone"));  
158 - try_to_remove(containers, $("#select_institution"));  
159 - try_to_remove(containers, $("#user_secondary_email").parent().parent());  
160 - try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_email"));  
161 - try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_name"));  
162 - try_to_remove(containers, $(".pseudoformlabel").parent().parent());  
163 - try_to_remove(containers, $("h2")[0]);  
164 -  
165 - return containers;  
166 - }  
167 -  
168 -  
169 - function change_edit_fields_order() {  
170 - var form = $("#profile-data");  
171 -  
172 - if( form.length !== 0 ) {  
173 - var containers = get_edit_fields_in_insertion_order();  
174 -  
175 - containers.forEach(function(container){  
176 - form.prepend(container);  
177 - });  
178 - }  
179 - }  
180 -  
181 -  
182 - function set_fields_validations() {  
183 - $("#profile_data_country").blur(show_or_hide_phone_mask);  
184 -  
185 - $("#profile_data_birth_date").mask("99/99/9999");  
186 -  
187 - fix_phone_mask_format("#profile_data_cell_phone");  
188 - fix_phone_mask_format("#profile_data_comercial_phone");  
189 - fix_phone_mask_format("#profile_data_contact_phone");  
190 -  
191 - add_blur_fields("#profile_data_email", "email_error", invalid_email_validation);  
192 - add_blur_fields("#user_secondary_email", "email_error", invalid_email_validation, true);  
193 - add_blur_fields("#profile_data_personal_website", "site_error", invalid_site_validation);  
194 - add_blur_fields("#profile_data_organization_website", "site_error", invalid_site_validation);  
195 - }  
196 -  
197 -  
198 - return {  
199 - isCurrentPage: function() {  
200 - return $('#profile_data_email').length === 1;  
201 - },  
202 -  
203 -  
204 - init: function() {  
205 - change_edit_fields_order(); // To change the fields order, it MUST be the first function executed  
206 -  
207 - show_state_if_country_is_brazil();  
208 -  
209 - show_or_hide_phone_mask();  
210 -  
211 - set_fields_validations();  
212 -  
213 - CreateInstitution.init();  
214 - }  
215 - }  
216 -});  
test/functional/profile_editor_controller_test.rb
1 require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
2 -require File.dirname(__FILE__) + '/../helpers/institution_test_helper'  
3 require( 2 require(
4 File.dirname(__FILE__) + 3 File.dirname(__FILE__) +
5 '/../../../../app/controllers/my_profile/profile_editor_controller' 4 '/../../../../app/controllers/my_profile/profile_editor_controller'
test/functional/software_communities_plugin_controller_test.rb
1 require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
2 -require File.dirname(__FILE__) + '/../helpers/institution_test_helper'  
3 require File.dirname(__FILE__) + '/../../controllers/software_communities_plugin_controller' 2 require File.dirname(__FILE__) + '/../../controllers/software_communities_plugin_controller'
4 3
5 class SoftwareCommunitiesPluginController; def rescue_action(e) raise e end; end 4 class SoftwareCommunitiesPluginController; def rescue_action(e) raise e end; end
test/helpers/institution_test_helper.rb
@@ -1,59 +0,0 @@ @@ -1,59 +0,0 @@
1 -module InstitutionTestHelper  
2 -  
3 - def self.generate_form_fields name, country, state, city, cnpj, type  
4 - fields = {  
5 - :community => {  
6 - :name => name,  
7 - :country => country,  
8 - :state => state,  
9 - :city => city  
10 - },  
11 - :institutions => {  
12 - :cnpj=> cnpj,  
13 - :type => type,  
14 - :acronym => "",  
15 - :governmental_power => "",  
16 - :governmental_sphere => "",  
17 - :juridical_nature => "",  
18 - :corporate_name => "coporate default"  
19 - }  
20 - }  
21 - fields  
22 - end  
23 -  
24 - def self.create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s, cnpj  
25 - institution = PublicInstitution.new  
26 - institution.community = institution_community(name, country, state, city)  
27 - institution.name = name  
28 - institution.juridical_nature = juridical_nature  
29 - institution.acronym = acronym  
30 - institution.governmental_power = gov_p  
31 - institution.governmental_sphere = gov_s  
32 - institution.cnpj = cnpj  
33 - institution.corporate_name = "corporate default"  
34 - institution.save  
35 - institution  
36 - end  
37 -  
38 - def self.create_private_institution name, acronym, country, state, city, cnpj  
39 - institution = PrivateInstitution.new  
40 - institution.community = institution_community(name, country, state, city)  
41 - institution.name = name  
42 - institution.acronym = acronym  
43 - institution.cnpj = cnpj  
44 - institution.corporate_name = "corporate default"  
45 - institution.save  
46 -  
47 - institution  
48 - end  
49 -  
50 - def self.institution_community name, country, state, city  
51 - institution_community = Community::new  
52 - institution_community.name = name  
53 - institution_community.country = country  
54 - institution_community.state = state  
55 - institution_community.city = city  
56 - institution_community.save  
57 - institution_community  
58 - end  
59 -end  
60 \ No newline at end of file 0 \ No newline at end of file
test/helpers/plugin_test_helper.rb
1 -require File.dirname(__FILE__) + '/../helpers/institution_test_helper'  
2 -  
3 module PluginTestHelper 1 module PluginTestHelper
4 2
5 - def create_public_institution *params  
6 - InstitutionTestHelper.create_public_institution *params  
7 - end  
8 -  
9 def create_community name 3 def create_community name
10 community = fast_create(Community) 4 community = fast_create(Community)
11 community.name = name 5 community.name = name
@@ -25,27 +19,6 @@ module PluginTestHelper @@ -25,27 +19,6 @@ module PluginTestHelper
25 software_info 19 software_info
26 end 20 end
27 21
28 - def create_private_institution name, acronym, country, state, city, cnpj  
29 - InstitutionTestHelper.create_private_institution(  
30 - name,  
31 - acronym,  
32 - country,  
33 - state,  
34 - city,  
35 - cnpj  
36 - )  
37 - end  
38 -  
39 - def create_community_institution name, country, state, city  
40 - community = fast_create(Community)  
41 - community.name = name  
42 - community.country = country  
43 - community.state = state  
44 - community.city = city  
45 - community.save  
46 - community  
47 - end  
48 -  
49 def create_person name, email, password, password_confirmation, state, city 22 def create_person name, email, password, password_confirmation, state, city
50 user = create_user( 23 user = create_user(
51 name.to_slug, 24 name.to_slug,
test/unit/communities_block_test.rb
1 require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
2 -require File.dirname(__FILE__) + '/../helpers/institution_test_helper'  
3 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' 2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
4 3
5 class CommunitiesBlockTest < ActiveSupport::TestCase 4 class CommunitiesBlockTest < ActiveSupport::TestCase
@@ -7,13 +6,6 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase @@ -7,13 +6,6 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase
7 def setup 6 def setup
8 @person = create_person("My Name", "user@email.com", "123456", "123456", "Any State", "Some City") 7 @person = create_person("My Name", "user@email.com", "123456", "123456", "Any State", "Some City")
9 8
10 - @gov_power = GovernmentalPower.create(:name=>"Some Gov Power")  
11 - @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")  
12 - @juridical_nature = JuridicalNature.create(:name => "Autarquia")  
13 -  
14 - @institution = InstitutionTestHelper.create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @gov_power, @gov_sphere, "12.345.678/9012-45")  
15 - @institution.community.add_member(@person)  
16 -  
17 @software_info = create_software_info("Novo Software") 9 @software_info = create_software_info("Novo Software")
18 @software_info.community.add_member(@person) 10 @software_info.community.add_member(@person)
19 11
@@ -26,12 +18,8 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase @@ -26,12 +18,8 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase
26 end 18 end
27 19
28 def teardown 20 def teardown
29 - GovernmentalPower.destroy_all  
30 - GovernmentalSphere.destroy_all  
31 - JuridicalNature.destroy_all  
32 CommunitiesBlock.destroy_all 21 CommunitiesBlock.destroy_all
33 @person = nil 22 @person = nil
34 - @institution = nil  
35 @community = nil 23 @community = nil
36 @software_info = nil 24 @software_info = nil
37 end 25 end
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
test/unit/institution_test.rb
@@ -1,62 +0,0 @@ @@ -1,62 +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 !@institution.save  
33 - assert @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 !@institution.save, 'Invalid type'  
40 - assert @institution.errors.full_messages.include? invalid_msg  
41 - end  
42 -  
43 - should "not save without country" do  
44 - @institution.community.country = nil  
45 - assert !@institution.save, "Country can't be blank"  
46 - assert @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 !@institution.save, "State can't be blank"  
53 - assert @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 -  
59 - assert !@institution.save, "City can't be blank"  
60 - assert @institution.errors.full_messages.include? "City can't be blank"  
61 - end  
62 -end  
test/unit/institutions_block_test.rb
@@ -1,50 +0,0 @@ @@ -1,50 +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 - "DF",  
31 - "Gama"  
32 - )  
33 -  
34 - institution = create_private_institution(  
35 - "inst name",  
36 - "IN",  
37 - "country",  
38 - "state",  
39 - "city",  
40 - "00.111.222/3333-44"  
41 - )  
42 - institution.community.add_member(user)  
43 -  
44 - block = InstitutionsBlock.new  
45 - block.expects(:owner).at_least_once.returns(user)  
46 -  
47 - assert_equivalent [institution.community], block.profiles  
48 - end  
49 -  
50 -end  
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  
test/unit/private_institution_test.rb
@@ -1,50 +0,0 @@ @@ -1,50 +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 "not save without a cnpj" do  
23 - @institution.cnpj = nil  
24 -  
25 - assert !@institution.save  
26 - assert @institution.errors.full_messages.include? "Cnpj can't be blank"  
27 - end  
28 -  
29 - should "not save with a repeated cnpj" do  
30 - msg = "Cnpj has already been taken"  
31 - assert @institution.save  
32 - sec_institution = create_private_institution(  
33 - "Another Private Institution",  
34 - "API",  
35 - "BR",  
36 - "DF",  
37 - "Gama",  
38 - "00.000.000/0001-00"  
39 - )  
40 -  
41 - assert sec_institution.errors.full_messages.include? msg  
42 - end  
43 -  
44 - should "save without fantasy name" do  
45 - @institution.acronym = nil  
46 - @institution.community.save  
47 -  
48 - assert @institution.save  
49 - end  
50 -end  
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 "not 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  
test/unit/software_communities_person_test.rb
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 require File.dirname(__FILE__) + '/../../../../test/test_helper' 3 require File.dirname(__FILE__) + '/../../../../test/test_helper'
4 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' 4 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
5 5
6 -class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase 6 +class GovUserPluginPersonTest < ActiveSupport::TestCase
7 include PluginTestHelper 7 include PluginTestHelper
8 8
9 def setup 9 def setup
@@ -11,50 +11,19 @@ class SoftwareCommunitiesPluginPersonTest &lt; ActiveSupport::TestCase @@ -11,50 +11,19 @@ class SoftwareCommunitiesPluginPersonTest &lt; ActiveSupport::TestCase
11 11
12 @user = fast_create(User) 12 @user = fast_create(User)
13 @person = create_person( 13 @person = create_person(
14 - "My Name",  
15 - "user@email.com",  
16 - "123456",  
17 - "123456",  
18 - "Any State",  
19 - "Some City"  
20 - ) 14 + "My Name",
  15 + "user@email.com",
  16 + "123456",
  17 + "123456",
  18 + "Any State",
  19 + "Some City"
  20 + )
21 end 21 end
22 22
23 def teardown 23 def teardown
24 @plugin = nil 24 @plugin = nil
25 end 25 end
26 26
27 - should 'be a noosfero plugin' do  
28 - assert_kind_of Noosfero::Plugin, @plugin  
29 - end  
30 -  
31 - should 'save person with a valid full name' do  
32 - p = Person::new :name=>"S1mpl3 0f N4m3", :identifier=>"simple-name"  
33 - p.user = fast_create(:user)  
34 -  
35 - assert_equal true, p.save  
36 - end  
37 -  
38 - should 'save person with a valid full name with accents' do  
39 - name = 'Jônatàs dâ Sîlvã Jösé'  
40 - identifier = "jonatas-jose-da-silva"  
41 - p = Person::new :name=>name, :identifier=>identifier  
42 - p.user = fast_create(:user)  
43 -  
44 - assert_equal true, p.save  
45 - end  
46 -  
47 - should 'not save person whose name has not capital letter' do  
48 - p = Person::new :name=>"simple name"  
49 - assert !p.save, _("Name Should begin with a capital letter and no special characters")  
50 - end  
51 -  
52 - should 'not save person whose name has special characters' do  
53 - p = Person::new :name=>"Simple N@me"  
54 -  
55 - assert !p.save , _("Name Should begin with a capital letter and no special characters")  
56 - end  
57 -  
58 should 'get a list of softwares of a person' do 27 should 'get a list of softwares of a person' do
59 software1 = create_software_info "noosfero" 28 software1 = create_software_info "noosfero"
60 software2 = create_software_info "colab" 29 software2 = create_software_info "colab"
views/person_editor_extras.html.erb
@@ -1,33 +0,0 @@ @@ -1,33 +0,0 @@
1 -<div class="formfieldline" id="select_institution">  
2 - <%= label_tag "user[institution_ids]", _('Institutions'), :class=>"formlabel" %>  
3 -  
4 - <div class="institution_container">  
5 - <%= text_field_tag(:institution, "", :id=>"input_institution") %>  
6 -  
7 - <% context.profile.user.institutions.each do |institution| %>  
8 - <%= hidden_field_tag("user[institution_ids][]", institution.id, :class => 'user_institutions') %>  
9 - <% end %>  
10 - </div>  
11 -  
12 - <%= content_tag(:div, _("No institution found"), :id=>"institution_empty_ajax_message", :class=>"errorExplanation hide-field") %>  
13 - <%= link_to(_("Add new institution"), "#", :class=>'button with-text icon-add', :id => 'add_new_institution') %>  
14 - <%= link_to(_("Create new institution"), "#", :id=>"create_institution_link", :class=>'button with-text icon-add') %>  
15 - <%= content_tag(:div, "", :id=>"institution_dialog") %>  
16 -  
17 - <%= hidden_field_tag("user[institution_ids][]", "", :class => 'user_institutions') %>  
18 - <%= hidden_field_tag("institution_selected", "") %>  
19 -  
20 - <ul class="institutions_added">  
21 - <% context.profile.user.institutions.each do |institution| %>  
22 - <li data-institution="<%= institution.id %>">  
23 - <%= institution.name %>  
24 - <%= link_to("", "#", :class => "button without-text icon-remove remove-institution") %>  
25 - </li>  
26 - <% end %>  
27 - </ul>  
28 -</div>  
29 -  
30 -<%= hidden_field_tag("full_name_error", _("Should begin with a capital letter and no special characters")) %>  
31 -<%= hidden_field_tag("email_error", _("Email should have the following format: name@host.br")) %>  
32 -<%= hidden_field_tag("site_error", _("Site should have a valid format: http://name.hosts")) %>  
33 -<div id="email_public_message"><%= _("If you work in a public agency use your government e-Mail") %> </div>  
views/profile/_institution_tab.html.erb
@@ -1,21 +0,0 @@ @@ -1,21 +0,0 @@
1 -<table>  
2 - <tr>  
3 - <th colspan='2'><%= _('Institution Information')%></th>  
4 - </tr>  
5 -  
6 - <%= display_mpog_field(_('Type:'), profile.institution, :type, true) %>  
7 - <%= display_mpog_field(_('CNPJ:'), profile.institution, :cnpj, true) %>  
8 - <%= display_mpog_field(_('Last modification:'), profile.institution, :date_modification, true) %>  
9 - <%= display_mpog_field(_('Country:'), profile.institution.community, :country, true) %>  
10 - <%= display_mpog_field(_('State:'), profile.institution.community, :state, true) %>  
11 - <%= display_mpog_field(_('City:'), profile.institution.community, :city, true) %>  
12 - <% if profile.institution.type == "PrivateInstitution"%>  
13 - <%= display_mpog_field(_('Fantasy Name:'), profile.institution, :acronym, true) %>  
14 - <% else %>  
15 - <%= display_mpog_field(_('Acronym:'), profile.institution, :acronym, true) %>  
16 - <%= display_mpog_field(_('Governmental Power:'), profile.institution.governmental_power, :name, true) %>  
17 - <%= display_mpog_field(_('Governmental Sphere:'), profile.institution.governmental_sphere, :name, true) %>  
18 - <%= display_mpog_field(_('Juridical Nature:'), profile.institution.juridical_nature, :name, true) %>  
19 - <%= content_tag('tr', content_tag('td', _("SISP:")) + content_tag('td', profile.institution.sisp ? _("Yes") : _("No"))) %>  
20 - <% end %>  
21 -</table>  
views/profile/_profile_tab.html.erb
@@ -1,3 +0,0 @@ @@ -1,3 +0,0 @@
1 -<table>  
2 - <%= display_mpog_profile_information %>  
3 -</table>  
views/search/institutions.html.erb
@@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
1 -<%= search_page_title( @titles[@asset], @category ) %>  
2 -  
3 -<%= render :partial => 'search_form', :locals => { :hint => _("Type words about the %s you're looking for") % @asset.to_s.singularize } %>  
4 -  
5 -<%= display_results(@searches, @asset) %>  
6 -<% if params[:display] != 'map' %>  
7 - <%= pagination_links @searches[@asset][:results] %>  
8 -<% end %>  
9 -  
10 -<div style="clear: both"></div>  
11 -  
12 -<% if @asset == :product %>  
13 - <%= javascript_tag do %>  
14 - jQuery('.search-product-price-details').altBeautify();  
15 - <% end %>  
16 -<% end %>  
views/software_communities_plugin_myprofile/edit_institution.html.erb
@@ -1,119 +0,0 @@ @@ -1,119 +0,0 @@
1 -<h1><%= _('Edit Institution') %></h1>  
2 -  
3 -<% if environment.enabled?('admin_must_approve_new_communities') %>  
4 - <div class='explanation'>  
5 - <%= _("Note that the creation of communities in this environment is restricted. Your request to create this new community will be sent to %{environment} administrators and will be approved or rejected according to their methods and criteria.") % { :environment => environment.name }%>  
6 - </div>  
7 -<%end %>  
8 -  
9 -<% unless flash[:errors].nil? %>  
10 -<div class="errorExplanation" id="errorExplanation">  
11 - <h2> <%= _("Can`t create new Institution: #{flash[:errors].length} errors") %> </h2>  
12 - <ul>  
13 - <% flash[:errors].each do |error| %>  
14 - <li> <%= error %> </li>  
15 - <% end %>  
16 - </ul>  
17 -</div>  
18 -<% end %>  
19 -  
20 -<div id = 'create_institution_errors' class='errorExplanation hide-field'></div>  
21 -  
22 -<div>  
23 - <div class="fields-required">  
24 - <span class="errorExplanation"><%= _("All fields with (*) are mandatory") %></span>  
25 - </div>  
26 - <br/>  
27 - <%= labelled_form_for :community,:html => { :multipart => true, :id=>"institution_form" } do |f| %>  
28 - <%= hidden_field_tag "edit_institution_page", true %>  
29 - <%= fields_for :institutions do |inst| %>  
30 - <span class=''>  
31 - <div class='formfield type-radio'>  
32 - <label> <%= _("Public Institution") %>  
33 - <%= radio_button_tag("institutions[type]", "PublicInstitution", (@institution.type == "PublicInstitution" ? true : false)) %>  
34 - </label>  
35 -  
36 - <label>  
37 - <%= _("Private Institution") %>  
38 - <%= radio_button_tag("institutions[type]" ,"PrivateInstitution", (@institution.type == "PrivateInstitution" ? true : false))%>  
39 - </label>  
40 - </div>  
41 - </span>  
42 -  
43 - <%= required f.text_field(:name, :value => @institution.community.name) %>  
44 - <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %>  
45 -  
46 - <span class='required-field'>  
47 - <div class="formfield type-text">  
48 - <%= inst.label "corporate_name", _("Corporate Name"), :class=>"formlabel" %>  
49 - <%= required inst.text_field(:corporate_name, :value => @institution.corporate_name) %>  
50 - </div>  
51 - </span>  
52 -  
53 - <%= required select_country(_('Country'), 'community', 'country', {:class => 'type-select', :id => "community_country"}, :selected => @institution.community.country) %>  
54 -  
55 - <span class='required-field'>  
56 - <div class="formfield">  
57 - <label for="community_state" class="formlabel"><%= _("State") %></label>  
58 - <%= f.select(:state, @state_list.collect {|state| [state.name, state.name]}, :selected => @institution.community.state) %>  
59 - </div>  
60 - </span>  
61 -  
62 - <%= required f.text_field(:city, :value => @institution.community.city) %>  
63 -  
64 -  
65 - <span class='required-field'>  
66 - <div class="formfield type-text">  
67 - <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %>  
68 - <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field", :value => @institution.cnpj) %>  
69 - </div>  
70 - </span>  
71 -  
72 - <span class='optional-field'>  
73 - <div class="formfield type-text">  
74 - <%= hidden_field_tag "acronym_translate", _("Acronym") %>  
75 - <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %>  
76 - <%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %>  
77 - <%= inst.text_field(:acronym, :value => @institution.acronym) %>  
78 - </div>  
79 - </span>  
80 -  
81 - <span class='required-field public-institutions-fields'>  
82 - <div class="formfield type-text">  
83 - <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %>  
84 - <%= inst.select(:governmental_sphere, [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}, {:selected=>@institution.governmental_power_id})%>  
85 - </div>  
86 - </span>  
87 -  
88 - <span class='required-field public-institutions-fields'>  
89 - <div class="formfield type-text">  
90 - <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %>  
91 - <%= inst.select(:governmental_power, [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}, {:selected=> @institution.governmental_sphere_id})%>  
92 - </div>  
93 - </span>  
94 - <span class='required-field public-institutions-fields'>  
95 - <div class="formfield type-text">  
96 - <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %>  
97 - <%= inst.select(:juridical_nature, [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}, {:selected=> @institution.juridical_nature_id})%>  
98 - </div>  
99 - </span>  
100 -  
101 - <span class='required-field public-institutions-fields'>  
102 - <div class="formfield type-text">  
103 - <%= _("SISP?") %>  
104 - <% if @show_sisp_field %>  
105 - <%= inst.label("sisp" ,_("Yes")) %>  
106 - <%= inst.radio_button(:sisp, true, :checked=>(@institution.sisp ? true : false)) %>  
107 - <%= inst.label("sisp" ,_("No")) %>  
108 - <%= inst.radio_button(:sisp, false, :checked=>(@institution.sisp ? false : true)) %>  
109 - <% else %>  
110 - <%= inst.label("sisp", _("No")) %>  
111 - <% end %>  
112 - </div>  
113 - </span>  
114 - <br />  
115 -  
116 - <%= submit_button :save, _('Save') %>  
117 - <% end %>  
118 -<% end %>  
119 -