Commit cdc4afefd801365b24f92ded36d7ca8ad4a5bd31

Authored by Luciano Prestes
Committed by David Silva
1 parent a95f5e27

Remove trailing whitespace

Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
lib/categories_software_block.rb
... ... @@ -9,7 +9,8 @@ class CategoriesSoftwareBlock &lt; Block
9 9 end
10 10  
11 11 def help
12   - _('This block displays the categories and the amount of softwares for each category.')
  12 + _('This block displays the categories and the amount of softwares for
  13 + each category.')
13 14 end
14 15  
15 16 def content(args={})
... ...
lib/database_helper.rb
... ... @@ -3,11 +3,12 @@ module DatabaseHelper
3 3 def self.valid_database? database
4 4 return false if SoftwareHelper.all_table_is_empty?(database)
5 5  
6   - database_description_id_list = DatabaseDescription.select(:id).collect {|dd| dd.id }
  6 + database_description_id_list = DatabaseDescription.select(:id).
  7 + collect {|dd| dd.id}
7 8  
8   - return false unless database_description_id_list.include?(database[:database_description_id].to_i)
9   -
10   - true
  9 + return database_description_id_list.include?(
  10 + database[:database_description_id].to_i
  11 + )
11 12 end
12 13  
13 14 def self.list_database new_databases
... ... @@ -17,7 +18,10 @@ module DatabaseHelper
17 18 new_databases.each do |new_database|
18 19 if valid_database? new_database
19 20 database = SoftwareDatabase.new
20   - database.database_description_id = new_database[:database_description_id]
  21 +
  22 + database.database_description_id =
  23 + new_database[:database_description_id]
  24 +
21 25 database.version = new_database[:version]
22 26 database.operating_system = new_database[:operating_system]
23 27 list_databases << database
... ... @@ -46,7 +50,9 @@ module DatabaseHelper
46 50 ApplicationHelper
47 51 )
48 52  
49   - return database_html_structure({:database_description_id => "", :version => "", :operating_system => ""}) if list_databases.nil?
  53 + return database_html_structure(
  54 + {:database_description_id => "", :version => "", :operating_system => ""}
  55 + ) if list_databases.nil?
50 56  
51 57 lambdas_list = []
52 58  
... ... @@ -61,30 +67,78 @@ module DatabaseHelper
61 67 database_name = if database_data[:database_description_id].blank?
62 68 ""
63 69 else
64   - DatabaseDescription.find(database_data[:database_description_id], :select=>"name").name
  70 + DatabaseDescription.find(
  71 + database_data[:database_description_id],
  72 + :select=>"name"
  73 + ).name
