Commit 3c29449be56832b4946173cc02b121c86adc7aba

Authored by Victor Costa
1 parent f892761b

rails3: fix profile_controller tests

app/controllers/public/profile_controller.rb
@@ -219,7 +219,7 @@ class ProfileController < PublicController @@ -219,7 +219,7 @@ class ProfileController < PublicController
219 219
220 render :update do |page| 220 render :update do |page|
221 page.insert_html :bottom, 'profile-wall-activities-comments-'+params[:activity], 221 page.insert_html :bottom, 'profile-wall-activities-comments-'+params[:activity],
222 - :partial => 'comment', :collection => activity.comments.paginate(:per_page => comments_per_page, :page => comment_page) 222 + :partial => 'comment', :collection => activity.comments.flatten.paginate(:per_page => comments_per_page, :page => comment_page)
223 223
224 if no_more_pages 224 if no_more_pages
225 page.remove 'profile-wall-activities-comments-more-'+params[:activity] 225 page.remove 'profile-wall-activities-comments-more-'+params[:activity]
test/functional/profile_controller_test.rb
@@ -6,9 +6,6 @@ class ProfileController; def rescue_action(e) raise e end; end @@ -6,9 +6,6 @@ class ProfileController; def rescue_action(e) raise e end; end
6 6
7 class ProfileControllerTest < ActionController::TestCase 7 class ProfileControllerTest < ActionController::TestCase
8 def setup 8 def setup
9 - @controller = ProfileController.new  
10 - @request = ActionController::TestRequest.new  
11 - @response = ActionController::TestResponse.new  
12 Environment.default.enable('products_for_enterprises') 9 Environment.default.enable('products_for_enterprises')
13 @profile = create_user('testuser').person 10 @profile = create_user('testuser').person
14 end 11 end
@@ -766,13 +763,14 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -766,13 +763,14 @@ class ProfileControllerTest &lt; ActionController::TestCase
766 end 763 end
767 764
768 should 'see all the activities in the current profile network' do 765 should 'see all the activities in the current profile network' do
769 - p1= Person.first 766 + p1= fast_create(Person)
770 p2= fast_create(Person) 767 p2= fast_create(Person)
771 assert !p1.is_a_friend?(p2) 768 assert !p1.is_a_friend?(p2)
772 p3= fast_create(Person) 769 p3= fast_create(Person)
773 p3.add_friend(p1) 770 p3.add_friend(p1)
774 assert p3.is_a_friend?(p1) 771 assert p3.is_a_friend?(p1)
775 ActionTracker::Record.destroy_all 772 ActionTracker::Record.destroy_all
  773 + UserStampSweeper.any_instance.stubs(:current_user).returns(p1)
776 create(Scrap, defaults_for_scrap(:sender => p1, :receiver => p1)) 774 create(Scrap, defaults_for_scrap(:sender => p1, :receiver => p1))
777 a1 = ActionTracker::Record.last 775 a1 = ActionTracker::Record.last
778 UserStampSweeper.any_instance.stubs(:current_user).returns(p2) 776 UserStampSweeper.any_instance.stubs(:current_user).returns(p2)
@@ -793,18 +791,18 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -793,18 +791,18 @@ class ProfileControllerTest &lt; ActionController::TestCase
793 process_delayed_job_queue 791 process_delayed_job_queue
794 get :index, :profile => p1.identifier 792 get :index, :profile => p1.identifier
795 assert_not_nil assigns(:network_activities) 793 assert_not_nil assigns(:network_activities)
796 - assert_equal [], [a1,a3] - assigns(:network_activities)  
797 - assert_equal assigns(:network_activities) - [a1, a3], [] 794 + assert_equivalent [a1,a3], assigns(:network_activities)
798 end 795 end
799 796
800 should 'the network activity be visible only to profile followers' do 797 should 'the network activity be visible only to profile followers' do
801 - p1= Person.first 798 + p1= fast_create(Person)
802 p2= fast_create(Person) 799 p2= fast_create(Person)
803 assert !p1.is_a_friend?(p2) 800 assert !p1.is_a_friend?(p2)
804 p3= fast_create(Person) 801 p3= fast_create(Person)
805 p3.add_friend(p1) 802 p3.add_friend(p1)
806 assert p3.is_a_friend?(p1) 803 assert p3.is_a_friend?(p1)
807 ActionTracker::Record.destroy_all 804 ActionTracker::Record.destroy_all
  805 + UserStampSweeper.any_instance.stubs(:current_user).returns(p1)
