Commit 8260f4030791a33d9647067ee147cd025fec3d86

Authored by Rafael Martins
1 parent d63bddce

Fixes for unit tests (after merge)

* A few syntax problems
* Removed tests for removed models
* Replaced 'browse' with 'search' controller
* Created EnterpriseHomepageHelperTest
* Fixes to work with Solr
test/unit/application_helper_test.rb
@@ -98,7 +98,7 @@ class ApplicationHelperTest < ActiveSupport::TestCase @@ -98,7 +98,7 @@ class ApplicationHelperTest < ActiveSupport::TestCase
98 Environment.any_instance.expects(:default_hostname).returns('example.com') 98 Environment.any_instance.expects(:default_hostname).returns('example.com')
99 99
100 result = "/cat/my-category/my-subcatagory" 100 result = "/cat/my-category/my-subcatagory"
101 - expects(:link_to).with('category name', :controller => 'search', :action => 'category_index', :category_path => ['my-category', 'my-subcatagory'], :host => 'example.com').returns(result) 101 + expects(:link_to).with('category name', {:controller => 'search', :action => 'category_index', :category_path => ['my-category', 'my-subcatagory'], :host => 'example.com'}, {}).returns(result)
102 assert_same result, link_to_category(cat) 102 assert_same result, link_to_category(cat)
103 end 103 end
104 104
test/unit/category_finder_test.rb
@@ -1,526 +0,0 @@ @@ -1,526 +0,0 @@
1 -require File.dirname(__FILE__) + '/../test_helper'  
2 -  
3 -class CategoryFinderTest < ActiveSupport::TestCase  
4 -  
5 - def setup  
6 - ActiveSupport::TestCase::setup  
7 - @category = Category.create!(:name => 'my category', :environment => Environment.default)  
8 - @finder = CategoryFinder.new(@category)  
9 - @product_category = fast_create(ProductCategory, :name => 'Products')  
10 -  
11 - Profile.rebuild_index  
12 -# This doesn't exist/never existed; either we remove or implement?  
13 -# Comment.skip_captcha!  
14 - end  
15 -  
16 - should 'search for articles in a specific category' do  
17 - person = create_user('teste').person  
18 -  
19 - # in category  
20 - art1 = person.articles.build(:name => 'an article to be found')  
21 - art1.add_category(@category)  
22 - art1.save!  
23 -  
24 - # not in category  
25 - art2 = person.articles.build(:name => 'another article to be found')  
26 - art2.save!  
27 -  
28 - list = @finder.find(:articles, 'found')  
29 - assert_includes list, art1  
30 - assert_not_includes list, art2  
31 - end  
32 -  
33 - should 'search with query for articles in a specific category' do  
34 - person = create_user('teste').person  
35 -  
36 - # in category  
37 - art1 = person.articles.build(:name => 'an article to be found')  
38 - art1.add_category(@category)  
39 - art1.save!  
40 -  
41 - # not in category  
42 - art2 = person.articles.build(:name => 'another article to be found')  
43 - art2.save!  
44 -  
45 - assert_includes @finder.find('articles', 'found'), art1  
46 - assert_not_includes @finder.find('articles','found'), art2  
47 - end  
48 -  
49 - should 'search for enterprises in a specific category' do  
50 -  
51 - # in category  
52 - ent1 = Enterprise.create!(:name => 'beautiful enterprise 1', :identifier => 'test1', :category_ids => [@category.id])  
53 -  
54 - # not in category  
55 - ent2 = fast_create(Enterprise, :name => 'beautiful enterprise 2', :identifier => 'test2')  
56 -  
57 - list = @finder.find(:enterprises, 'beautiful')  
58 - assert_includes list, ent1  
59 - assert_not_includes list, ent2  
60 - end  
61 -  
62 - should 'search for people in a specific category' do  
63 - p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.add_category(@category); p1.save!  
64 - p2 = create_user('people_2').person; p2.name = 'another beautiful person'; p2.save!  
65 -  
66 - list = @finder.find(:people, 'beautiful')  
67 - assert_includes list, p1  
68 - assert_not_includes list, p2  
69 - end  
70 -  
71 - should 'search for communities in a specific category' do  
72 - c1 = fast_create(Community, :name => 'a beautiful community', :identifier => 'bea_comm', :environment_id => Environment.default.id)  
73 - c2 = fast_create(Community, :name => 'another beautiful community', :identifier => 'an_bea_comm', :environment_id => Environment.default.id)  
74 - c1.add_category(@category); c1.save!  
75 -  
76 - list = @finder.find(:communities, 'beautiful')  
77 - assert_includes list, c1  
78 - assert_not_includes list, c2  
79 - end  
80 -  
81 - should 'search for products in a specific category' do  
82 - ent1 = fast_create(Enterprise, :name => 'teste1', :identifier => 'teste1'); ent1.add_category(@category)  
83 - ent2 = fast_create(Enterprise, :name => 'teste2', :identifier => 'teste2')  
84 - prod1 = ent1.products.create!(:name => 'a beautiful product', :product_category => @product_category)  
85 - prod2 = ent2.products.create!(:name => 'another beautiful product', :product_category => @product_category)  
86 -  
87 - list = @finder.find(:products, 'beautiful')  
88 - assert_includes list, prod1  
89 - assert_not_includes list, prod2  
90 - end  
91 -  
92 - should 'search people in category hierarchy' do  
93 - parent = fast_create(Category, :name => 'parent category', :environment_id => Environment.default.id)  
94 - child = fast_create(Category, :name => 'child category', :environment_id => Environment.default.id, :parent_id => parent.id)  
95 - p1 = create_user('people_1').person  
96 - p1.name = 'a beautiful person'  
97 - p1.add_category(child)  
98 - p1.save!  
99 -  
100 - parent.reload  
101 -  
102 - f = CategoryFinder.new(parent)  
103 - assert_includes f.find(:people, 'beautiful'), p1  
104 - end  
105 -  
106 - should 'search article in category hierarchy' do  
107 - parent = fast_create(Category, :name => 'parent category', :environment_id => Environment.default.id)  
108 - child = fast_create(Category, :name => 'child category', :environment_id => Environment.default.id, :parent_id => parent.id)  
109 -  
110 - p1 = create_user('people_1').person  
111 -  
112 - article = p1.articles.create!(:name => 'a beautiful article', :category_ids => [child.id])  
113 -  
114 - parent.reload  
115 -  
116 - f = CategoryFinder.new(parent)  
117 - assert_includes f.find(:articles, 'beautiful'), article  
118 - end  
119 -  
120 - should 'list recent enterprises' do  
121 - ent = Enterprise.create!(:name => 'teste', :identifier => 'teste', :category_ids => [@category.id])  
122 - assert_includes @finder.recent('enterprises'), ent  
123 - end  
124 -  
125 - should 'respond to total_entries in the recent enterprises result' do  
126 - ent = Enterprise.create!(:name => 'teste', :identifier => 'teste', :category_ids => [@category.id])  
127 - assert_respond_to @finder.recent('enterprises'), :total_entries  
128 - end  
129 -  
130 - should 'not list more enterprises than limit' do  
131 - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1', :category_ids => [@category.id])  
132 - ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2', :category_ids => [@category.id])  
133 - result = @finder.recent('enterprises', 1)  
134 -  
135 - assert_equal 1, result.size  
136 - end  
137 -  
138 - should 'paginate the list of more enterprises than limit' do  
139 - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1', :category_ids => [@category.id])  
140 - ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2', :category_ids => [@category.id])  
141 -  
142 - page_1 = @finder.find('enterprises', nil, :per_page => 1, :page => 1)  
143 - page_2 = @finder.find('enterprises', nil, :per_page => 1, :page => 2)  
144 -  
145 - assert_equal 1, page_1.size  
146 - assert_equal 1, page_2.size  
147 - assert_equivalent [ent1, ent2], page_1 + page_2  
148 - end  
149 -  
150 - should 'paginate the list of more enterprises than limit with query' do  
151 - ent1 = Enterprise.create!(:name => 'teste 1', :identifier => 'teste1', :category_ids => [@category.id])  
152 - ent2 = Enterprise.create!(:name => 'teste 2', :identifier => 'teste2', :category_ids => [@category.id])  
153 -  
154 - p1 = @finder.find('enterprises', 'teste', :per_page => 1, :page => 1)  
155 - p2 = @finder.find('enterprises', 'teste', :per_page => 1, :page => 2)  
156 -  
157 - assert_respond_to p1, :total_entries  
158 - assert_respond_to p2, :total_entries  
159 - assert (p1 == [ent1] && p2 == [ent2]) || (p1 == [ent2] && p2 == [ent1]) # consistent paging  
160 - end  
161 -  
162 - should 'not list more people than limit' do  
163 - p1 = create_user('test1').person; p1.add_category(@category)  
164 - p2 = create_user('test2').person; p2.add_category(@category)  
165 - result = @finder.recent('people', 1)  
166 -  
167 - assert_equal 1, result.size  
168 - end  
169 -  
170 - should 'list recent articles' do  
171 - person = create_user('teste').person  
172 - art1 = person.articles.create!(:name => 'an article to be found', :category_ids => [@category.id])  
173 - art2 = person.articles.create!(:name => 'another article to be found', :category_ids => [@category.id])  
174 -  
175 - result = @finder.recent('articles', 1)  
176 -  
177 - assert_equal [art2], result  
178 - end  
179 -  
180 - should 'not return the same result twice' do  
181 - parent = fast_create(Category, :name => 'parent category', :environment_id => Environment.default.id)  
182 - child = fast_create(Category, :name => 'child category', :environment_id => Environment.default.id, :parent_id => parent.id)  
183 - p1 = create_user('people_1').person  
184 - p1.name = 'a beautiful person'  
185 - p1.category_ids = [child.id, parent.id]; p1.save!  
186 -  
187 - f = CategoryFinder.new(parent)  
188 - result = f.find(:people, 'beautiful')  
189 -  
190 - assert_equal [p1], result  
191 - assert_equal 1, result.size  
192 - end  
193 -  
194 - should 'return most commented articles' do  
195 - Article.delete_all  
196 -  
197 - person = create_user('testuser').person  
198 - articles = (1..4).map {|n| a = person.articles.build(:name => "art #{n}", :category_ids => [@category.id]); a.save!; a }  
199 -  
200 - 2.times { articles[0].comments.build(:title => 'test', :body => 'asdsad', :author => person).save! }  
201 - 4.times { articles[1].comments.build(:title => 'test', :body => 'asdsad', :author => person).save! }  
202 -  
203 - result = @finder.most_commented_articles(2)  
204 - # should respect the order (more commented comes first)  
205 - assert_equal [articles[1], articles[0]], result  
206 - assert_respond_to result, :total_entries  
207 - end  
208 -  
209 - should 'find person and enterprise by radius and region' do  
210 - finder = CategoryFinder.new(@category)  
211 -  
212 - region = fast_create(Region, :name => 'r-test', :environment_id => Environment.default.id, :lat => 45.0, :lng => 45.0)  
213 - ent1 = Enterprise.create!(:name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0, :category_ids => [@category.id])  
214 - p1 = create_user('test2').person  
215 - p1.name = 'test 2'; p1.lat = 45.0; p1.lng = 45.0; p1.add_category(@category); p1.save!  
216 - ent2 = Enterprise.create!(:name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0, :category_ids => [@category.id])  
217 - p2 = create_user('test4').person  
218 - p2.name = 'test 4'; p2.lat = 30.0; p2.lng = 30.0; p2.add_category(@category); p2.save!  
219 -  
220 - ents = finder.find(:enterprises, 'test', :within => 10, :region => region.id)  
221 - people = finder.find(:people, 'test', :within => 10, :region => region.id)  
222 -  
223 - assert_includes ents, ent1  
224 - assert_not_includes ents, ent2  
225 - assert_includes people, p1  
226 - assert_not_includes people, p2  
227 - end  
228 -  
229 - should 'find current events' do  
230 - finder = CategoryFinder.new(@category)  
231 - person = create_user('testuser').person  
232 -  
233 - e1 = Event.create!(:name => 'e1', :profile => person, :start_date => Date.new(2008,1,1), :category_ids => [@category.id])  
234 -  
235 - # not in category  
236 - e2 = fast_create(Event, :name => 'e2', :profile_id => person.id, :start_date => Date.new(2008,1,15))  
237 -  
238 - events = finder.current_events(2008, 1)  
239 - assert_includes events, e1  
240 - assert_not_includes events, e2  
241 - end  
242 -  
243 - should 'list upcoming events' do  
244 - person = create_user('testuser').person  
245 -  
246 - Date.expects(:today).returns(Date.new(2008, 1, 15)).at_least_once  
247 -  
248 - past_event = Event.create!(:name => 'past event', :profile => person, :start_date => Date.new(2008,1,1), :category_ids => [@category.id])  
249 -  
250 - # event 2 is created after, but must be listed before (since it happens before)  
251 - upcoming_event_2 = Event.create!(:name => 'upcoming event 2', :profile => person, :start_date => Date.new(2008,1,25), :category_ids => [@category.id])  
252 - upcoming_event_1 = Event.create!(:name => 'upcoming event 1', :profile => person, :start_date => Date.new(2008,1,20), :category_ids => [@category.id])  
253 - not_in_category = fast_create(Event, :name => 'e1', :profile_id => person.id, :start_date => Date.new(2008,1,20))  
254 -  
255 - assert_equal [upcoming_event_1, upcoming_event_2], @finder.upcoming_events  
256 - end  
257 -  
258 - should 'find person and enterprise in category by radius and region even without query' do  
259 - cat = fast_create(Category, :name => 'test category', :environment_id => Environment.default.id)  
260 - finder = CategoryFinder.new(cat)  
261 -  
262 - region = fast_create(Region, :name => 'r-test', :environment_id => Environment.default.id, :lat => 45.0, :lng => 45.0)  
263 - ent1 = Enterprise.create!(:name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0, :category_ids => [cat.id])  
264 - p1 = create_user('test2').person  
265 - p1.name = 'test 2'; p1.lat = 45.0; p1.lng = 45.0; p1.add_category(cat); p1.save!  
266 - ent2 = Enterprise.create!(:name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0, :category_ids => [cat.id])  
267 - p2 = create_user('test4').person  
268 - p2.name = 'test 4'; p2.lat = 30.0; p2.lng = 30.0; p2.add_category(cat); p2.save!  
269 -  
270 - ents = finder.find(:enterprises, nil, :within => 10, :region => region.id)  
271 - people = finder.find(:people, nil, :within => 10, :region => region.id)  
272 -  
273 - assert_includes ents, ent1  
274 - assert_not_includes ents, ent2  
275 - assert_includes people, p1  
276 - assert_not_includes people, p2  
277 - end  
278 -  
279 - should 'find products in category wihin product category' do  
280 - cat = fast_create(Category, :name => 'test category', :environment_id => Environment.default.id)  
281 - finder = CategoryFinder.new(cat)  
282 -  
283 - prod_cat = fast_create(ProductCategory, :name => 'test product category', :environment_id => Environment.default.id)  
284 - ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :category_ids => [cat.id])  
285 - prod1 = ent.products.create!(:name => 'test product 1', :product_category => prod_cat)  
286 - prod2 = ent.products.create!(:name => 'test product 2', :product_category => @product_category)  
287 -  
288 - prods = finder.find(:products, nil, :product_category => prod_cat)  
289 -  
290 - assert_includes prods, prod1  
291 - assert_not_includes prods, prod2  
292 - end  
293 -  
294 - should 'find enterprises by its products categories without query' do  
295 - pc1 = fast_create(ProductCategory, :name => 'test_cat1', :environment_id => Environment.default.id)  
296 - pc2 = fast_create(ProductCategory, :name => 'test_cat2', :environment_id => Environment.default.id)  
297 -  
298 - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1', :category_ids => [@category.id])  
299 - ent1.products.create!(:name => 'test product 1', :product_category => pc1)  
300 - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'test_ent2', :category_ids => [@category.id])  
301 - ent2.products.create!(:name => 'test product 2', :product_category => pc2)  
302 -  
303 - ents = @finder.find(:enterprises, nil, :product_category => pc1)  
304 -  
305 - assert_includes ents, ent1  
306 - assert_not_includes ents, ent2  
307 - end  
308 -  
309 - should 'find enterprises by its products categories with query' do  
310 - pc1 = fast_create(ProductCategory, :name => 'test_cat1', :environment_id => Environment.default.id)  
311 - pc2 = fast_create(ProductCategory, :name => 'test_cat2', :environment_id => Environment.default.id)  
312 -  
313 - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1', :category_ids => [@category.id])  
314 - ent1.products.create!(:name => 'test product 1', :product_category => pc1)  
315 - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'test_ent2', :category_ids => [@category.id])  
316 - ent2.products.create!(:name => 'test product 2', :product_category => pc2)  
317 -  
318 - ents = @finder.find(:enterprises, 'test', :product_category => pc1)  
319 -  
320 - assert_includes ents, ent1  
321 - assert_not_includes ents, ent2  
322 - end  
323 -  
324 - should 'count product categories results by products' do  
325 - pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id)  
326 - pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default.id, :parent_id => pc1.id)  
327 - pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id)  
328 - pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id)  
329 -  
330 - ent = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1', :category_ids => [@category.id])  
331 - p1 = ent.products.create!(:name => 'test product 1', :product_category => pc1)  
332 - p2 = ent.products.create!(:name => 'test product 2', :product_category => pc11)  
333 - p3 = ent.products.create!(:name => 'test product 3', :product_category => pc2)  
334 - p4 = ent.products.create!(:name => 'test product 4', :product_category => pc2) # not in the count  
335 - p5 = ent.products.create!(:name => 'test product 5', :product_category => pc3) # not in the count  
336 -  
337 - ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2')  
338 - p6 = ent2.products.create!(:name => 'test product 6', :product_category => pc1)  
339 -  
340 - counts = @finder.product_categories_count(:products, [pc1.id, pc11.id, pc2.id], [p1.id, p2.id, p3.id, p5.id, p6.id] )  
341 -  
342 - assert_equal 2, counts[pc1.id]  
343 - assert_equal 1, counts[pc11.id]  
344 - assert_equal 1, counts[pc2.id]  
345 - assert_nil counts[pc3.id]  
346 - end  
347 -  
348 - should 'count product categories results by all products' do  
349 - pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id)  
350 - pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default.id, :parent_id => pc1.id)  
351 - pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id)  
352 - pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id)  
353 -  
354 - ent = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1', :category_ids => [@category.id])  
355 - p1 = ent.products.create!(:name => 'test product 1', :product_category => pc1)  
356 - p2 = ent.products.create!(:name => 'test product 2', :product_category => pc11)  
357 - p3 = ent.products.create!(:name => 'test product 3', :product_category => pc2)  
358 - p4 = ent.products.create!(:name => 'test product 4', :product_category => pc3) # not in the count  
359 -  
360 - ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2')  
361 - p6 = ent2.products.create!(:name => 'test product 6', :product_category => pc1)  
362 -  
363 -  
364 - counts = @finder.product_categories_count(:products, [pc1.id, pc11.id, pc2.id] )  
365 -  
366 - assert_equal 2, counts[pc1.id]  
367 - assert_equal 1, counts[pc11.id]  
368 - assert_equal 1, counts[pc2.id]  
369 - assert_nil counts[pc3.id]  
370 - end  
371 -  
372 - should 'count product categories results by enterprises' do  
373 - pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id)  
374 - pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default.id, :parent_id => pc1.id)  
375 - pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id)  
376 - pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id)  
377 -  
378 - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1', :category_ids => [@category.id])  
379 - ent1.products.create!(:name => 'test product 1', :product_category => pc1)  
380 - ent1.products.create!(:name => 'test product 2', :product_category => pc1)  
381 - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'test_ent2', :category_ids => [@category.id])  
382 - ent2.products.create!(:name => 'test product 2', :product_category => pc11)  
383 - ent3 = Enterprise.create!(:name => 'test enterprise 3', :identifier => 'test_ent3', :category_ids => [@category.id])  
384 - ent3.products.create!(:name => 'test product 3', :product_category => pc2)  
385 - ent4 = Enterprise.create!(:name => 'test enterprise 4', :identifier => 'test_ent4', :category_ids => [@category.id])  
386 - ent4.products.create!(:name => 'test product 4', :product_category => pc2)  
387 - ent5 = Enterprise.create!(:name => 'test enterprise 5', :identifier => 'test_ent5', :category_ids => [@category.id])  
388 - ent5.products.create!(:name => 'test product 5', :product_category => pc2)  
389 - ent5.products.create!(:name => 'test product 6', :product_category => pc3)  
390 -  
391 - ent6 = fast_create(Enterprise, :name => 'test enterprise 6', :identifier => 'test_ent6')  
392 - p6 = ent2.products.create!(:name => 'test product 6', :product_category => pc1)  
393 -  
394 - counts = @finder.product_categories_count(:enterprises, [pc1.id, pc11.id, pc2.id], [ent1.id, ent2.id, ent3.id, ent4.id] )  
395 -  
396 - assert_equal 2, counts[pc1.id]  
397 - assert_equal 1, counts[pc11.id]  
398 - assert_equal 2, counts[pc2.id]  
399 - assert_nil counts[pc3.id]  
400 - end  
401 -  
402 - should 'count product categories results by all enterprises' do  
403 - pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id)  
404 - pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default, :parent_id => pc1.id)  
405 - pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id)  
406 - pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id)  
407 -  
408 - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1', :category_ids => [@category.id])  
409 - ent1.products.create!(:name => 'test product 1', :product_category => pc1)  
410 - ent1.products.create!(:name => 'test product 2', :product_category => pc1)  
411 - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'test_ent2', :category_ids => [@category.id])  
412 - ent2.products.create!(:name => 'test product 2', :product_category => pc11)  
413 - ent3 = Enterprise.create!(:name => 'test enterprise 3', :identifier => 'test_ent3', :category_ids => [@category.id])  
414 - ent3.products.create!(:name => 'test product 3', :product_category => pc2)  
415 - ent4 = Enterprise.create!(:name => 'test enterprise 4', :identifier => 'test_ent4', :category_ids => [@category.id])  
416 - ent4.products.create!(:name => 'test product 4', :product_category => pc2)  
417 - ent4.products.create!(:name => 'test product 5', :product_category => pc3)  
418 -  
419 - ent5 = fast_create(Enterprise, :name => 'test enterprise 5', :identifier => 'test_ent5')  
420 - p6 = ent2.products.create!(:name => 'test product 6', :product_category => pc1)  
421 -  
422 - counts = @finder.product_categories_count(:enterprises, [pc1.id, pc11.id, pc2.id] )  
423 -  
424 - assert_equal 2, counts[pc1.id]  
425 - assert_equal 1, counts[pc11.id]  
426 - assert_equal 2, counts[pc2.id]  
427 - assert_nil counts[pc3.id]  
428 - end  
429 -  
430 - should 'find enterprises in alphabetical order of name' do  
431 - ent1 = Enterprise.create!(:name => 'test enterprise B', :identifier => 'test_ent_b', :category_ids => [@category.id])  
432 - ent2 = Enterprise.create!(:name => 'test enterprise A', :identifier => 'test_ent_a', :category_ids => [@category.id])  
433 - ent3 = Enterprise.create!(:name => 'test enterprise C', :identifier => 'test_ent_c', :category_ids => [@category.id])  
434 -  
435 - ents = @finder.find(:enterprises, nil)  
436 -  
437 - assert ents.index(ent2) < ents.index(ent1), "expected #{ents.index(ent2)} be smaller than #{ents.index(ent1)}"  
438 - assert ents.index(ent1) < ents.index(ent3), "expected #{ents.index(ent1)} be smaller than #{ents.index(ent3)}"  
439 - end  
440 -  
441 - should 'search for text articles in a specific category' do  
442 - person = create_user('teste').person  
443 -  
444 - # in category  
445 - art1 = fast_create(TextileArticle, :name => 'an article to be found', :profile_id => person.id)  
446 - art1.add_category(@category)  
447 - art1.save!  
448 -  
449 - # not in category  
450 - art2 = fast_create(TextileArticle, :name => 'another article to be found', :profile_id => person.id)  
451 -  
452 - list = @finder.find(:text_articles, 'found')  
453 - assert_includes list, art1  
454 - assert_not_includes list, art2  
455 - end  
456 -  
457 - should 'find events in a date range' do  
458 - person = create_user('testuser').person  
459 -  
460 - date_range = Date.new(2009, 11, 28)..Date.new(2009, 12, 3)  
461 -  
462 - event_in_range = Event.create!(:name => 'Event in range', :profile => person, :start_date => Date.new(2009, 11, 27), :end_date => date_range.last, :category_ids => [@category.id])  
463 - event_out_of_range = Event.create!(:name => 'Event out of range', :profile => person, :start_date => Date.new(2009, 12, 4), :category_ids => [@category.id])  
464 -  
465 - events_found = @finder.find(:events, '', :date_range => date_range)  
466 -  
467 - assert_includes events_found, event_in_range  
468 - assert_not_includes events_found, event_out_of_range  
469 - end  
470 -  
471 - should 'not paginate events' do  
472 - person = create_user('testuser').person  
473 -  
474 - create(:event, :profile_id => person.id, :category_ids => [@category.id])  
475 - create(:event, :profile_id => person.id, :category_ids => [@category.id])  
476 -  
477 - assert_equal 2, @finder.find(:events, '', :per_page => 1).size  
478 - end  
479 -  
480 - should 'not paginate events within a range' do  
481 - person = create_user('testuser').person  
482 -  
483 - create(:event, :profile_id => person.id, :category_ids => [@category.id])  
484 - create(:event, :profile_id => person.id, :category_ids => [@category.id])  
485 -  
486 - date_range = Date.today..Date.today  
487 - assert_equal 2, @finder.find(:events, '', :date_range => date_range, :per_page => 1).size  
488 - end  
489 -  
490 - should 'not paginate current events' do  
491 - person = create_user('testuser').person  
492 -  
493 - create(:event, :profile_id => person.id, :category_ids => [@category.id])  
494 - create(:event, :profile_id => person.id, :category_ids => [@category.id])  
495 -  
496 - assert_equal 2, @finder.current_events(Date.today.year, Date.today.month, :per_page => 1).size  
497 - end  
498 -  
499 - should 'not paginate upcoming events' do  
500 - person = create_user('testuser').person  
501 -  
502 - create(:event, :profile_id => person.id, :category_ids => [@category.id])  
503 - create(:event, :profile_id => person.id, :category_ids => [@category.id])  
504 -  
505 - assert_equal 2, @finder.upcoming_events(:per_page => 1).size  
506 - end  
507 -  
508 - should 'not paginate searching for specific event' do  
509 - person = create_user('teste').person  
510 -  
511 - today = Date.today  
512 -  
513 - event_to_found1 = Event.create!(:name => 'ToFound 1', :profile => person, :category_ids => [@category.id], :start_date => today)  
514 - event_to_found2 = Event.create!(:name => 'ToFound 2', :profile => person, :category_ids => [@category.id], :start_date => today)  
515 - event_to_not_found1 = Event.create!(:name => 'ToNotFound 1', :profile => person, :category_ids => [@category.id], :start_date => today)  
516 - event_to_not_found2 = Event.create!(:name => 'ToNotFound 2', :profile => person, :category_ids => [@category.id], :start_date => today)  
517 -  
518 - result = @finder.find(:events, 'ToFound', :per_page => 1)  
519 -  
520 - assert_includes result, event_to_found1  
521 - assert_includes result, event_to_found2  
522 - assert_not_includes result, event_to_not_found1  
523 - assert_not_includes result, event_to_not_found2  
524 - end  
525 -  
526 -end  
test/unit/communities_block_test.rb
@@ -43,7 +43,7 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase @@ -43,7 +43,7 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase
43 block = CommunitiesBlock.new 43 block = CommunitiesBlock.new
44 block.expects(:owner).returns(env) 44 block.expects(:owner).returns(env)
45 45
46 - expects(:link_to).with('View all', :controller => "browse", :action => 'communities') 46 + expects(:link_to).with('View all', :controller => "search", :action => 'communities')
47 47
48 instance_eval(&block.footer) 48 instance_eval(&block.footer)
49 end 49 end
test/unit/enterprise_homepage_helper_test.rb 0 → 100644
@@ -0,0 +1,64 @@ @@ -0,0 +1,64 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class EnterpriseHomepageHelperTest < ActiveSupport::TestCase
  4 +
  5 + include EnterpriseHomepageHelper
  6 +
  7 + def setup
  8 + @profile = mock
  9 + profile.stubs(:profile_image).returns('profileimage.png')
  10 + self.stubs(:url_for).returns('link to profile')
  11 + profile.stubs(:name).returns('Name of Profile')
  12 + profile.stubs(:url).returns('')
  13 + profile.stubs(:products).returns([Product.new(:name => 'product test')])
  14 + profile.stubs(:identifier).returns('name-of-profile')
  15 + profile.stubs(:region).returns(Region.new(:name => 'Brazil'))
  16 + profile.stubs(:address).returns('Address of Profile')
  17 + profile.stubs(:contact_email).returns('Email of Profile')
  18 + profile.stubs(:contact_phone).returns('Phone of Profile')
  19 + profile.stubs(:contact_person).returns('Profile Owner')
  20 + profile.stubs(:location).returns('Profile Location');
  21 + profile.stubs(:economic_activity).returns('Profile Economic Activity');
  22 + end
  23 + attr_reader :profile
  24 +
  25 + should 'display profile info' do
  26 + result = display_profile_info(profile)
  27 + assert_match /Profile Owner/, result
  28 + assert_match /Email of Profile/, result
  29 + assert_match /Phone of Profile/, result
  30 + assert_match /Profile Location/, result
  31 + assert_match /Address of Profile/, result
  32 + assert_match /Profile Economic Activity/, result
  33 + end
  34 +
  35 + should 'not display attribute if nil' do
  36 + profile.stubs(:contact_person).returns(nil);
  37 + result = display_profile_info(profile)
  38 + assert_no_match /Profile Owner/, result
  39 + end
  40 +
  41 + should 'not display attribute if blank' do
  42 + profile.stubs(:contact_person).returns('');
  43 + result = display_profile_info(profile)
  44 + assert_no_match /Profile Owner/, result
  45 + end
  46 +
  47 + should 'display distance' do
  48 + profile.stubs(:distance).returns(100.345);
  49 + result = display_profile_info(profile)
  50 + assert_match /Distance:/, result
  51 + assert_match /100.34/, result
  52 + end
  53 +
  54 + should 'not display distance if nil' do
  55 + profile.stubs(:distance).returns(nil);
  56 + result = display_profile_info(profile)
  57 + assert_no_match /Distance:/, result
  58 + assert_no_match /100.34/, result
  59 + end
  60 +
  61 + protected
  62 + include NoosferoTestHelper
  63 +
  64 +end
