Commit 3732543d000790391372f65b9417eac7faaeaac9

Authored by Gabriela Navarro
1 parent 99ece19b

Fix tests for search controller

Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Signed-off-by: Gustavo Jaruga <darksshades@gmail.com>
Signed-off-by: Luiz Matos <luizff.matos@gmail.com>
lib/mpog_software_plugin.rb
@@ -131,7 +131,6 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin @@ -131,7 +131,6 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
131 params[:license_info][:id], params[:e_ping], params[:e_mag], params[:internacionalizable], 131 params[:license_info][:id], params[:e_ping], params[:e_mag], params[:internacionalizable],
132 params[:icp_brasil], params[:e_arq], params[:software_categories]) 132 params[:icp_brasil], params[:e_arq], params[:software_categories])
133 communities = [] 133 communities = []
134 -  
135 softwares.each do |s| 134 softwares.each do |s|
136 communities << s.community 135 communities << s.community
137 end 136 end
@@ -139,7 +138,6 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin @@ -139,7 +138,6 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
139 results = results.paginate(:per_page => 24, :page => params[:page]) 138 results = results.paginate(:per_page => 24, :page => params[:page])
140 @searches[@asset] = {:results => results} 139 @searches[@asset] = {:results => results}
141 @search = results 140 @search = results
142 -  
143 render :action => :communities 141 render :action => :communities
144 end 142 end
145 end 143 end
@@ -402,7 +400,6 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin @@ -402,7 +400,6 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
402 else 400 else
403 "community" 401 "community"
404 end 402 end
405 - puts  
406 expanded_template('search/search_community_filter.html.erb') 403 expanded_template('search/search_community_filter.html.erb')
407 end 404 end
408 end 405 end
test/functional/search_controller_test.rb
1 require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
2 require File.dirname(__FILE__) + '/../../../../app/controllers/public/search_controller' 2 require File.dirname(__FILE__) + '/../../../../app/controllers/public/search_controller'
  3 +require File.dirname(__FILE__) + '/software_test_helper'
3 4
4 class SearchController; def rescue_action(e) raise e end; end 5 class SearchController; def rescue_action(e) raise e end; end
5 6
6 class SearchControllerTest < ActionController::TestCase 7 class SearchControllerTest < ActionController::TestCase
7 - 8 + include SoftwareTestHelper
8 def setup 9 def setup
9 environment = Environment.default 10 environment = Environment.default
10 environment.enabled_plugins = ['MpogSoftwarePlugin'] 11 environment.enabled_plugins = ['MpogSoftwarePlugin']
@@ -83,25 +84,30 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -83,25 +84,30 @@ class SearchControllerTest &lt; ActionController::TestCase
83 end 84 end
84 85
85 should "search for software by identifier" do 86 should "search for software by identifier" do
86 - software = create_software("beautiful os") 87 + fields = software_fields
  88 + software = create_software fields
  89 + software.save
87 90
88 - params = {"type"=>"Software", "query"=>"", "name"=>"beautiful-os", "database_description"=>{"id"=>""}, "programming_language"=>{"id"=>""}, "operating_system"=>{"id"=>""}, "software_categories"=>"", "license_info"=>{"id"=>""}, "e_ping"=>"", "e_mag"=>"", "icp_brasil"=>"", "e_arq"=>"", "internacionalizable"=>"", "commit"=>"Search"} 91 + params = {"type"=>"Software", "query"=>"", "name"=>"debian", "database_description"=>{"id"=>""}, "programming_language"=>{"id"=>""}, "operating_system"=>{"id"=>""}, "software_categories"=>"", "license_info"=>{"id"=>""}, "e_ping"=>"", "e_mag"=>"", "icp_brasil"=>"", "e_arq"=>"", "internacionalizable"=>"", "commit"=>"Search"}
89 get :communities, params 92 get :communities, params
90 93
91 assert_includes assigns(:searches)[:communities][:results], software.community 94 assert_includes assigns(:searches)[:communities][:results], software.community
92 end 95 end
93 96
94 should "search for software by name" do 97 should "search for software by name" do
95 - software = create_software("beautiful") 98 + fields = software_fields
  99 + software = create_software fields
  100 + software.save
