Commit 8bef50d2a64f3cfeefdc33bd63180dfa194f1648
1 parent
8d58c842
Exists in
master
and in
29 other branches
search-optimizations: fix broken tests
Showing
11 changed files
with
60 additions
and
37 deletions
Show diff stats
app/models/profile.rb
... | ... | @@ -608,10 +608,10 @@ private :generate_url, :url_options |
608 | 608 | # Adds a person as member of this Profile. |
609 | 609 | def add_member(person) |
610 | 610 | if self.has_members? |
611 | - if self.closed? && members_count > 0 | |
611 | + if self.closed? && members.count > 0 | |
612 | 612 | AddMember.create!(:person => person, :organization => self) unless self.already_request_membership?(person) |
613 | 613 | else |
614 | - self.affiliate(person, Profile::Roles.admin(environment.id)) if members_count == 0 | |
614 | + self.affiliate(person, Profile::Roles.admin(environment.id)) if members.count == 0 | |
615 | 615 | self.affiliate(person, Profile::Roles.member(environment.id)) |
616 | 616 | end |
617 | 617 | else | ... | ... |
test/functional/invite_controller_test.rb
... | ... | @@ -230,7 +230,8 @@ class InviteControllerTest < ActionController::TestCase |
230 | 230 | |
231 | 231 | contact_list = ContactList.create |
232 | 232 | post :select_friends, :profile => profile.identifier, :manual_import_addresses => "#{friend.name} <#{friend.email}>", :import_from => "manual", :mail_template => "click: <url>", :contact_list => contact_list.id |
233 | - assert_equal 'pt', Delayed::Job.first.payload_object.locale | |
233 | + job = Delayed::Job.where("handler LIKE '%InvitationJob%'").first | |
234 | + assert_equal 'pt', job.payload_object.locale | |
234 | 235 | end |
235 | 236 | |
236 | 237 | private | ... | ... |
test/functional/profile_controller_test.rb
... | ... | @@ -766,23 +766,28 @@ class ProfileControllerTest < ActionController::TestCase |
766 | 766 | end |
767 | 767 | |
768 | 768 | should 'see all the activities in the current profile network' do |
769 | - p1= Person.first | |
769 | + p1= fast_create(Person) | |
770 | 770 | p2= fast_create(Person) |
771 | 771 | assert !p1.is_a_friend?(p2) |
772 | + | |
772 | 773 | p3= fast_create(Person) |
773 | 774 | p3.add_friend(p1) |
774 | 775 | assert p3.is_a_friend?(p1) |
775 | - ActionTracker::Record.destroy_all | |
776 | + | |
777 | + ActionTracker::Record.delete_all | |
778 | + | |
779 | + UserStampSweeper.any_instance.stubs(:current_user).returns(p1) | |
776 | 780 | Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p1)) |
777 | 781 | a1 = ActionTracker::Record.last |
782 | + | |
778 | 783 | UserStampSweeper.any_instance.stubs(:current_user).returns(p2) |
779 | 784 | Scrap.create!(defaults_for_scrap(:sender => p2, :receiver => p3)) |
780 | 785 | a2 = ActionTracker::Record.last |
786 | + | |
781 | 787 | UserStampSweeper.any_instance.stubs(:current_user).returns(p3) |
782 | 788 | Scrap.create!(defaults_for_scrap(:sender => p3, :receiver => p1)) |
783 | 789 | a3 = ActionTracker::Record.last |
784 | 790 | |
785 | - | |
786 | 791 | @controller.stubs(:logged_in?).returns(true) |
787 | 792 | user = mock() |
788 | 793 | user.stubs(:person).returns(p3) |
... | ... | @@ -792,24 +797,29 @@ class ProfileControllerTest < ActionController::TestCase |
792 | 797 | |
793 | 798 | process_delayed_job_queue |
794 | 799 | get :index, :profile => p1.identifier |
795 | - assert_not_nil assigns(:network_activities) | |
796 | - assert_equal [], [a1,a3] - assigns(:network_activities) | |
797 | - assert_equal assigns(:network_activities) - [a1, a3], [] | |
800 | + | |
801 | + assert_equivalent [a1,a3].map(&:id), assigns(:network_activities).map(&:id) | |
798 | 802 | end |
799 | 803 | |
800 | 804 | should 'the network activity be visible only to profile followers' do |
801 | - p1= Person.first | |
805 | + p1= fast_create(Person) | |
802 | 806 | p2= fast_create(Person) |
803 | 807 | assert !p1.is_a_friend?(p2) |
808 | + | |
804 | 809 | p3= fast_create(Person) |
805 | 810 | p3.add_friend(p1) |
806 | 811 | assert p3.is_a_friend?(p1) |
807 | - ActionTracker::Record.destroy_all | |
812 | + | |
813 | + ActionTracker::Record.delete_all | |
814 | + | |
815 | + UserStampSweeper.any_instance.stubs(:current_user).returns(p1) | |
808 | 816 | Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p1)) |
809 | 817 | a1 = ActionTracker::Record.last |
818 | + | |
810 | 819 | UserStampSweeper.any_instance.stubs(:current_user).returns(p2) |
811 | 820 | Scrap.create!(defaults_for_scrap(:sender => p2, :receiver => p3)) |
812 | 821 | a2 = ActionTracker::Record.last |
822 | + | |
813 | 823 | UserStampSweeper.any_instance.stubs(:current_user).returns(p3) |
814 | 824 | Scrap.create!(defaults_for_scrap(:sender => p3, :receiver => p1)) |
815 | 825 | a3 = ActionTracker::Record.last |
... | ... | @@ -819,8 +829,9 @@ class ProfileControllerTest < ActionController::TestCase |
819 | 829 | user.stubs(:person).returns(p2) |
820 | 830 | user.stubs(:login).returns('some') |
821 | 831 | @controller.stubs(:current_user).returns(user) |
832 | + | |
822 | 833 | get :index, :profile => p1.identifier |
823 | - assert_equal [], assigns(:network_activities) | |
834 | + assert assigns(:network_activities).blank? | |
824 | 835 | |
825 | 836 | user = mock() |
826 | 837 | user.stubs(:person).returns(p3) |
... | ... | @@ -828,9 +839,9 @@ class ProfileControllerTest < ActionController::TestCase |
828 | 839 | @controller.stubs(:current_user).returns(user) |
829 | 840 | Person.any_instance.stubs(:follows?).returns(true) |
830 | 841 | process_delayed_job_queue |
842 | + | |
831 | 843 | get :index, :profile => p3.identifier |
832 | - assert_equal [], [a1,a3] - assigns(:network_activities) | |
833 | - assert_equal assigns(:network_activities) - [a1, a3], [] | |
844 | + assert_equivalent [a1,a3], assigns(:network_activities) | |
834 | 845 | end |
835 | 846 | |
836 | 847 | should 'the network activity be paginated' do | ... | ... |
test/functional/search_controller_test.rb
... | ... | @@ -549,9 +549,9 @@ class SearchControllerTest < ActionController::TestCase |
549 | 549 | c2 = create(Community, :name => 'Testing community 2') |
550 | 550 | c3 = create(Community, :name => 'Testing community 3') |
551 | 551 | ActionTracker::Record.delete_all |
552 | - fast_create(ActionTracker::Record, :target_id => c1, :user_type => 'Profile', :user_id => person, :created_at => Time.now) | |
553 | - fast_create(ActionTracker::Record, :target_id => c2, :user_type => 'Profile', :user_id => person, :created_at => Time.now) | |
554 | - fast_create(ActionTracker::Record, :target_id => c2, :user_type => 'Profile', :user_id => person, :created_at => Time.now) | |
552 | + ActionTracker::Record.create!(:target => c1, :user => person, :created_at => Time.now, :verb => 'leave_scrap') | |
553 | + ActionTracker::Record.create!(:target => c2, :user => person, :created_at => Time.now, :verb => 'leave_scrap') | |
554 | + ActionTracker::Record.create!(:target => c2, :user => person, :created_at => Time.now, :verb => 'leave_scrap') | |
555 | 555 | get :communities, :filter => 'more_active' |
556 | 556 | assert_equal [c2,c1,c3] , assigns(:searches)[:communities][:results] |
557 | 557 | end | ... | ... |
test/unit/action_tracker_ext_test.rb
... | ... | @@ -12,6 +12,7 @@ class ActionTrackerExtTest < ActiveSupport::TestCase |
12 | 12 | should 'decrease person activities_count on activity removal' do |
13 | 13 | person = fast_create(Person) |
14 | 14 | record = ActionTracker::Record.create! :verb => :leave_scrap, :user => person, :target => fast_create(Profile) |
15 | + person.reload | |
15 | 16 | assert_difference person, :activities_count, -1 do |
16 | 17 | record.destroy |
17 | 18 | person.reload |
... | ... | @@ -23,6 +24,7 @@ class ActionTrackerExtTest < ActiveSupport::TestCase |
23 | 24 | record = ActionTracker::Record.create! :verb => :leave_scrap, :user => person, :target => fast_create(Profile) |
24 | 25 | record.created_at = record.created_at - ActionTracker::Record::RECENT_DELAY.days - 1.day |
25 | 26 | record.save! |
27 | + person.reload | |
26 | 28 | assert_no_difference person, :activities_count do |
27 | 29 | record.destroy |
28 | 30 | person.reload |
... | ... | @@ -42,6 +44,7 @@ class ActionTrackerExtTest < ActiveSupport::TestCase |
42 | 44 | person = fast_create(Person) |
43 | 45 | organization = fast_create(Organization) |
44 | 46 | record = ActionTracker::Record.create! :verb => :leave_scrap, :user => person, :target => organization |
47 | + organization.reload | |
45 | 48 | assert_difference organization, :activities_count, -1 do |
46 | 49 | record.destroy |
47 | 50 | organization.reload |
... | ... | @@ -52,6 +55,7 @@ class ActionTrackerExtTest < ActiveSupport::TestCase |
52 | 55 | person = fast_create(Person) |
53 | 56 | organization = fast_create(Organization) |
54 | 57 | record = ActionTracker::Record.create! :verb => :leave_scrap, :user => person, :target => organization, :created_at => (ActionTracker::Record::RECENT_DELAY + 1).days.ago |
58 | + organization.reload | |
55 | 59 | assert_no_difference organization, :activities_count do |
56 | 60 | record.destroy |
57 | 61 | organization.reload | ... | ... |
test/unit/activities_counter_cache_job_test.rb
... | ... | @@ -6,6 +6,7 @@ class ActivitiesCounterCacheJobTest < ActiveSupport::TestCase |
6 | 6 | person = create_user('person').person |
7 | 7 | ActionTracker::Record.create!(:user => person, :verb => 'create_article') |
8 | 8 | ActionTracker::Record.create!(:user => person, :verb => 'create_article') |
9 | + person.reload | |
9 | 10 | assert_equal 2, person.activities_count |
10 | 11 | |
11 | 12 | person.activities_count = 0 |
... | ... | @@ -21,6 +22,7 @@ class ActivitiesCounterCacheJobTest < ActiveSupport::TestCase |
21 | 22 | organization = Organization.create!(:name => 'Organization1', :identifier => 'organization1') |
22 | 23 | ActionTracker::Record.create!(:user => person, :verb => 'create_article', :target => organization) |
23 | 24 | ActionTracker::Record.create!(:user => person, :verb => 'create_article', :target => organization) |
25 | + organization.reload | |
24 | 26 | assert_equal 2, organization.activities_count |
25 | 27 | |
26 | 28 | organization.activities_count = 0 | ... | ... |
test/unit/article_test.rb
... | ... | @@ -1625,10 +1625,10 @@ class ArticleTest < ActiveSupport::TestCase |
1625 | 1625 | |
1626 | 1626 | should 'not allow all community members to edit by default' do |
1627 | 1627 | community = fast_create(Community) |
1628 | - admin = create_user('community-admin').person | |
1629 | - member = create_user.person | |
1630 | - | |
1628 | + admin = fast_create(Person) | |
1629 | + member = fast_create(Person) | |
1631 | 1630 | community.add_admin(admin) |
1631 | + community.reload | |
1632 | 1632 | community.add_member(member) |
1633 | 1633 | a = Article.new(:profile => community) |
1634 | 1634 | ... | ... |
test/unit/organization_mailing_test.rb
... | ... | @@ -62,18 +62,21 @@ class OrganizationMailingTest < ActiveSupport::TestCase |
62 | 62 | |
63 | 63 | should 'deliver mailing to each member after create' do |
64 | 64 | mailing = OrganizationMailing.create(:source => community, :subject => 'Hello', :body => 'We have some news', :person => person) |
65 | + community.reload | |
65 | 66 | process_delayed_job_queue |
66 | 67 | assert_equal 2, ActionMailer::Base.deliveries.count |
67 | 68 | end |
68 | 69 | |
69 | 70 | should 'deliver mailing when there are many mailings created' do |
70 | 71 | 50.times { OrganizationMailing.create(:source => community, :subject => 'Hello', :body => 'We have some news', :person => person) } |
72 | + community.reload | |
71 | 73 | process_delayed_job_queue |
72 | 74 | assert_equal 50*community.members_count, ActionMailer::Base.deliveries.count |
73 | 75 | end |
74 | 76 | |
75 | 77 | should 'create mailing sent to each recipient after delivering mailing' do |
76 | 78 | mailing = OrganizationMailing.create(:source => community, :subject => 'Hello', :body => 'We have some news', :person => person) |
79 | + community.reload | |
77 | 80 | assert_difference MailingSent, :count, 2 do |
78 | 81 | process_delayed_job_queue |
79 | 82 | end | ... | ... |
test/unit/person_test.rb
... | ... | @@ -407,11 +407,11 @@ class PersonTest < ActiveSupport::TestCase |
407 | 407 | admin = fast_create(Person) |
408 | 408 | community.add_member(admin) |
409 | 409 | member = fast_create(Person) |
410 | + community.reload | |
410 | 411 | community.add_member(member) |
411 | 412 | community.tasks << Task.new |
412 | 413 | |
413 | - | |
414 | - assert_not_includes Person.with_pending_tasks, person | |
414 | + assert_not_includes Person.with_pending_tasks, member | |
415 | 415 | end |
416 | 416 | |
417 | 417 | should 'person has organization pending tasks' do |
... | ... | @@ -641,17 +641,16 @@ class PersonTest < ActiveSupport::TestCase |
641 | 641 | end |
642 | 642 | |
643 | 643 | should 'find more popular people' do |
644 | + extend CacheCounterHelper | |
645 | + | |
644 | 646 | Person.delete_all |
645 | 647 | p1 = fast_create(Person) |
646 | 648 | p2 = fast_create(Person) |
647 | 649 | p3 = fast_create(Person) |
648 | 650 | |
649 | - p1.friends_count = 1 | |
650 | - p2.friends_count = 2 | |
651 | - p3.friends_count = 3 | |
652 | - p1.save! | |
653 | - p2.save! | |
654 | - p3.save! | |
651 | + update_cache_counter(:friends_count, p1, 1) | |
652 | + update_cache_counter(:friends_count, p2, 2) | |
653 | + update_cache_counter(:friends_count, p3, 3) | |
655 | 654 | |
656 | 655 | assert_order [p3, p2, p1], Person.more_popular |
657 | 656 | end |
... | ... | @@ -893,6 +892,7 @@ class PersonTest < ActiveSupport::TestCase |
893 | 892 | p1 = fast_create(Person) |
894 | 893 | p2 = fast_create(Person) |
895 | 894 | p3 = fast_create(Person) |
895 | + p4 = fast_create(Person) | |
896 | 896 | |
897 | 897 | community.add_member(p1) |
898 | 898 | assert p1.is_member_of?(community) |
... | ... | @@ -1136,12 +1136,12 @@ class PersonTest < ActiveSupport::TestCase |
1136 | 1136 | p3 = fast_create(Person) |
1137 | 1137 | |
1138 | 1138 | ActionTracker::Record.destroy_all |
1139 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p1) | |
1140 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2) | |
1141 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p2) | |
1142 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p3) | |
1143 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p3) | |
1144 | - fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => p3) | |
1139 | + ActionTracker::Record.create!(:user => p1, :verb => 'leave_scrap') | |
1140 | + ActionTracker::Record.create!(:user => p2, :verb => 'leave_scrap') | |
1141 | + ActionTracker::Record.create!(:user => p2, :verb => 'leave_scrap') | |
1142 | + ActionTracker::Record.create!(:user => p3, :verb => 'leave_scrap') | |
1143 | + ActionTracker::Record.create!(:user => p3, :verb => 'leave_scrap') | |
1144 | + ActionTracker::Record.create!(:user => p3, :verb => 'leave_scrap') | |
1145 | 1145 | |
1146 | 1146 | assert_order [p3,p2,p1] , Person.more_active |
1147 | 1147 | end | ... | ... |
test/unit/role_assignment_ext_test.rb
... | ... | @@ -20,6 +20,7 @@ class RoleAssignmentExtTest < ActiveSupport::TestCase |
20 | 20 | organization = Organization.create!(:name => 'Organization', :identifier => 'organization') |
21 | 21 | RoleAssignment.create!(:accessor => member, :resource => organization, :role => role1) |
22 | 22 | RoleAssignment.create!(:accessor => member, :resource => organization, :role => role2) |
23 | + organization.reload | |
23 | 24 | assert_difference organization, :members_count, -1 do |
24 | 25 | organization.role_assignments.destroy_all |
25 | 26 | organization.reload | ... | ... |
test/unit/uploaded_file_test.rb
... | ... | @@ -327,12 +327,13 @@ class UploadedFileTest < ActiveSupport::TestCase |
327 | 327 | |
328 | 328 | should 'group trackers activity of image\'s upload' do |
329 | 329 | gallery = fast_create(Gallery, :profile_id => profile.id) |
330 | - | |
330 | + count = ActionTracker::Record.find_all_by_verb('upload_image').count | |
331 | 331 | image1 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => gallery, :profile => profile) |
332 | - assert_equal 1, ActionTracker::Record.find_all_by_verb('upload_image').count | |
332 | + count += 1 | |
333 | + assert_equal count, ActionTracker::Record.find_all_by_verb('upload_image').count | |
333 | 334 | |
334 | 335 | image2 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/other-pic.jpg', 'image/jpg'), :parent => gallery, :profile => profile) |
335 | - assert_equal 1, ActionTracker::Record.find_all_by_verb('upload_image').count | |
336 | + assert_equal count, ActionTracker::Record.find_all_by_verb('upload_image').count | |
336 | 337 | end |
337 | 338 | |
338 | 339 | { | ... | ... |