test/unit/environment_finder_test.rb
@@ -1,361 +0,0 @@ @@ -1,361 +0,0 @@
1 -require File.dirname(__FILE__) + '/../test_helper'  
2 -  
3 -class EnvironmentFinderTest < ActiveSupport::TestCase  
4 -  
5 - def setup  
6 - ActiveSupport::TestCase::setup  
7 - @product_category = fast_create(ProductCategory, :name => 'Products')  
8 - end  
9 -  
10 - should 'find articles' do  
11 - person = create_user('teste').person  
12 - art = person.articles.build(:name => 'an article to be found'); art.save!  
13 - finder = EnvironmentFinder.new(Environment.default)  
14 - assert_includes finder.find(:articles, 'found'), art  
15 - end  
16 -  
17 - should 'find people' do  
18 - p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.save!  
19 - finder = EnvironmentFinder.new(Environment.default)  
20 - assert_includes finder.find(:people, 'beautiful'), p1  
21 - end  
22 -  
23 - should 'find communities' do  
24 - c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default)  
25 - finder = EnvironmentFinder.new(Environment.default)  
26 - assert_includes finder.find(:communities, 'beautiful'), c1  
27 - end  
28 -  
29 - should 'find products' do  
30 - finder = EnvironmentFinder.new(Environment.default)  
31 - ent = fast_create(Enterprise, :name => 'teste', :identifier => 'teste')  
32 - prod = ent.products.create!(:name => 'a beautiful product', :product_category => @product_category)  
33 - assert_includes finder.find(:products, 'beautiful'), prod  
34 - end  
35 -  
36 - should 'find enterprises' do  
37 - finder = EnvironmentFinder.new(Environment.default)  
38 - ent = Enterprise.create!(:name => 'a beautiful enterprise', :identifier => 'teste')  
39 - assert_includes finder.find(:enterprises, 'beautiful'), ent  
40 - end  
41 -  
42 - should 'list recent enterprises' do  
43 - finder = EnvironmentFinder.new(Environment.default)  
44 - ent = fast_create(Enterprise, :name => 'teste', :identifier => 'teste')  
45 - assert_includes finder.recent('enterprises'), ent  
46 - end  
47 -  
48 - should 'not list more enterprises than limit' do  
49 - finder = EnvironmentFinder.new(Environment.default)  
50 - ent1 = fast_create(Enterprise, :name => 'teste1', :identifier => 'teste1')  
51 - ent2 = fast_create(Enterprise, :name => 'teste2', :identifier => 'teste2')  
52 - recent = finder.recent('enterprises', 1)  
53 -  
54 - assert_equal 1, recent.size  
55 - end  
56 -  
57 - should 'paginate the list of more enterprises than limit' do  
58 - finder = EnvironmentFinder.new(Environment.default)  
59 - ent1 = fast_create(Enterprise, :name => 'teste1', :identifier => 'teste1')  
60 - ent2 = fast_create(Enterprise, :name => 'teste2', :identifier => 'teste2')  
61 -  
62 - assert_equal 1, finder.find('enterprises', nil, :per_page => 1, :page => 1).size  
63 - end  
64 -  
65 - should 'paginate the list of more enterprises than limit with query' do  
66 - finder = EnvironmentFinder.new(Environment.default)  
67 -  
68 - ent1 = Enterprise.create!(:name => 'teste 1', :identifier => 'teste1')  
69 - ent2 = Enterprise.create!(:name => 'teste 2', :identifier => 'teste2')  
70 -  
71 - p1 = finder.find('enterprises', 'teste', :per_page => 1, :page => 1)  
72 - p2 = finder.find('enterprises', 'teste', :per_page => 1, :page => 2)  
73 -  
74 - assert (p1 == [ent1] && p2 == [ent2]) || (p1 == [ent2] && p2 == [ent1])  
75 - end  
76 -  
77 - should 'find person and enterprise by radius and region' do  
78 - finder = EnvironmentFinder.new(Environment.default)  
79 -  
80 - region = fast_create(Region, :name => 'r-test', :environment_id => Environment.default.id, :lat => 45.0, :lng => 45.0)  
81 - ent1 = fast_create(Enterprise, {:name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0}, :search => true)  
82 - p1 = create_user('test2').person  
83 - p1.name = 'test 2'; p1.lat = 45.0; p1.lng = 45.0; p1.save!  
84 - ent2 = fast_create(Enterprise, {:name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0}, :search => true)  
85 - p2 = create_user('test4').person  
86 - p2.name = 'test 4'; p2.lat = 30.0; p2.lng = 30.0; p2.save!  
87 -  
88 - ents = finder.find(:enterprises, 'test', :within => 10, :region => region.id)  
89 - people = finder.find(:people, 'test', :within => 10, :region => region.id)  
90 -  
91 - assert_includes ents, ent1  
92 - assert_not_includes ents, ent2  
93 - assert_includes people, p1  
94 - assert_not_includes people, p2  
95 - end  
96 -  
97 - should 'find person and enterprise by radius and region even without query' do  
98 - finder = EnvironmentFinder.new(Environment.default)  
99 -  
100 - region = fast_create(Region, :name => 'r-test', :environment_id => Environment.default.id, :lat => 45.0, :lng => 45.0)  
101 - ent1 = fast_create(Enterprise, :name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0)  
102 - p1 = create_user('test2').person  
103 - p1.name = 'test 2'; p1.lat = 45.0; p1.lng = 45.0; p1.save!  
104 - ent2 = fast_create(Enterprise, :name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0)  
105 - p2 = create_user('test4').person  
106 - p2.name = 'test 4'; p2.lat = 30.0; p2.lng = 30.0; p2.save!  
107 -  
108 - ents = finder.find(:enterprises, nil, :within => 10, :region => region.id)  
109 - people = finder.find(:people, nil, :within => 10, :region => region.id)  
110 -  
111 - assert_includes ents, ent1  
112 - assert_not_includes ents, ent2  
113 - assert_includes people, p1  
114 - assert_not_includes people, p2  
115 - end  
116 -  
117 - should 'find products wihin product category' do  
118 - finder = EnvironmentFinder.new(Environment.default)  
119 - cat = fast_create(ProductCategory, :name => 'test category', :environment_id => Environment.default.id)  
120 - ent = fast_create(Enterprise, :name => 'test enterprise', :identifier => 'test_ent')  
121 - prod1 = ent.products.create!(:name => 'test product 1', :product_category => cat)  
122 - prod2 = ent.products.create!(:name => 'test product 2', :product_category => @product_category)  
123 -  
124 - prods = finder.find(:products, nil, :product_category => cat)  
125 -  
126 - assert_includes prods, prod1  
127 - assert_not_includes prods, prod2  
128 - end  
129 -  
130 - should 'find products wihin product category with query' do  
131 - finder = EnvironmentFinder.new(Environment.default)  
132 - cat = fast_create(ProductCategory, :name => 'test category', :environment_id => Environment.default.id)  
133 - ent = fast_create(Enterprise, :name => 'test enterprise', :identifier => 'test_ent')  
134 - prod1 = ent.products.create!(:name => 'test product a_word 1', :product_category => cat)  
135 - prod2 = ent.products.create!(:name => 'test product b_word 1', :product_category => cat)  
136 - prod3 = ent.products.create!(:name => 'test product a_word 2', :product_category => @product_category)  
137 - prod4 = ent.products.create!(:name => 'test product b_word 2', :product_category => @product_category)  
138 -  
139 - prods = finder.find(:products, 'a_word', :product_category => cat)  
140 -  
141 - assert_includes prods, prod1  
142 - assert_not_includes prods, prod2  
143 - assert_not_includes prods, prod3  
144 - assert_not_includes prods, prod4  
145 - end  
146 -  
147 - should 'find enterprises in alphabetical order of name' do  
148 - finder = EnvironmentFinder.new(Environment.default)  
149 -  
150 - ent1 = fast_create(Enterprise, :name => 'test enterprise B', :identifier => 'test_ent_b')  
151 - ent2 = fast_create(Enterprise, :name => 'test enterprise A', :identifier => 'test_ent_a')  
152 - ent3 = fast_create(Enterprise, :name => 'test enterprise C', :identifier => 'test_ent_c')  
153 -  
154 - ents = finder.find(:enterprises, nil)  
155 -  
156 - assert ents.index(ent2) < ents.index(ent1), "expected #{ents.index(ent2)} be smaller than #{ents.index(ent1)}"  
157 - assert ents.index(ent1) < ents.index(ent3), "expected #{ents.index(ent1)} be smaller than #{ents.index(ent3)}"  
158 - end  
159 -  
160 - should 'find enterprises by its products categories' do  
161 - finder = EnvironmentFinder.new(Environment.default)  
162 -  
163 - pc1 = fast_create(ProductCategory, :name => 'test_cat1', :environment_id => Environment.default.id)  
164 - pc2 = fast_create(ProductCategory, :name => 'test_cat2', :environment_id => Environment.default.id)  
165 -  
166 - ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1')  
167 - ent1.products.create!(:name => 'test product 1', :product_category => pc1)  
168 - ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2')  
169 - ent2.products.create!(:name => 'test product 2', :product_category => pc2)  
170 -  
171 - ents = finder.find(:enterprises, nil, :product_category => pc1)  
172 -  
173 - assert_includes ents, ent1  
174 - assert_not_includes ents, ent2  
175 - end  
176 -  
177 - should 'find enterprises by its products categories with query' do  
178 - finder = EnvironmentFinder.new(Environment.default)  
179 -  
180 - pc1 = fast_create(ProductCategory, :name => 'test_cat1', :environment_id => Environment.default.id)  
181 - pc2 = fast_create(ProductCategory, :name => 'test_cat2', :environment_id => Environment.default.id)  
182 -  
183 - ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1')  
184 - ent1.products.create!(:name => 'test product 1', :product_category => pc1)  
185 - ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2')  
186 - ent2.products.create!(:name => 'test product 2', :product_category => pc2)  
187 -  
188 - ents = finder.find(:enterprises, 'test', :product_category => pc1)  
189 -  
190 - assert_includes ents, ent1  
191 - assert_not_includes ents, ent2  
192 - end  
193 -  
194 - should 'find enterprises by a product category with name with spaces' do  
195 - finder = EnvironmentFinder.new(Environment.default)  
196 -  
197 - pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id)  
198 - pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id)  
199 -  
200 - ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1')  
201 - ent1.products.create!(:name => 'test product 1', :product_category => pc1)  
202 - ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2')  
203 - ent2.products.create!(:name => 'test product 2', :product_category => pc2)  
204 -  
205 - ents = finder.find(:enterprises, 'test', :product_category => pc1)  
206 -  
207 - assert_includes ents, ent1  
208 - assert_not_includes ents, ent2  
209 - end  
210 -  
211 - should 'count product categories results by products' do  
212 - finder = EnvironmentFinder.new(Environment.default)  
213 -  
214 - pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id)  
215 - pc11= fast_create(ProductCategory, :name => 'test cat11',:environment_id => Environment.default.id, :parent_id => pc1.id)  
216 - pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id)  
217 - pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id)  
218 -  
219 -  
220 - ent = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1')  
221 - p1 = ent.products.create!(:name => 'test product 1', :product_category => pc1)  
222 - p2 = ent.products.create!(:name => 'test product 2', :product_category => pc11)  
223 - p3 = ent.products.create!(:name => 'test product 3', :product_category => pc2)  
224 - p4 = ent.products.create!(:name => 'test product 4', :product_category => pc2) # not in the count  
225 - p5 = ent.products.create!(:name => 'test product 5', :product_category => pc3) # not in the count  
226 -  
227 - counts = finder.product_categories_count(:products, [pc1.id, pc11.id, pc2.id], [p1.id, p2.id, p3.id] )  
228 -  
229 - assert_equal 2, counts[pc1.id]  
230 - assert_equal 1, counts[pc11.id]  
231 - assert_equal 1, counts[pc2.id]  
232 - assert_nil counts[pc3.id]  
233 - end  
234 -  
235 - should 'count product categories results by all products' do  
236 - finder = EnvironmentFinder.new(Environment.default)  
237 -  
238 - pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id)  
239 - pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default.id, :parent_id => pc1.id)  
240 - pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id)  
241 - pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id)  
242 -  
243 -  
244 - ent = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1')  
245 - p1 = ent.products.create!(:name => 'test product 1', :product_category => pc1)  
246 - p2 = ent.products.create!(:name => 'test product 2', :product_category => pc11)  
247 - p3 = ent.products.create!(:name => 'test product 3', :product_category => pc2)  
248 - p4 = ent.products.create!(:name => 'test product 4', :product_category => pc3) # not in the count  
249 -  
250 - counts = finder.product_categories_count(:products, [pc1.id, pc11.id, pc2.id] )  
251 -  
252 - assert_equal 2, counts[pc1.id]  
253 - assert_equal 1, counts[pc11.id]  
254 - assert_equal 1, counts[pc2.id]  
255 - assert_nil counts[pc3.id]  
256 - end  
257 -  
258 - should 'count product categories results by enterprises' do  
259 - finder = EnvironmentFinder.new(Environment.default)  
260 -  
261 - pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id)  
262 - pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default.id, :parent_id => pc1.id)  
263 - pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id)  
264 - pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id)  
265 -  
266 - ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1')  
267 - ent1.products.create!(:name => 'test product 1', :product_category => pc1)  
268 - ent1.products.create!(:name => 'test product 2', :product_category => pc1)  
269 - ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2')  
270 - ent2.products.create!(:name => 'test product 2', :product_category => pc11)  
271 - ent3 = fast_create(Enterprise, :name => 'test enterprise 3', :identifier => 'test_ent3')  
272 - ent3.products.create!(:name => 'test product 3', :product_category => pc2)  
273 - ent4 = fast_create(Enterprise, :name => 'test enterprise 4', :identifier => 'test_ent4')  
274 - ent4.products.create!(:name => 'test product 4', :product_category => pc2)  
275 - ent5 = fast_create(Enterprise, :name => 'test enterprise 5', :identifier => 'test_ent5') # not in the count  
276 - ent5.products.create!(:name => 'test product 5', :product_category => pc2)  
277 - ent5.products.create!(:name => 'test product 6', :product_category => pc3)  
278 -  
279 - counts = finder.product_categories_count(:enterprises, [pc1.id, pc11.id, pc2.id], [ent1.id, ent2.id, ent3.id, ent4.id] )  
280 -  
281 - assert_equal 2, counts[pc1.id]  
282 - assert_equal 1, counts[pc11.id]  
283 - assert_equal 2, counts[pc2.id]  
284 - assert_nil counts[pc3.id]  
285 - end  
286 -  
287 - should 'count product categories results by all enterprises' do  
288 - finder = EnvironmentFinder.new(Environment.default)  
289 -  
290 - pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id)  
291 - pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default.id, :parent_id => pc1.id)  
292 - pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id)  
293 - pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id)  
294 -  
295 - ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1')  
296 - ent1.products.create!(:name => 'test product 1', :product_category => pc1)  
297 - ent1.products.create!(:name => 'test product 2', :product_category => pc1)  
298 - ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2')  
299 - ent2.products.create!(:name => 'test product 2', :product_category => pc11)  
300 - ent3 = fast_create(Enterprise, :name => 'test enterprise 3', :identifier => 'test_ent3')  
301 - ent3.products.create!(:name => 'test product 3', :product_category => pc2)  
302 - ent4 = fast_create(Enterprise, :name => 'test enterprise 4', :identifier => 'test_ent4')  
303 - ent4.products.create!(:name => 'test product 4', :product_category => pc2)  
304 - ent4.products.create!(:name => 'test product 5', :product_category => pc3)  
305 -  
306 - counts = finder.product_categories_count(:enterprises, [pc1.id, pc11.id, pc2.id] )  
307 -  
308 - assert_equal 2, counts[pc1.id]  
309 - assert_equal 1, counts[pc11.id]  
310 - assert_equal 2, counts[pc2.id]  
311 - assert_nil counts[pc3.id]  
312 - end  
313 -  
314 - should 'should retrieve more than 10 entries' do  
315 - Enterprise.destroy_all  
316 - finder = EnvironmentFinder.new(Environment.default)  
317 -  
318 - ('1'..'20').each do |n|  
319 - Enterprise.create!(:name => 'test ' + n, :identifier => 'test_' + n)  
320 - end  
321 -  
322 - assert_equal 20, finder.find(:enterprises, 'test').total_entries  
323 - end  
324 -  
325 - should 'find events in a date range' do  
326 - finder = EnvironmentFinder.new(Environment.default)  
327 - person = create_user('testuser').person  
328 -  
329 - date_range = Date.new(2009, 11, 28)..Date.new(2009, 12, 3)  
330 -  
331 - event_in_range = fast_create(Event, :name => 'Event in range', :profile_id => person.id, :start_date => Date.new(2009, 11, 27), :end_date => date_range.last)  
332 - event_out_of_range = fast_create(Event, :name => 'Event out of range', :profile_id => person.id, :start_date => Date.new(2009, 12, 4))  
333 -  
334 - events_found = finder.find(:events, '', :date_range => date_range)  
335 -  
336 - assert_includes events_found, event_in_range  
337 - assert_not_includes events_found, event_out_of_range  
338 - end  
339 -  
340 - should 'not paginate events' do  
341 - finder = EnvironmentFinder.new(Environment.default)  
342 - person = create_user('testuser').person  
343 -  
344 - fast_create(:event, :profile_id => person.id)  
345 - fast_create(:event, :profile_id => person.id)  
346 -  
347 - assert_equal 2, finder.find(:events, '', :per_page => 1, :page => 1).size  
348 - end  
349 -  
350 - should 'not paginate events within date range' do  
351 - finder = EnvironmentFinder.new(Environment.default)  
352 - person = create_user('testuser').person  
353 -  
354 - fast_create(:event, :profile_id => person.id)  
355 - fast_create(:event, :profile_id => person.id)  
356 -  
357 - date_range = Date.today..Date.today  
358 - assert_equal 2, finder.find(:events, '', :date_range => date_range, :per_page => 1, :page => 1).size  
359 - end  
360 -  
361 -end  
test/unit/environment_test.rb
@@ -5,6 +5,7 @@ class EnvironmentTest &lt; ActiveSupport::TestCase @@ -5,6 +5,7 @@ class EnvironmentTest &lt; ActiveSupport::TestCase
5 5
6 def setup 6 def setup
7 ActiveSupport::TestCase::setup 7 ActiveSupport::TestCase::setup
  8 + Article.rebuild_index