96 101
97 - params = {"type"=>"Software", "query"=>"", "name"=>"beautiful", "database_description"=>{"id"=>""}, "programming_language"=>{"id"=>""}, "operating_system"=>{"id"=>""}, "software_categories"=>"", "license_info"=>{"id"=>""}, "e_ping"=>"", "e_mag"=>"", "icp_brasil"=>"", "e_arq"=>"", "internacionalizable"=>"", "commit"=>"Search"} 102 + params = {"type"=>"Software", "query"=>"", "name"=>"debian", "database_description"=>{"id"=>""}, "programming_language"=>{"id"=>""}, "operating_system"=>{"id"=>""}, "software_categories"=>"", "license_info"=>{"id"=>""}, "e_ping"=>"", "e_mag"=>"", "icp_brasil"=>"", "e_arq"=>"", "internacionalizable"=>"", "commit"=>"Search"}
98 get :communities, params 103 get :communities, params
99 104
100 assert_includes assigns(:searches)[:communities][:results], software.community 105 assert_includes assigns(:searches)[:communities][:results], software.community
101 end 106 end
102 107
103 should "search for software by database" do 108 should "search for software by database" do
104 - software = create_software("beautiful") 109 + fields = software_fields
  110 + software = create_software fields
105 software.software_databases.clear() 111 software.software_databases.clear()
106 software.software_databases << SoftwareDatabase.last 112 software.software_databases << SoftwareDatabase.last
107 software.save! 113 software.save!
@@ -117,7 +123,8 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -117,7 +123,8 @@ class SearchControllerTest &lt; ActionController::TestCase
117 end 123 end
118 124
119 should "search for software by programming language" do 125 should "search for software by programming language" do
120 - software = create_software("beautiful") 126 + fields = software_fields
  127 + software = create_software fields
121 software.software_languages.clear() 128 software.software_languages.clear()
122 software.software_languages << SoftwareLanguage.last 129 software.software_languages << SoftwareLanguage.last
123 software.save! 130 software.save!
@@ -133,14 +140,16 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -133,14 +140,16 @@ class SearchControllerTest &lt; ActionController::TestCase
133 end 140 end
134 141
135 should "search for software by operating system" do 142 should "search for software by operating system" do
136 - software = create_software("beautiful") 143 + fields = software_fields
  144 + software = create_software fields
  145 + software.save!
137 software.operating_systems.clear() 146 software.operating_systems.clear()
138 software.operating_systems << OperatingSystem.last 147 software.operating_systems << OperatingSystem.last
139 software.save! 148 software.save!
140 149
141 params = {"type"=>"Software", "query"=>"", "name"=>"", "database_description"=>{"id"=>""}, 150 params = {"type"=>"Software", "query"=>"", "name"=>"", "database_description"=>{"id"=>""},
142 "programming_language"=>{"id"=>""}, 151 "programming_language"=>{"id"=>""},
143 - "operating_system"=>{"id"=>OperatingSystem.last.id}, 152 + "operating_system"=>{"id"=>OperatingSystemName.last.id},
144 "software_categories"=>"", "license_info"=>{"id"=>""}, "e_ping"=>"", "e_mag"=>"", "icp_brasil"=>"", "e_arq"=>"", "internacionalizable"=>"", 153 "software_categories"=>"", "license_info"=>{"id"=>""}, "e_ping"=>"", "e_mag"=>"", "icp_brasil"=>"", "e_arq"=>"", "internacionalizable"=>"",
145 "commit"=>"Search"} 154 "commit"=>"Search"}
146 get :communities, params 155 get :communities, params
@@ -148,11 +157,12 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -148,11 +157,12 @@ class SearchControllerTest &lt; ActionController::TestCase
148 assert_includes assigns(:searches)[:communities][:results], software.community 157 assert_includes assigns(:searches)[:communities][:results], software.community
149 end 158 end
150 159
151 - should "search for software by controlled vocabulary" do  
152 - software = create_software("beautiful") 160 + should "search for software by software categories" do
  161 + fields = software_fields
  162 + software = create_software fields
