Commit 4e00577f5a104c6ff46eeba0a82dbd9064f5c162
1 parent
4111d3d5
Exists in
master
and in
28 other branches
Changes on SearchControllerTest to adapt to new searching method
Showing
2 changed files
with
24 additions
and
772 deletions
Show diff stats
app/controllers/public/search_controller.rb
| ... | ... | @@ -293,7 +293,7 @@ class SearchController < PublicController |
| 293 | 293 | solr_options.merge! asset_class.facets_find_options(params[:facet]) |
| 294 | 294 | solr_options[:all_facets] = true |
| 295 | 295 | solr_options[:limit] = 0 if @facets_only |
| 296 | - solr_options[:facets][:browse] << asset_class.facet_category_query.call(@category) if @category and asset_class.facet_category_query | |
| 296 | + #solr_options[:facets][:browse] << asset_class.facet_category_query.call(@category) if @category and asset_class.facet_category_query | |
| 297 | 297 | end |
| 298 | 298 | solr_options[:order] = params[:order_by] if params[:order_by] |
| 299 | 299 | solr_options[:filter_queries] ||= [] | ... | ... |
test/functional/search_controller_test.rb
| ... | ... | @@ -14,7 +14,13 @@ class SearchControllerTest < ActionController::TestCase |
| 14 | 14 | |
| 15 | 15 | @category = Category.create!(:name => 'my category', :environment => Environment.default) |
| 16 | 16 | |
| 17 | - domain = Environment.default.domains.first | |
| 17 | + env = Environment.default | |
| 18 | + domain = env.domains.first | |
| 19 | + if !domain | |
| 20 | + domain = Domain.create!(:name => "localhost") | |
| 21 | + env.domains = [domain] | |
| 22 | + env.save! | |
| 23 | + end | |
| 18 | 24 | domain.google_maps_key = 'ENVIRONMENT_KEY' |
| 19 | 25 | domain.save! |
| 20 | 26 | |
| ... | ... | @@ -68,20 +74,6 @@ class SearchControllerTest < ActionController::TestCase |
| 68 | 74 | assert_includes assigns(:results)[:articles], art |
| 69 | 75 | end |
| 70 | 76 | |
| 71 | - should 'search for articles in a specific category' do | |
| 72 | - person = fast_create(Person) | |
| 73 | - | |
| 74 | - # in category | |
| 75 | - art1 = create_article_with_optional_category('an article to be found', person, @category) | |
| 76 | - # not in category | |
| 77 | - art2 = create_article_with_optional_category('another article to be found', person) | |
| 78 | - | |
| 79 | - get :index, :category_path => [ 'my-category' ], :query => 'article found', :find_in => [ 'articles' ] | |
| 80 | - | |
| 81 | - assert_includes assigns(:results)[:articles], art1 | |
| 82 | - assert_not_includes assigns(:results)[:articles], art2 | |
| 83 | - end | |
| 84 | - | |
| 85 | 77 | # 'assets' outside any category |
| 86 | 78 | should 'list articles in general' do |
| 87 | 79 | person = fast_create(Person) |
| ... | ... | @@ -95,42 +87,12 @@ class SearchControllerTest < ActionController::TestCase |
| 95 | 87 | assert_includes assigns(:results)[:articles], art2 |
| 96 | 88 | end |
| 97 | 89 | |
| 98 | - # 'assets' inside a category | |
| 99 | - should 'list articles in a specific category' do | |
| 100 | - person = fast_create(Person) | |
| 101 | - | |
| 102 | - # in category | |
| 103 | - art1 = create_article_with_optional_category('one article', person, @category) | |
| 104 | - art2 = create_article_with_optional_category('two article', person, @category) | |
| 105 | - # not in category | |
| 106 | - art3 = create_article_with_optional_category('another article', person) | |
| 107 | - | |
| 108 | - get :articles, :category_path => ['my-category'] | |
| 109 | - | |
| 110 | - assert_includes assigns(:results)[:articles], art1 | |
| 111 | - assert_includes assigns(:results)[:articles], art2 | |
| 112 | - assert_not_includes assigns(:results)[:articles], art3 | |
| 113 | - end | |
| 114 | - | |
| 115 | 90 | should 'find enterprises' do |
| 116 | 91 | ent = create_profile_with_optional_category(Enterprise, 'teste') |
| 117 | 92 | get 'index', :query => 'teste', :find_in => [ 'enterprises' ] |
| 118 | 93 | assert_includes assigns(:results)[:enterprises], ent |
| 119 | 94 | end |
| 120 | 95 | |
| 121 | - should 'find enterprises in a specified category' do | |
| 122 | - | |
| 123 | - # in category | |
| 124 | - ent1 = create_profile_with_optional_category(Enterprise, 'testing enterprise 1', @category) | |
| 125 | - # not in category | |
| 126 | - ent2 = create_profile_with_optional_category(Enterprise, 'testing enterprise 2') | |
| 127 | - | |
| 128 | - get :index, :category_path => [ 'my-category' ], :query => 'testing', :find_in => [ 'enterprises' ] | |
| 129 | - | |
| 130 | - assert_includes assigns(:results)[:enterprises], ent1 | |
| 131 | - assert_not_includes assigns(:results)[:enterprises], ent2 | |
| 132 | - end | |
| 133 | - | |
| 134 | 96 | should 'list enterprises in general' do |
| 135 | 97 | ent1 = create_profile_with_optional_category(Enterprise, 'teste 1') |
| 136 | 98 | ent2 = create_profile_with_optional_category(Enterprise, 'teste 2') |
| ... | ... | @@ -140,32 +102,12 @@ class SearchControllerTest < ActionController::TestCase |
| 140 | 102 | assert_includes assigns(:results)[:enterprises], ent2 |
| 141 | 103 | end |
| 142 | 104 | |
| 143 | - # 'assets' menu inside a category | |
| 144 | - should 'list enterprises in a specified category' do | |
| 145 | - # in category | |
| 146 | - ent1 = create_profile_with_optional_category(Enterprise, 'teste 1', @category) | |
| 147 | - # not in category | |
| 148 | - ent2 = create_profile_with_optional_category(Enterprise, 'teste 2') | |
| 149 | - | |
| 150 | - get :enterprises, :category_path => [ 'my-category' ] | |
| 151 | - assert_includes assigns(:results)[:enterprises], ent1 | |
| 152 | - assert_not_includes assigns(:results)[:enterprises], ent2 | |
| 153 | - end | |
| 154 | - | |
| 155 | 105 | should 'find people' do |
| 156 | 106 | p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.save! |
| 157 | 107 | get :index, :query => 'beautiful', :find_in => [ 'people' ] |
| 158 | 108 | assert_includes assigns(:results)[:people], p1 |
| 159 | 109 | end |
| 160 | 110 | |
| 161 | - should 'find people in a specific category' do | |
| 162 | - p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.add_category @category; p1.save! | |
| 163 | - p2 = create_user('people_2').person; p2.name = 'another beautiful person'; p2.save! | |
| 164 | - get :index, :category_path => [ 'my-category' ], :query => 'beautiful', :find_in => [ 'people' ] | |
| 165 | - assert_includes assigns(:results)[:people], p1 | |
| 166 | - assert_not_includes assigns(:results)[:people], p2 | |
| 167 | - end | |
| 168 | - | |
| 169 | 111 | # 'assets' menu outside any category |
| 170 | 112 | should 'list people in general' do |
| 171 | 113 | Profile.delete_all |
| ... | ... | @@ -178,34 +120,12 @@ class SearchControllerTest < ActionController::TestCase |
| 178 | 120 | assert_equivalent [p2,p1], assigns(:results)[:people] |
| 179 | 121 | end |
| 180 | 122 | |
| 181 | - # 'assets' menu inside a category | |
| 182 | - should 'list people in a specified category' do | |
| 183 | - Profile.delete_all | |
| 184 | - | |
| 185 | - # in category | |
| 186 | - p1 = create_user('test1').person; p1.add_category @category | |
| 187 | - | |
| 188 | - # not in category | |
| 189 | - p2 = create_user('test2').person | |
| 190 | - | |
| 191 | - get :people, :category_path => [ 'my-category' ] | |
| 192 | - assert_equal [p1], assigns(:results)[:people] | |
| 193 | - end | |
| 194 | - | |
| 195 | 123 | should 'find communities' do |
| 196 | 124 | c1 = create_profile_with_optional_category(Community, 'a beautiful community') |
| 197 | 125 | get :index, :query => 'beautiful', :find_in => [ 'communities' ] |
| 198 | 126 | assert_includes assigns(:results)[:communities], c1 |
| 199 | 127 | end |
| 200 | 128 | |
| 201 | - should 'find communities in a specified category' do | |
| 202 | - c1 = create_profile_with_optional_category(Community, 'a beautiful community', @category) | |
| 203 | - c2 = create_profile_with_optional_category(Community, 'another beautiful community') | |
| 204 | - get :index, :category_path => [ 'my-category' ], :query => 'beautiful', :find_in => [ 'communities' ] | |
| 205 | - assert_includes assigns(:results)[:communities], c1 | |
| 206 | - assert_not_includes assigns(:results)[:communities], c2 | |
| 207 | - end | |
| 208 | - | |
| 209 | 129 | # 'assets' menu outside any category |
| 210 | 130 | should 'list communities in general' do |
| 211 | 131 | c1 = create_profile_with_optional_category(Community, 'a beautiful community') |
| ... | ... | @@ -215,23 +135,6 @@ class SearchControllerTest < ActionController::TestCase |
| 215 | 135 | assert_equivalent [c2, c1], assigns(:results)[:communities] |
| 216 | 136 | end |
| 217 | 137 | |
| 218 | - # 'assets' menu | |
| 219 | - should 'list communities in a specified category' do | |
| 220 | - | |
| 221 | - # in category | |
| 222 | - c1 = create_profile_with_optional_category(Community, 'a beautiful community', @category) | |
| 223 | - | |
| 224 | - # not in category | |
| 225 | - c2 = create_profile_with_optional_category(Community, 'another beautiful community') | |
| 226 | - | |
| 227 | - # in category | |
| 228 | - c3 = create_profile_with_optional_category(Community, 'yet another beautiful community', @category) | |
| 229 | - | |
| 230 | - get :communities, :category_path => [ 'my-category' ] | |
| 231 | - | |
| 232 | - assert_equivalent [c3, c1], assigns(:results)[:communities] | |
| 233 | - end | |
| 234 | - | |
| 235 | 138 | should 'find products' do |
| 236 | 139 | ent = create_profile_with_optional_category(Enterprise, 'teste') |
| 237 | 140 | prod = ent.products.create!(:name => 'a beautiful product', :product_category => @product_category) |
| ... | ... | @@ -239,16 +142,6 @@ class SearchControllerTest < ActionController::TestCase |
| 239 | 142 | assert_includes assigns(:results)[:products], prod |
| 240 | 143 | end |
| 241 | 144 | |
| 242 | - should 'find products in a specific category' do | |
| 243 | - ent1 = create_profile_with_optional_category(Enterprise, 'teste1', @category) | |
| 244 | - ent2 = create_profile_with_optional_category(Enterprise, 'teste2') | |
| 245 | - prod1 = ent1.products.create!(:name => 'a beautiful product', :product_category => @product_category) | |
| 246 | - prod2 = ent2.products.create!(:name => 'another beautiful product', :product_category => @product_category) | |
| 247 | - get :index, :category_path => @category.path.split('/'), :query => 'beautiful', :find_in => ['products'] | |
| 248 | - assert_includes assigns(:results)[:products], prod1 | |
| 249 | - assert_not_includes assigns(:results)[:products], prod2 | |
| 250 | - end | |
| 251 | - | |
| 252 | 145 | # 'assets' menu outside any category |
| 253 | 146 | should 'list products in general' do |
| 254 | 147 | Profile.delete_all |
| ... | ... | @@ -262,23 +155,6 @@ class SearchControllerTest < ActionController::TestCase |
| 262 | 155 | assert_equivalent [prod2, prod1], assigns(:results)[:products] |
| 263 | 156 | end |
| 264 | 157 | |
| 265 | - # 'assets' menu inside a category | |
| 266 | - should 'list products in a specific category' do | |
| 267 | - Profile.delete_all | |
| 268 | - | |
| 269 | - # in category | |
| 270 | - ent1 = create_profile_with_optional_category(Enterprise, 'teste1', @category) | |
| 271 | - prod1 = ent1.products.create!(:name => 'a beautiful product', :product_category => @product_category) | |
| 272 | - | |
| 273 | - # not in category | |
| 274 | - ent2 = create_profile_with_optional_category(Enterprise, 'teste2') | |
| 275 | - prod2 = ent2.products.create!(:name => 'another beautiful product', :product_category => @product_category) | |
| 276 | - | |
| 277 | - get :products, :category_path => [ 'my-category' ] | |
| 278 | - | |
| 279 | - assert_equal [prod1], assigns(:results)[:products] | |
| 280 | - end | |
| 281 | - | |
| 282 | 158 | should 'include extra content supplied by plugins on product asset' do |
| 283 | 159 | class Plugin1 < Noosfero::Plugin |
| 284 | 160 | def asset_product_extras(product, enterprise) |
| ... | ... | @@ -293,13 +169,13 @@ class SearchControllerTest < ActionController::TestCase |
| 293 | 169 | end |
| 294 | 170 | |
| 295 | 171 | enterprise = fast_create(Enterprise) |
| 296 | - product = fast_create(Product, :enterprise_id => enterprise.id) | |
| 172 | + product = fast_create(Product, :enterprise_id => enterprise.id, :name => "produto1") | |
| 297 | 173 | |
| 298 | 174 | e = Environment.default |
| 299 | 175 | e.enable_plugin(Plugin1.name) |
| 300 | 176 | e.enable_plugin(Plugin2.name) |
| 301 | 177 | |
| 302 | - get :assets, :asset => 'products' | |
| 178 | + get :assets, {:asset => 'products', :query => 'produto1'} | |
| 303 | 179 | |
| 304 | 180 | assert_tag :tag => 'span', :content => 'This is Plugin1 speaking!', :attributes => {:id => 'plugin1'} |
| 305 | 181 | assert_tag :tag => 'span', :content => 'This is Plugin2 speaking!', :attributes => {:id => 'plugin2'} |
| ... | ... | @@ -317,13 +193,13 @@ class SearchControllerTest < ActionController::TestCase |
| 317 | 193 | end |
| 318 | 194 | end |
| 319 | 195 | enterprise = fast_create(Enterprise) |
| 320 | - product = fast_create(Product, :enterprise_id => enterprise.id) | |
| 196 | + product = fast_create(Product, :enterprise_id => enterprise.id, :name => "produto1") | |
| 321 | 197 | |
| 322 | 198 | environment = Environment.default |
| 323 | 199 | environment.enable_plugin(Plugin1.name) |
| 324 | 200 | environment.enable_plugin(Plugin2.name) |
| 325 | 201 | |
| 326 | - get :products | |
| 202 | + get :products, :query => "produto1" | |
| 327 | 203 | |
| 328 | 204 | assert_tag :tag => 'li', :content => /Property1/, :child => {:tag => 'a', :attributes => {:href => '/plugin1'}, :content => product.name} |
| 329 | 205 | assert_tag :tag => 'li', :content => /Property2/, :child => {:tag => 'a', :attributes => {:href => '/plugin2'}, :content => product.name} |
| ... | ... | @@ -339,173 +215,16 @@ class SearchControllerTest < ActionController::TestCase |
| 339 | 215 | assert_equal 1, assigns(:results)[:enterprises].size |
| 340 | 216 | end |
| 341 | 217 | |
| 342 | - should 'display search results' do | |
| 343 | - ent = create_profile_with_optional_category(Enterprise, 'display enterprise') | |
| 344 | - product = ent.products.create!(:name => 'display product', :product_category => @product_category) | |
| 345 | - person = create_user('displayperson').person; person.name = 'display person'; person.save! | |
| 346 | - article = person.articles.create!(:name => 'display article') | |
| 347 | - event = Event.new(:name => 'display event', :start_date => Date.today); event.profile = person; event.save! | |
| 348 | - comment = article.comments.create!(:title => 'display comment', :body => '...', :author => person) | |
| 349 | - community = create_profile_with_optional_category(Community, 'display community') | |
| 350 | - | |
| 351 | - get :index, :query => 'display' | |
| 352 | - | |
| 353 | - names = { | |
| 354 | - :articles => ['Articles', article], | |
| 355 | - :enterprises => ['Enterprises', ent], | |
| 356 | - :communities => ['Communities', community], | |
| 357 | - :products => ['Products', product], | |
| 358 | - :events => ['Events', event], | |
| 359 | - } | |
| 360 | - names.each do |thing, pair| | |
| 361 | - description, object = pair | |
| 362 | - assert_tag :tag => 'div', :attributes => { :class => /search-results-#{thing}/ }, :descendant => { :tag => 'h3', :content => Regexp.new(description) } | |
| 363 | - assert_tag :tag => 'a', :content => object.respond_to?(:short_name) ? object.short_name : object.name | |
| 364 | - end | |
| 365 | - | |
| 366 | - # display only first name on people listing | |
| 367 | - assert_tag :tag => 'div', :attributes => { :class => /search-results-people/ }, :descendant => { :tag => 'h3', :content => /People/ } | |
| 368 | - end | |
| 369 | - | |
| 370 | - should 'present options of where to search' do | |
| 371 | - get :popup | |
| 372 | - names = { | |
| 373 | - :articles => 'Articles', | |
| 374 | - :people => 'People', | |
| 375 | - :enterprises => 'Enterprises', | |
| 376 | - :communities => 'Communities', | |
| 377 | - :products => 'Products', | |
| 378 | - :events => 'Events', | |
| 379 | - } | |
| 380 | - names.each do |thing,description| | |
| 381 | - assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => "find_in[]", :value => thing.to_s, :checked => 'checked' } | |
| 382 | - assert_tag :tag => 'label', :content => description | |
| 383 | - end | |
| 384 | - end | |
| 385 | - | |
| 386 | - should 'not display option to choose where to search when not inside filter' do | |
| 387 | - get :popup | |
| 388 | - assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'search_whole_site', :value => 'yes' } | |
| 389 | - end | |
| 390 | - | |
| 391 | - should 'display option to choose searching in whole site or in current category' do | |
| 392 | - parent = Category.create!(:name => 'cat', :environment => Environment.default) | |
| 393 | - Category.create!(:name => 'sub', :environment => Environment.default, :parent => parent) | |
| 394 | - | |
| 395 | - get :popup, :category_path => [ 'cat', 'sub'] | |
| 396 | - assert_tag :tag => 'input', :attributes => { :type => 'submit', :name => 'search_whole_site_yes' } | |
| 397 | - assert_tag :tag => 'input', :attributes => { :type => 'submit', :name => 'search_whole_site_no' } | |
| 398 | - end | |
| 399 | - | |
| 400 | - should 'display option to search within a given point and distance' do | |
| 401 | - state = State.create!(:name => "Bahia", :environment => Environment.default) | |
| 402 | - get :popup | |
| 403 | - | |
| 404 | - assert_tag :tag => 'select', :attributes => {:name => 'radius'} | |
| 405 | - assert_tag :tag => 'select', :attributes => {:name => 'state'} | |
| 406 | - assert_tag :tag => 'select', :attributes => {:name => 'city'} | |
| 407 | - end | |
| 408 | - | |
| 409 | - should 'search in whole site when told so' do | |
| 410 | - parent = Category.create!(:name => 'randomcat', :environment => Environment.default) | |
| 411 | - Category.create!(:name => 'randomchild', :environment => Environment.default, :parent => parent) | |
| 412 | - | |
| 413 | - get :index, :category_path => [ 'randomcat', 'randomchild' ], :query => 'some random query', :search_whole_site => 'yes' | |
| 414 | - | |
| 415 | - # search_whole_site must be removed to precent a infinite redirect loop | |
| 416 | - assert_redirected_to :controller.to_s => 'search', :action.to_s => 'index', :category_path.to_s => [], :query.to_s => 'some random query', :search_whole_site.to_s => nil, :search_whole_site_yes.to_s => nil | |
| 417 | - end | |
| 418 | - | |
| 419 | - should 'submit form to root when not inside a filter' do | |
| 420 | - get :popup | |
| 421 | - assert_tag :tag => 'form', :attributes => { :action => '/search' } | |
| 422 | - end | |
| 423 | - | |
| 424 | - should 'submit form to category path when inside a filter' do | |
| 425 | - get :popup, :category_path => Category.create!(:name => 'mycat', :environment => Environment.default).explode_path | |
| 426 | - assert_tag :tag => 'form', :attributes => { :action => '/search/index/mycat' } | |
| 427 | - end | |
| 428 | - | |
| 429 | - should 'use GET method to search' do | |
| 430 | - get :popup | |
| 431 | - assert_tag :tag => 'form' , :attributes => { :method => 'get' } | |
| 432 | - end | |
| 433 | - | |
| 434 | 218 | should 'display a given category' do |
| 435 | 219 | get :category_index, :category_path => [ 'my-category' ] |
| 436 | 220 | assert_equal @category, assigns(:category) |
| 437 | 221 | end |
| 438 | 222 | |
| 439 | - should 'expose category in a method' do | |
| 440 | - get :category_index, :category_path => [ 'my-category' ] | |
| 441 | - assert_same assigns(:category), @controller.category | |
| 442 | - end | |
| 443 | - | |
| 444 | - should 'list recent articles in the category' do | |
| 445 | - recent = [] | |
| 446 | - finder = CategoryFinder.new(@category) | |
| 447 | - finder.expects(:recent).with(any_parameters).at_least_once | |
| 448 | - finder.expects(:recent).with('text_articles', anything).returns(recent) | |
| 449 | - CategoryFinder.stubs(:new).with(@category).returns(finder) | |
| 450 | - | |
| 451 | - get :category_index, :category_path => [ 'my-category' ] | |
| 452 | - assert_same recent, assigns(:results)[:articles] | |
| 453 | - end | |
| 454 | - | |
| 455 | - should 'list most commented articles in the category' do | |
| 456 | - most_commented = [] | |
| 457 | - finder = CategoryFinder.new(@category) | |
| 458 | - finder.expects(:most_commented_articles).returns(most_commented) | |
| 459 | - CategoryFinder.stubs(:new).with(@category).returns(finder) | |
| 460 | - | |
| 461 | - get :category_index, :category_path => [ 'my-category' ] | |
| 462 | - assert_same most_commented, assigns(:results)[:most_commented_articles] | |
| 463 | - end | |
| 464 | - | |
| 465 | - should 'list recently registered people in the category' do | |
| 466 | - recent_people = [] | |
| 467 | - finder = CategoryFinder.new(@category) | |
| 468 | - finder.expects(:recent).with(any_parameters).at_least_once | |
| 469 | - finder.expects(:recent).with('people', kind_of(Integer)).returns(recent_people) | |
| 470 | - CategoryFinder.stubs(:new).with(@category).returns(finder) | |
| 471 | - | |
| 472 | - get :category_index, :category_path => [ 'my-category' ] | |
| 473 | - assert_same recent_people, assigns(:results)[:people] | |
| 474 | - end | |
| 475 | - | |
| 476 | - should 'list recently registered communities in the category' do | |
| 477 | - recent_communities = [] | |
| 478 | - finder = CategoryFinder.new(@category) | |
| 479 | - finder.expects(:recent).with(any_parameters).at_least_once | |
| 480 | - finder.expects(:recent).with('communities', anything).returns(recent_communities) | |
| 481 | - CategoryFinder.stubs(:new).with(@category).returns(finder) | |
| 482 | - | |
| 483 | - get :category_index, :category_path => [ 'my-category' ] | |
| 484 | - assert_same recent_communities, assigns(:results)[:communities] | |
| 485 | - end | |
| 486 | - | |
| 487 | - should 'list recently registered enterprises in the category' do | |
| 488 | - recent_enterptises = [] | |
| 489 | - finder = CategoryFinder.new(@category) | |
| 490 | - finder.expects(:recent).with(any_parameters).at_least_once | |
| 491 | - finder.expects(:recent).with('enterprises', anything).returns(recent_enterptises) | |
| 492 | - CategoryFinder.stubs(:new).with(@category).returns(finder) | |
| 493 | - | |
| 494 | - get :category_index, :category_path => [ 'my-category' ] | |
| 495 | - assert_same recent_enterptises, assigns(:results)[:enterprises] | |
| 496 | - end | |
| 497 | - | |
| 498 | 223 | should 'not list "Search for ..." in category_index' do |
| 499 | 224 | get :category_index, :category_path => [ 'my-category' ] |
| 500 | 225 | assert_no_tag :content => /Search for ".*" in the whole site/ |
| 501 | 226 | end |
| 502 | 227 | |
| 503 | - # SECURITY | |
| 504 | - should 'not allow unrecognized assets' do | |
| 505 | - get :unexisting_asset | |
| 506 | - assert_response 403 | |
| 507 | - end | |
| 508 | - | |
| 509 | 228 | should 'not use design blocks' do |
| 510 | 229 | get :index |
| 511 | 230 | assert_no_tag :tag => 'div', :attributes => { :id => 'boxes', :class => 'boxes' } |
| ... | ... | @@ -527,15 +246,6 @@ class SearchControllerTest < ActionController::TestCase |
| 527 | 246 | } |
| 528 | 247 | end |
| 529 | 248 | |
| 530 | - should 'display only category name in "search results for ..." title' do | |
| 531 | - parent = Category.create!(:name => 'Parent Category', :environment => Environment.default) | |
| 532 | - child = Category.create!(:name => "Child Category", :environment => Environment.default, :parent => parent) | |
| 533 | - | |
| 534 | - get :index, :category_path => [ 'parent-category', 'child-category' ], :query => 'a sample search' | |
| 535 | - assert_tag :tag => 'h2', :content => /Searched for 'a sample search'/ | |
| 536 | - assert_tag :tag => 'h2', :content => /In category Child Category/ | |
| 537 | - end | |
| 538 | - | |
| 539 | 249 | should 'search in category hierachy' do |
| 540 | 250 | parent = Category.create!(:name => 'Parent Category', :environment => Environment.default) |
| 541 | 251 | child = Category.create!(:name => 'Child Category', :environment => Environment.default, :parent => parent) |
| ... | ... | @@ -547,15 +257,6 @@ class SearchControllerTest < ActionController::TestCase |
| 547 | 257 | assert_includes assigns(:results)[:people], p |
| 548 | 258 | end |
| 549 | 259 | |
| 550 | - # FIXME how do test link_to_remote? | |
| 551 | - should 'keep asset selection for new searches' do | |
| 552 | - get :index, :query => 'a sample query', :find_in => [ 'people', 'communities' ] | |
| 553 | - assert_tag :tag => 'input', :attributes => { :name => 'find_in[]', :value => 'people', :checked => 'checked' } | |
| 554 | - assert_tag :tag => 'input', :attributes => { :name => 'find_in[]', :value => 'communities', :checked => 'checked' } | |
| 555 | - assert_no_tag :tag => 'input', :attributes => { :name => 'find_in[]', :value => 'enterprises', :checked => 'checked' } | |
| 556 | - assert_no_tag :tag => 'input', :attributes => { :name => 'find_in[]', :value => 'products', :checked => 'checked' } | |
| 557 | - end | |
| 558 | - | |
| 559 | 260 | should 'find enterprise by product category' do |
| 560 | 261 | ent1 = create_profile_with_optional_category(Enterprise, 'test1') |
| 561 | 262 | prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default) |
| ... | ... | @@ -589,57 +290,6 @@ class SearchControllerTest < ActionController::TestCase |
| 589 | 290 | assert_includes assigns(:results)[:events], ev |
| 590 | 291 | end |
| 591 | 292 | |
| 592 | - should 'search for events in a specific category' do | |
| 593 | - person = create_user('teste').person | |
| 594 | - | |
| 595 | - # in category | |
| 596 | - ev1 = create_event(person, :name => 'an event to be found') | |
| 597 | - ev1.add_category @category | |
| 598 | - ev1.save! | |
| 599 | - | |
| 600 | - # not in category | |
| 601 | - ev2 = create_event(person, :name => 'another event to be found') | |
| 602 | - ev2.save! | |
| 603 | - | |
| 604 | - get :index, :category_path => [ 'my-category' ], :query => 'event found', :find_in => [ 'events' ] | |
| 605 | - | |
| 606 | - assert_includes assigns(:results)[:events], ev1 | |
| 607 | - assert_not_includes assigns(:results)[:events], ev2 | |
| 608 | - end | |
| 609 | - | |
| 610 | - # 'assets' outside any category | |
| 611 | - should 'list events in general' do | |
| 612 | - person = create_user('testuser').person | |
| 613 | - person2 = create_user('anotheruser').person | |
| 614 | - | |
| 615 | - ev1 = create_event(person, :name => 'one event', :category_ids => [@category.id]) | |
| 616 | - | |
| 617 | - ev2 = create_event(person2, :name => 'two event', :category_ids => [@category.id]) | |
| 618 | - | |
| 619 | - get :events | |
| 620 | - | |
| 621 | - assert_includes assigns(:results)[:events], ev1 | |
| 622 | - assert_includes assigns(:results)[:events], ev2 | |
| 623 | - end | |
| 624 | - | |
| 625 | - # 'assets' inside a category | |
| 626 | - should 'list events in a specific category' do | |
| 627 | - person = create_user('testuser').person | |
| 628 | - | |
| 629 | - # in category | |
| 630 | - ev1 = create_event(person, :name => 'one event', :category_ids => [@category.id]) | |
| 631 | - ev2 = create_event(person, :name => 'other event', :category_ids => [@category.id]) | |
| 632 | - | |
| 633 | - # not in category | |
| 634 | - ev3 = create_event(person, :name => 'another event') | |
| 635 | - | |
| 636 | - get :events, :category_path => ['my-category'] | |
| 637 | - | |
| 638 | - assert_includes assigns(:results)[:events], ev1 | |
| 639 | - assert_includes assigns(:results)[:events], ev2 | |
| 640 | - assert_not_includes assigns(:results)[:events], ev3 | |
| 641 | - end | |
| 642 | - | |
| 643 | 293 | should 'list events for a given month' do |
| 644 | 294 | person = create_user('testuser').person |
| 645 | 295 | |
| ... | ... | @@ -651,59 +301,13 @@ class SearchControllerTest < ActionController::TestCase |
| 651 | 301 | assert_equal [ 'upcoming event 1' ], assigns(:results)[:events].map(&:name) |
| 652 | 302 | end |
| 653 | 303 | |
| 654 | - should 'list events for a given month in a specific category' do | |
| 655 | - person = create_user('testuser').person | |
| 656 | - | |
| 657 | - create_event(person, :name => 'upcoming event 1', :category_ids => [@category.id], :start_date => Date.new(2008, 1, 25)) | |
| 658 | - create_event(person, :name => 'upcoming event 2', :category_ids => [@category.id], :start_date => Date.new(2008, 4, 27)) | |
| 659 | - | |
| 660 | - get :events, :category_path => [ 'my-category' ], :year => '2008', :month => '1' | |
| 661 | - | |
| 662 | - assert_equal [ 'upcoming event 1' ], assigns(:results)[:events].map(&:name) | |
| 663 | - end | |
| 664 | - | |
| 665 | - should 'list upcoming events in a specific category' do | |
| 666 | - person = create_user('testuser').person | |
| 667 | - | |
| 668 | - # today is January 15th, 2008 | |
| 669 | - Date.expects(:today).returns(Date.new(2008,1,15)).at_least_once | |
| 670 | - | |
| 671 | - # in category, but in the past | |
| 672 | - create_event(person, :name => 'past event', :category_ids => [@category.id], :start_date => Date.new(2008, 1, 1)) | |
| 673 | - | |
| 674 | - # in category, upcoming | |
| 675 | - create_event(person, :name => 'upcoming event 1', :category_ids => [@category.id], :start_date => Date.new(2008, 1, 25)) | |
| 676 | - create_event(person, :name => 'upcoming event 2', :category_ids => [@category.id], :start_date => Date.new(2008, 1, 27)) | |
| 677 | - | |
| 678 | - # not in category | |
| 679 | - create_event(person, :name => 'event not in category') | |
| 680 | - | |
| 681 | - get :category_index, :category_path => ['my-category'] | |
| 682 | - | |
| 683 | - assert_equal [ 'upcoming event 1', 'upcoming event 2' ], assigns(:results)[:events].map(&:name) | |
| 684 | - end | |
| 685 | - | |
| 686 | - | |
| 687 | 304 | %w[ people enterprises articles events communities products ].each do |asset| |
| 688 | 305 | should "render asset-specific template when searching for #{asset}" do |
| 689 | - get :index, :find_in => [ asset ] | |
| 306 | + get "#{asset}" | |
| 690 | 307 | assert_template asset |
| 691 | 308 | end |
| 692 | 309 | end |
| 693 | 310 | |
| 694 | - should 'list only categories with products' do | |
| 695 | - cat1 = ProductCategory.create!(:name => 'pc test 1', :environment => Environment.default) | |
| 696 | - cat2 = ProductCategory.create!(:name => 'pc test 2', :environment => Environment.default) | |
| 697 | - ent = create_profile_with_optional_category(Enterprise, 'test ent') | |
| 698 | - | |
| 699 | - cat1.products.create!(:name => 'prod test 1', :enterprise => ent) | |
| 700 | - | |
| 701 | - get :index, :find_in => 'products', :query => 'test' | |
| 702 | - | |
| 703 | - assert_tag :attributes => { :id => "product-categories-menu" }, :descendant => { :tag => 'a', :content => /pc test 1/ } | |
| 704 | - assert_no_tag :attributes => { :id => "product-categories-menu" }, :descendant => { :tag => 'a', :content => /pc test c/ } | |
| 705 | - end | |
| 706 | - | |
| 707 | 311 | should 'display only within a product category when specified' do |
| 708 | 312 | prod_cat = ProductCategory.create!(:name => 'prod cat test', :environment => Environment.default) |
| 709 | 313 | ent = create_profile_with_optional_category(Enterprise, 'test ent') |
| ... | ... | @@ -716,120 +320,17 @@ class SearchControllerTest < ActionController::TestCase |
| 716 | 320 | end |
| 717 | 321 | |
| 718 | 322 | should 'display properly in conjuntion with a category' do |
| 719 | - cat = Category.create(:name => 'cat', :environment => Environment.default) | |
| 720 | - prod_cat1 = ProductCategory.create!(:name => 'prod cat test 1', :environment => Environment.default) | |
| 721 | - prod_cat2 = ProductCategory.create!(:name => 'prod cat test 2', :environment => Environment.default, :parent => prod_cat1) | |
| 722 | - ent = create_profile_with_optional_category(Enterprise, 'test ent', cat) | |
| 723 | - | |
| 724 | - p = prod_cat2.products.create!(:name => 'prod test 1', :enterprise => ent) | |
| 725 | - | |
| 726 | - get :index, :find_in => 'products', :category_path => cat.path.split('/'), :product_category => prod_cat1.id | |
| 727 | - | |
| 728 | - assert_includes assigns(:results)[:products], p | |
| 729 | - end | |
| 730 | - | |
| 731 | - should 'display only top level product categories that has products when no product category filter is specified' do | |
| 732 | - cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) | |
| 733 | - cat2 = ProductCategory.create(:name => 'prod cat 2', :environment => Environment.default) | |
| 734 | - ent = create_profile_with_optional_category(Enterprise, 'test ent') | |
| 735 | - p = cat1.products.create!(:name => 'prod test 1', :enterprise => ent) | |
| 736 | 323 | |
| 737 | - get :index, :find_in => 'products' | |
| 738 | - | |
| 739 | - assert_tag :attributes => { :id => "product-categories-menu" }, :descendant => { :tag => 'a', :content => /prod cat 1/ } | |
| 740 | - assert_no_tag :attributes => { :id => "product-categories-menu" }, :descendant => { :tag => 'a', :content => /prod cat 2/ } | |
| 741 | - end | |
| 742 | - | |
| 743 | - should 'display children categories that has products when product category filter is selected' do | |
| 744 | - cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) | |
| 745 | - cat11 = ProductCategory.create(:name => 'prod cat 11', :environment => Environment.default, :parent => cat1) | |
| 746 | - cat12 = ProductCategory.create(:name => 'prod cat 12', :environment => Environment.default, :parent => cat1) | |
| 747 | - ent = create_profile_with_optional_category(Enterprise, 'test ent') | |
| 748 | - p = cat11.products.create!(:name => 'prod test 1', :enterprise => ent) | |
| 749 | - | |
| 750 | - get :index, :find_in => 'products', :product_category => cat1.id | |
| 751 | - | |
| 752 | - assert_tag :attributes => { :id => "product-categories-menu" }, :descendant => { :tag => 'a', :content => /prod cat 11/ } | |
| 753 | - assert_no_tag :attributes => { :id => "product-categories-menu" }, :descendant => { :tag => 'a', :content => /prod cat 12/ } | |
| 754 | - end | |
| 755 | - | |
| 756 | - should 'list only product categories with enterprises' do | |
| 757 | - cat1 = ProductCategory.create!(:name => 'pc test 1', :environment => Environment.default) | |
| 758 | - cat2 = ProductCategory.create!(:name => 'pc test 2', :environment => Environment.default) | |
| 759 | - ent = create_profile_with_optional_category(Enterprise, 'test ent') | |
| 760 | - | |
| 761 | - cat1.products.create!(:name => 'prod test 1', :enterprise => ent) | |
| 762 | - | |
| 763 | - get :index, :find_in => 'enterprises', :query => 'test' | |
| 764 | - | |
| 765 | - assert_tag :attributes => { :id => "product-categories-menu" }, :descendant => { :tag => 'a', :content => /pc test 1/ } | |
| 766 | - assert_no_tag :attributes => { :id => "product-categories-menu" }, :descendant => { :tag => 'a', :content => /pc test c/ } | |
| 767 | - end | |
| 768 | - | |
| 769 | - should 'display only enterprises in the product category when its specified' do | |
| 770 | - prod_cat = ProductCategory.create!(:name => 'prod cat test', :environment => Environment.default) | |
| 771 | - ent1 = create_profile_with_optional_category(Enterprise, 'test_ent1') | |
| 772 | - p = prod_cat.products.create!(:name => 'prod test 1', :enterprise => ent1) | |
| 773 | - | |
| 774 | - ent2 = create_profile_with_optional_category(Enterprise, 'test_ent2') | |
| 775 | - | |
| 776 | - get :index, :find_in => 'enterprises', :product_category => prod_cat.id | |
| 777 | - | |
| 778 | - assert_includes assigns(:results)[:enterprises], ent1 | |
| 779 | - assert_not_includes assigns(:results)[:enterprises], ent2 | |
| 780 | - end | |
| 781 | - | |
| 782 | - should 'display enterprises properly in conjuntion with a category' do | |
| 783 | 324 | cat = Category.create(:name => 'cat', :environment => Environment.default) |
| 784 | 325 | prod_cat1 = ProductCategory.create!(:name => 'prod cat test 1', :environment => Environment.default) |
| 785 | 326 | prod_cat2 = ProductCategory.create!(:name => 'prod cat test 2', :environment => Environment.default, :parent => prod_cat1) |
| 786 | - ent1 = create_profile_with_optional_category(Enterprise, 'test ent 1', cat) | |
| 787 | - p = prod_cat2.products.create!(:name => 'prod test 1', :enterprise => ent1) | |
| 788 | - | |
| 789 | - ent2 = create_profile_with_optional_category(Enterprise, 'test ent 2', cat) | |
| 790 | - | |
| 791 | - get :index, :find_in => 'enterprises', :category_path => cat.path.split('/'), :product_category => prod_cat1.id | |
| 792 | - | |
| 793 | - assert_includes assigns(:results)[:enterprises], ent1 | |
| 794 | - assert_not_includes assigns(:results)[:enterprises], ent2 | |
| 795 | - end | |
| 796 | - | |
| 797 | - should 'display only top level product categories that has enterprises when no product category filter is specified' do | |
| 798 | - cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) | |
| 799 | - cat2 = ProductCategory.create(:name => 'prod cat 2', :environment => Environment.default) | |
| 800 | - ent = create_profile_with_optional_category(Enterprise, 'test ent') | |
| 801 | - p = cat1.products.create!(:name => 'prod test 1', :enterprise => ent) | |
| 802 | - | |
| 803 | - get :index, :find_in => 'enterprises' | |
| 804 | - | |
| 805 | - assert_tag :attributes => { :id => "product-categories-menu" }, :descendant => { :tag => 'a', :content => /prod cat 1/ } | |
| 806 | - assert_no_tag :attributes => { :id => "product-categories-menu" }, :descendant => { :tag => 'a', :content => /prod cat 2/ } | |
| 807 | - end | |
| 808 | - | |
| 809 | - should 'display children categories that has enterprises when product category filter is selected' do | |
| 810 | - cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) | |
| 811 | - cat11 = ProductCategory.create(:name => 'prod cat 11', :environment => Environment.default, :parent => cat1) | |
| 812 | - cat12 = ProductCategory.create(:name => 'prod cat 12', :environment => Environment.default, :parent => cat1) | |
| 813 | - ent = create_profile_with_optional_category(Enterprise, 'test ent') | |
| 814 | - p = cat11.products.create!(:name => 'prod test 1', :enterprise => ent) | |
| 815 | - | |
| 816 | - get :index, :find_in => 'enterprises', :product_category => cat1.id | |
| 817 | - | |
| 818 | - assert_tag :attributes => { :id => "product-categories-menu" }, :descendant => { :tag => 'a', :content => /prod cat 11/ } | |
| 819 | - assert_no_tag :attributes => { :id => "product-categories-menu" }, :descendant => { :tag => 'a', :content => /prod cat 12/ } | |
| 820 | - end | |
| 327 | + ent = create_profile_with_optional_category(Enterprise, 'test ent', cat) | |
| 821 | 328 | |
| 822 | - should 'load two level of the product categories tree' do | |
| 823 | - cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) | |
| 824 | - cat11 = ProductCategory.create(:name => 'prod cat 11', :environment => Environment.default, :parent => cat1) | |
| 825 | - cat12 = ProductCategory.create(:name => 'prod cat 12', :environment => Environment.default, :parent => cat1) | |
| 826 | - ent = create_profile_with_optional_category(Enterprise, 'test ent') | |
| 827 | - p = cat11.products.create!(:name => 'prod test 1', :enterprise => ent) | |
| 329 | + product = prod_cat2.products.create!(:name => 'prod test 1', :enterprise_id => ent.id) | |
| 828 | 330 | |
| 829 | - get :index, :find_in => 'enterprises' | |
| 331 | + get :products, {:category_path => cat.path.split('/'), :product_category => prod_cat1.id} | |
| 830 | 332 | |
| 831 | - assert_tag :attributes => { :id => "product-categories-menu" }, :descendant => { :tag => 'a', :content => /prod cat 11/ } | |
| 832 | - assert_no_tag :attributes => { :id => "product-categories-menu" }, :descendant => { :tag => 'a', :content => /prod cat 12/ } | |
| 333 | + assert_includes assigns(:results)[:products], product | |
| 833 | 334 | end |
| 834 | 335 | |
| 835 | 336 | should 'provide calendar for events' do |
| ... | ... | @@ -844,11 +345,6 @@ class SearchControllerTest < ActionController::TestCase |
| 844 | 345 | assert_tag :tag => 'table', :attributes => {:class => /current-month/}, :descendant => {:tag => 'caption', :content => /August 2008/} |
| 845 | 346 | end |
| 846 | 347 | |
| 847 | - should 'submit search form to /search when viewing asset' do | |
| 848 | - get :people | |
| 849 | - assert_tag :tag => "form", :attributes => { :class => 'search_form', :action => '/search' } | |
| 850 | - end | |
| 851 | - | |
| 852 | 348 | should 'found TextileArticle in articles' do |
| 853 | 349 | person = create_user('teste').person |
| 854 | 350 | art = TextileArticle.create!(:name => 'an text_article article to be found', :profile => person) |
| ... | ... | @@ -858,33 +354,6 @@ class SearchControllerTest < ActionController::TestCase |
| 858 | 354 | assert_includes assigns(:results)[:articles], art |
| 859 | 355 | end |
| 860 | 356 | |
| 861 | - should 'know about disabled assets' do | |
| 862 | - env = mock | |
| 863 | - %w[ articles enterprises people communities events].each do |item| | |
| 864 | - env.expects(:enabled?).with('disable_asset_' + item).returns(false).at_least_once | |
| 865 | - end | |
| 866 | - env.expects(:enabled?).with('disable_asset_products').returns(true).at_least_once | |
| 867 | - @controller.stubs(:environment).returns(env) | |
| 868 | - | |
| 869 | - %w[ articles enterprises people communities events].each do |item| | |
| 870 | - assert_includes @controller.where_to_search.map(&:first), item.to_sym | |
| 871 | - end | |
| 872 | - assert_not_includes @controller.where_to_search.map(&:first), :products | |
| 873 | - end | |
| 874 | - | |
| 875 | - should 'search for products by origin and radius correctly' do | |
| 876 | - s = City.create!(:name => 'Salvador', :lat => -12.97, :lng => -38.51, :environment => Environment.default) | |
| 877 | - e1 = create_profile_with_optional_category(Enterprise, 'test ent 1', nil, :lat => -12.97, :lng => -38.51) | |
| 878 | - p1 = e1.products.create!(:name => 'test_product1', :product_category => @product_category) | |
| 879 | - e2 = create_profile_with_optional_category(Enterprise, 'test ent 2', nil, :lat => -14.97, :lng => -40.51) | |
| 880 | - p2 = e2.products.create!(:name => 'test_product2', :product_category => @product_category) | |
| 881 | - | |
| 882 | - get :assets, :asset => 'products', :city => s.id, :radius => 15 | |
| 883 | - | |
| 884 | - assert_includes assigns(:results)[:products], p1 | |
| 885 | - assert_not_includes assigns(:results)[:products], p2 | |
| 886 | - end | |
| 887 | - | |
| 888 | 357 | should 'show link to article asset in the see all foot link of the articles block in the category page' do |
| 889 | 358 | a = create_user('test1').person.articles.create!(:name => 'an article to be found') |
| 890 | 359 | a.add_category @category |
| ... | ... | @@ -909,20 +378,6 @@ class SearchControllerTest < ActionController::TestCase |
| 909 | 378 | assert_equal 20, assigns(:results)[:enterprises].total_entries |
| 910 | 379 | end |
| 911 | 380 | |
| 912 | - should 'add link to list in all categories when in a category' do | |
| 913 | - ['people', 'enterprises', 'products', 'communities', 'articles'].each do |asset| | |
| 914 | - get asset, :category_path => [ 'my-category' ] | |
| 915 | - assert_tag :tag => 'div', :content => 'In all categories' | |
| 916 | - end | |
| 917 | - end | |
| 918 | - | |
| 919 | - should 'not add link to list in all categories when not in a category' do | |
| 920 | - ['people', 'enterprises', 'products', 'communities', 'articles'].each do |asset| | |
| 921 | - get asset | |
| 922 | - assert_no_tag :tag => 'div', :content => 'In all categories' | |
| 923 | - end | |
| 924 | - end | |
| 925 | - | |
| 926 | 381 | should 'find products when enterprises has own hostname' do |
| 927 | 382 | ent = create_profile_with_optional_category(Enterprise, 'teste') |
| 928 | 383 | ent.domains << Domain.new(:name => 'testent.com'); ent.save! |
| ... | ... | @@ -938,12 +393,14 @@ class SearchControllerTest < ActionController::TestCase |
| 938 | 393 | end |
| 939 | 394 | |
| 940 | 395 | should 'add script tag for google maps if searching enterprises' do |
| 396 | + ent = create_profile_with_optional_category(Enterprise, 'teste') | |
| 941 | 397 | get 'index', :query => 'enterprise', :display => 'map', :find_in => ['enterprises'] |
| 942 | 398 | |
| 943 | 399 | assert_tag :tag => 'script', :attributes => { :src => 'http://maps.google.com/maps?file=api&v=2&key=ENVIRONMENT_KEY'} |
| 944 | 400 | end |
| 945 | 401 | |
| 946 | 402 | should 'not add script tag for google maps if searching articles' do |
| 403 | + ent = create_profile_with_optional_category(Enterprise, 'teste') | |
| 947 | 404 | get 'index', :query => 'article', :display => 'map', :find_in => ['articles'] |
| 948 | 405 | |
| 949 | 406 | assert_no_tag :tag => 'script', :attributes => { :src => 'http://maps.google.com/maps?file=api&v=2&key=ENVIRONMENT_KEY'} |
| ... | ... | @@ -970,34 +427,6 @@ class SearchControllerTest < ActionController::TestCase |
| 970 | 427 | assert_tag :tag => 'a', :content => /Joao Birthday/ |
| 971 | 428 | end |
| 972 | 429 | |
| 973 | - should 'filter events by category' do | |
| 974 | - person = create_user('anotheruser').person | |
| 975 | - | |
| 976 | - searched_category = Category.create!(:name => 'Category with events', :environment => Environment.default) | |
| 977 | - | |
| 978 | - event_in_searched_category = create_event(person, :name => 'Maria Birthday', :start_date => Date.today, :category_ids => [searched_category.id]) | |
| 979 | - event_in_non_searched_category = create_event(person, :name => 'Joao Birthday', :start_date => Date.today, :category_ids => [@category.id]) | |
| 980 | - | |
| 981 | - get :events, :category_path => ['category-with-events'] | |
| 982 | - | |
| 983 | - assert_includes assigns(:events_of_the_day), event_in_searched_category | |
| 984 | - assert_not_includes assigns(:events_of_the_day), event_in_non_searched_category | |
| 985 | - end | |
| 986 | - | |
| 987 | - should 'filter events by category of specific day' do | |
| 988 | - person = create_user('anotheruser').person | |
| 989 | - | |
| 990 | - searched_category = Category.create!(:name => 'Category with events', :environment => Environment.default) | |
| 991 | - | |
| 992 | - event_in_searched_category = create_event(person, :name => 'Maria Birthday', :start_date => Date.new(2009, 10, 28), :category_ids => [searched_category.id]) | |
| 993 | - event_in_non_searched_category = create_event(person, :name => 'Joao Birthday', :start_date => Date.new(2009, 10, 28), :category_ids => [@category.id]) | |
| 994 | - | |
| 995 | - get :events_by_day, :year => 2009, :month => 10, :day => 28, :category_id => searched_category.id | |
| 996 | - | |
| 997 | - assert_tag :tag => 'a', :content => /Maria Birthday/ | |
| 998 | - assert_no_tag :tag => 'a', :content => /Joao Birthday/ | |
| 999 | - end | |
| 1000 | - | |
| 1001 | 430 | should 'ignore filter of events if category not exists' do |
| 1002 | 431 | person = create_user('anotheruser').person |
| 1003 | 432 | create_event(person, :name => 'Joao Birthday', :start_date => Date.new(2009, 10, 28), :category_ids => [@category.id]) |
| ... | ... | @@ -1011,158 +440,26 @@ class SearchControllerTest < ActionController::TestCase |
| 1011 | 440 | assert_tag :tag => 'a', :content => /Maria Birthday/ |
| 1012 | 441 | end |
| 1013 | 442 | |
| 1014 | - should 'search for people' do | |
| 1015 | - Person.delete_all | |
| 1016 | - small = create(Person, :name => 'A small person for testing', :user_id => 1) | |
| 1017 | - create(Person, :name => 'A big person for testing', :user_id => 2) | |
| 1018 | - | |
| 1019 | - get :people, :query => 'small' | |
| 1020 | - assert_equal [small], assigns(:results) | |
| 1021 | - end | |
| 1022 | - | |
| 1023 | - should 'list all people order by more recent one by default' do | |
| 1024 | - Person.delete_all | |
| 1025 | - p1 = create(Person, :name => 'Testing person 1', :user_id => 1, :created_at => DateTime.now - 2) | |
| 1026 | - p2 = create(Person, :name => 'Testing person 2', :user_id => 2, :created_at => DateTime.now - 1) | |
| 1027 | - p3 = create(Person, :name => 'Testing person 3', :user_id => 3) | |
| 1028 | - | |
| 1029 | - get :people | |
| 1030 | - assert_equal [p3,p2,p1] , assigns(:results) | |
| 1031 | - end | |
| 1032 | - | |
| 1033 | 443 | should 'paginate search of people in groups of 27' do |
| 1034 | 444 | Person.delete_all |
| 1035 | 445 | |
| 1036 | 446 | 1.upto(30).map do |n| |
| 1037 | - create(Person, :name => 'Testing person', :user_id => n) | |
| 447 | + create(User) | |
| 1038 | 448 | end |
| 1039 | 449 | |
| 1040 | 450 | get :people |
| 1041 | - assert_equal 30 , Person.count | |
| 1042 | - assert_equal 27 , assigns(:results).count | |
| 1043 | - assert_tag :a, '', :attributes => {:class => 'next_page'} | |
| 1044 | - end | |
| 1045 | - | |
| 1046 | - should 'paginate ferret search of people in groups of 27' do | |
| 1047 | - Person.delete_all | |
| 1048 | - | |
| 1049 | - 1.upto(30).map do |n| | |
| 1050 | - create(Person, :name => 'Testing person', :user_id => n) | |
| 1051 | - end | |
| 1052 | - | |
| 1053 | - get :people, :query => 'Testing' | |
| 1054 | - assert_equal 27 , assigns(:results).count | |
| 451 | + assert_equal 30, Person.count | |
| 452 | + assert_equal 27, assigns(:results).count | |
| 1055 | 453 | assert_tag :a, '', :attributes => {:class => 'next_page'} |
| 1056 | 454 | end |
| 1057 | 455 | |
| 1058 | - should 'not return nil results in the more_active people list' do | |
| 1059 | - Profile.delete_all | |
| 1060 | - p1 = fast_create(Person) | |
| 1061 | - p2 = fast_create(Person) | |
| 1062 | - p3 = fast_create(Person) | |
| 1063 | - fast_create(Article, :profile_id => p1, :created_at => 1.day.ago) | |
| 1064 | - fast_create(Article, :profile_id => p2, :created_at => 1.day.ago) | |
| 1065 | - fast_create(Article, :profile_id => p2, :created_at => 1.day.ago) | |
| 1066 | - fast_create(Article, :profile_id => p2, :created_at => 1.day.ago) | |
| 1067 | - fast_create(Article, :profile_id => p3, :created_at => 1.day.ago) | |
| 1068 | - | |
| 1069 | - per_page = 1 | |
| 1070 | - @controller.stubs(:per_page).returns(per_page) | |
| 1071 | - | |
| 1072 | - get :people, :filter => 'more_active' | |
| 1073 | - | |
| 1074 | - assert_equal Person.count/per_page, assigns(:results).total_entries | |
| 1075 | - end | |
| 1076 | - | |
| 1077 | - should 'list all people filter by more active' do | |
| 1078 | - Person.delete_all | |
| 1079 | - p1 = create(Person, :name => 'Testing person 1', :user_id => 1) | |
| 1080 | - p2 = create(Person, :name => 'Testing person 2', :user_id => 2) | |
| 1081 | - p3 = create(Person, :name => 'Testing person 3', :user_id => 3) | |
| 1082 | - ActionTracker::Record.delete_all | |
| 1083 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p1, :created_at => Time.now) | |
| 1084 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => Time.now) | |
| 1085 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => Time.now) | |
| 1086 | - get :people, :filter => 'more_active' | |
| 1087 | - assert_equal [p2,p1,p3] , assigns(:results) | |
| 1088 | - end | |
| 1089 | - | |
| 1090 | - should 'filter more popular people' do | |
| 1091 | - Person.delete_all | |
| 1092 | - p1 = create(Person, :name => 'Testing person 1', :user_id => 1) | |
| 1093 | - p2 = create(Person, :name => 'Testing person 2', :user_id => 2) | |
| 1094 | - p3 = create(Person, :name => 'Testing person 3', :user_id => 3) | |
| 1095 | - | |
| 1096 | - p1.add_friend(p2) | |
| 1097 | - p2.add_friend(p1) | |
| 1098 | - p2.add_friend(p3) | |
| 1099 | - get :people, :filter => 'more_popular' | |
| 1100 | - assert_equal [p2,p1,p3] , assigns(:results) | |
| 1101 | - end | |
| 1102 | - | |
| 1103 | - should 'set filter be only the hardcoded one' do | |
| 1104 | - get :people, :filter => 'more_recent' | |
| 1105 | - assert_equal 'more_recent' , assigns(:filter) | |
| 1106 | - get :people, :filter => 'more_active' | |
| 1107 | - assert_equal 'more_active' , assigns(:filter) | |
| 1108 | - get :people, :filter => 'more_popular' | |
| 1109 | - assert_equal 'more_popular' , assigns(:filter) | |
| 1110 | - get :people, :filter => 'more_anything' | |
| 1111 | - assert_equal 'more_recent' , assigns(:filter) | |
| 1112 | - | |
| 1113 | - get :communities, :filter => 'more_recent' | |
| 1114 | - assert_equal 'more_recent' , assigns(:filter) | |
| 1115 | - get :communities, :filter => 'more_active' | |
| 1116 | - assert_equal 'more_active' , assigns(:filter) | |
| 1117 | - get :communities, :filter => 'more_popular' | |
| 1118 | - assert_equal 'more_popular' , assigns(:filter) | |
| 1119 | - get :communities, :filter => 'more_anything' | |
| 1120 | - assert_equal 'more_recent' , assigns(:filter) | |
| 1121 | - end | |
| 1122 | - | |
| 1123 | - should 'the people filter define the title' do | |
| 1124 | - get :people, :filter => 'more_recent' | |
| 1125 | - assert_equal 'More recent people from network' , assigns(:filter_title) | |
| 1126 | - assert_tag :h1, :content => 'More recent people from network' | |
| 1127 | - get :people, :filter => 'more_active' | |
| 1128 | - assert_equal 'More active people from network' , assigns(:filter_title) | |
| 1129 | - assert_tag :h1, :content => 'More active people from network' | |
| 1130 | - get :people, :filter => 'more_popular' | |
| 1131 | - assert_equal 'More popular people from network' , assigns(:filter_title) | |
| 1132 | - assert_tag :h1, :content => 'More popular people from network' | |
| 1133 | - get :people, :filter => 'more_anything' | |
| 1134 | - assert_equal 'More recent people from network' , assigns(:filter_title) | |
| 1135 | - assert_tag :h1, :content => 'More recent people from network' | |
| 1136 | - get :communities, :filter => 'more_recent' | |
| 1137 | - | |
| 1138 | - assert_equal 'More recent communities from network' , assigns(:filter_title) | |
| 1139 | - assert_tag :h1, :content => 'More recent communities from network' | |
| 1140 | - get :communities, :filter => 'more_active' | |
| 1141 | - assert_equal 'More active communities from network' , assigns(:filter_title) | |
| 1142 | - assert_tag :h1, :content => 'More active communities from network' | |
| 1143 | - get :communities, :filter => 'more_popular' | |
| 1144 | - assert_equal 'More popular communities from network' , assigns(:filter_title) | |
| 1145 | - assert_tag :h1, :content => 'More popular communities from network' | |
| 1146 | - get :communities, :filter => 'more_anything' | |
| 1147 | - assert_equal 'More recent communities from network' , assigns(:filter_title) | |
| 1148 | - assert_tag :h1, :content => 'More recent communities from network' | |
| 1149 | - end | |
| 1150 | - | |
| 1151 | - should 'search for community' do | |
| 1152 | - small = create(Community, :name => 'A small community for testing') | |
| 1153 | - create(Community, :name => 'A big community for testing') | |
| 1154 | - | |
| 1155 | - get :communities, :query => 'small' | |
| 1156 | - assert_equal [small], assigns(:results) | |
| 1157 | - end | |
| 1158 | - | |
| 1159 | 456 | should 'list all community order by more recent one by default' do |
| 1160 | 457 | c1 = create(Community, :name => 'Testing community 1', :created_at => DateTime.now - 2) |
| 1161 | 458 | c2 = create(Community, :name => 'Testing community 2', :created_at => DateTime.now - 1) |
| 1162 | 459 | c3 = create(Community, :name => 'Testing community 3') |
| 1163 | 460 | |
| 1164 | 461 | get :communities |
| 1165 | - assert_equal [c3,c2,c1] , assigns(:results) | |
| 462 | + assert_equal [c3,c2,c1] , assigns(:results)[:communities] | |
| 1166 | 463 | end |
| 1167 | 464 | |
| 1168 | 465 | should 'paginate search of communities in groups of 27' do |
| ... | ... | @@ -1176,36 +473,6 @@ class SearchControllerTest < ActionController::TestCase |
| 1176 | 473 | assert_tag :a, '', :attributes => {:class => 'next_page'} |
| 1177 | 474 | end |
| 1178 | 475 | |
| 1179 | - should 'paginate ferret search of communities in groups of 27' do | |
| 1180 | - 1.upto(30).map do |n| | |
| 1181 | - create(Community, :name => 'Testing community') | |
| 1182 | - end | |
| 1183 | - | |
| 1184 | - get :communities, :query => 'Testing' | |
| 1185 | - assert_equal 27 , assigns(:results).count | |
| 1186 | - assert_tag :a, '', :attributes => {:class => 'next_page'} | |
| 1187 | - end | |
| 1188 | - | |
| 1189 | - should 'not return nil results in the more_active communities list' do | |
| 1190 | - Profile.delete_all | |
| 1191 | - c1 = fast_create(Community) | |
| 1192 | - c2 = fast_create(Community) | |
| 1193 | - c3 = fast_create(Community) | |
| 1194 | - fast_create(Article, :profile_id => c1, :created_at => 1.day.ago) | |
| 1195 | - fast_create(Article, :profile_id => c2, :created_at => 1.day.ago) | |
| 1196 | - fast_create(Article, :profile_id => c2, :created_at => 1.day.ago) | |
| 1197 | - fast_create(Article, :profile_id => c2, :created_at => 1.day.ago) | |
| 1198 | - fast_create(Article, :profile_id => c3, :created_at => 1.day.ago) | |
| 1199 | - | |
| 1200 | - per_page = 1 | |
| 1201 | - @controller.stubs(:per_page).returns(per_page) | |
| 1202 | - | |
| 1203 | - get :communities, :filter => 'more_active' | |
| 1204 | - | |
| 1205 | - assert_equal Community.count/per_page, assigns(:results).total_pages | |
| 1206 | - end | |
| 1207 | - | |
| 1208 | - | |
| 1209 | 476 | should 'list all communities filter by more active' do |
| 1210 | 477 | person = fast_create(Person) |
| 1211 | 478 | c1 = create(Community, :name => 'Testing community 1') |
| ... | ... | @@ -1216,22 +483,7 @@ class SearchControllerTest < ActionController::TestCase |
| 1216 | 483 | fast_create(ActionTracker::Record, :target_id => c2, :user_type => 'Profile', :user_id => person, :created_at => Time.now) |
| 1217 | 484 | fast_create(ActionTracker::Record, :target_id => c2, :user_type => 'Profile', :user_id => person, :created_at => Time.now) |
| 1218 | 485 | get :communities, :filter => 'more_active' |
| 1219 | - assert_equal [c2,c1,c3] , assigns(:results) | |
| 1220 | - end | |
| 1221 | - | |
| 1222 | - should 'filter more popular communities' do | |
| 1223 | - Person.delete_all | |
| 1224 | - Community.delete_all | |
| 1225 | - c1 = create(Community, :name => 'Testing community 1') | |
| 1226 | - c2 = create(Community, :name => 'Testing community 2') | |
| 1227 | - | |
| 1228 | - p1 = create(Person, :name => 'Testing person 1', :user_id => 1) | |
| 1229 | - p2 = create(Person, :name => 'Testing person 2', :user_id => 2) | |
| 1230 | - c1.add_member(p1) | |
| 1231 | - c2.add_member(p1) | |
| 1232 | - c2.add_member(p2) | |
| 1233 | - get :communities, :filter => 'more_popular' | |
| 1234 | - assert_equal [c2,c1] , assigns(:results) | |
| 486 | + assert_equal [c2,c1,c3] , assigns(:results)[:communities] | |
| 1235 | 487 | end |
| 1236 | 488 | |
| 1237 | 489 | should "only include visible people in more_recent filter" do | ... | ... |