8 end 9 end
9 10
10 def test_exists_default_and_it_is_unique 11 def test_exists_default_and_it_is_unique
test/unit/featured_products_block_test.rb
@@ -10,6 +10,7 @@ class FeaturedProductsBlockTest &lt; ActiveSupport::TestCase @@ -10,6 +10,7 @@ class FeaturedProductsBlockTest &lt; ActiveSupport::TestCase
10 attr_reader :profile 10 attr_reader :profile
11 11
12 should 'refer to products' do 12 should 'refer to products' do
  13 + profile = fast_create(Enterprise)
13 products = [] 14 products = []
14 category = fast_create(ProductCategory) 15 category = fast_create(ProductCategory)
15 3.times {|n| products.push(Product.create!(:name => "product #{n}", :enterprise_id => profile.id, :product_category_id => category.id)) } 16 3.times {|n| products.push(Product.create!(:name => "product #{n}", :enterprise_id => profile.id, :product_category_id => category.id)) }
test/unit/manage_products_helper_test.rb
@@ -191,6 +191,7 @@ class ManageProductsHelperTest &lt; ActiveSupport::TestCase @@ -191,6 +191,7 @@ class ManageProductsHelperTest &lt; ActiveSupport::TestCase
191 qualifier = fast_create(Qualifier) 191 qualifier = fast_create(Qualifier)
192 certifier = fast_create(Certifier) 192 certifier = fast_create(Certifier)
193 ProductQualifier.create!(:product => product, :qualifier => qualifier, :certifier => certifier) 193 ProductQualifier.create!(:product => product, :qualifier => qualifier, :certifier => certifier)
  194 +# The relationship between product, certifiers and qualifiers is extremely complicated