65 74 end
66 75  
67 76 Proc::new do
68   - content_tag('table',
69   - content_tag('tr',
  77 + content_tag(
  78 + 'table',
  79 + content_tag(
  80 + 'tr',
70 81 content_tag('td', label_tag(_("database Name: ")))+
71   - content_tag('td',
72   - text_field_tag("database_autocomplete", database_name, :class=>"database_autocomplete", :placeholder=>_("Autocomplete field, type something")) +
73   - content_tag('div', _("Pick an item on the list"), :class=>"autocomplete_validation_message hide-field")
  82 + content_tag(
  83 + 'td',
  84 + text_field_tag(
  85 + "database_autocomplete",
  86 + database_name,
  87 + :class=>"database_autocomplete",
  88 + :placeholder=>_("Autocomplete field, type something")
  89 + ) +
  90 + content_tag(
  91 + 'div',
  92 + _("Pick an item on the list"),
  93 + :class=>"autocomplete_validation_message hide-field"
  94 + )
74 95 )+
75   - content_tag('td', hidden_field_tag("database[][database_description_id]", database_data[:database_description_id], :class=>"database_description_id", data:{label:database_name}))
  96 + content_tag(
  97 + 'td',
  98 + hidden_field_tag(
  99 + "database[][database_description_id]",
  100 + database_data[:database_description_id],
  101 + :class => "database_description_id",
  102 + :data => {:label => database_name}
  103 + )
  104 + )
76 105 )+
77 106  
78   - content_tag('tr',
  107 + content_tag(
  108 + 'tr',
79 109 content_tag('td', label_tag(_("Version")))+
80   - content_tag('td', text_field_tag("database[][version]", database_data[:version], :maxlength=>"20"))+
  110 + content_tag(
  111 + 'td',
  112 + text_field_tag(
  113 + "database[][version]",
  114 + database_data[:version],
  115 + :maxlength=>"20"
  116 + )
  117 + )+
81 118 content_tag('td')
82 119 )+
83 120  
84   - content_tag('tr',
85   - content_tag('td', label_tag(_("Operating System")))+
86   - content_tag('td', text_field_tag("database[][operating_system]", database_data[:operating_system], :maxlength=>"20"))+
87   - content_tag('td', button_without_text(:delete, _('Delete'), "#" , :class=>"delete-dynamic-table"), :align => 'right')
  121 + content_tag(
  122 + 'tr',
  123 + content_tag('td', label_tag(_("Operating System")))+
  124 + content_tag(
  125 + 'td',
  126 + text_field_tag(
  127 + "database[][operating_system]",
  128 + database_data[:operating_system],
  129 + :maxlength=>"20"
  130 + )
  131 + )+
  132 + content_tag(
  133 + 'td',
  134 + button_without_text(
  135 + :delete,
  136 + _('Delete'),
  137 + "#" ,
  138 + :class=>"delete-dynamic-table"
  139 + ),
  140 + :align => 'right'
  141 + )
88 142 ), :class => 'dynamic-table database-table'
89 143 )
90 144 end
... ... @@ -93,4 +147,4 @@ module DatabaseHelper
93 147 def self.add_dynamic_table
94 148 database_as_tables(nil).call
95 149 end
96 150 -end
  151 +end
97 152 \ No newline at end of file
... ...
lib/ext/community.rb
... ... @@ -10,7 +10,9 @@ class Community
10 10 def self.create_after_moderation(requestor, attributes = {})
11 11 community = Community.new(attributes)
12 12  
13   - if community.environment.enabled?('admin_must_approve_new_communities') and !community.environment.admins.include?(requestor)
  13 + if community.environment.enabled?('admin_must_approve_new_communities') &&
  14 + !community.environment.admins.include?(requestor)
  15 +
14 16 cc = CreateCommunity.create(attributes.merge(:requestor => requestor))
15 17 else
16 18 community = Community.create(attributes)
... ...
lib/ext/profile_helper.rb
1 1 require_dependency 'profile_helper'
2 2  
3 3 module ProfileHelper
4   - PERSON_CATEGORIES[:mpog_profile_information] = [:secondary_email, :institutions]
  4 + PERSON_CATEGORIES[:mpog_profile_information] = [:secondary_email,
  5 + :institutions]
5 6  
6 7 def display_mpog_field(title, profile, field, force = false)
7 8 unless force || profile.may_display_field_to?(field, user)
... ... @@ -12,7 +13,11 @@ module ProfileHelper
12 13 if block_given?
13 14 value = yield(value)
14 15 end
15   - content_tag('tr', content_tag('td', title, :class => 'field-name') + content_tag('td', value))
  16 + content_tag(
  17 + 'tr',
  18 + content_tag('td', title, :class => 'field-name') +
  19 + content_tag('td', value)
  20 + )
16 21 else
17 22 ''
18 23 end
... ...
lib/ext/search_controller.rb
... ... @@ -4,7 +4,7 @@ class SearchController
4 4  
5 5 def communities
6 6 results = filter_communities_list do |community|
7   - !community.software? && !community.institution?
  7 + !community.software? and !community.institution?
8 8 end
9 9 results = results.paginate(:per_page => 24, :page => params[:page])
10 10 @searches[@asset] = {:results => results}
... ... @@ -55,9 +55,7 @@ class SearchController
55 55  
56 56 filtered_communities_list = []
57 57 unfiltered_software_infos_list.each do |software|
58   - unless software.community.is_template?
59   - filtered_communities_list << software.community
60   - end
  58 + filtered_communities_list << software.community
61 59 end
62 60  
63 61 if not params[:filter].blank?
... ...
lib/ext/user.rb
... ... @@ -12,18 +12,27 @@ class User
12 12 }
13 13  
14 14 def email_different_secondary?
15   - self.errors.add(:base, _("Email must be different from secondary email.")) if self.email == self.secondary_email
  15 + self.errors.add(
  16 + :base,
  17 + _("Email must be different from secondary email.")
  18 + ) if self.email == self.secondary_email
16 19 end
17 20  
18 21 def email_has_already_been_used?
19   - user_already_saved = User.find(:first, :conditions=>["email = ?", self.email])
  22 + user_already_saved = User.find(:first,
  23 + :conditions => ["email = ?", self.email])
20 24  
21 25 if user_already_saved.nil?
22   - primary_email_hasnt_been_used = User.primary_or_secondary_email_already_used?(self.email).empty?
  26 + primary_email_hasnt_been_used =
  27 + User.primary_or_secondary_email_already_used?(self.email).empty?
  28 +
23 29 if !self.secondary_email.nil? and self.secondary_email.empty?
24 30 self.secondary_email = nil
25 31 end
26   - secondary_email_hasnt_been_used = User.primary_or_secondary_email_already_used?(self.secondary_email).empty?
  32 +
  33 + secondary_email_hasnt_been_used =
  34 + User.primary_or_secondary_email_already_used?(self.secondary_email).
  35 + empty?
27 36  
28 37 if !primary_email_hasnt_been_used or !secondary_email_hasnt_been_used
29 38 self.errors.add(:base, _("E-mail or secondary e-mail already taken."))
... ... @@ -34,7 +43,10 @@ class User
34 43 def secondary_email_format
35 44 if !self.secondary_email.nil? and self.secondary_email.length > 0
36 45 test = /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/
37   - self.errors.add(:base, _("Invalid secondary email format.")) unless test.match(self.secondary_email)
  46 +
  47 + unless test.match(self.secondary_email)
  48 + self.errors.add(:base, _("Invalid secondary email format."))
  49 + end
38 50 end
39 51 end
40 52  
... ... @@ -49,12 +61,18 @@ class User
49 61  
50 62 unless primary_email_has_gov_suffix
51 63 if !self.secondary_email.nil? and self.secondary_email.length > 0
52   - secondary_email_has_gov_suffix = true if test.match(self.secondary_email)
  64 + secondary_email_has_gov_suffix = !!test.match(self.secondary_email)
53 65 end
54   - self.errors.add(:base, _("The governamental email must be the primary one.")) if secondary_email_has_gov_suffix
  66 + self.errors.add(
  67 + :base,
  68 + _("The governamental email must be the primary one.")
  69 + ) if secondary_email_has_gov_suffix
55 70 end
56 71  
57   - self.errors.add(:base, _("Institution is obligatory if user has a government email.")) if primary_email_has_gov_suffix and self.institutions.blank?
  72 + self.errors.add(
  73 + :base,
  74 + _("Institution is obligatory if user has a government email.")
  75 + ) if primary_email_has_gov_suffix and self.institutions.blank?
58 76 end
59 77  
60 78 -end
  79 +end
61 80 \ No newline at end of file
... ...
lib/governmental_power.rb
... ... @@ -5,6 +5,9 @@ class GovernmentalPower &lt; ActiveRecord::Base
5 5 has_many :institutions
6 6  
7 7 def public_institutions
8   - Institution.where(:type=>"PublicInstitution", :governmental_power_id=>self.id)
  8 + Institution.where(
  9 + :type=>"PublicInstitution",
  10 + :governmental_power_id=>self.id
  11 + )
9 12 end
10 13 end
... ...
lib/juridical_nature.rb
... ... @@ -7,6 +7,9 @@ class JuridicalNature &lt; ActiveRecord::Base
7 7 validates_uniqueness_of :name
8 8  
9 9 def public_institutions
10   - Institution.where(:type=>"PublicInstitution", :governmental_power_id=>self.id)
  10 + Institution.where(
  11 + :type=>"PublicInstitution",
  12 + :governmental_power_id=>self.id
  13 + )
11 14 end
12 15 end
... ...
lib/library_helper.rb
... ... @@ -34,7 +34,13 @@ module LibraryHelper
34 34 ApplicationHelper
35 35 )
36 36  
37   - return library_html_structure({:name=>"", :version=>"", :license=>""}) if list_libraries.nil?
  37 + return library_html_structure(
  38 + {
  39 + :name=>"",
  40 + :version=>"",
  41 + :license=>""
  42 + }
  43 + ) if list_libraries.nil?
38 44  
39 45 lambdas_list = []
40 46  
... ... @@ -47,27 +53,47 @@ module LibraryHelper
47 53  
48 54 def self.library_html_structure library_data
49 55 Proc::new do
50   - content_tag('table',
51   - content_tag('tr',
  56 + content_tag(
  57 + 'table',
  58 + content_tag(
  59 + 'tr',
52 60 content_tag('td', label_tag(_("Name")))+
53   - content_tag('td', text_field_tag("library[][name]", library_data[:name]))+
  61 + content_tag(
  62 + 'td',
  63 + text_field_tag("library[][name]", library_data[:name])
  64 + )+
54 65 content_tag('td')
55 66 )+
56 67  
57   - content_tag('tr',
  68 + content_tag(
  69 + 'tr',
58 70 content_tag('td', label_tag(_("Version")))+
59   - content_tag('td', text_field_tag("library[][version]", library_data[:version]))+
  71 + content_tag(
  72 + 'td',
  73 + text_field_tag("library[][version]", library_data[:version])
  74 + )+
60 75 content_tag('td')
61 76 )+
62 77  
63   - content_tag('tr',
  78 + content_tag(
  79 + 'tr',
64 80 content_tag('td', label_tag(_("License")))+
65   - content_tag('td', text_field_tag("library[][license]", library_data[:license])) +
66   - content_tag('td',
67   - button_without_text(:delete, _('Delete'), "#" , :class=>"delete-dynamic-table"),
  81 + content_tag(
  82 + 'td',
  83 + text_field_tag("library[][license]", library_data[:license])) +
  84 + content_tag(
  85 + 'td',
  86 + button_without_text(
  87 + :delete,
  88 + _('Delete'),
  89 + "#" ,
  90 + :class=>"delete-dynamic-table"
  91 + ),
68 92 :align => 'right'
69 93 )
70   - ), :class => 'dynamic-table library-table'
  94 + ),
  95 +
  96 + :class => 'dynamic-table library-table'
71 97 )
72 98 end
73 99 end
... ...
lib/license_helper.rb
... ... @@ -2,4 +2,4 @@ module LicenseHelper
2 2 def self.getListLicenses
3 3 LicenseInfo.all
4 4 end
5 5 -end
  6 +end
6 7 \ No newline at end of file
... ...
lib/mpog_software_plugin.rb
... ... @@ -21,7 +21,9 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
21 21 def profile_editor_extras
22 22 if context.profile.person?
23 23 expanded_template('person_editor_extras.html.erb')
24   - elsif context.profile.respond_to? :software_info and !context.profile.software_info.nil?
  24 + elsif context.profile.respond_to? :software_info &&
  25 + !context.profile.software_info.nil?
  26 +
25 27 if context.profile.software_info.first_edit?
26 28 context.profile.software_info.first_edit = false
27 29 context.profile.software_info.save!
... ... @@ -55,7 +57,10 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
55 57 if context.params.has_key?(:operating_system)
56 58 operating_system_transaction
57 59 end
58   - if context.params.has_key?(:institution) || context.params.has_key?(:governmental_power) || context.params.has_key?(:governmental_sphere)
  60 + if context.params.has_key?(:institution) ||
  61 + context.params.has_key?(:governmental_power) ||
  62 + context.params.has_key?(:governmental_sphere)
  63 +
59 64 institution_transaction
60 65 end
61 66  
... ... @@ -77,8 +82,10 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
77 82 unless is_admin
78 83 institution = profile.user.institutions
79 84  
80   - if !params[:institution].blank? and !params[:institution][:sisp].nil?
81   - params[:institution][:sisp] = institution.sisp if params[:institution][:sisp] != institution.sisp
  85 + if !params[:institution].blank? && !params[:institution][:sisp].nil?
  86 + if params[:institution][:sisp] != institution.sisp
  87 + params[:institution][:sisp] = institution.sisp
  88 + end
82 89 end
83 90 end
84 91 end
... ... @@ -109,12 +116,32 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
109 116  
110 117 def control_panel_buttons
111 118 if context.profile.software?
112   - return { :title => _("Software Info"), :icon => "edit-profile-group control-panel-software-link", :url => {:controller => "mpog_software_plugin_myprofile", :action => "edit_software"} }
  119 + return {
  120 + :title => _("Software Info"),
  121 + :icon => "edit-profile-group control-panel-software-link",
  122 + :url => {
  123 + :controller => "mpog_software_plugin_myprofile",
  124 + :action => "edit_software"
  125 + }
  126 + }
113 127 elsif context.profile.person?
114   - return { :title => _("Create a new software"), :icon => "design-editor", :url => {:controller => "mpog_software_plugin_myprofile", :action => "new_software"} }
  128 + return {
  129 + :title => _("Create a new software"),
  130 + :icon => "design-editor",
  131 + :url => {
  132 + :controller => "mpog_software_plugin_myprofile",
  133 + :action => "new_software"
  134 + }
  135 + }
115 136 return nil
116 137 elsif context.profile.institution?
117   - return { :title => _("Institution Info"), :icon => "edit-profile-group control-panel-instituton-link", :url => {:controller => "mpog_software_plugin_myprofile", :action => "edit_institution"} }
  138 + return {
  139 + :title => _("Institution Info"),
  140 + :icon => "edit-profile-group control-panel-instituton-link",
  141 + :url => {
  142 + :controller => "mpog_software_plugin_myprofile",
  143 + :action => "edit_institution"}
  144 + }
118 145 end
119 146 end
120 147  
... ... @@ -152,7 +179,12 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
152 179  
153 180 def add_new_organization_buttons
154 181 Proc::new do
155   - button(:add, _('Create a new software'), :controller => 'mpog_software_plugin_myprofile', :action => 'new_software')
  182 + button(
  183 + :add,
  184 + _('Create a new software'),
  185 + :controller => 'mpog_software_plugin_myprofile',
  186 + :action => 'new_software'
  187 + )
156 188 end
157 189 end
158 190  
... ... @@ -162,7 +194,8 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
162 194 end
163 195  
164 196 def profile_blocks_extra_content
165   - return if context.session[:user].nil? or context.session[:hide_incomplete_percentage] == true
  197 + return if context.session[:user].nil? or
  198 + !!context.session[:hide_incomplete_percentage]
166 199  
167 200 person = Person.where(:user_id=>context.session[:user]).first
168 201  
... ... @@ -176,10 +209,32 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
176 209 end
177 210 end
178 211  
  212 + def custom_user_registration_attributes user
  213 + unless context.params[:user][:institution_ids].nil?
  214 + context.params[:user][:institution_ids].delete("")
  215 +
  216 + context.params[:user][:institution_ids].each do |institution_id|
  217 + institution = Institution.find institution_id
  218 + user.institutions << institution
  219 +
  220 + if institution.community.admins.blank?
  221 + institution.community.add_admin(user.person)
  222 + end
  223 + end
  224 + end
  225 + user.save unless user.institution_ids.empty?
  226 +
  227 + user.institutions.each do |institution|
  228 + community = institution.community
  229 + community.add_member user.person
  230 + end
  231 + end
  232 +
179 233 def calc_percentage_registration person
180 234 required_list = profile_required_list
181 235 empty_fields = profile_required_empty_list person
182   - count = required_list[:person_fields].count + required_list[:user_fields].count
  236 + count = required_list[:person_fields].count +
  237 + required_list[:user_fields].count
183 238 percentege = 100 - ((empty_fields.count*100)/count)
184 239 person.percentage_incomplete = percentege
185 240 person.save(validate: false)
... ... @@ -187,7 +242,15 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
187 242 end
188 243  
189 244 def admin_panel_links
190   - [{:title => _('Create Institution'), :url => {:controller => 'mpog_software_plugin', :action => 'create_institution_admin'}}]
  245 + [
  246 + {
  247 + :title => _('Create Institution'),
  248 + :url => {
  249 + :controller => 'mpog_software_plugin',
  250 + :action => 'create_institution_admin'
  251 + }
  252 + }
  253 + ]
191 254 end
192 255  
193 256 protected
... ... @@ -201,7 +264,18 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
201 264  
202 265 def profile_required_list
203 266 fields = Hash.new
204   - fields[:person_fields] = ["cell_phone","contact_phone","comercial_phone","country","city","state","organization_website", "image", "identifier", "name"]
  267 + fields[:person_fields] = [
  268 + "cell_phone",
  269 + "contact_phone",
  270 + "comercial_phone",
  271 + "country",
  272 + "city",
  273 + "state",
  274 + "organization_website",
  275 + "image",
  276 + "identifier",
  277 + "name"
  278 + ]
205 279 fields[:user_fields] = ["secondary_email", "email"]
206 280 fields
207 281 end
... ... @@ -225,10 +299,15 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
225 299  
226 300 def operating_system_transaction
227 301 OperatingSystem.transaction do
228   - list_operating = OperatingSystemHelper.list_operating_system(context.params[:operating_system])
  302 + list_operating = OperatingSystemHelper.list_operating_system(
  303 + context.params[:operating_system]
  304 + )
229 305  
230 306 if OperatingSystemHelper.valid_list_operating_system?(list_operating)
231   - OperatingSystem.where(:software_info_id => context.profile.software_info.id).destroy_all
  307 + OperatingSystem.where(
  308 + :software_info_id => context.profile.software_info.id
  309 + ).destroy_all
  310 +
232 311 list_operating.each do |operating_system|
233 312 operating_system.software_info = context.profile.software_info
234 313 operating_system.save!
... ... @@ -252,30 +331,40 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
252 331 institution.save
253 332  
254 333 if context.params.has_key?(:governmental_power)
255   - context.profile.institution.governmental_power_id = context.params[:governmental_power]
  334 + context.profile.institution.governmental_power_id =
  335 + context.params[:governmental_power]
  336 +
256 337 context.profile.institution.save!
257 338 end
258 339  
259 340 if context.params.has_key?(:governmental_sphere)
260   - context.profile.institution.governmental_sphere_id = context.params[:governmental_sphere]
  341 + context.profile.institution.governmental_sphere_id =
  342 + context.params[:governmental_sphere]
  343 +
261 344 context.profile.institution.save!
262 345 end
263 346  
264 347 if context.params.has_key?(:juridical_nature)
265   - context.profile.institution.juridical_nature_id = context.params[:juridical_nature]
  348 + context.profile.institution.juridical_nature_id =
  349 + context.params[:juridical_nature]
  350 +
266 351 context.profile.institution.save!
267 352 end
268 353  
269 354 if context.params.has_key?(:institution)
270 355 Institution.transaction do
271   - context.profile.institution.update_attributes!(context.params[:institution])
  356 + context.profile.
  357 + institution.
  358 + update_attributes!(context.params[:institution])
272 359 end
273 360 end
274 361 end
275 362  
276 363 def software_info_transaction
277 364 SoftwareInfo.transaction do
278   - context.profile.software_info.update_attributes!(context.params[:software_info])
  365 + context.profile.
  366 + software_info.
  367 + update_attributes!(context.params[:software_info])
279 368 end
280 369 end
281 370  
... ... @@ -284,7 +373,9 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
284 373 list_libraries = LibraryHelper.list_libraries(context.params[:library])
285 374  
286 375 if LibraryHelper.valid_list_libraries?(list_libraries)
287   - Library.where(:software_info_id=> context.profile.software_info.id).destroy_all
  376 + Library.where(
  377 + :software_info_id=> context.profile.software_info.id
  378 + ).destroy_all
288 379  
289 380 list_libraries.each do |library|
290 381 library.software_info_id = context.profile.software_info.id
... ... @@ -301,7 +392,10 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
301 392 list_databases = DatabaseHelper.list_database(context.params[:database])
302 393  
303 394 if DatabaseHelper.valid_list_database?(list_databases)
304   - SoftwareDatabase.where(:software_info_id => context.profile.software_info.id).destroy_all
  395 + SoftwareDatabase.where(
  396 + :software_info_id => context.profile.software_info.id
  397 + ).destroy_all
  398 +
305 399 list_databases.each do |database|
306 400 database.software_info = context.profile.software_info
307 401 database.save!
... ... @@ -320,10 +414,14 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
320 414  
321 415 def language_transaction
322 416 SoftwareLanguage.transaction do
323   - list_language = SoftwareLanguageHelper.list_language(context.params[:language])
  417 + list_language = SoftwareLanguageHelper.list_language(
  418 + context.params[:language]
  419 + )
324 420  
325 421 if SoftwareLanguageHelper.valid_list_language?(list_language)
326   - SoftwareLanguage.where(:software_info_id => context.profile.software_info.id).destroy_all
  422 + SoftwareLanguage.where(
  423 + :software_info_id => context.profile.software_info.id
  424 + ).destroy_all
327 425  
328 426 list_language.each do |language|
329 427 language.software_info = context.profile.software_info
... ... @@ -337,7 +435,10 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
337 435  
338 436 def software_categories_transaction
339 437 ControlledVocabulary.transaction do
340   - context.profile.software_info.software_categories.update_attributes!(context.params[:software_categories])
  438 + context.profile.
  439 + software_info.
  440 + software_categories.
  441 + update_attributes!(context.params[:software_categories])
341 442 end
342 443 end
343 444  
... ...
lib/operating_system_helper.rb
1 1 module OperatingSystemHelper
2 2 def self.list_operating_system new_operating_systems
3   - return [] if new_operating_systems.nil? or new_operating_systems.length == 0
  3 + return [] if new_operating_systems.nil? or new_operating_systems.length == 0
4 4 list_operating_system = []
5 5  
6 6 new_operating_systems.each do |new_operating_system|
7   - unless SoftwareHelper.all_table_is_empty? new_operating_system, ["operating_system_name_id"]
  7 + unless SoftwareHelper.all_table_is_empty?(
  8 + new_operating_system,
  9 + ["operating_system_name_id"]
  10 + )
  11 +
8 12 operating_system = OperatingSystem.new
9   - operating_system.operating_system_name = OperatingSystemName.find(new_operating_system[:operating_system_name_id])
  13 + operating_system.operating_system_name = OperatingSystemName.find(
  14 + new_operating_system[:operating_system_name_id]
  15 + )
  16 +
10 17 operating_system.version = new_operating_system[:version]
11 18 list_operating_system << operating_system
12 19 end
... ... @@ -15,7 +22,7 @@ module OperatingSystemHelper
15 22 end
16 23  
17 24 def self.valid_list_operating_system? list_operating_system
18   - return false if list_operating_system.nil? or list_operating_system.length == 0
  25 + return !(list_operating_system.nil? || list_operating_system.length == 0)
19 26  
20 27 list_operating_system.each do |operating_system|
21 28 return false unless operating_system.valid?
... ... @@ -23,7 +30,7 @@ module OperatingSystemHelper
23 30 true
24 31 end
25 32  
26   - def self.operating_system_as_tables (list_operating_system, have_delete_button = true, show_information = false)
  33 + def self.operating_system_as_tables(list_operating_system, have_delete_button = true, show_information = false)
27 34 extend(
28 35 ActionView::Helpers::TagHelper,
29 36 ActionView::Helpers::FormTagHelper,
... ... @@ -35,10 +42,16 @@ module OperatingSystemHelper
35 42 lambdas_list = []
36 43  
37 44 if not show_information
38   - return operating_system_html_structure({:operating_system_name_id => "", :version => ""}, have_delete_button) if list_operating_system.nil?
  45 + return operating_system_html_structure(
  46 + {:operating_system_name_id => "", :version => ""},
  47 + have_delete_button
  48 + ) if list_operating_system.nil?
39 49  
40 50 list_operating_system.each do |operating_system|
41   - lambdas_list << operating_system_html_structure(operating_system,have_delete_button)
  51 + lambdas_list << operating_system_html_structure(
  52 + operating_system,
  53 + have_delete_button
  54 + )
42 55 end
43 56 else
44 57 list_operating_system.each do |operating_system|
... ... @@ -51,19 +64,43 @@ module OperatingSystemHelper
51 64  
52 65 def self.operating_system_html_structure (operating_system_data,have_delete_button = true)
53 66 Proc::new do
54   - content_tag('table',
55   - content_tag('tr',
  67 + content_tag(
  68 + 'table',
  69 + content_tag(
  70 + 'tr',
56 71 content_tag('td', label_tag(_("Name")))+
57   - content_tag('td', select_tag("operating_system[][operating_system_name_id]", SoftwareHelper.select_options(OperatingSystemName.all, operating_system_data[:operating_system_name_id]) ))+
  72 + content_tag(
  73 + 'td',
  74 + select_tag(
  75 + "operating_system[][operating_system_name_id]",
  76 + SoftwareHelper.select_options(
  77 + OperatingSystemName.all,
  78 + operating_system_data[:operating_system_name_id]
  79 + )
  80 + )
  81 + )+
58 82 content_tag('td')
59 83 )+
60 84  
61   - content_tag('tr',
  85 + content_tag(
  86 + 'tr',
62 87 content_tag('td', label_tag(_("Version")))+
63   - content_tag('td', text_field_tag("operating_system[][version]", operating_system_data[:version]))+
  88 + content_tag(
  89 + 'td',
  90 + text_field_tag(
  91 + "operating_system[][version]",
  92 + operating_system_data[:version]
  93 + )
  94 + )+
64 95 if have_delete_button
65   - content_tag('td',
66   - button_without_text(:delete, _('Delete'), "#" , :class=>"delete-dynamic-table"),
  96 + content_tag(
  97 + 'td',
  98 + button_without_text(
  99 + :delete,
  100 + _('Delete'),
  101 + "#" ,
  102 + :class=>"delete-dynamic-table"
  103 + ),
67 104 :align => 'right'
68 105 )
69 106 else
... ...
lib/public_institution.rb
1 1 class PublicInstitution < Institution
2   - validates :governmental_power, :governmental_sphere, :juridical_nature, :presence=>true
3   - validates :acronym, :allow_blank => true, :allow_nil => true, :uniqueness=>true
  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 +
4 8 validates :cnpj, :uniqueness=>true
5   - validates_format_of :cnpj, :with => /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/, :allow_nil => true, :allow_blank => true
  9 +
  10 + validates_format_of(
  11 + :cnpj,
  12 + :with => /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/,
  13 + :allow_nil => true, :allow_blank => true
  14 + )
6 15 end
... ...
lib/software_database.rb
... ... @@ -4,10 +4,22 @@ class SoftwareDatabase &lt; ActiveRecord::Base
4 4 belongs_to :software_info
5 5 belongs_to :database_description
6 6  
7   - validates_length_of :version, maximum: 20, too_long: _("Software database is too long (maximum is 20 characters)")
8   - validates_length_of :operating_system, maximum: 20, too_long: _("Software database is too long (maximum is 20 characters)")
  7 + validates_length_of(
  8 + :version,
  9 + :maximum => 20,
  10 + :too_long => _("Software database is too long (maximum is 20 characters)")
  11 + )
  12 +
  13 + validates_length_of(
  14 + :operating_system,
  15 + :maximum => 20,
  16 + :too_long => _("Software database is too long (maximum is 20 characters)")
  17 + )
9 18  
10 19 validates_presence_of :database_description_id, :version, :operating_system
11   - validates :database_description_id, :numericality => { :greater_than_or_equal_to => 1 }
  20 + validates(
  21 + :database_description_id,
  22 + :numericality => {:greater_than_or_equal_to => 1}
  23 + )
12 24  
13 25 end
... ...
lib/software_info.rb
... ... @@ -6,9 +6,14 @@ class SoftwareInfo &lt; ActiveRecord::Base
6 6 'full'
7 7 end
8 8  
9   - attr_accessible :e_mag, :icp_brasil, :intern, :e_ping, :e_arq, :operating_platform
10   - attr_accessible :demonstration_url, :acronym, :objectives, :features, :license_info
11   - attr_accessible :community_id, :finality, :repository_link, :public_software, :first_edit
  9 + attr_accessible :e_mag, :icp_brasil, :intern, :e_ping, :e_arq,
  10 + :operating_platform
  11 +
  12 + attr_accessible :demonstration_url, :acronym, :objectives, :features,
  13 + :license_info
  14 +
  15 + attr_accessible :community_id, :finality, :repository_link, :public_software,
  16 + :first_edit
12 17  
13 18 has_many :libraries, :dependent => :destroy
14 19 has_many :software_databases
... ... @@ -31,7 +36,9 @@ class SoftwareInfo &lt; ActiveRecord::Base
31 36  
32 37 # used on find_by_contents
33 38 scope :like_search, lambda{ |name|
34   - joins(:community).where("name ILIKE ? OR acronym ILIKE ?", "%#{name}%", "%#{name}%")
  39 + joins(:community).where(
  40 + "name ILIKE ? OR acronym ILIKE ?", "%#{name}%", "%#{name}%"
  41 + )
35 42 }
36 43  
37 44 scope :search, lambda { |name="", database_description_id = "",
... ... @@ -57,7 +64,10 @@ class SoftwareInfo &lt; ActiveRecord::Base
57 64  
58 65 def validate_name_lenght
59 66 if self.community.name.size > 100
60   - self.errors.add(:base, _("Name is too long (maximum is %{count} characters)"))
  67 + self.errors.add(
  68 + :base,
  69 + _("Name is too long (maximum is %{count} characters)")
  70 + )
61 71 false
62 72 end
63 73 true
... ... @@ -70,12 +80,23 @@ class SoftwareInfo &lt; ActiveRecord::Base
70 80 license_info = attributes.delete(:license_info)
71 81 software_info = SoftwareInfo.new(attributes)
72 82 if !environment.admins.include? requestor
73   - CreateSoftware.create!(attributes.merge(:requestor => requestor, :environment => environment, :name => name, :license_info => license_info))
  83 + CreateSoftware.create!(
  84 + attributes.merge(
  85 + :requestor => requestor,
  86 + :environment => environment,
  87 + :name => name,
  88 + :license_info => license_info
  89 + )
  90 + )
74 91 else
75 92 software_template = Community["software"]
76 93 community = Community.new(:name => name)
77 94 community.environment = environment
78   - community.template_id = software_template.id if (!software_template.blank? && software_template.is_template)
  95 +
  96 + if (!software_template.blank? && software_template.is_template)
  97 + community.template_id = software_template.id
  98 + end
  99 +
79 100 software_info.license_info = license_info
80 101 software_info.save
81 102 community.software_info = software_info
... ... @@ -99,15 +120,21 @@ class SoftwareInfo &lt; ActiveRecord::Base
99 120 end
100 121  
101 122 def valid_operating_systems
102   - self.errors.add(:operating_system, _(": at least one must be filled")) if self.operating_systems.empty?
  123 + if self.operating_systems.empty?
  124 + self.errors.add(:operating_system, _(": at least one must be filled"))
  125 + end
103 126 end
104 127  
105 128 def valid_software_info
106   - self.errors.add(:software_languages, _(": at least one must be filled")) if self.software_languages.empty?
  129 + if self.software_languages.empty?
  130 + self.errors.add(:software_languages, _(": at least one must be filled"))
  131 + end
107 132 end
108 133  
109 134 def valid_databases
110   - self.errors.add(:software_databases, _(": at least one must be filled")) if self.software_databases.empty?
  135 + if self.software_databases.empty?
  136 + self.errors.add(:software_databases, _(": at least one must be filled"))
  137 + end
111 138 end
112 139  
113 140 def visible?
... ...
lib/software_language.rb
... ... @@ -4,8 +4,17 @@ class SoftwareLanguage &lt; ActiveRecord::Base
4 4 belongs_to :software_info
5 5 belongs_to :programming_language
6 6  
7   - validates_length_of :version, maximum: 20, too_long: _("Software language is too long (maximum is 20 characters)")
8   - validates_length_of :operating_system, maximum: 20, too_long: _("Software language is too long (maximum is 20 characters)")
  7 + validates_length_of(
  8 + :version,
  9 + :maximum => 20,
  10 + :too_long => _("Software language is too long (maximum is 20 characters)")
  11 + )
  12 +
  13 + validates_length_of(
  14 + :operating_system,
  15 + :maximum => 20,
  16 + :too_long => _("Software language is too long (maximum is 20 characters)")
  17 + )
9 18  
10 19 validates_presence_of :version,:programming_language,:operating_system
11 20 end
... ...
test/functional/mpog_software_plugin_myprofile_controller_test.rb
1 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
2   -require File.dirname(__FILE__) + '/../../controllers/mpog_software_plugin_myprofile_controller'
3 2 require File.dirname(__FILE__) + '/software_test_helper'
4 3 require File.dirname(__FILE__) + '/../helpers/institution_test_helper'
  4 +require(
  5 + File.dirname(__FILE__) +
  6 + '/../../controllers/mpog_software_plugin_myprofile_controller'
  7 +)
5 8  
6 9 class MpogSoftwarePluginMyprofileController; def rescue_action(e) raise e end;
7 10 end
... ... @@ -17,7 +20,11 @@ class MpogSoftwarePluginMyprofileControllerTest &lt; ActionController::TestCase
17 20 @offer_1 = create_user('Ana de Souza')
18 21 @offer_2 = create_user('Angelo Roberto')
19 22  
20   - LicenseInfo.create(:version=>"CC-GPL-V2", :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt")
  23 + LicenseInfo.create(
  24 + :version=>"CC-GPL-V2",
  25 + :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt"
  26 + )
  27 +
21 28 ProgrammingLanguage.create(:name =>"language")
22 29 DatabaseDescription.create(:name => "database")
23 30 OperatingSystemName.create(:name=>"Debian")
... ... @@ -67,28 +74,50 @@ class MpogSoftwarePluginMyprofileControllerTest &lt; ActionController::TestCase
67 74 should 'create a new software with all fields filled in' do
68 75 fields = software_fields
69 76 @environment.add_admin(@person)
70   - post :new_software, :profile => @person.identifier, :community => fields[1], :license_info => fields[0],
71   - :software_info => fields[2]
  77 + post(
  78 + :new_software,
  79 + :profile => @person.identifier,
  80 + :community => fields[1],
  81 + :license_info => fields[0],
  82 + :software_info => fields[2]
  83 + )
72 84 assert_equal SoftwareInfo.last.community.name, "Debian"
73 85 end
74 86  
75 87 should 'edit a new software adding basic information' do
76   - fields_software = software_fields
77   - fields = software_edit_basic_fields
  88 + fields_software = software_fields
  89 + fields = software_edit_basic_fields
78 90  
79   - software = create_software fields_software
80   - post :edit_software, :profile => software.community.identifier, :license => fields[1], :software => fields[0], :library => {}, :operating_system => {}, :language => {}, :database => {}
81   - assert_equal SoftwareInfo.last.repository_link, "www.github.com/test"
  91 + software = create_software fields_software
  92 + post(
  93 + :edit_software,
  94 + :profile => software.community.identifier,
  95 + :license => fields[1],
  96 + :software => fields[0],
  97 + :library => {},
  98 + :operating_system => {},
  99 + :language => {},
  100 + :database => {}
  101 + )
  102 + assert_equal SoftwareInfo.last.repository_link, "www.github.com/test"
82 103 end
83 104  
84 105 should 'edit a new software adding specific information' do
85   - fields_software = software_fields
86   - fields = software_edit_specific_fields
  106 + fields_software = software_fields
  107 + fields = software_edit_specific_fields
87 108  
88   - software = create_software fields_software
89   - post :edit_software, :profile => software.community.identifier, :library => fields[0], :language => fields[1],
90   - :database => fields[2], :operating_system => fields[3], :software => fields[4], :license => fields[5]
91   - assert_equal SoftwareInfo.last.acronym, "test"
  109 + software = create_software fields_software
  110 + post(
  111 + :edit_software,
  112 + :profile => software.community.identifier,
  113 + :library => fields[0],
  114 + :language => fields[1],
  115 + :database => fields[2],
  116 + :operating_system => fields[3],
  117 + :software => fields[4],
  118 + :license => fields[5]
  119 + )
  120 + assert_equal SoftwareInfo.last.acronym, "test"
92 121 end
93 122  
94 123 should 'upgrade a generic software to a public software' do
... ... @@ -97,8 +126,18 @@ class MpogSoftwarePluginMyprofileControllerTest &lt; ActionController::TestCase
97 126  
98 127 fields[4]['public_software'] = true
99 128 software = create_software fields_software
100   - post :edit_software, :profile => software.community.identifier, :library => fields[0], :language => fields[1],
101   - :database => fields[2], :operating_system => fields[3], :software => fields[4], :license => fields[5]
  129 +
  130 + post(
  131 + :edit_software,
  132 + :profile => software.community.identifier,
  133 + :library => fields[0],
  134 + :language => fields[1],
  135 + :database => fields[2],
  136 + :operating_system => fields[3],
  137 + :software => fields[4],
  138 + :license => fields[5]
  139 + )
  140 +
102 141 assert_equal true, SoftwareInfo.last.public_software?
103 142 end
104 143  
... ... @@ -107,12 +146,35 @@ class MpogSoftwarePluginMyprofileControllerTest &lt; ActionController::TestCase
107 146 govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
108 147 juridical_nature = JuridicalNature.create(:name => "Autarquia")
109 148  
110   - institution = InstitutionTestHelper.create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", juridical_nature, govPower, govSphere, "12.345.678/9012-45")
111   - identifier = institution.community.identifier
  149 + institution = InstitutionTestHelper.create_public_institution(
  150 + "Ministerio Publico da Uniao",
  151 + "MPU",
  152 + "BR",
  153 + "DF",
  154 + "Gama",
  155 + juridical_nature,
  156 + govPower,
  157 + govSphere,
  158 + "12.345.678/9012-45"
  159 + )
112 160  
113   - fields = InstitutionTestHelper.generate_form_fields "institution new name", "BR", "DF", "Gama", "12.345.678/9012-45", "PrivateInstitution"
  161 + identifier = institution.community.identifier
114 162  
115   - post :edit_institution, :profile=>institution.community.identifier, :community=>fields[:community], :institutions=>fields[:institutions]
  163 + fields = InstitutionTestHelper.generate_form_fields(
  164 + "institution new name",
  165 + "BR",
  166 + "DF",
  167 + "Gama",
  168 + "12.345.678/9012-45",
  169 + "PrivateInstitution"
  170 + )
  171 +
  172 + post(
  173 + :edit_institution,
  174 + :profile=>institution.community.identifier,
  175 + :community=>fields[:community],
  176 + :institutions=>fields[:institutions]
  177 + )
116 178  
117 179 institution = Community[identifier].institution
118 180 assert_not_equal "Ministerio Publico da Uniao", institution.community.name
... ... @@ -123,12 +185,35 @@ class MpogSoftwarePluginMyprofileControllerTest &lt; ActionController::TestCase
123 185 govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
124 186 juridical_nature = JuridicalNature.create(:name => "Autarquia")
125 187  
126   - institution = InstitutionTestHelper.create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", juridical_nature, govPower, govSphere, "12.345.678/9012-45")
127   - identifier = institution.community.identifier
  188 + institution = InstitutionTestHelper.create_public_institution(
  189 + "Ministerio Publico da Uniao",
  190 + "MPU",
  191 + "BR",
  192 + "DF",
  193 + "Gama",
  194 + juridical_nature,
  195 + govPower,
  196 + govSphere,
  197 + "12.345.678/9012-45"
  198 + )
128 199  
129   - fields = InstitutionTestHelper.generate_form_fields "", "BR", "DF", "Gama", "6465465465", "PrivateInstitution"
  200 + identifier = institution.community.identifier
130 201  
131   - post :edit_institution, :profile=>institution.community.identifier, :community=>fields[:community], :institutions=>fields[:institutions]
  202 + fields = InstitutionTestHelper.generate_form_fields(
  203 + "",
  204 + "BR",
  205 + "DF",
  206 + "Gama",
  207 + "6465465465",
  208 + "PrivateInstitution"
  209 + )
  210 +
  211 + post(
  212 + :edit_institution,
  213 + :profile=>institution.community.identifier,
  214 + :community=>fields[:community],
  215 + :institutions=>fields[:institutions]
  216 + )
132 217  
133 218 institution = Community[identifier].institution
134 219 assert_equal "Ministerio Publico da Uniao", institution.community.name
... ...
test/functional/profile_editor_controller_test.rb
1 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
2 2 require File.dirname(__FILE__) + '/../helpers/institution_test_helper'
3   -require File.dirname(__FILE__) + '/../../../../app/controllers/my_profile/profile_editor_controller'
  3 +require(
  4 + File.dirname(__FILE__) +
  5 + '/../../../../app/controllers/my_profile/profile_editor_controller'
  6 +)
4 7  
5 8 class ProfileEditorController; def rescue_action(e) raise e end; end
6 9  
... ... @@ -11,7 +14,13 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
11 14 @request = ActionController::TestRequest.new
12 15 @response = ActionController::TestResponse.new
13 16 @profile = create_user('default_user').person
14   - Environment.default.affiliate(@profile, [Environment::Roles.admin(Environment.default.id)] + Profile::Roles.all_roles(Environment.default.id))
  17 +
  18 + Environment.default.affiliate(
  19 + @profile,
  20 + [Environment::Roles.admin(Environment.default.id)] +
  21 + Profile::Roles.all_roles(Environment.default.id)
  22 + )
  23 +
15 24 @environment = Environment.default
16 25 @environment.enabled_plugins = ['MpogSoftwarePlugin']
17 26 admin = create_user("adminuser").person
... ... @@ -25,8 +34,29 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
25 34 @juridical_nature = JuridicalNature.create(:name => "Autarquia")
26 35  
27 36 @institution_list = []
28   - @institution_list << InstitutionTestHelper.create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @govPower, @govSphere, "12.345.678/9012-45")
29   - @institution_list << InstitutionTestHelper.create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", @juridical_nature, @govPower, @govSphere, "12.345.678/9012-90")
  37 + @institution_list << InstitutionTestHelper.create_public_institution(
  38 + "Ministerio Publico da Uniao",
  39 + "MPU",
  40 + "BR",
  41 + "DF",
  42 + "Gama",
  43 + @juridical_nature,
  44 + @govPower,
  45 + @govSphere,
  46 + "12.345.678/9012-45"
  47 + )
  48 +
  49 + @institution_list << InstitutionTestHelper.create_public_institution(
  50 + "Tribunal Regional da Uniao",
  51 + "TRU",
  52 + "BR",
  53 + "DF",
  54 + "Brasilia",
  55 + @juridical_nature,
  56 + @govPower,
  57 + @govSphere,
  58 + "12.345.678/9012-90"
  59 + )
30 60 end
31 61  
32 62 should "add new institution for user into edit profile" do
... ...
test/functional/search_controller_test.rb
1 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
2   -require File.dirname(__FILE__) + '/../../../../app/controllers/public/search_controller'
3 2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +require(
  4 + File.dirname(__FILE__) +
  5 + '/../../../../app/controllers/public/search_controller'
  6 +)
4 7  
5 8 class SearchController; def rescue_action(e) raise e end; end
6 9  
... ... @@ -17,58 +20,68 @@ class SearchControllerTest &lt; ActionController::TestCase
17 20 @request.stubs(:ssl?).returns(:false)
18 21 @response = ActionController::TestResponse.new
19 22  
20   - @category_software = Category.create!(:name => _("Software"), :environment => @environment)
  23 + @category_software = Category.create!(
  24 + :name => _("Software"),
  25 + :environment => @environment
  26 + )
21 27 end
22 28  
23   - # should "communities searches don't have software or institution" do
24   - # community = create_community("New Community")
25   - # software = create_software_info("New Software")
26   - # institution = create_private_institution("New Private Institution", "NPI" , "Brazil", "DF", "Gama", "66.544.314/0001-63")
  29 + should "communities searches don't have software or institution" do
  30 + community = create_community("New Community")
  31 + software = create_software_info("New Software")
  32 + institution = create_private_institution(
  33 + "New Private Institution",
  34 + "NPI" ,
  35 + "Brazil",
  36 + "DF",
  37 + "Gama",
  38 + "66.544.314/0001-63"
  39 + )
27 40  
28   - # get :communities, :query => "New"
  41 + get :communities, :query => "New"
29 42  
30   - # assert_includes assigns(:searches)[:communities][:results], community
31   - # assert_not_includes assigns(:searches)[:communities][:results], software
32   - # assert_not_includes assigns(:searches)[:communities][:results], institution
33   - # end
  43 + assert_includes assigns(:searches)[:communities][:results], community
  44 + assert_not_includes assigns(:searches)[:communities][:results], software
  45 + assert_not_includes assigns(:searches)[:communities][:results], institution
  46 + end
34 47  
35   - # should "software_infos search don't have community or institution" do
36   - # community = create_community("New Community")
37   - # software = create_software_info("New Software")
38   - # institution = create_private_institution("New Private Institution", "NPI" , "Brazil", "DF", "Gama", "66.544.314/0001-63")
  48 + should "software_infos search don't have community or institution" do
  49 + community = create_community("New Community")
  50 + software = create_software_info("New Software")
  51 + institution = create_private_institution("New Private Institution", "NPI" , "Brazil", "DF", "Gama", "66.544.314/0001-63")
39 52  
40   - # get :software_infos, :query => "New"
  53 + get :software_infos, :query => "New"
41 54  
42   - # assert_includes assigns(:searches)[:software_infos][:results], software.community
43   - # assert_not_includes assigns(:searches)[:software_infos][:results], community
44   - # assert_not_includes assigns(:searches)[:software_infos][:results], institution.community
45   - # end
  55 + assert_includes assigns(:searches)[:software_infos][:results], software.community
  56 + assert_not_includes assigns(:searches)[:software_infos][:results], community
  57 + assert_not_includes assigns(:searches)[:software_infos][:results], institution.community
  58 + end
46 59  
47   - # should "software_infos search by category" do
48   - # software_with_category = create_software_info("New Software With Category")
49   - # software_without_category = create_software_info("New Software Without Category")
50   - # category = Category.create!(:name => "Health", :environment => @environment, :parent => @category_software)
  60 + should "software_infos search by category" do
  61 + software_with_category = create_software_info("New Software With Category")
  62 + software_without_category = create_software_info("New Software Without Category")
  63 + category = Category.create!(:name => "Health", :environment => @environment, :parent => @category_software)
51 64  
52   - # software_with_category.community.categories << category
53   - # software_with_category.save!
  65 + software_with_category.community.categories << category
  66 + software_with_category.save!
54 67  
55   - # get :software_infos, :query => "New", :filter => category.id
  68 + get :software_infos, :query => "New", :filter => category.id
56 69  
57   - # assert_includes assigns(:searches)[:software_infos][:results], software_with_category.community
58   - # assert_not_includes assigns(:searches)[:software_infos][:results], software_without_category.community
59   - # end
  70 + assert_includes assigns(:searches)[:software_infos][:results], software_with_category.community
  71 + assert_not_includes assigns(:searches)[:software_infos][:results], software_without_category.community
  72 + end
60 73  
61   - # should "institutions_search don't have community or software" do
62   - # community = create_community("New Community")
63   - # software = create_software_info("New Software")
64   - # institution = create_private_institution("New Private Institution", "NPI" , "Brazil", "DF", "Gama", "66.544.314/0001-63")
  74 + should "institutions_search don't have community or software" do
  75 + community = create_community("New Community")
  76 + software = create_software_info("New Software")
  77 + institution = create_private_institution("New Private Institution", "NPI" , "Brazil", "DF", "Gama", "66.544.314/0001-63")
65 78  
66   - # get :institutions, :query => "New"
  79 + get :institutions, :query => "New"
67 80  
68   - # assert_includes assigns(:searches)[:institutions][:results], institution.community
69   - # assert_not_includes assigns(:searches)[:institutions][:results], community
70   - # assert_not_includes assigns(:searches)[:institutions][:results], software.community
71   - # end
  81 + assert_includes assigns(:searches)[:institutions][:results], institution.community
  82 + assert_not_includes assigns(:searches)[:institutions][:results], community
  83 + assert_not_includes assigns(:searches)[:institutions][:results], software.community
  84 + end
72 85  
73 86 should "Don't found template in communities search" do
74 87 community = create_community("New Community")
... ... @@ -76,7 +89,14 @@ class SearchControllerTest &lt; ActionController::TestCase
76 89 software.license_info = LicenseInfo.create(:version => "GPL")
77 90 software.save!
78 91  
79   - institution = create_private_institution("New Private Institution", "NPI" , "Brazil", "DF", "Gama", "66.544.314/0001-63")
  92 + institution = create_private_institution(
  93 + "New Private Institution",
  94 + "NPI" ,
  95 + "Brazil",
  96 + "DF",
  97 + "Gama",
  98 + "66.544.314/0001-63"
  99 + )
80 100  
81 101 community_template = create_community("New Community Template")
82 102 community_template.is_template = true
... ... @@ -84,10 +104,14 @@ class SearchControllerTest &lt; ActionController::TestCase
84 104  
85 105 get :communities, :query => "New"
86 106  
87   - assert_includes assigns(:searches)[:communities][:results], community
  107 + assert_includes(
  108 + assigns(:searches)[:software_infos][:results],
  109 + software.community
  110 + )
  111 + assert_not_includes assigns(:searches)[:software_infos][:results], community
88 112 assert_not_includes(
89   - assigns(:searches)[:communities][:results],
90   - community_template
  113 + assigns(:searches)[:software_infos][:results],
  114 + institution.community
91 115 )
92 116 end
93 117  
... ... @@ -95,10 +119,17 @@ class SearchControllerTest &lt; ActionController::TestCase
95 119 software_with_category = create_software_info("New Software With Category")
96 120 software_with_category.license_info = LicenseInfo.create(:version => "GPL")
97 121  
98   - software_without_category = create_software_info("New Software Without Category")
99   - software_without_category.license_info = LicenseInfo.create(:version => "GPL")
  122 + software_without_category =
  123 + create_software_info("New Software Without Category")
100 124  
101   - category = Category.create!(:name => "Health", :environment => @environment, :parent => @category_software)
  125 + software_without_category.license_info =
  126 + LicenseInfo.create(:version => "GPL")
  127 +
  128 + category = Category.create!(
  129 + :name => "Health",
  130 + :environment => @environment,
  131 + :parent => @category_software
  132 + )
102 133  
103 134 software_template = create_software_info("New Software Template")
104 135 software_template.license_info = LicenseInfo.last
... ... @@ -110,44 +141,37 @@ class SearchControllerTest &lt; ActionController::TestCase
110 141  
111 142 assert_includes(
112 143 assigns(:searches)[:software_infos][:results],
113   - software.community
  144 + software_with_category.community
114 145 )
115 146 assert_not_includes(
116 147 assigns(:searches)[:software_infos][:results],
117   - software_template.community
  148 + software_without_category.community
118 149 )
119 150 end
120 151  
121   - should "Not found template in institutions search" do
  152 + should "institutions_search don't have community or software" do
  153 + community = create_community("New Community")
  154 + software = create_software_info("New Software")
122 155 institution = create_private_institution(
123 156 "New Private Institution",
124   - "NPI",
  157 + "NPI" ,
125 158 "Brazil",
126 159 "DF",
127 160 "Gama",
128 161 "66.544.314/0001-63"
129 162 )
130 163  
131   - institution_template = create_private_institution(
132   - "New Private Institution Template",
133   - "NPIT",
134   - "Brazil",
135   - "DF",
136   - "Gama",
137   - "66.544.314/0001-63"
138   - )
139   - institution_template.community.is_template = true
140   - institution_template.community.save!
141   -
142 164 get :institutions, :query => "New"
143 165  
144 166 assert_includes(
145 167 assigns(:searches)[:institutions][:results],
146 168 institution.community
147 169 )
  170 + assert_not_includes assigns(:searches)[:institutions][:results], community
148 171 assert_not_includes(
149 172 assigns(:searches)[:institutions][:results],
150   - institution_template.community
  173 + software.community
151 174 )
  175 +
152 176 end
153 177 end
... ...
test/helpers/plugin_test_helper.rb
... ... @@ -22,7 +22,14 @@ module PluginTestHelper
22 22 end
23 23  
24 24 def create_private_institution name, acronym, country, state, city, cnpj
25   - InstitutionTestHelper.create_private_institution(name, acronym, country, state, city, cnpj)
  25 + InstitutionTestHelper.create_private_institution(
  26 + name,
  27 + acronym,
  28 + country,
  29 + state,
  30 + city,
  31 + cnpj
  32 + )
26 33 end
27 34  
28 35 def create_community_institution name, country, state, city
... ... @@ -36,7 +43,13 @@ module PluginTestHelper
36 43 end
37 44  
38 45 def create_person name, email, password, password_confirmation, secondary_email, state, city
39   - user = create_user(name.to_slug, email, password, password_confirmation, secondary_email)
  46 + user = create_user(
  47 + name.to_slug,
  48 + email,
  49 + password,
  50 + password_confirmation,
  51 + secondary_email
  52 + )
40 53 person = Person::new
41 54  
42 55 user.person = person
... ...