Commit 3c29449be56832b4946173cc02b121c86adc7aba
1 parent
f892761b
Exists in
master
and in
29 other branches
rails3: fix profile_controller tests
Showing
2 changed files
with
32 additions
and
22 deletions
Show diff stats
app/controllers/public/profile_controller.rb
... | ... | @@ -219,7 +219,7 @@ class ProfileController < PublicController |
219 | 219 | |
220 | 220 | render :update do |page| |
221 | 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 | 224 | if no_more_pages |
225 | 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 | 6 | |
7 | 7 | class ProfileControllerTest < ActionController::TestCase |
8 | 8 | def setup |
9 | - @controller = ProfileController.new | |
10 | - @request = ActionController::TestRequest.new | |
11 | - @response = ActionController::TestResponse.new | |
12 | 9 | Environment.default.enable('products_for_enterprises') |
13 | 10 | @profile = create_user('testuser').person |
14 | 11 | end |
... | ... | @@ -766,13 +763,14 @@ class ProfileControllerTest < ActionController::TestCase |
766 | 763 | end |
767 | 764 | |
768 | 765 | should 'see all the activities in the current profile network' do |
769 | - p1= Person.first | |
766 | + p1= fast_create(Person) | |
770 | 767 | p2= fast_create(Person) |
771 | 768 | assert !p1.is_a_friend?(p2) |
772 | 769 | p3= fast_create(Person) |
773 | 770 | p3.add_friend(p1) |
774 | 771 | assert p3.is_a_friend?(p1) |
775 | 772 | ActionTracker::Record.destroy_all |
773 | + UserStampSweeper.any_instance.stubs(:current_user).returns(p1) | |
776 | 774 | create(Scrap, defaults_for_scrap(:sender => p1, :receiver => p1)) |
777 | 775 | a1 = ActionTracker::Record.last |
778 | 776 | UserStampSweeper.any_instance.stubs(:current_user).returns(p2) |
... | ... | @@ -793,18 +791,18 @@ class ProfileControllerTest < ActionController::TestCase |
793 | 791 | process_delayed_job_queue |
794 | 792 | get :index, :profile => p1.identifier |
795 | 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 | 795 | end |
799 | 796 | |
800 | 797 | should 'the network activity be visible only to profile followers' do |
801 | - p1= Person.first | |
798 | + p1= fast_create(Person) | |
802 | 799 | p2= fast_create(Person) |
803 | 800 | assert !p1.is_a_friend?(p2) |
804 | 801 | p3= fast_create(Person) |
805 | 802 | p3.add_friend(p1) |
806 | 803 | assert p3.is_a_friend?(p1) |
807 | 804 | ActionTracker::Record.destroy_all |
805 | + UserStampSweeper.any_instance.stubs(:current_user).returns(p1) | |
808 | 806 | create(Scrap, defaults_for_scrap(:sender => p1, :receiver => p1)) |
809 | 807 | a1 = ActionTracker::Record.last |
810 | 808 | UserStampSweeper.any_instance.stubs(:current_user).returns(p2) |
... | ... | @@ -829,12 +827,11 @@ class ProfileControllerTest < ActionController::TestCase |
829 | 827 | Person.any_instance.stubs(:follows?).returns(true) |
830 | 828 | process_delayed_job_queue |
831 | 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 | 831 | end |
835 | 832 | |
836 | 833 | should 'the network activity be paginated' do |
837 | - p1= Person.first | |
834 | + p1= fast_create(Person) | |
838 | 835 | 40.times{fast_create(ActionTrackerNotification, :action_tracker_id => fast_create(ActionTracker::Record), :profile_id => p1.id)} |
839 | 836 | |
840 | 837 | @controller.stubs(:logged_in?).returns(true) |
... | ... | @@ -847,7 +844,7 @@ class ProfileControllerTest < ActionController::TestCase |
847 | 844 | end |
848 | 845 | |
849 | 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 | 848 | p2= fast_create(Person) |
852 | 849 | assert !p1.is_a_friend?(p2) |
853 | 850 | p3= fast_create(Person) |
... | ... | @@ -882,7 +879,7 @@ class ProfileControllerTest < ActionController::TestCase |
882 | 879 | end |
883 | 880 | |
884 | 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 | 883 | community = fast_create(Community) |
887 | 884 | p2= fast_create(Person) |
888 | 885 | assert !p1.is_a_friend?(p2) |
... | ... | @@ -909,7 +906,7 @@ class ProfileControllerTest < ActionController::TestCase |
909 | 906 | end |
910 | 907 | |
911 | 908 | should 'the self activity not crashes with user not logged in' do |
912 | - p1= Person.first | |
909 | + p1= fast_create(Person) | |
913 | 910 | p2= fast_create(Person) |
914 | 911 | assert !p1.is_a_friend?(p2) |
915 | 912 | p3= fast_create(Person) |
... | ... | @@ -953,7 +950,7 @@ class ProfileControllerTest < ActionController::TestCase |
953 | 950 | end |
954 | 951 | |
955 | 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 | 954 | p2 = fast_create(Person) |
958 | 955 | p3 = fast_create(Person) |
959 | 956 | s1 = fast_create(Scrap, :sender_id => p1.id, :receiver_id => p2.id) |
... | ... | @@ -990,7 +987,7 @@ class ProfileControllerTest < ActionController::TestCase |
990 | 987 | end |
991 | 988 | |
992 | 989 | should 'the activities be paginated in people profiles' do |
993 | - p1 = Person.first | |
990 | + p1= fast_create(Person) | |
994 | 991 | 40.times{fast_create(Scrap, :receiver_id => p1.id, :created_at => Time.now)} |
995 | 992 | |
996 | 993 | @controller.stubs(:logged_in?).returns(true) |
... | ... | @@ -1005,7 +1002,7 @@ class ProfileControllerTest < ActionController::TestCase |
1005 | 1002 | end |
1006 | 1003 | |
1007 | 1004 | should 'the activities be paginated in community profiles' do |
1008 | - p1 = Person.first | |
1005 | + p1= fast_create(Person) | |
1009 | 1006 | c = fast_create(Community) |
1010 | 1007 | 40.times{fast_create(Scrap, :receiver_id => c.id)} |
1011 | 1008 | |
... | ... | @@ -1383,17 +1380,23 @@ class ProfileControllerTest < ActionController::TestCase |
1383 | 1380 | assert_equal "Comment successfully added.", assigns(:message) |
1384 | 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 | 1384 | UserStampSweeper.any_instance.stubs(:current_user).returns(profile) |
1388 | 1385 | article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software') |
1389 | 1386 | to_be_removed = create_user('removed_user').person |
1390 | 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 | 1388 | to_be_removed.destroy |
1392 | 1389 | |
1390 | + activity = ActionTracker::Record.last | |
1391 | + | |
1392 | + activity = ActionTracker::Record.last | |
1393 | + | |
1393 | 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 | 1400 | end |
1398 | 1401 | |
1399 | 1402 | should 'not display spam comments in wall' do |
... | ... | @@ -1407,7 +1410,7 @@ class ProfileControllerTest < ActionController::TestCase |
1407 | 1410 | assert !/This article makes me hungry/.match(@response.body), 'Spam comment was shown!' |
1408 | 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 | 1414 | UserStampSweeper.any_instance.stubs(:current_user).returns(profile) |
1412 | 1415 | article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software') |
1413 | 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 < ActionController::TestCase |
1415 | 1418 | login_as(profile.identifier) |
1416 | 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 | 1429 | end |
1420 | 1430 | |
1421 | 1431 | should 'add locale on mailing' do | ... | ... |