194 certifier.destroy 195 certifier.destroy
195 assert_nothing_raised do 196 assert_nothing_raised do
196 result = display_qualifiers(product) 197 result = display_qualifiers(product)
test/unit/people_block_test.rb
@@ -40,7 +40,7 @@ class PeopleBlockTest &lt; ActiveSupport::TestCase @@ -40,7 +40,7 @@ class PeopleBlockTest &lt; ActiveSupport::TestCase
40 block.stubs(:owner).returns(Environment.default) 40 block.stubs(:owner).returns(Environment.default)
41 41
42 expects(:_).with('View all').returns('View all people') 42 expects(:_).with('View all').returns('View all people')
43 - expects(:link_to).with('View all people', :controller => 'browse', :action => 'people') 43 + expects(:link_to).with('View all people', :controller => 'search', :action => 'people')
44 instance_eval(&block.footer) 44 instance_eval(&block.footer)
45 end 45 end
46 46
test/unit/product_category_test.rb
@@ -6,12 +6,13 @@ class ProductCategoryTest &lt; ActiveSupport::TestCase @@ -6,12 +6,13 @@ class ProductCategoryTest &lt; ActiveSupport::TestCase
6 c0 = ProductCategory.create!(:name => 'base_cat', :environment => Environment.default) 6 c0 = ProductCategory.create!(:name => 'base_cat', :environment => Environment.default)
7 assert_equivalent [], c0.all_products 7 assert_equivalent [], c0.all_products
8 8
9 - p0 = Product.create(:name => 'product1', :product_category => c0) 9 + profile = fast_create(Enterprise)
  10 + p0 = Product.create(:name => 'product1', :product_category => c0, :enterprise_id => profile.id)