808 create(Scrap, defaults_for_scrap(:sender => p1, :receiver => p1)) 806 create(Scrap, defaults_for_scrap(:sender => p1, :receiver => p1))
809 a1 = ActionTracker::Record.last 807 a1 = ActionTracker::Record.last
810 UserStampSweeper.any_instance.stubs(:current_user).returns(p2) 808 UserStampSweeper.any_instance.stubs(:current_user).returns(p2)
@@ -829,12 +827,11 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -829,12 +827,11 @@ class ProfileControllerTest &lt; ActionController::TestCase
829 Person.any_instance.stubs(:follows?).returns(true) 827 Person.any_instance.stubs(:follows?).returns(true)
830 process_delayed_job_queue 828 process_delayed_job_queue
831 get :index, :profile => p3.identifier 829 get :index, :profile => p3.identifier
832 - assert_equal [], [a1,a3] - assigns(:network_activities)  
833 - assert_equal assigns(:network_activities) - [a1, a3], [] 830 + assert_equivalent [a1,a3], assigns(:network_activities)
834 end 831 end
835 832
836 should 'the network activity be paginated' do 833 should 'the network activity be paginated' do
837 - p1= Person.first 834 + p1= fast_create(Person)
838 40.times{fast_create(ActionTrackerNotification, :action_tracker_id => fast_create(ActionTracker::Record), :profile_id => p1.id)} 835 40.times{fast_create(ActionTrackerNotification, :action_tracker_id => fast_create(ActionTracker::Record), :profile_id => p1.id)}
839 836
840 @controller.stubs(:logged_in?).returns(true) 837 @controller.stubs(:logged_in?).returns(true)
@@ -847,7 +844,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -847,7 +844,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
847 end 844 end
848 845
849 should 'the network activity be visible only to logged users' do 846 should 'the network activity be visible only to logged users' do
850 - p1= ActionTracker::Record.current_user_from_model 847 + p1= fast_create(Person)
851 p2= fast_create(Person) 848 p2= fast_create(Person)
852 assert !p1.is_a_friend?(p2) 849 assert !p1.is_a_friend?(p2)
853 p3= fast_create(Person) 850 p3= fast_create(Person)
@@ -882,7 +879,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -882,7 +879,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
882 end 879 end
883 880
884 should 'the network activity be visible to uses not logged in on communities and enterprises' do 881 should 'the network activity be visible to uses not logged in on communities and enterprises' do
885 - p1= Person.first 882 + p1= fast_create(Person)
886 community = fast_create(Community) 883 community = fast_create(Community)
887 p2= fast_create(Person) 884 p2= fast_create(Person)
888 assert !p1.is_a_friend?(p2) 885 assert !p1.is_a_friend?(p2)
@@ -909,7 +906,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -909,7 +906,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
909 end 906 end
910 907
911 should 'the self activity not crashes with user not logged in' do 908 should 'the self activity not crashes with user not logged in' do
912 - p1= Person.first 909 + p1= fast_create(Person)
913 p2= fast_create(Person) 910 p2= fast_create(Person)
914 assert !p1.is_a_friend?(p2) 911 assert !p1.is_a_friend?(p2)
915 p3= fast_create(Person) 912 p3= fast_create(Person)
@@ -953,7 +950,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -953,7 +950,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
953 end 950 end
954 951
955 should 'the activities be the received scraps in people profile' do 952 should 'the activities be the received scraps in people profile' do
956 - p1 = ActionTracker::Record.current_user_from_model 953 + p1 = fast_create(Person)
957 p2 = fast_create(Person) 954 p2 = fast_create(Person)
958 p3 = fast_create(Person) 955 p3 = fast_create(Person)
959 s1 = fast_create(Scrap, :sender_id => p1.id, :receiver_id => p2.id) 956 s1 = fast_create(Scrap, :sender_id => p1.id, :receiver_id => p2.id)
@@ -990,7 +987,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -990,7 +987,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
990 end 987 end
991 988
992 should 'the activities be paginated in people profiles' do 989 should 'the activities be paginated in people profiles' do
993 - p1 = Person.first 990 + p1= fast_create(Person)
994 40.times{fast_create(Scrap, :receiver_id => p1.id, :created_at => Time.now)} 991 40.times{fast_create(Scrap, :receiver_id => p1.id, :created_at => Time.now)}
995 992
996 @controller.stubs(:logged_in?).returns(true) 993 @controller.stubs(:logged_in?).returns(true)
@@ -1005,7 +1002,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1005,7 +1002,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1005 end 1002 end
1006 1003
1007 should 'the activities be paginated in community profiles' do 1004 should 'the activities be paginated in community profiles' do
1008 - p1 = Person.first 1005 + p1= fast_create(Person)
1009 c = fast_create(Community) 1006 c = fast_create(Community)
1010 40.times{fast_create(Scrap, :receiver_id => c.id)} 1007 40.times{fast_create(Scrap, :receiver_id => c.id)}
1011 1008
@@ -1383,17 +1380,23 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1383,17 +1380,23 @@ class ProfileControllerTest &lt; ActionController::TestCase
1383 assert_equal "Comment successfully added.", assigns(:message) 1380 assert_equal "Comment successfully added.", assigns(:message)
1384 end 1381 end
1385 1382
1386 - should 'display comment in wall if user was removed' do 1383 + should 'display comment in wall if user was removed after click in view all comments' do
1387 UserStampSweeper.any_instance.stubs(:current_user).returns(profile) 1384 UserStampSweeper.any_instance.stubs(:current_user).returns(profile)
1388 article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software') 1385 article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software')
1389 to_be_removed = create_user('removed_user').person 1386 to_be_removed = create_user('removed_user').person
1390 comment = create(Comment, :author => to_be_removed, :title => 'Test Comment', :body => 'My author does not exist =(', :source_id => article.id, :source_type => 'Article') 1387 comment = create(Comment, :author => to_be_removed, :title => 'Test Comment', :body => 'My author does not exist =(', :source_id => article.id, :source_type => 'Article')
1391 to_be_removed.destroy 1388 to_be_removed.destroy
1392 1389
  1390 + activity = ActionTracker::Record.last
  1391 +
  1392 + activity = ActionTracker::Record.last
  1393 +
