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 131 params[:license_info][:id], params[:e_ping], params[:e_mag], params[:internacionalizable],
132 132 params[:icp_brasil], params[:e_arq], params[:software_categories])
133 133 communities = []
134   -
135 134 softwares.each do |s|
136 135 communities << s.community
137 136 end
... ... @@ -139,7 +138,6 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
139 138 results = results.paginate(:per_page => 24, :page => params[:page])
140 139 @searches[@asset] = {:results => results}
141 140 @search = results
142   -
143 141 render :action => :communities
144 142 end
145 143 end
... ... @@ -402,7 +400,6 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
402 400 else
403 401 "community"
404 402 end
405   - puts
406 403 expanded_template('search/search_community_filter.html.erb')
407 404 end
408 405 end
... ...
test/functional/search_controller_test.rb
1 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
2 2 require File.dirname(__FILE__) + '/../../../../app/controllers/public/search_controller'
  3 +require File.dirname(__FILE__) + '/software_test_helper'
3 4  
4 5 class SearchController; def rescue_action(e) raise e end; end
5 6  
6 7 class SearchControllerTest < ActionController::TestCase
7   -
  8 + include SoftwareTestHelper
8 9 def setup
9 10 environment = Environment.default
10 11 environment.enabled_plugins = ['MpogSoftwarePlugin']
... ... @@ -83,25 +84,30 @@ class SearchControllerTest &lt; ActionController::TestCase
83 84 end
84 85  
85 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 92 get :communities, params
90 93  
91 94 assert_includes assigns(:searches)[:communities][:results], software.community
92 95 end
93 96  
94 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 103 get :communities, params
99 104  
100 105 assert_includes assigns(:searches)[:communities][:results], software.community
101 106 end
102 107  
103 108 should "search for software by database" do
104   - software = create_software("beautiful")
  109 + fields = software_fields
  110 + software = create_software fields
105 111 software.software_databases.clear()
106 112 software.software_databases << SoftwareDatabase.last
107 113 software.save!
... ... @@ -117,7 +123,8 @@ class SearchControllerTest &lt; ActionController::TestCase
117 123 end
118 124  
119 125 should "search for software by programming language" do
120   - software = create_software("beautiful")
  126 + fields = software_fields
  127 + software = create_software fields
121 128 software.software_languages.clear()
122 129 software.software_languages << SoftwareLanguage.last
123 130 software.save!
... ... @@ -133,14 +140,16 @@ class SearchControllerTest &lt; ActionController::TestCase
133 140 end
134 141  
135 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 146 software.operating_systems.clear()
138 147 software.operating_systems << OperatingSystem.last
139 148 software.save!
140 149  
141 150 params = {"type"=>"Software", "query"=>"", "name"=>"", "database_description"=>{"id"=>""},
142 151 "programming_language"=>{"id"=>""},
143   - "operating_system"=>{"id"=>OperatingSystem.last.id},
  152 + "operating_system"=>{"id"=>OperatingSystemName.last.id},
144 153 "software_categories"=>"", "license_info"=>{"id"=>""}, "e_ping"=>"", "e_mag"=>"", "icp_brasil"=>"", "e_arq"=>"", "internacionalizable"=>"",
145 154 "commit"=>"Search"}
146 155 get :communities, params
... ... @@ -148,11 +157,12 @@ class SearchControllerTest &lt; ActionController::TestCase
148 157 assert_includes assigns(:searches)[:communities][:results], software.community
149 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 163 software.software_categories.habitation = true
154 164 software.software_categories.save!
155   -
  165 + software.save
156 166 params = {"type"=>"Software", "query"=>"", "name"=>"", "database_description"=>{"id"=>""},
157 167 "programming_language"=>{"id"=>""},
158 168 "operating_system"=>{"id"=>""},
... ... @@ -164,7 +174,8 @@ class SearchControllerTest &lt; ActionController::TestCase
164 174 end
165 175  
166 176 should "search for software by license info" do
167   - software = create_software("beautiful")
  177 + fields = software_fields
  178 + software = create_software fields
168 179 software.license_info = LicenseInfo.last
169 180 software.save!
170 181  
... ... @@ -180,7 +191,8 @@ class SearchControllerTest &lt; ActionController::TestCase
180 191  
181 192  
182 193 should "search for software by e_mag" do
183   - software = create_software("beautiful")
  194 + fields = software_fields
  195 + software = create_software fields
184 196 software.e_mag = true
185 197 software.save!
186 198  
... ... @@ -196,7 +208,8 @@ class SearchControllerTest &lt; ActionController::TestCase
196 208  
197 209  
198 210 should "search for software by e_ping" do
199   - software = create_software("beautiful")
  211 + fields = software_fields
  212 + software = create_software fields
200 213 software.e_ping = true
201 214 software.save!
202 215  
... ... @@ -212,7 +225,8 @@ class SearchControllerTest &lt; ActionController::TestCase
212 225  
213 226  
214 227 should "search for software by icp_brasil" do
215   - software = create_software("beautiful")
  228 + fields = software_fields
  229 + software = create_software fields
216 230 software.icp_brasil = true
217 231 software.save!
218 232  
... ... @@ -227,7 +241,8 @@ class SearchControllerTest &lt; ActionController::TestCase
227 241 end
228 242  
229 243 should "search for software by e_arq" do
230   - software = create_software("beautiful")
  244 + fields = software_fields
  245 + software = create_software fields
231 246 software.e_arq = true
232 247 software.save!
233 248  
... ... @@ -242,7 +257,8 @@ class SearchControllerTest &lt; ActionController::TestCase
242 257 end
243 258  
244 259 should "search for software by internacionalizable" do
245   - software = create_software("beautiful")
  260 + fields = software_fields
  261 + software = create_software fields
246 262 software.intern = true
247 263 software.save!
248 264  
... ... @@ -257,7 +273,8 @@ class SearchControllerTest &lt; ActionController::TestCase
257 273 end
258 274  
259 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 278 software.e_arq = true
262 279 software.e_ping = true
263 280 software.save!
... ... @@ -285,32 +302,4 @@ class SearchControllerTest &lt; ActionController::TestCase
285 302 user
286 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 305 end
... ...