10 c0.reload 11 c0.reload
11 assert_equivalent [p0], c0.all_products 12 assert_equivalent [p0], c0.all_products
12 13
13 c1 = ProductCategory.create!(:name => 'cat_1', :parent => c0, :environment => Environment.default) 14 c1 = ProductCategory.create!(:name => 'cat_1', :parent => c0, :environment => Environment.default)
14 - p1 = Product.create(:name => 'product2', :product_category => c1) 15 + p1 = Product.create(:name => 'product2', :product_category => c1, :enterprise_id => profile.id)
15 c0.reload; c1.reload 16 c0.reload; c1.reload
16 assert_equivalent [p0, p1], c0.all_products 17 assert_equivalent [p0, p1], c0.all_products
17 assert_equivalent [p1], c1.all_products 18 assert_equivalent [p1], c1.all_products
test/unit/product_test.rb
@@ -5,11 +5,12 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -5,11 +5,12 @@ class ProductTest &lt; ActiveSupport::TestCase
5 def setup 5 def setup
6 ActiveSupport::TestCase::setup 6 ActiveSupport::TestCase::setup
7 @product_category = fast_create(ProductCategory, :name => 'Products') 7 @product_category = fast_create(ProductCategory, :name => 'Products')
  8 + @profile = fast_create(Enterprise)