1393 login_as(profile.identifier) 1394 login_as(profile.identifier)
1394 - get :index, :profile => profile.identifier 1395 + get :more_comments, :profile => profile.identifier, :activity => activity.id, :comment_page => 1, :tab_action => 'wall'
1395 1396
1396 - assert_tag :tag => 'span', :content => '(removed user)', :attributes => {:class => 'comment-user-status comment-user-status-wall icon-user-removed'} 1397 + assert_select_rjs :insert_html do
  1398 + assert_select 'span', :content => '(removed user)', :attributes => {:class => 'comment-user-status comment-user-status-wall icon-user-removed'}
  1399 + end
1397 end 1400 end
1398 1401
1399 should 'not display spam comments in wall' do 1402 should 'not display spam comments in wall' do
@@ -1407,7 +1410,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1407,7 +1410,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1407 assert !/This article makes me hungry/.match(@response.body), 'Spam comment was shown!' 1410 assert !/This article makes me hungry/.match(@response.body), 'Spam comment was shown!'
1408 end 1411 end
1409 1412
1410 - should 'display comment in wall from non logged users' do 1413 + should 'display comment in wall from non logged users after click in view all comments' do
1411 UserStampSweeper.any_instance.stubs(:current_user).returns(profile) 1414 UserStampSweeper.any_instance.stubs(:current_user).returns(profile)
1412 article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software') 1415 article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software')
1413 comment = create(Comment, :name => 'outside user', :email => 'outside@localhost.localdomain', :title => 'Test Comment', :body => 'My author does not exist =(', :source_id => article.id, :source_type => 'Article') 1416 comment = create(Comment, :name => 'outside user', :email => 'outside@localhost.localdomain', :title => 'Test Comment', :body => 'My author does not exist =(', :source_id => article.id, :source_type => 'Article')
@@ -1415,7 +1418,14 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1415,7 +1418,14 @@ class ProfileControllerTest &lt; ActionController::TestCase
1415 login_as(profile.identifier) 1418 login_as(profile.identifier)
1416 get :index, :profile => profile.identifier 1419 get :index, :profile => profile.identifier
1417 1420
1418 - assert_tag :tag => 'span', :content => '(unauthenticated user)', :attributes => {:class => 'comment-user-status comment-user-status-wall icon-user-unknown'} 1421 + activity = ActionTracker::Record.last
  1422 +
  1423 + login_as(profile.identifier)
  1424 + get :more_comments, :profile => profile.identifier, :activity => activity.id, :comment_page => 1, :tab_action => 'wall'
  1425 +
  1426 + assert_select_rjs :insert_html do
  1427 + assert_select 'span', :content => '(unauthenticated user)', :attributes => {:class => 'comment-user-status comment-user-status-wall icon-user-unknown'}
  1428 + end
1419 end 1429 end
1420 1430
1421 should 'add locale on mailing' do 1431 should 'add locale on mailing' do