153 software.software_categories.habitation = true 163 software.software_categories.habitation = true
154 software.software_categories.save! 164 software.software_categories.save!
155 - 165 + software.save
156 params = {"type"=>"Software", "query"=>"", "name"=>"", "database_description"=>{"id"=>""}, 166 params = {"type"=>"Software", "query"=>"", "name"=>"", "database_description"=>{"id"=>""},
157 "programming_language"=>{"id"=>""}, 167 "programming_language"=>{"id"=>""},
158 "operating_system"=>{"id"=>""}, 168 "operating_system"=>{"id"=>""},
@@ -164,7 +174,8 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -164,7 +174,8 @@ class SearchControllerTest &lt; ActionController::TestCase
164 end 174 end
165 175
166 should "search for software by license info" do 176 should "search for software by license info" do
167 - software = create_software("beautiful") 177 + fields = software_fields
  178 + software = create_software fields
168 software.license_info = LicenseInfo.last 179 software.license_info = LicenseInfo.last
169 software.save! 180 software.save!
170 181
@@ -180,7 +191,8 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -180,7 +191,8 @@ class SearchControllerTest &lt; ActionController::TestCase
180 191
181 192
182 should "search for software by e_mag" do 193 should "search for software by e_mag" do
183 - software = create_software("beautiful") 194 + fields = software_fields
  195 + software = create_software fields
184 software.e_mag = true 196 software.e_mag = true
185 software.save! 197 software.save!
186 198
@@ -196,7 +208,8 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -196,7 +208,8 @@ class SearchControllerTest &lt; ActionController::TestCase
196 208
197 209
198 should "search for software by e_ping" do 210 should "search for software by e_ping" do
199 - software = create_software("beautiful") 211 + fields = software_fields
  212 + software = create_software fields
200 software.e_ping = true 213 software.e_ping = true
201 software.save! 214 software.save!
202 215
@@ -212,7 +225,8 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -212,7 +225,8 @@ class SearchControllerTest &lt; ActionController::TestCase
212 225
213 226
214 should "search for software by icp_brasil" do 227 should "search for software by icp_brasil" do
215 - software = create_software("beautiful") 228 + fields = software_fields
  229 + software = create_software fields
216 software.icp_brasil = true 230 software.icp_brasil = true
217 software.save! 231 software.save!
218 232
@@ -227,7 +241,8 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -227,7 +241,8 @@ class SearchControllerTest &lt; ActionController::TestCase
227 end 241 end
228 242
229 should "search for software by e_arq" do 243 should "search for software by e_arq" do
230 - software = create_software("beautiful") 244 + fields = software_fields
  245 + software = create_software fields
231 software.e_arq = true 246 software.e_arq = true
232 software.save! 247 software.save!
233 248
@@ -242,7 +257,8 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -242,7 +257,8 @@ class SearchControllerTest &lt; ActionController::TestCase
242 end 257 end
243 258
244 should "search for software by internacionalizable" do 259 should "search for software by internacionalizable" do
245 - software = create_software("beautiful") 260 + fields = software_fields
  261 + software = create_software fields
246 software.intern = true 262 software.intern = true
247 software.save! 263 software.save!
248 264
@@ -257,7 +273,8 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -257,7 +273,8 @@ class SearchControllerTest &lt; ActionController::TestCase
257 end 273 end
258 274
259 should "search by e_arq and e_ping" do 275 should "search by e_arq and e_ping" do
260 - software = create_software("beautiful") 276 + fields = software_fields
  277 + software = create_software fields
261 software.e_arq = true 278 software.e_arq = true
262 software.e_ping = true 279 software.e_ping = true
263 software.save! 280 software.save!
@@ -285,32 +302,4 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -285,32 +302,4 @@ class SearchControllerTest &lt; ActionController::TestCase
285 user 302 user
286 end 303 end
287 304
288 - def create_software name  
289 - community = Community.create(:name => name)  
290 - software_info = SoftwareInfo::new(:acronym=>"SFT", :operating_platform=>"windows")  
291 - software_info.community = community  
292 - software_info.software_languages << SoftwareLanguage.last  
293 - software_info.software_databases << SoftwareDatabase.last  
294 - software_info.operating_systems << OperatingSystem.last  
295 - software_info.license_info = LicenseInfo.last  
296 -  
297 -  
298 - sc = SoftwareCategories.new()  
299 - sc.attributes.each do |key|  
300 - if(key.first == 'id' || key.first == 'software_info_id')  
301 - next  
302 - end  
303 - sc.update_attribute(key.first, false)  
304 - end  
305 - sc.save!  
306 -  
307 - software_info.software_categories = sc  
308 -  
309 - software_info.save!  
310 -  
311 - community.save!  
312 -  
313 - software_info  
314 - end  
315 -  
316 end 305 end