8 end 9 end
9 10
10 should 'create product' do 11 should 'create product' do
11 assert_difference Product, :count do 12 assert_difference Product, :count do
12 - p = Product.new(:name => 'test product1', :product_category => @product_category) 13 + p = Product.new(:name => 'test product1', :product_category => @product_category, :enterprise_id => @profile.id)
13 assert p.save 14 assert p.save
14 end 15 end
15 end 16 end
@@ -68,7 +69,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -68,7 +69,7 @@ class ProductTest &lt; ActiveSupport::TestCase
68 assert_difference Product, :count do 69 assert_difference Product, :count do
69 p = Product.create!(:name => 'test product1', :product_category => @product_category, :image_builder => { 70 p = Product.create!(:name => 'test product1', :product_category => @product_category, :image_builder => {
70 :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') 71 :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')
71 - }) 72 + }, :enterprise_id => @profile.id)
72 assert_equal p.image(true).filename, 'rails.png' 73 assert_equal p.image(true).filename, 'rails.png'
73 end 74 end
74 end 75 end
@@ -89,7 +90,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -89,7 +90,7 @@ class ProductTest &lt; ActiveSupport::TestCase
89 end 90 end
90 91
91 should 'be indexed by category full name' do 92 should 'be indexed by category full name' do
92 - p = Product.new(:name => 'a test product', :product_category => @product_category) 93 + p = Product.create(:name => 'a test product', :product_category => @product_category, :enterprise_id => @profile.id)
93 p.stubs(:category_full_name).returns('interesting category') 94 p.stubs(:category_full_name).returns('interesting category')
94 p.save! 95 p.save!
95 96
@@ -147,7 +148,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -147,7 +148,7 @@ class ProductTest &lt; ActiveSupport::TestCase
147 148
148 assert ProductCategorization.find(:first, :conditions => {:product_id => p, :category_id => cat}) 149 assert ProductCategorization.find(:first, :conditions => {:product_id => p, :category_id => cat})
149 end 150 end
150 - 151 +
151 should 'categorize parent cateogries with product categorization' do 152 should 'categorize parent cateogries with product categorization' do
152 parent_cat = fast_create(ProductCategory, :name => 'test cat', :environment_id => Environment.default.id) 153 parent_cat = fast_create(ProductCategory, :name => 'test cat', :environment_id => Environment.default.id)
153 child_cat = fast_create(ProductCategory, :name => 'test cat', :environment_id => Environment.default.id, :parent_id => parent_cat.id) 154 child_cat = fast_create(ProductCategory, :name => 'test cat', :environment_id => Environment.default.id, :parent_id => parent_cat.id)
@@ -362,7 +363,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -362,7 +363,7 @@ class ProductTest &lt; ActiveSupport::TestCase
362 363
363 should 'index by schema name when database is postgresql' do 364 should 'index by schema name when database is postgresql' do
364 uses_postgresql 'schema_one' 365 uses_postgresql 'schema_one'
365 - p1 = Product.create!(:name => 'some thing', :product_category => @product_category) 366 + p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id)
366 assert_equal Product.find_by_contents('thing')[:results], [p1] 367 assert_equal Product.find_by_contents('thing')[:results], [p1]
367 uses_postgresql 'schema_two' 368 uses_postgresql 'schema_two'
368 p2 = Product.create!(:name => 'another thing', :product_category => @product_category) 369 p2 = Product.create!(:name => 'another thing', :product_category => @product_category)
@@ -376,9 +377,9 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -376,9 +377,9 @@ class ProductTest &lt; ActiveSupport::TestCase
376 377
377 should 'not index by schema name when database is not postgresql' do 378 should 'not index by schema name when database is not postgresql' do
378 uses_sqlite 379 uses_sqlite
379 - p1 = Product.create!(:name => 'some thing', :product_category => @product_category) 380 + p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id)
380 assert_equal Product.find_by_contents('thing')[:results], [p1] 381 assert_equal Product.find_by_contents('thing')[:results], [p1]
381 - p2 = Product.create!(:name => 'another thing', :product_category => @product_category) 382 + p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :enterprise_id => @profile.id)
382 assert_includes Product.find_by_contents('thing')[:results], p1 383 assert_includes Product.find_by_contents('thing')[:results], p1
383 assert_includes Product.find_by_contents('thing')[:results], p2 384 assert_includes Product.find_by_contents('thing')[:results], p2
384 end 385 end
test/unit/profile_test.rb
@@ -192,7 +192,8 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -192,7 +192,8 @@ class ProfileTest &lt; ActiveSupport::TestCase
192 assert_not_equal list.object_id, other_list.object_id 192 assert_not_equal list.object_id, other_list.object_id
193 end 193 end
194 194
195 - should 'be able to find profiles by their names with ferret' do 195 +# This problem should be solved; talk to Bráulio if it fails
  196 + should 'be able to find profiles by their names' do
