Commit 558cde5142dd3e37926c64015123cee40e49bb4d
1 parent
91d24abf
Exists in
master
and in
28 other branches
Initial merge of browse and search tests
Showing
2 changed files
with
262 additions
and
375 deletions
Show diff stats
test/functional/browse_controller_test.rb
| ... | ... | @@ -1,375 +0,0 @@ |
| 1 | -require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | -require 'browse_controller' | |
| 3 | - | |
| 4 | -# Re-raise errors caught by the controller. | |
| 5 | -class BrowseController; def rescue_action(e) raise e end; end | |
| 6 | - | |
| 7 | -class BrowseControllerTest < Test::Unit::TestCase | |
| 8 | - | |
| 9 | - def setup | |
| 10 | - Test::Unit::TestCase::setup | |
| 11 | - @controller = BrowseController.new | |
| 12 | - @request = ActionController::TestRequest.new | |
| 13 | - @request.stubs(:ssl?).returns(false) | |
| 14 | - @response = ActionController::TestResponse.new | |
| 15 | - | |
| 16 | - # By pass user validation on person creation | |
| 17 | - user = mock() | |
| 18 | - user.stubs(:id).returns(1) | |
| 19 | - user.stubs(:valid?).returns(true) | |
| 20 | - user.stubs(:email).returns('some@test.com') | |
| 21 | - user.stubs(:save!).returns(true) | |
| 22 | - Person.any_instance.stubs(:user).returns(user) | |
| 23 | - @profile = create_user('testinguser').person | |
| 24 | - Article.destroy_all | |
| 25 | - end | |
| 26 | - attr_reader :profile | |
| 27 | - | |
| 28 | - should 'search for people' do | |
| 29 | - Person.delete_all | |
| 30 | - small = create(Person, :name => 'A small person for testing', :user_id => 1) | |
| 31 | - create(Person, :name => 'A big person for testing', :user_id => 2) | |
| 32 | - | |
| 33 | - get :people, :query => 'small' | |
| 34 | - assert_equal [small], assigns(:results) | |
| 35 | - end | |
| 36 | - | |
| 37 | - should 'list all people order by more recent one by default' do | |
| 38 | - Person.delete_all | |
| 39 | - p1 = create(Person, :name => 'Testing person 1', :user_id => 1, :created_at => DateTime.now - 2) | |
| 40 | - p2 = create(Person, :name => 'Testing person 2', :user_id => 2, :created_at => DateTime.now - 1) | |
| 41 | - p3 = create(Person, :name => 'Testing person 3', :user_id => 3) | |
| 42 | - | |
| 43 | - get :people | |
| 44 | - assert_equal [p3,p2,p1] , assigns(:results) | |
| 45 | - end | |
| 46 | - | |
| 47 | - should 'paginate search of people in groups of 27' do | |
| 48 | - Person.delete_all | |
| 49 | - | |
| 50 | - 1.upto(30).map do |n| | |
| 51 | - create(Person, :name => 'Testing person', :user_id => n) | |
| 52 | - end | |
| 53 | - | |
| 54 | - get :people | |
| 55 | - assert_equal 30 , Person.count | |
| 56 | - assert_equal 27 , assigns(:results).count | |
| 57 | - assert_tag :a, '', :attributes => {:class => 'next_page'} | |
| 58 | - end | |
| 59 | - | |
| 60 | - should 'paginate ferret search of people in groups of 27' do | |
| 61 | - Person.delete_all | |
| 62 | - | |
| 63 | - 1.upto(30).map do |n| | |
| 64 | - create(Person, :name => 'Testing person', :user_id => n) | |
| 65 | - end | |
| 66 | - | |
| 67 | - get :people, :query => 'Testing' | |
| 68 | - assert_equal 27 , assigns(:results).count | |
| 69 | - assert_tag :a, '', :attributes => {:class => 'next_page'} | |
| 70 | - end | |
| 71 | - | |
| 72 | - should 'not return nil results in the more_active people list' do | |
| 73 | - Profile.delete_all | |
| 74 | - p1 = fast_create(Person) | |
| 75 | - p2 = fast_create(Person) | |
| 76 | - p3 = fast_create(Person) | |
| 77 | - fast_create(Article, :profile_id => p1, :created_at => 1.day.ago) | |
| 78 | - fast_create(Article, :profile_id => p2, :created_at => 1.day.ago) | |
| 79 | - fast_create(Article, :profile_id => p2, :created_at => 1.day.ago) | |
| 80 | - fast_create(Article, :profile_id => p2, :created_at => 1.day.ago) | |
| 81 | - fast_create(Article, :profile_id => p3, :created_at => 1.day.ago) | |
| 82 | - | |
| 83 | - per_page = 1 | |
| 84 | - @controller.stubs(:per_page).returns(per_page) | |
| 85 | - | |
| 86 | - get :people, :filter => 'more_active' | |
| 87 | - | |
| 88 | - assert_equal Person.count/per_page, assigns(:results).total_pages | |
| 89 | - end | |
| 90 | - | |
| 91 | - should 'list all people filter by more active' do | |
| 92 | - Person.delete_all | |
| 93 | - p1 = create(Person, :name => 'Testing person 1', :user_id => 1) | |
| 94 | - p2 = create(Person, :name => 'Testing person 2', :user_id => 2) | |
| 95 | - p3 = create(Person, :name => 'Testing person 3', :user_id => 3) | |
| 96 | - ActionTracker::Record.delete_all | |
| 97 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p1, :created_at => Time.now) | |
| 98 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => Time.now) | |
| 99 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => Time.now) | |
| 100 | - get :people, :filter => 'more_active' | |
| 101 | - assert_equal [p2,p1,p3] , assigns(:results) | |
| 102 | - end | |
| 103 | - | |
| 104 | - should 'filter more popular people' do | |
| 105 | - Person.delete_all | |
| 106 | - p1 = create(Person, :name => 'Testing person 1', :user_id => 1) | |
| 107 | - p2 = create(Person, :name => 'Testing person 2', :user_id => 2) | |
| 108 | - p3 = create(Person, :name => 'Testing person 3', :user_id => 3) | |
| 109 | - | |
| 110 | - p1.add_friend(p2) | |
| 111 | - p2.add_friend(p1) | |
| 112 | - p2.add_friend(p3) | |
| 113 | - get :people, :filter => 'more_popular' | |
| 114 | - assert_equal [p2,p1,p3] , assigns(:results) | |
| 115 | - end | |
| 116 | - | |
| 117 | - should 'the people filter be only the hardcoded one' do | |
| 118 | - get :people, :filter => 'more_recent' | |
| 119 | - assert_equal 'more_recent' , assigns(:filter) | |
| 120 | - | |
| 121 | - get :people, :filter => 'more_active' | |
| 122 | - assert_equal 'more_active' , assigns(:filter) | |
| 123 | - | |
| 124 | - get :people, :filter => 'more_popular' | |
| 125 | - assert_equal 'more_popular' , assigns(:filter) | |
| 126 | - | |
| 127 | - get :people, :filter => 'more_anything' | |
| 128 | - assert_equal 'more_recent' , assigns(:filter) | |
| 129 | - end | |
| 130 | - | |
| 131 | - should 'the people filter define the title' do | |
| 132 | - get :people, :filter => 'more_recent' | |
| 133 | - assert_equal 'More recent people' , assigns(:title) | |
| 134 | - assert_tag :h1, :content => 'More recent people' | |
| 135 | - | |
| 136 | - get :people, :filter => 'more_active' | |
| 137 | - assert_equal 'More active people' , assigns(:title) | |
| 138 | - assert_tag :h1, :content => 'More active people' | |
| 139 | - | |
| 140 | - get :people, :filter => 'more_popular' | |
| 141 | - assert_equal 'More popular people' , assigns(:title) | |
| 142 | - assert_tag :h1, :content => 'More popular people' | |
| 143 | - | |
| 144 | - get :people, :filter => 'more_anything' | |
| 145 | - assert_equal 'More recent people' , assigns(:title) | |
| 146 | - assert_tag :h1, :content => 'More recent people' | |
| 147 | - end | |
| 148 | - | |
| 149 | - should 'search for community' do | |
| 150 | - small = create(Community, :name => 'A small community for testing') | |
| 151 | - create(Community, :name => 'A big community for testing') | |
| 152 | - | |
| 153 | - get :communities, :query => 'small' | |
| 154 | - assert_equal [small], assigns(:results) | |
| 155 | - end | |
| 156 | - | |
| 157 | - should 'list all community order by more recent one by default' do | |
| 158 | - c1 = create(Community, :name => 'Testing community 1', :created_at => DateTime.now - 2) | |
| 159 | - c2 = create(Community, :name => 'Testing community 2', :created_at => DateTime.now - 1) | |
| 160 | - c3 = create(Community, :name => 'Testing community 3') | |
| 161 | - | |
| 162 | - get :communities | |
| 163 | - assert_equal [c3,c2,c1] , assigns(:results) | |
| 164 | - end | |
| 165 | - | |
| 166 | - should 'paginate search of communities in groups of 27' do | |
| 167 | - 1.upto(30).map do |n| | |
| 168 | - create(Community, :name => 'Testing community') | |
| 169 | - end | |
| 170 | - | |
| 171 | - get :communities | |
| 172 | - assert_equal 30 , Community.count | |
| 173 | - assert_equal 27 , assigns(:results).count | |
| 174 | - assert_tag :a, '', :attributes => {:class => 'next_page'} | |
| 175 | - end | |
| 176 | - | |
| 177 | - should 'paginate ferret search of communities in groups of 27' do | |
| 178 | - 1.upto(30).map do |n| | |
| 179 | - create(Community, :name => 'Testing community') | |
| 180 | - end | |
| 181 | - | |
| 182 | - get :communities, :query => 'Testing' | |
| 183 | - assert_equal 27 , assigns(:results).count | |
| 184 | - assert_tag :a, '', :attributes => {:class => 'next_page'} | |
| 185 | - end | |
| 186 | - | |
| 187 | - should 'not return nil results in the more_active communities list' do | |
| 188 | - Profile.delete_all | |
| 189 | - c1 = fast_create(Community) | |
| 190 | - c2 = fast_create(Community) | |
| 191 | - c3 = fast_create(Community) | |
| 192 | - fast_create(Article, :profile_id => c1, :created_at => 1.day.ago) | |
| 193 | - fast_create(Article, :profile_id => c2, :created_at => 1.day.ago) | |
| 194 | - fast_create(Article, :profile_id => c2, :created_at => 1.day.ago) | |
| 195 | - fast_create(Article, :profile_id => c2, :created_at => 1.day.ago) | |
| 196 | - fast_create(Article, :profile_id => c3, :created_at => 1.day.ago) | |
| 197 | - | |
| 198 | - per_page = 1 | |
| 199 | - @controller.stubs(:per_page).returns(per_page) | |
| 200 | - | |
| 201 | - get :communities, :filter => 'more_active' | |
| 202 | - | |
| 203 | - assert_equal Community.count/per_page, assigns(:results).total_pages | |
| 204 | - end | |
| 205 | - | |
| 206 | - | |
| 207 | - should 'list all communities filter by more active' do | |
| 208 | - person = fast_create(Person) | |
| 209 | - c1 = create(Community, :name => 'Testing community 1') | |
| 210 | - c2 = create(Community, :name => 'Testing community 2') | |
| 211 | - c3 = create(Community, :name => 'Testing community 3') | |
| 212 | - ActionTracker::Record.delete_all | |
| 213 | - fast_create(ActionTracker::Record, :target_id => c1, :user_type => 'Profile', :user_id => person, :created_at => Time.now) | |
| 214 | - fast_create(ActionTracker::Record, :target_id => c2, :user_type => 'Profile', :user_id => person, :created_at => Time.now) | |
| 215 | - fast_create(ActionTracker::Record, :target_id => c2, :user_type => 'Profile', :user_id => person, :created_at => Time.now) | |
| 216 | - get :communities, :filter => 'more_active' | |
| 217 | - assert_equal [c2,c1,c3] , assigns(:results) | |
| 218 | - end | |
| 219 | - | |
| 220 | - should 'filter more popular communities' do | |
| 221 | - Person.delete_all | |
| 222 | - Community.delete_all | |
| 223 | - c1 = create(Community, :name => 'Testing community 1') | |
| 224 | - c2 = create(Community, :name => 'Testing community 2') | |
| 225 | - | |
| 226 | - p1 = create(Person, :name => 'Testing person 1', :user_id => 1) | |
| 227 | - p2 = create(Person, :name => 'Testing person 2', :user_id => 2) | |
| 228 | - c1.add_member(p1) | |
| 229 | - c2.add_member(p1) | |
| 230 | - c2.add_member(p2) | |
| 231 | - get :communities, :filter => 'more_popular' | |
| 232 | - assert_equal [c2,c1] , assigns(:results) | |
| 233 | - end | |
| 234 | - | |
| 235 | - should 'the communities filter be only the hardcoded one' do | |
| 236 | - get :communities, :filter => 'more_recent' | |
| 237 | - assert_equal 'more_recent' , assigns(:filter) | |
| 238 | - | |
| 239 | - get :communities, :filter => 'more_active' | |
| 240 | - assert_equal 'more_active' , assigns(:filter) | |
| 241 | - | |
| 242 | - get :communities, :filter => 'more_popular' | |
| 243 | - assert_equal 'more_popular' , assigns(:filter) | |
| 244 | - | |
| 245 | - get :communities, :filter => 'more_anything' | |
| 246 | - assert_equal 'more_recent' , assigns(:filter) | |
| 247 | - end | |
| 248 | - | |
| 249 | - should 'the communities filter define the title' do | |
| 250 | - get :communities, :filter => 'more_recent' | |
| 251 | - assert_equal 'More recent communities' , assigns(:title) | |
| 252 | - assert_tag :h1, :content => 'More recent communities' | |
| 253 | - | |
| 254 | - get :communities, :filter => 'more_active' | |
| 255 | - assert_equal 'More active communities' , assigns(:title) | |
| 256 | - assert_tag :h1, :content => 'More active communities' | |
| 257 | - | |
| 258 | - get :communities, :filter => 'more_popular' | |
| 259 | - assert_equal 'More popular communities' , assigns(:title) | |
| 260 | - assert_tag :h1, :content => 'More popular communities' | |
| 261 | - | |
| 262 | - get :communities, :filter => 'more_anything' | |
| 263 | - assert_equal 'More recent communities' , assigns(:title) | |
| 264 | - assert_tag :h1, :content => 'More recent communities' | |
| 265 | - end | |
| 266 | - | |
| 267 | - should "only include visible people in more_recent filter" do | |
| 268 | - # assuming that all filters behave the same! | |
| 269 | - p1 = fast_create(Person, :visible => false) | |
| 270 | - get :people, :filter => 'more_recent' | |
| 271 | - assert_not_includes assigns(:results), p1 | |
| 272 | - end | |
| 273 | - | |
| 274 | - should "only include visible communities in more_recent filter" do | |
| 275 | - # assuming that all filters behave the same! | |
| 276 | - p1 = fast_create(Community, :visible => false) | |
| 277 | - get :communities, :filter => 'more_recent' | |
| 278 | - assert_not_includes assigns(:results), p1 | |
| 279 | - end | |
| 280 | - | |
| 281 | - should 'search for contents' do | |
| 282 | - small = create(TinyMceArticle, :name => 'Testing article', :body => 'A small article for testing', :profile => profile) | |
| 283 | - create(TinyMceArticle, :name => 'Testing article 2', :body => 'A big article for testing', :profile => profile) | |
| 284 | - | |
| 285 | - get :contents, :query => 'small' | |
| 286 | - assert_equal [small], assigns(:results) | |
| 287 | - end | |
| 288 | - | |
| 289 | - should 'list all contents ordered by more recent by default' do | |
| 290 | - c1 = create(TinyMceArticle, :name => 'Testing article 1', :body => 'Article body 1', :profile => profile, :created_at => DateTime.now - 2) | |
| 291 | - c2 = create(TinyMceArticle, :name => 'Testing article 2', :body => 'Article body 2', :profile => profile, :created_at => DateTime.now - 1) | |
| 292 | - c3 = create(TinyMceArticle, :name => 'Testing article 3', :body => 'Article body 3', :profile => profile) | |
| 293 | - | |
| 294 | - get :contents | |
| 295 | - assert_equal [c3,c2,c1], assigns(:results) | |
| 296 | - end | |
| 297 | - | |
| 298 | - should 'paginate search of contents in groups of 27' do | |
| 299 | - 1.upto(30).map do |n| | |
| 300 | - create(TinyMceArticle, :name => "Testing article #{n}", :body => "Article body #{n}", :profile => profile) | |
| 301 | - end | |
| 302 | - | |
| 303 | - get :contents | |
| 304 | - assert_equal 27 , assigns(:results).count | |
| 305 | - assert_tag :a, '', :attributes => {:class => 'next_page'} | |
| 306 | - end | |
| 307 | - | |
| 308 | - should 'paginate ferret search of contents in groups of 27' do | |
| 309 | - 1.upto(30).map do |n| | |
| 310 | - create(TinyMceArticle, :name => "Testing article #{n}", :body => "Article body #{n}", :profile => profile) | |
| 311 | - end | |
| 312 | - | |
| 313 | - get :contents, :query => 'Testing' | |
| 314 | - assert_equal 27 , assigns(:results).count | |
| 315 | - assert_tag :a, '', :attributes => {:class => 'next_page'} | |
| 316 | - end | |
| 317 | - | |
| 318 | - should 'list all contents filter by more comments' do | |
| 319 | - article1 = fast_create(TinyMceArticle, :body => '<p>Article to test browse contents', :profile_id => profile.id, :comments_count => 5) | |
| 320 | - article2 = fast_create(TinyMceArticle, :body => '<p>Another article to test browse contents</p>', :profile_id => profile.id, :comments_count => 10) | |
| 321 | - article3 = fast_create(TinyMceArticle, :body => '<p>Another article to test browse contents</p>', :profile_id => profile.id, :comments_count => 1) | |
| 322 | - | |
| 323 | - get :contents, :filter => 'more_comments' | |
| 324 | - assert_equal [article2,article1,article3] , assigns(:results) | |
| 325 | - end | |
| 326 | - | |
| 327 | - should 'list all contents filter by more views' do | |
| 328 | - article1 = fast_create(TinyMceArticle, :body => '<p>Article to test browse contents', :profile_id => profile.id, :hits => 5) | |
| 329 | - article2 = fast_create(TinyMceArticle, :body => '<p>Another article to test browse contents</p>', :profile_id => profile.id, :hits => 10) | |
| 330 | - article3 = fast_create(TinyMceArticle, :body => '<p>Another article to test browse contents</p>', :profile_id => profile.id, :hits => 1) | |
| 331 | - | |
| 332 | - get :contents, :filter => 'more_views' | |
| 333 | - assert_equal [article2,article1,article3], assigns(:results) | |
| 334 | - end | |
| 335 | - | |
| 336 | - should 'have the more_recent filter by default' do | |
| 337 | - get :contents, :filter => 'more_recent' | |
| 338 | - assert_equal 'more_recent' , assigns(:filter) | |
| 339 | - | |
| 340 | - get :contents, :filter => 'more_comments' | |
| 341 | - assert_equal 'more_comments' , assigns(:filter) | |
| 342 | - | |
| 343 | - get :contents, :filter => 'more_views' | |
| 344 | - assert_equal 'more_views' , assigns(:filter) | |
| 345 | - | |
| 346 | - get :contents, :filter => 'more_anything' | |
| 347 | - assert_equal 'more_recent' , assigns(:filter) | |
| 348 | - end | |
| 349 | - | |
| 350 | - should 'the contents filter define the title' do | |
| 351 | - get :contents, :filter => 'more_recent' | |
| 352 | - assert_equal 'More recent contents' , assigns(:title) | |
| 353 | - assert_tag :h1, :content => 'More recent contents' | |
| 354 | - | |
| 355 | - get :contents, :filter => 'more_views' | |
| 356 | - assert_equal 'Most viewed contents' , assigns(:title) | |
| 357 | - assert_tag :h1, :content => 'Most viewed contents' | |
| 358 | - | |
| 359 | - get :contents, :filter => 'more_comments' | |
| 360 | - assert_equal 'Most commented contents' , assigns(:title) | |
| 361 | - assert_tag :h1, :content => 'Most commented contents' | |
| 362 | - | |
| 363 | - get :contents, :filter => 'more_anything' | |
| 364 | - assert_equal 'More recent contents' , assigns(:title) | |
| 365 | - assert_tag :h1, :content => 'More recent contents' | |
| 366 | - end | |
| 367 | - | |
| 368 | - should "only include published contents in more_recent filter" do | |
| 369 | - # assuming that all filters behave the same! | |
| 370 | - article = fast_create(TinyMceArticle, :body => '<p>Article to test browse contents', :profile_id => profile.id, :published => false) | |
| 371 | - get :contents, :filter => 'more_recent' | |
| 372 | - assert_not_includes assigns(:results), article | |
| 373 | - end | |
| 374 | - | |
| 375 | -end |
test/functional/search_controller_test.rb
| ... | ... | @@ -9,6 +9,7 @@ class SearchControllerTest < Test::Unit::TestCase |
| 9 | 9 | Test::Unit::TestCase::setup |
| 10 | 10 | @controller = SearchController.new |
| 11 | 11 | @request = ActionController::TestRequest.new |
| 12 | + @request.stubs(:ssl?).returns(false) | |
| 12 | 13 | @response = ActionController::TestResponse.new |
| 13 | 14 | |
| 14 | 15 | @category = Category.create!(:name => 'my category', :environment => Environment.default) |
| ... | ... | @@ -18,6 +19,14 @@ class SearchControllerTest < Test::Unit::TestCase |
| 18 | 19 | domain.save! |
| 19 | 20 | |
| 20 | 21 | @product_category = fast_create(ProductCategory) |
| 22 | + | |
| 23 | + # By pass user validation on person creation | |
| 24 | + user = mock() | |
| 25 | + user.stubs(:id).returns(1) | |
| 26 | + user.stubs(:valid?).returns(true) | |
| 27 | + user.stubs(:email).returns('some@test.com') | |
| 28 | + user.stubs(:save!).returns(true) | |
| 29 | + Person.any_instance.stubs(:user).returns(user) | |
| 21 | 30 | end |
| 22 | 31 | |
| 23 | 32 | def create_article_with_optional_category(name, profile, category = nil) |
| ... | ... | @@ -1097,6 +1106,259 @@ class SearchControllerTest < Test::Unit::TestCase |
| 1097 | 1106 | assert_tag :tag => 'a', :content => /Maria Birthday/ |
| 1098 | 1107 | end |
| 1099 | 1108 | |
| 1109 | + should 'search for people' do | |
| 1110 | + Person.delete_all | |
| 1111 | + small = create(Person, :name => 'A small person for testing', :user_id => 1) | |
| 1112 | + create(Person, :name => 'A big person for testing', :user_id => 2) | |
| 1113 | + | |
| 1114 | + get :people, :query => 'small' | |
| 1115 | + assert_equal [small], assigns(:results) | |
| 1116 | + end | |
| 1117 | + | |
| 1118 | + should 'list all people order by more recent one by default' do | |
| 1119 | + Person.delete_all | |
| 1120 | + p1 = create(Person, :name => 'Testing person 1', :user_id => 1, :created_at => DateTime.now - 2) | |
| 1121 | + p2 = create(Person, :name => 'Testing person 2', :user_id => 2, :created_at => DateTime.now - 1) | |
| 1122 | + p3 = create(Person, :name => 'Testing person 3', :user_id => 3) | |
| 1123 | + | |
| 1124 | + get :people | |
| 1125 | + assert_equal [p3,p2,p1] , assigns(:results) | |
| 1126 | + end | |
| 1127 | + | |
| 1128 | + should 'paginate search of people in groups of 27' do | |
| 1129 | + Person.delete_all | |
| 1130 | + | |
| 1131 | + 1.upto(30).map do |n| | |
| 1132 | + create(Person, :name => 'Testing person', :user_id => n) | |
| 1133 | + end | |
| 1134 | + | |
| 1135 | + get :people | |
| 1136 | + assert_equal 30 , Person.count | |
| 1137 | + assert_equal 27 , assigns(:results).count | |
| 1138 | + assert_tag :a, '', :attributes => {:class => 'next_page'} | |
| 1139 | + end | |
| 1140 | + | |
| 1141 | + should 'paginate ferret search of people in groups of 27' do | |
| 1142 | + Person.delete_all | |
| 1143 | + | |
| 1144 | + 1.upto(30).map do |n| | |
| 1145 | + create(Person, :name => 'Testing person', :user_id => n) | |
| 1146 | + end | |
| 1147 | + | |
| 1148 | + get :people, :query => 'Testing' | |
| 1149 | + assert_equal 27 , assigns(:results).count | |
| 1150 | + assert_tag :a, '', :attributes => {:class => 'next_page'} | |
| 1151 | + end | |
| 1152 | + | |
| 1153 | + should 'not return nil results in the more_active people list' do | |
| 1154 | + Profile.delete_all | |
| 1155 | + p1 = fast_create(Person) | |
| 1156 | + p2 = fast_create(Person) | |
| 1157 | + p3 = fast_create(Person) | |
| 1158 | + fast_create(Article, :profile_id => p1, :created_at => 1.day.ago) | |
| 1159 | + fast_create(Article, :profile_id => p2, :created_at => 1.day.ago) | |
| 1160 | + fast_create(Article, :profile_id => p2, :created_at => 1.day.ago) | |
| 1161 | + fast_create(Article, :profile_id => p2, :created_at => 1.day.ago) | |
| 1162 | + fast_create(Article, :profile_id => p3, :created_at => 1.day.ago) | |
| 1163 | + | |
| 1164 | + per_page = 1 | |
| 1165 | + @controller.stubs(:per_page).returns(per_page) | |
| 1166 | + | |
| 1167 | + get :people, :filter => 'more_active' | |
| 1168 | + | |
| 1169 | + assert_equal Person.count/per_page, assigns(:results).total_pages | |
| 1170 | + end | |
| 1171 | + | |
| 1172 | + should 'list all people filter by more active' do | |
| 1173 | + Person.delete_all | |
| 1174 | + p1 = create(Person, :name => 'Testing person 1', :user_id => 1) | |
| 1175 | + p2 = create(Person, :name => 'Testing person 2', :user_id => 2) | |
| 1176 | + p3 = create(Person, :name => 'Testing person 3', :user_id => 3) | |
| 1177 | + ActionTracker::Record.delete_all | |
| 1178 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p1, :created_at => Time.now) | |
| 1179 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => Time.now) | |
| 1180 | + fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2, :created_at => Time.now) | |
| 1181 | + get :people, :filter => 'more_active' | |
| 1182 | + assert_equal [p2,p1,p3] , assigns(:results) | |
| 1183 | + end | |
| 1184 | + | |
| 1185 | + should 'filter more popular people' do | |
| 1186 | + Person.delete_all | |
| 1187 | + p1 = create(Person, :name => 'Testing person 1', :user_id => 1) | |
| 1188 | + p2 = create(Person, :name => 'Testing person 2', :user_id => 2) | |
| 1189 | + p3 = create(Person, :name => 'Testing person 3', :user_id => 3) | |
| 1190 | + | |
| 1191 | + p1.add_friend(p2) | |
| 1192 | + p2.add_friend(p1) | |
| 1193 | + p2.add_friend(p3) | |
| 1194 | + get :people, :filter => 'more_popular' | |
| 1195 | + assert_equal [p2,p1,p3] , assigns(:results) | |
| 1196 | + end | |
| 1197 | + | |
| 1198 | + should 'the people filter be only the hardcoded one' do | |
| 1199 | + get :people, :filter => 'more_recent' | |
| 1200 | + assert_equal 'more_recent' , assigns(:filter) | |
| 1201 | + | |
| 1202 | + get :people, :filter => 'more_active' | |
| 1203 | + assert_equal 'more_active' , assigns(:filter) | |
| 1204 | + | |
| 1205 | + get :people, :filter => 'more_popular' | |
| 1206 | + assert_equal 'more_popular' , assigns(:filter) | |
| 1207 | + | |
| 1208 | + get :people, :filter => 'more_anything' | |
| 1209 | + assert_equal 'more_recent' , assigns(:filter) | |
| 1210 | + end | |
| 1211 | + | |
| 1212 | + should 'the people filter define the title' do | |
| 1213 | + get :people, :filter => 'more_recent' | |
| 1214 | + assert_equal 'More recent people' , assigns(:title) | |
| 1215 | + assert_tag :h1, :content => 'More recent people' | |
| 1216 | + | |
| 1217 | + get :people, :filter => 'more_active' | |
| 1218 | + assert_equal 'More active people' , assigns(:title) | |
| 1219 | + assert_tag :h1, :content => 'More active people' | |
| 1220 | + | |
| 1221 | + get :people, :filter => 'more_popular' | |
| 1222 | + assert_equal 'More popular people' , assigns(:title) | |
| 1223 | + assert_tag :h1, :content => 'More popular people' | |
| 1224 | + | |
| 1225 | + get :people, :filter => 'more_anything' | |
| 1226 | + assert_equal 'More recent people' , assigns(:title) | |
| 1227 | + assert_tag :h1, :content => 'More recent people' | |
| 1228 | + end | |
| 1229 | + | |
| 1230 | + should 'search for community' do | |
| 1231 | + small = create(Community, :name => 'A small community for testing') | |
| 1232 | + create(Community, :name => 'A big community for testing') | |
| 1233 | + | |
| 1234 | + get :communities, :query => 'small' | |
| 1235 | + assert_equal [small], assigns(:results) | |
| 1236 | + end | |
| 1237 | + | |
| 1238 | + should 'list all community order by more recent one by default' do | |
| 1239 | + c1 = create(Community, :name => 'Testing community 1', :created_at => DateTime.now - 2) | |
| 1240 | + c2 = create(Community, :name => 'Testing community 2', :created_at => DateTime.now - 1) | |
| 1241 | + c3 = create(Community, :name => 'Testing community 3') | |
| 1242 | + | |
| 1243 | + get :communities | |
| 1244 | + assert_equal [c3,c2,c1] , assigns(:results) | |
| 1245 | + end | |
| 1246 | + | |
| 1247 | + should 'paginate search of communities in groups of 27' do | |
| 1248 | + 1.upto(30).map do |n| | |
| 1249 | + create(Community, :name => 'Testing community') | |
| 1250 | + end | |
| 1251 | + | |
| 1252 | + get :communities | |
| 1253 | + assert_equal 30 , Community.count | |
| 1254 | + assert_equal 27 , assigns(:results).count | |
| 1255 | + assert_tag :a, '', :attributes => {:class => 'next_page'} | |
| 1256 | + end | |
| 1257 | + | |
| 1258 | + should 'paginate ferret search of communities in groups of 27' do | |
| 1259 | + 1.upto(30).map do |n| | |
| 1260 | + create(Community, :name => 'Testing community') | |
| 1261 | + end | |
| 1262 | + | |
| 1263 | + get :communities, :query => 'Testing' | |
| 1264 | + assert_equal 27 , assigns(:results).count | |
| 1265 | + assert_tag :a, '', :attributes => {:class => 'next_page'} | |
| 1266 | + end | |
| 1267 | + | |
| 1268 | + should 'not return nil results in the more_active communities list' do | |
| 1269 | + Profile.delete_all | |
| 1270 | + c1 = fast_create(Community) | |
| 1271 | + c2 = fast_create(Community) | |
| 1272 | + c3 = fast_create(Community) | |
| 1273 | + fast_create(Article, :profile_id => c1, :created_at => 1.day.ago) | |
| 1274 | + fast_create(Article, :profile_id => c2, :created_at => 1.day.ago) | |
| 1275 | + fast_create(Article, :profile_id => c2, :created_at => 1.day.ago) | |
| 1276 | + fast_create(Article, :profile_id => c2, :created_at => 1.day.ago) | |
| 1277 | + fast_create(Article, :profile_id => c3, :created_at => 1.day.ago) | |
| 1278 | + | |
| 1279 | + per_page = 1 | |
| 1280 | + @controller.stubs(:per_page).returns(per_page) | |
| 1281 | + | |
| 1282 | + get :communities, :filter => 'more_active' | |
| 1283 | + | |
| 1284 | + assert_equal Community.count/per_page, assigns(:results).total_pages | |
| 1285 | + end | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + should 'list all communities filter by more active' do | |
| 1289 | + person = fast_create(Person) | |
| 1290 | + c1 = create(Community, :name => 'Testing community 1') | |
| 1291 | + c2 = create(Community, :name => 'Testing community 2') | |
| 1292 | + c3 = create(Community, :name => 'Testing community 3') | |
| 1293 | + ActionTracker::Record.delete_all | |
| 1294 | + fast_create(ActionTracker::Record, :target_id => c1, :user_type => 'Profile', :user_id => person, :created_at => Time.now) | |
| 1295 | + fast_create(ActionTracker::Record, :target_id => c2, :user_type => 'Profile', :user_id => person, :created_at => Time.now) | |
| 1296 | + fast_create(ActionTracker::Record, :target_id => c2, :user_type => 'Profile', :user_id => person, :created_at => Time.now) | |
| 1297 | + get :communities, :filter => 'more_active' | |
| 1298 | + assert_equal [c2,c1,c3] , assigns(:results) | |
| 1299 | + end | |
| 1300 | + | |
| 1301 | + should 'filter more popular communities' do | |
| 1302 | + Person.delete_all | |
| 1303 | + Community.delete_all | |
| 1304 | + c1 = create(Community, :name => 'Testing community 1') | |
| 1305 | + c2 = create(Community, :name => 'Testing community 2') | |
| 1306 | + | |
| 1307 | + p1 = create(Person, :name => 'Testing person 1', :user_id => 1) | |
| 1308 | + p2 = create(Person, :name => 'Testing person 2', :user_id => 2) | |
| 1309 | + c1.add_member(p1) | |
| 1310 | + c2.add_member(p1) | |
| 1311 | + c2.add_member(p2) | |
| 1312 | + get :communities, :filter => 'more_popular' | |
| 1313 | + assert_equal [c2,c1] , assigns(:results) | |
| 1314 | + end | |
| 1315 | + | |
| 1316 | + should 'the communities filter be only the hardcoded one' do | |
| 1317 | + get :communities, :filter => 'more_recent' | |
| 1318 | + assert_equal 'more_recent' , assigns(:filter) | |
| 1319 | + | |
| 1320 | + get :communities, :filter => 'more_active' | |
| 1321 | + assert_equal 'more_active' , assigns(:filter) | |
| 1322 | + | |
| 1323 | + get :communities, :filter => 'more_popular' | |
| 1324 | + assert_equal 'more_popular' , assigns(:filter) | |
| 1325 | + | |
| 1326 | + get :communities, :filter => 'more_anything' | |
| 1327 | + assert_equal 'more_recent' , assigns(:filter) | |
| 1328 | + end | |
| 1329 | + | |
| 1330 | + should 'the communities filter define the title' do | |
| 1331 | + get :communities, :filter => 'more_recent' | |
| 1332 | + assert_equal 'More recent communities' , assigns(:title) | |
| 1333 | + assert_tag :h1, :content => 'More recent communities' | |
| 1334 | + | |
| 1335 | + get :communities, :filter => 'more_active' | |
| 1336 | + assert_equal 'More active communities' , assigns(:title) | |
| 1337 | + assert_tag :h1, :content => 'More active communities' | |
| 1338 | + | |
| 1339 | + get :communities, :filter => 'more_popular' | |
| 1340 | + assert_equal 'More popular communities' , assigns(:title) | |
| 1341 | + assert_tag :h1, :content => 'More popular communities' | |
| 1342 | + | |
| 1343 | + get :communities, :filter => 'more_anything' | |
| 1344 | + assert_equal 'More recent communities' , assigns(:title) | |
| 1345 | + assert_tag :h1, :content => 'More recent communities' | |
| 1346 | + end | |
| 1347 | + | |
| 1348 | + should "only include visible people in more_recent filter" do | |
| 1349 | + # assuming that all filters behave the same! | |
| 1350 | + p1 = fast_create(Person, :visible => false) | |
| 1351 | + get :people, :filter => 'more_recent' | |
| 1352 | + assert_not_includes assigns(:results), p1 | |
| 1353 | + end | |
| 1354 | + | |
| 1355 | + should "only include visible communities in more_recent filter" do | |
| 1356 | + # assuming that all filters behave the same! | |
| 1357 | + p1 = fast_create(Community, :visible => false) | |
| 1358 | + get :communities, :filter => 'more_recent' | |
| 1359 | + assert_not_includes assigns(:results), p1 | |
| 1360 | + end | |
| 1361 | + | |
| 1100 | 1362 | ################################################################## |
| 1101 | 1363 | ################################################################## |
| 1102 | 1364 | ... | ... |