196 small = create(Profile, :name => 'A small profile for testing') 197 small = create(Profile, :name => 'A small profile for testing')
197 big = create(Profile, :name => 'A big profile for testing') 198 big = create(Profile, :name => 'A big profile for testing')
198 199
@@ -1669,7 +1670,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1669,7 +1670,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1669 should 'index by schema name when database is postgresql' do 1670 should 'index by schema name when database is postgresql' do
1670 uses_postgresql 'schema_one' 1671 uses_postgresql 'schema_one'
1671 p1 = Profile.create!(:name => 'some thing', :identifier => 'some-thing') 1672 p1 = Profile.create!(:name => 'some thing', :identifier => 'some-thing')
1672 - assert_equal Profile.find_by_contents('thing')[:results], [p1] 1673 + assert_equal [p1], Profile.find_by_contents('thing')[:results]
1673 uses_postgresql 'schema_two' 1674 uses_postgresql 'schema_two'
1674 p2 = Profile.create!(:name => 'another thing', :identifier => 'another-thing') 1675 p2 = Profile.create!(:name => 'another thing', :identifier => 'another-thing')
1675 assert_not_includes Profile.find_by_contents('thing')[:results], p1 1676 assert_not_includes Profile.find_by_contents('thing')[:results], p1
test/unit/search_helper_test.rb
@@ -1,69 +0,0 @@ @@ -1,69 +0,0 @@
1 -require File.dirname(__FILE__) + '/../test_helper'  
2 -  
3 -class SearchHelperTest < ActiveSupport::TestCase  
4 -  
5 - include SearchHelper  
6 -  
7 - def _(any)  
8 - any  
9 - end  
10 -  
11 - def setup  
12 - @profile = mock  
13 - self.stubs(:profile_image).returns('profileimage.png')  
14 - self.stubs(:url_for).returns('link to profile')  
15 - profile.stubs(:name).returns('Name of Profile')  
16 - profile.stubs(:url).returns('')  
17 - profile.stubs(:products).returns([Product.new(:name => 'product test')])  
18 - profile.stubs(:identifier).returns('name-of-profile')  
19 - profile.stubs(:region).returns(Region.new(:name => 'Brazil'))  
20 - end  
21 - attr_reader :profile  
22 -  
23 - should 'display profile info' do  
24 - profile.stubs(:address).returns('Address of Profile')  
25 - profile.stubs(:contact_email).returns('Email of Profile')  
26 - profile.stubs(:contact_phone).returns('Phone of Profile')  
27 -  
28 - result = self.display_profile_info(profile)  
29 - assert_match /profileimage.png/, result  
30 - assert_match /link to profile/, result  
31 - assert_match /Email of Profile/, result  
32 - assert_match /Phone of Profile/, result  
33 - assert_match /Address of Profile/, result  
34 - end  
35 -  
36 - should 'not display field if nil in profile info' do  
37 - profile.stubs(:address).returns('nil')  
38 - profile.stubs(:contact_email).returns('nil')  
39 - profile.stubs(:contact_phone).returns('nil')  
40 -  
41 - result = self.display_profile_info(profile)  
42 - assert_match /profileimage.png/, result  
43 - assert_match /link to profile/, result  
44 - assert_no_match /Email of Profile/, result  
45 - assert_no_match /Phone of Profile/, result  
46 - assert_no_match /Address of Profile/, result  
47 - end  
48 -  
49 - should 'link to products and services of an profile' do  
50 - enterprise = fast_create(Enterprise)  
51 - product1 = fast_create(Product, :enterprise_id => enterprise.id)  
52 - product2 = fast_create(Product, :enterprise_id => enterprise.id)  
53 - result = display_profile_info(enterprise)  
54 - assert_tag_in_string result, :tag => 'a', :attributes => {:href => /:id=>#{product1.id}/}, :content => product1.name  
55 - assert_tag_in_string result, :tag => 'a', :attributes => {:href => /:id=>#{product2.id}/}, :content => product2.name  
56 - end  
57 -  
58 - should 'link to manage_products controller on display_profile_info' do  
59 - enterprise = fast_create(Enterprise)  
60 - product = fast_create(Product, :enterprise_id => enterprise.id)  
61 - result = display_profile_info(enterprise)  
62 - assert_tag_in_string result, :tag => 'a', :attributes => {:href => /:controller=>\"manage_products\"/}, :content => product.name  
63 - assert_no_tag_in_string result, :tag => 'a', :attributes => {:href => /:id=>\"catalog\"/}, :content => product.name  
64 - end  
65 -  
66 - protected  
67 - include NoosferoTestHelper  
68 -  
69 -end