A platform for community discussion. Free, open, simple.
PERF: Speed up the tests by pre-fabricating more things (#15318)
Daniel Waterworth102fa71ef37d
diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rbindex 4948eb05483..0e723088f25 100644--- a/spec/components/post_creator_spec.rb+++ b/spec/components/post_creator_spec.rb@@ -7,6 +7,8 @@ require 'topic_subtype'describe PostCreator dofab!(:user) { Fabricate(:user) }+ fab!(:coding_horror) { Fabricate(:coding_horror) }+ fab!(:evil_trout) { Fabricate(:evil_trout) }let(:topic) { Fabricate(:topic, user: user) }context "new topic" do@@ -810,7 +812,7 @@ describe PostCreator docontext "topic stats" dobefore doPostCreator.new(- Fabricate(:coding_horror),+ coding_horror,raw: 'first post in topic',topic_id: topic.id,created_at: Time.zone.now - 24.hours@@ -916,7 +918,7 @@ describe PostCreator do# integration test ... minimise db workcontext 'private message' do- let(:target_user1) { Fabricate(:coding_horror) }+ let(:target_user1) { coding_horror }fab!(:target_user2) { Fabricate(:moderator) }fab!(:unrelated_user) { Fabricate(:user) }let(:post) do@@ -1021,7 +1023,7 @@ describe PostCreator doendcontext "warnings" do- let(:target_user1) { Fabricate(:coding_horror) }+ let(:target_user1) { coding_horror }fab!(:target_user2) { Fabricate(:moderator) }let(:base_args) do{ title: 'you need a warning buddy!',@@ -1102,7 +1104,7 @@ describe PostCreator doendcontext 'private message to group' do- let(:target_user1) { Fabricate(:coding_horror) }+ let(:target_user1) { coding_horror }fab!(:target_user2) { Fabricate(:moderator) }let(:group) dog = Fabricate.build(:group, messageable_level: Group::ALIAS_LEVELS[:everyone])@@ -1482,7 +1484,7 @@ describe PostCreator doendcontext "private message to a muted user" do- fab!(:muted_me) { Fabricate(:evil_trout) }+ fab!(:muted_me) { evil_trout }fab!(:another_user) { Fabricate(:user) }it 'should fail' do@@ -1523,7 +1525,7 @@ describe PostCreator doendcontext "private message to an ignored user" do- fab!(:ignorer) { Fabricate(:evil_trout) }+ fab!(:ignorer) { evil_trout }fab!(:another_user) { Fabricate(:user) }context "when post author is ignored" do@@ -1565,7 +1567,7 @@ describe PostCreator doendcontext "private message to user in allow list" do- fab!(:sender) { Fabricate(:evil_trout) }+ fab!(:sender) { evil_trout }fab!(:allowed_user) { Fabricate(:user) }context "when post author is allowed" do@@ -1611,7 +1613,7 @@ describe PostCreator doendcontext "private message to user not in allow list" do- fab!(:sender) { Fabricate(:evil_trout) }+ fab!(:sender) { evil_trout }fab!(:allowed_user) { Fabricate(:user) }fab!(:not_allowed_user) { Fabricate(:user) }@@ -1672,7 +1674,7 @@ describe PostCreator doendcontext "private message to multiple users and one is not allowed" do- fab!(:sender) { Fabricate(:evil_trout) }+ fab!(:sender) { evil_trout }fab!(:allowed_user) { Fabricate(:user) }fab!(:not_allowed_user) { Fabricate(:user) }@@ -1700,8 +1702,8 @@ describe PostCreator doendcontext "private message recipients limit (max_allowed_message_recipients) reached" do- fab!(:target_user1) { Fabricate(:coding_horror) }- fab!(:target_user2) { Fabricate(:evil_trout) }+ fab!(:target_user1) { coding_horror }+ fab!(:target_user2) { evil_trout }fab!(:target_user3) { Fabricate(:walter_white) }before dodiff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rbindex 530df2385ce..51a2bcc538a 100644--- a/spec/components/post_destroyer_spec.rb+++ b/spec/components/post_destroyer_spec.rb@@ -10,6 +10,7 @@ describe PostDestroyer dofab!(:moderator) { Fabricate(:moderator) }fab!(:admin) { Fabricate(:admin) }+ fab!(:coding_horror) { Fabricate(:coding_horror) }let(:post) { create_post }describe "destroy_old_hidden_posts" do@@ -92,7 +93,7 @@ describe PostDestroyer do# flag the post, it should not nuke the stub anymoretopic.recover!- reviewable = PostActionCreator.spam(Fabricate(:coding_horror), reply1).reviewable+ reviewable = PostActionCreator.spam(coding_horror, reply1).reviewablePostDestroyer.destroy_stubs@@ -321,7 +322,7 @@ describe PostDestroyer doenddescribe "recovery and post actions" do- fab!(:codinghorror) { Fabricate(:coding_horror) }+ fab!(:codinghorror) { coding_horror }let!(:like) { PostActionCreator.like(codinghorror, post).post_action }let!(:another_like) { PostActionCreator.like(moderator, post).post_action }@@ -644,7 +645,7 @@ describe PostDestroyer dofab!(:user) { Fabricate(:user) }let!(:post) { create_post(user: user) }let(:topic) { post.topic }- fab!(:second_user) { Fabricate(:coding_horror) }+ fab!(:second_user) { coding_horror }let!(:second_post) { create_post(topic: topic, user: second_user) }before do@@ -777,7 +778,7 @@ describe PostDestroyer dodescribe 'after delete' do- fab!(:coding_horror) { Fabricate(:coding_horror) }+ fab!(:coding_horror) { coding_horror }fab!(:post) { Fabricate(:post, raw: "Hello @CodingHorror") }it "should feature the users again (in case they've changed)" do@@ -930,7 +931,7 @@ describe PostDestroyer doenddescribe "user actions" do- let(:codinghorror) { Fabricate(:coding_horror) }+ let(:codinghorror) { coding_horror }let(:second_post) { Fabricate(:post, topic_id: post.topic_id) }def create_user_action(action_type)diff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rbindex d0c318a2c11..e45e95de338 100644--- a/spec/components/post_revisor_spec.rb+++ b/spec/components/post_revisor_spec.rb@@ -8,6 +8,7 @@ describe PostRevisor dofab!(:topic) { Fabricate(:topic) }fab!(:newuser) { Fabricate(:newuser, last_seen_at: Date.today) }fab!(:user) { Fabricate(:user) }+ fab!(:coding_horror) { Fabricate(:coding_horror) }fab!(:admin) { Fabricate(:admin) }fab!(:moderator) { Fabricate(:moderator) }let(:post_args) { { user: newuser, topic: topic } }@@ -523,7 +524,7 @@ describe PostRevisor doenddescribe 'rate limiter' do- fab!(:changed_by) { Fabricate(:coding_horror) }+ fab!(:changed_by) { coding_horror }before doRateLimiter.enable@@ -618,7 +619,7 @@ describe PostRevisor doSiteSetting.editing_grace_period_max_diff = 1000end- fab!(:changed_by) { Fabricate(:coding_horror) }+ fab!(:changed_by) { coding_horror }let!(:result) { subject.revise!(changed_by, raw: "lets update the body. Здравствуйте") }it 'correctly updates raw' dodiff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rbindex a99cde5c04b..449a5c10433 100644--- a/spec/models/notification_spec.rb+++ b/spec/models/notification_spec.rb@@ -3,6 +3,8 @@require 'rails_helper'describe Notification do+ fab!(:coding_horror) { Fabricate(:coding_horror) }+before doNotificationEmailer.enableend@@ -60,8 +62,6 @@ describe Notification do{ user: topic.user, topic: topic }end- let(:coding_horror) { Fabricate(:coding_horror) }-describe 'replies' dodef process_alerts(post)PostAlerter.post_created(post)@@ -89,7 +89,7 @@ describe Notification dodescribe 'watching' doit "does notify watching users of new posts" dopost = PostAlerter.post_created(Fabricate(:post, post_args))- user2 = Fabricate(:coding_horror)+ user2 = coding_horrorpost_args[:topic].notify_watch!(user2)expect {PostAlerter.post_created(Fabricate(:post, user: post.user, topic: post.topic))@@ -101,7 +101,7 @@ describe Notification doit "does not notify users of new posts" dopost = Fabricate(:post, post_args)user = post_args[:user]- user2 = Fabricate(:coding_horror)+ user2 = coding_horrorpost_args[:topic].notify_muted!(user)expect {diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rbindex ccd9e20481c..84475ff147e 100644--- a/spec/models/post_spec.rb+++ b/spec/models/post_spec.rb@@ -3,6 +3,8 @@require 'rails_helper'describe Post do+ fab!(:coding_horror) { Fabricate(:coding_horror) }+before { Oneboxer.stubs :onebox }let(:upload_path) { Discourse.store.upload_path }@@ -195,7 +197,7 @@ describe Post dodescribe 'flagging helpers' dofab!(:post) { Fabricate(:post) }- fab!(:user) { Fabricate(:coding_horror) }+ fab!(:user) { coding_horror }fab!(:admin) { Fabricate(:admin) }it 'is_flagged? is accurate' do@@ -736,7 +738,7 @@ describe Post doenddescribe 'rate limiter' do- let(:changed_by) { Fabricate(:coding_horror) }+ let(:changed_by) { coding_horror }it "triggers a rate limiter" doEditRateLimiter.any_instance.expects(:performed!)@@ -745,7 +747,7 @@ describe Post doenddescribe 'with a new body' do- let(:changed_by) { Fabricate(:coding_horror) }+ let(:changed_by) { coding_horror }let!(:result) { post.revise(changed_by, raw: 'updated body') }it 'acts correctly' do@@ -836,7 +838,7 @@ describe Post dodescribe 'a new reply' dofab!(:topic) { Fabricate(:topic) }- let(:other_user) { Fabricate(:coding_horror) }+ let(:other_user) { coding_horror }let(:reply_text) { "[quote=\"Evil Trout, post:1\"]\nhello\n[/quote]\nHmmm!" }let!(:post) { PostCreator.new(topic.user, raw: Fabricate.build(:post).raw, topic_id: topic.id).create }let!(:reply) { PostCreator.new(other_user, raw: reply_text, topic_id: topic.id, reply_to_post_number: post.post_number).create }@@ -1232,7 +1234,6 @@ describe Post dodescribe "#set_owner" dofab!(:post) { Fabricate(:post) }- fab!(:coding_horror) { Fabricate(:coding_horror) }it "will change owner of a post correctly" dopost.set_owner(coding_horror, Discourse.system_user)diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rbindex 75131283913..17c06689060 100644--- a/spec/models/topic_spec.rb+++ b/spec/models/topic_spec.rb@@ -6,7 +6,11 @@ require 'rails_helper'describe Topic dolet(:now) { Time.zone.local(2013, 11, 20, 8, 0) }fab!(:user) { Fabricate(:user) }+ fab!(:moderator) { Fabricate(:moderator) }+ fab!(:coding_horror) { Fabricate(:coding_horror) }+ fab!(:evil_trout) { Fabricate(:evil_trout) }fab!(:admin) { Fabricate(:admin) }+ fab!(:group) { Fabricate(:group) }fab!(:another_user) { Fabricate(:user) }fab!(:trust_level_2) { Fabricate(:user, trust_level: SiteSetting.min_trust_level_to_allow_invite) }@@ -262,8 +266,8 @@ describe Topic doendcontext 'topic title uniqueness' do- let!(:category1) { Fabricate(:category) }- let!(:category2) { Fabricate(:category) }+ fab!(:category1) { Fabricate(:category) }+ fab!(:category2) { Fabricate(:category) }let!(:topic) { Fabricate(:topic, category: category1) }let(:new_topic) { Fabricate.build(:topic, title: topic.title, category: category1) }@@ -849,8 +853,6 @@ describe Topic doenddescribe 'when topic belongs to a private category' do- fab!(:group) { Fabricate(:group) }-fab!(:category) doFabricate(:category_with_definition, groups: [group]).tap do |category|category.set_permissions(group => :full)@@ -932,8 +934,6 @@ describe Topic doendcontext 'private message' do- let(:coding_horror) { Fabricate(:coding_horror) }- fab!(:evil_trout) { Fabricate(:evil_trout) }let(:topic) doPostCreator.new(Fabricate(:user),@@ -957,8 +957,6 @@ describe Topic docontext 'existing user' docontext 'by group name' do- fab!(:group) { Fabricate(:group) }-it 'can add admin to allowed groups' doadmins = Group[:admins]admins.update!(messageable_level: Group::ALIAS_LEVELS[:everyone])@@ -1123,21 +1121,21 @@ describe Topic doit "bumps the topic when a new version is made of the last post" doexpect {- @last_post.revise(Fabricate(:moderator), raw: 'updated contents')+ @last_post.revise(moderator, raw: 'updated contents')topic.reload}.to change(topic, :bumped_at)endit "doesn't bump the topic when a post that isn't the last post receives a new version" doexpect {- @earlier_post.revise(Fabricate(:moderator), raw: 'updated contents')+ @earlier_post.revise(moderator, raw: 'updated contents')topic.reload}.not_to change(topic, :bumped_at)endit "doesn't bump the topic when a post have invalid topic title while edit" doexpect {- @last_post.revise(Fabricate(:moderator), title: 'invalid title')+ @last_post.revise(moderator, title: 'invalid title')topic.reload}.not_to change(topic, :bumped_at)end@@ -1145,7 +1143,6 @@ describe Topic doendcontext 'moderator posts' do- fab!(:moderator) { Fabricate(:moderator) }fab!(:topic) { Fabricate(:topic) }it 'creates a moderator post' do@@ -1340,7 +1337,6 @@ describe Topic doit_behaves_like 'a status that closes a topic'it 'should archive group message' do- group = Fabricate(:group)group.add(@user)topic = Fabricate(:private_message_topic, allowed_groups: [group])@@ -1474,7 +1470,7 @@ describe Topic docontext 'after a second post' dobefore do- @second_user = Fabricate(:coding_horror)+ @second_user = coding_horror@new_post = create_post(topic: @topic, user: @second_user)@topic.reloadend@@ -2173,7 +2169,6 @@ describe Topic doit 'should return the right topics' docategory = Fabricate(:category_with_definition, read_restricted: true)topic = Fabricate(:topic, category: category, created_at: 1.day.ago)- group = Fabricate(:group)user = Fabricate(:user)group.add(user)private_category = Fabricate(:private_category_with_definition, group: group)@@ -2189,7 +2184,6 @@ describe Topic doenddescribe 'all_allowed_users' do- fab!(:group) { Fabricate(:group) }fab!(:topic) { Fabricate(:topic, allowed_groups: [group]) }fab!(:allowed_user) { Fabricate(:user) }fab!(:allowed_group_user) { Fabricate(:user) }@@ -2274,7 +2268,6 @@ describe Topic dodescribe 'trash!' docontext "its category's topic count" do- fab!(:moderator) { Fabricate(:moderator) }fab!(:category) { Fabricate(:category_with_definition) }it "subtracts 1 if topic is being deleted" do@@ -2482,7 +2475,6 @@ describe Topic doexpect(topic.message_archived?(user)).to eq(false)- group = Fabricate(:group)group2 = Fabricate(:group)group.add(user)diff --git a/spec/models/user_action_spec.rb b/spec/models/user_action_spec.rbindex d1d781fd880..efc053952b6 100644--- a/spec/models/user_action_spec.rb+++ b/spec/models/user_action_spec.rb@@ -3,6 +3,7 @@require 'rails_helper'describe UserAction do+ fab!(:coding_horror) { Fabricate(:coding_horror) }before doUserActionManager.enable@@ -91,7 +92,7 @@ describe UserAction doexpect(stream).to eq([])group = Fabricate(:group)- u = Fabricate(:coding_horror)+ u = coding_horrorgroup.add(u)category.set_permissions(group => :full)@@ -167,7 +168,7 @@ describe UserAction dofab!(:post) { Fabricate(:post) }let(:likee) { post.user }- fab!(:liker) { Fabricate(:coding_horror) }+ fab!(:liker) { coding_horror }def likee_streamUserAction.stream(user_id: likee.id, guardian: Guardian.new)@@ -257,7 +258,7 @@ describe UserAction dodescribe 'when another user posts on the topic' dobefore do- @other_user = Fabricate(:coding_horror)+ @other_user = coding_horror@mentioned = Fabricate(:admin)@response = PostCreator.new(@other_user, reply_to_post_number: 1, topic_id: @post.topic_id, raw: "perhaps @#{@mentioned.username} knows how this works?").creatediff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rbindex 564503d6b3f..26db9bf921d 100644--- a/spec/models/user_spec.rb+++ b/spec/models/user_spec.rb@@ -3,6 +3,8 @@require 'rails_helper'describe User do+ fab!(:group) { Fabricate(:group) }+let(:user) { Fabricate(:user, last_seen_at: 1.day.ago) }def user_error_message(*keys)@@ -28,7 +30,6 @@ describe User dodescribe 'when group with a same name already exists' doit 'should not be valid' do- group = Fabricate(:group)new_user = Fabricate.build(:user, username: group.name.upcase)expect(new_user).to_not be_valid@@ -152,7 +153,7 @@ describe User doendcontext '.enqueue_welcome_message' do- let(:user) { Fabricate(:user) }+ fab!(:user) { Fabricate(:user) }it 'enqueues the system message' doSiteSetting.send_welcome_message = true@@ -172,7 +173,7 @@ describe User doendcontext 'enqueue_staff_welcome_message' do- let!(:first_admin) { Fabricate(:admin) }+ fab!(:first_admin) { Fabricate(:admin) }let(:user) { Fabricate(:user) }it 'enqueues message for admin' do@@ -261,7 +262,7 @@ describe User doenddescribe 'bookmark' do- before do+ before_all do@post = Fabricate(:post)end@@ -286,7 +287,7 @@ describe User doenddescribe 'delete posts in batches' do- before do+ before_all do@post1 = Fabricate(:post)@user = @post1.user@post2 = Fabricate(:post, topic: @post1.topic, user: @user)@@ -486,7 +487,7 @@ describe User doenddescribe 'email_hash' do- before do+ before_all do@user = Fabricate(:user)end@@ -652,7 +653,7 @@ describe User doenddescribe 'username uniqueness' do- before do+ before_all do@user = Fabricate.build(:user)@user.save!@codinghorror = Fabricate.build(:coding_horror)@@ -934,7 +935,7 @@ describe User doenddescribe "update_last_seen!" do- let(:user) { Fabricate(:user) }+ fab!(:user) { Fabricate(:user) }let!(:first_visit_date) { Time.zone.now }let!(:second_visit_date) { 2.hours.from_now }@@ -1092,10 +1093,10 @@ describe User dodescribe "flag_linked_posts_as_spam" dofab!(:user) { Fabricate(:user) }- let!(:admin) { Fabricate(:admin) }- let!(:post) { PostCreator.new(user, title: "this topic contains spam", raw: "this post has a link: http://discourse.org").create }- let!(:another_post) { PostCreator.new(user, title: "this topic also contains spam", raw: "this post has a link: http://discourse.org/asdfa").create }- let!(:post_without_link) { PostCreator.new(user, title: "this topic shouldn't be spam", raw: "this post has no links in it.").create }+ fab!(:admin) { Fabricate(:admin) }+ fab!(:post) { PostCreator.new(user, title: "this topic contains spam", raw: "this post has a link: http://discourse.org").create }+ fab!(:another_post) { PostCreator.new(user, title: "this topic also contains spam", raw: "this post has a link: http://discourse.org/asdfa").create }+ fab!(:post_without_link) { PostCreator.new(user, title: "this topic shouldn't be spam", raw: "this post has no links in it.").create }it "has flagged all the user's posts as spam" douser.flag_linked_posts_as_spam@@ -1366,7 +1367,7 @@ describe User dodescribe "update_posts_read!" docontext "with a UserVisit record" do- let!(:user) { Fabricate(:user) }+ fab!(:user) { Fabricate(:user) }let!(:now) { Time.zone.now }before { user.update_last_seen!(now) }after do@@ -1390,14 +1391,13 @@ describe User doenddescribe "primary_group_id" do- let!(:user) { Fabricate(:user) }+ fab!(:user) { Fabricate(:user) }it "has no primary_group_id by default" doexpect(user.primary_group_id).to eq(nil)endcontext "when the user has a group" do- let!(:group) { Fabricate(:group) }before dogroup.usernames = user.username@@ -1470,12 +1470,12 @@ describe User doenddescribe "#purge_unactivated" do- let!(:user) { Fabricate(:user) }- let!(:unactivated) { Fabricate(:user, active: false) }- let!(:unactivated_old) { Fabricate(:user, active: false, created_at: 1.month.ago) }- let!(:unactivated_old_with_system_pm) { Fabricate(:user, active: false, created_at: 2.months.ago) }- let!(:unactivated_old_with_human_pm) { Fabricate(:user, active: false, created_at: 2.months.ago) }- let!(:unactivated_old_with_post) { Fabricate(:user, active: false, created_at: 1.month.ago) }+ fab!(:user) { Fabricate(:user) }+ fab!(:unactivated) { Fabricate(:user, active: false) }+ fab!(:unactivated_old) { Fabricate(:user, active: false, created_at: 1.month.ago) }+ fab!(:unactivated_old_with_system_pm) { Fabricate(:user, active: false, created_at: 2.months.ago) }+ fab!(:unactivated_old_with_human_pm) { Fabricate(:user, active: false, created_at: 2.months.ago) }+ fab!(:unactivated_old_with_post) { Fabricate(:user, active: false, created_at: 1.month.ago) }before doPostCreator.new(Discourse.system_user,@@ -1540,7 +1540,7 @@ describe User dodescribe "automatic group membership" do- let!(:group) {+ fab!(:group) {Fabricate(:group,automatic_membership_email_domains: "bar.com|wat.com",grant_trust_level: 1,@@ -1599,10 +1599,9 @@ describe User dodescribe 'staff info' dofab!(:user) { Fabricate(:user) }+ fab!(:moderator) { Fabricate(:moderator) }describe "#number_of_flags_given" do- fab!(:moderator) { Fabricate(:moderator) }-it "doesn't count disagreed flags" dopost_agreed = Fabricate(:post)PostActionCreator.inappropriate(user, post_agreed).reviewable.perform(moderator, :agree_and_keep)@@ -1618,8 +1617,6 @@ describe User doenddescribe "number_of_deleted_posts" do- fab!(:moderator) { Fabricate(:moderator) }-it "counts all the posts" do# at least 1 "unchanged" postFabricate(:post, user: user)@@ -1841,7 +1838,7 @@ describe User dodescribe ".clear_global_notice_if_needed" dofab!(:user) { Fabricate(:user) }- let(:admin) { Fabricate(:admin) }+ fab!(:admin) { Fabricate(:admin) }before doSiteSetting.has_login_hint = true@@ -2449,9 +2446,9 @@ describe User doenddescribe 'Granting admin or moderator status' do- it 'approves the associated reviewable when granting admin status' do- reviewable_user = Fabricate(:reviewable_user)+ fab!(:reviewable_user) { Fabricate(:reviewable_user) }+ it 'approves the associated reviewable when granting admin status' doreviewable_user.target.grant_admin!expect(reviewable_user.reload.status).to eq Reviewable.statuses[:approved]@@ -2467,8 +2464,6 @@ describe User doendit 'approves the associated reviewable when granting moderator status' do- reviewable_user = Fabricate(:reviewable_user)-reviewable_user.target.grant_moderation!expect(reviewable_user.reload.status).to eq Reviewable.statuses[:approved]diff --git a/spec/requests/admin/users_controller_spec.rb b/spec/requests/admin/users_controller_spec.rbindex 19b41802705..9c2b249d339 100644--- a/spec/requests/admin/users_controller_spec.rb+++ b/spec/requests/admin/users_controller_spec.rb@@ -7,6 +7,7 @@ require 'rotp'RSpec.describe Admin::UsersController dofab!(:admin) { Fabricate(:admin) }fab!(:user) { Fabricate(:user) }+ fab!(:coding_horror) { Fabricate(:coding_horror) }it 'is a subclass of AdminController' doexpect(Admin::UsersController < Admin::AdminController).to eq(true)@@ -339,7 +340,7 @@ RSpec.describe Admin::UsersController doenddescribe '#grant_admin' do- fab!(:another_user) { Fabricate(:coding_horror) }+ fab!(:another_user) { coding_horror }after doDiscourse.redis.flushdb@@ -462,7 +463,10 @@ RSpec.describe Admin::UsersController doenddescribe '#trust_level' do- fab!(:another_user) { Fabricate(:coding_horror, created_at: 1.month.ago) }+ fab!(:another_user) {+ coding_horror.update!(created_at: 1.month.ago)+ coding_horror+ }it "raises an error when the user doesn't have permission" dosign_in(user)@@ -509,7 +513,7 @@ RSpec.describe Admin::UsersController doenddescribe '#grant_moderation' do- fab!(:another_user) { Fabricate(:coding_horror) }+ fab!(:another_user) { coding_horror }it "raises an error when the user doesn't have permission" dosign_in(user)@@ -570,7 +574,7 @@ RSpec.describe Admin::UsersController dodescribe '#primary_group' dofab!(:group) { Fabricate(:group) }- fab!(:another_user) { Fabricate(:coding_horror) }+ fab!(:another_user) { coding_horror }fab!(:another_group) { Fabricate(:group, title: 'New') }it "raises an error when the user doesn't have permission" dodiff --git a/spec/requests/post_actions_controller_spec.rb b/spec/requests/post_actions_controller_spec.rbindex f2b8d60dd8d..cfc829e7d06 100644--- a/spec/requests/post_actions_controller_spec.rb+++ b/spec/requests/post_actions_controller_spec.rb@@ -3,8 +3,11 @@require 'rails_helper'RSpec.describe PostActionsController do+ fab!(:user) { Fabricate(:user) }+ fab!(:coding_horror) { Fabricate(:coding_horror) }+describe '#destroy' do- fab!(:post) { Fabricate(:post, user: Fabricate(:coding_horror)) }+ fab!(:post) { Fabricate(:post, user: coding_horror) }it 'requires you to be logged in' dodelete "/post_actions/#{post.id}.json"@@ -12,8 +15,6 @@ RSpec.describe PostActionsController doendcontext 'logged in' do- fab!(:user) { Fabricate(:user) }-before dosign_in(user)end@@ -81,8 +82,8 @@ RSpec.describe PostActionsController doendit 'fails when the user does not have permission to see the post' do- sign_in(Fabricate(:user))- pm = Fabricate(:private_message_post, user: Fabricate(:coding_horror))+ sign_in(user)+ pm = Fabricate(:private_message_post, user: coding_horror)post "/post_actions.json", params: {id: pm.id,@@ -93,7 +94,7 @@ RSpec.describe PostActionsController doendit 'fails when the user tries to notify user that has disabled PM' do- sign_in(Fabricate(:user))+ sign_in(user)user2 = Fabricate(:user)post = Fabricate(:post, user: user2)@@ -115,7 +116,7 @@ RSpec.describe PostActionsController dodescribe 'as a moderator' dofab!(:user) { Fabricate(:moderator) }- fab!(:post_1) { Fabricate(:post, user: Fabricate(:coding_horror)) }+ fab!(:post_1) { Fabricate(:post, user: coding_horror) }before dosign_in(user)diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rbindex 1723c8fa0fc..9e03a0ba0cc 100644--- a/spec/services/post_alerter_spec.rb+++ b/spec/services/post_alerter_spec.rb@@ -26,8 +26,21 @@ endRSpec::Matchers.define_negated_matcher :not_add_notification, :add_notificationdescribe PostAlerter do+ fab!(:category) { Fabricate(:category) }+ fab!(:topic) { Fabricate(:topic) }+ fab!(:post) { Fabricate(:post) }++ fab!(:private_message_topic) { Fabricate(:private_message_topic) }+ fab!(:private_message_topic_post1) { Fabricate(:post, topic: private_message_topic) }+ fab!(:private_message_topic_post2) { Fabricate(:post, topic: private_message_topic) }++ fab!(:group) { Fabricate(:group) }++ fab!(:admin) { Fabricate(:admin) }fab!(:evil_trout) { Fabricate(:evil_trout) }+ fab!(:coding_horror) { Fabricate(:coding_horror) }+ fab!(:walterwhite) { Fabricate(:walter_white) }fab!(:user) { Fabricate(:user) }fab!(:tl2_user) { Fabricate(:user, trust_level: TrustLevel[2]) }@@ -174,7 +187,6 @@ describe PostAlerter doendit "Doesn't notify non-admin users when their post is quoted inside a whisper" do- admin = Fabricate(:admin)group.add(admin)TopicUser.change(user2.id, pm.id, notification_level: TopicUser.notification_levels[:regular])@@ -193,14 +205,13 @@ describe PostAlerter docontext "unread" doit "does not return whispers as unread posts" do- op = Fabricate(:post)_whisper = Fabricate(:post, raw: 'this is a whisper post',- user: Fabricate(:admin),- topic: op.topic,- reply_to_post_number: op.post_number,+ user: admin,+ topic: post.topic,+ reply_to_post_number: post.post_number,post_type: Post.types[:whisper])- expect(PostAlerter.new.first_unread_post(op.user, op.topic)).to be_blank+ expect(PostAlerter.new.first_unread_post(post.user, post.topic)).to be_blankendend@@ -211,8 +222,6 @@ describe PostAlerter dopost = Fabricate(:post, raw: 'I love waffles')- admin = Fabricate(:admin)-expect dopost.revise(admin, raw: 'I made a revision')end.to add_notification(post.user, :edited)@@ -254,8 +263,6 @@ describe PostAlerter doit 'notifies flaggers when flagged post gets unhidden by edit' dopost = create_post- walterwhite = Fabricate(:walter_white)- coding_horror = Fabricate(:coding_horror)PostActionNotifier.enableReviewable.set_priorities(high: 4.0)@@ -295,8 +302,8 @@ describe PostAlerter doendcontext 'quotes' do- let(:category) { Fabricate(:category) }- let(:topic) { Fabricate(:topic, category: category) }+ fab!(:category) { Fabricate(:category) }+ fab!(:topic) { Fabricate(:topic, category: category) }it 'does not notify for muted users' dopost = Fabricate(:post, raw: '[quote="EvilTrout, post:1"]whatup[/quote]', topic: topic)@@ -383,8 +390,6 @@ describe PostAlerter doexpect(user.notifications.count).to eq(1)- topic = Fabricate(:topic)-watcher = Fabricate(:user)TopicUser.create!(user_id: watcher.id, topic_id: topic.id, notification_level: TopicUser.notification_levels[:watching])@@ -409,7 +414,6 @@ describe PostAlerter doit "doesn't notify the linked user if the user is staged and the category is restricted and allows strangers" dostaged_user = Fabricate(:staged)- group = Fabricate(:group)group_member = Fabricate(:user)group.add(group_member)@@ -431,9 +435,8 @@ describe PostAlerter doendcontext '@here' do- let(:topic) { Fabricate(:topic) }let(:post) { create_post_with_alerts(raw: "Hello @here how are you?", user: tl2_user, topic: topic) }- let(:other_post) { Fabricate(:post, topic: topic) }+ fab!(:other_post) { Fabricate(:post, topic: topic) }before doJobs.run_immediately!@@ -567,13 +570,12 @@ describe PostAlerter doendit "notification comes from editor if mention is added later" do- admin = Fabricate(:admin)- post = create_post_with_alerts(user: user, raw: 'No mention here.')- expect {- post.revise(admin, raw: "Mention @eviltrout in this edit.")- }.to change(evil_trout.notifications, :count)- n = evil_trout.notifications.last- expect(n.data_hash["original_username"]).to eq(admin.username)+ post = create_post_with_alerts(user: user, raw: 'No mention here.')+ expect {+ post.revise(admin, raw: "Mention @eviltrout in this edit.")+ }.to change(evil_trout.notifications, :count)+ n = evil_trout.notifications.last+ expect(n.data_hash["original_username"]).to eq(admin.username)endit "doesn't notify the last post editor if they mention themselves" do@@ -984,7 +986,6 @@ describe PostAlerter dodescribe "create_notification_alert" doit "does nothing for suspended users" doevil_trout.update_columns(suspended_till: 1.year.from_now)- post = Fabricate(:post)events = nilmessages = MessageBus.track_publish do@@ -1006,7 +1007,6 @@ describe PostAlerter doit "does not publish to MessageBus /notification-alert if the user has not been seen for > 30 days, but still sends a push notification" doevil_trout.update_columns(last_seen_at: 31.days.ago)- post = Fabricate(:post)SiteSetting.allowed_user_api_push_urls = "https://site2.com/push"UserApiKey.create!(user_id: evil_trout.id,@@ -1035,7 +1035,6 @@ describe PostAlerter doenddescribe "watching_first_post" do- fab!(:group) { Fabricate(:group) }fab!(:user) { Fabricate(:user) }fab!(:category) { Fabricate(:category) }fab!(:tag) { Fabricate(:tag) }@@ -1092,8 +1091,6 @@ describe PostAlerter docontext "replies" doit "triggers :before_create_notifications_for_users" do- user = Fabricate(:user)- topic = Fabricate(:topic)_post = Fabricate(:post, user: user, topic: topic)reply = Fabricate(:post, topic: topic, reply_to_post_number: 1)events = DiscourseEvent.track_events do@@ -1103,8 +1100,6 @@ describe PostAlerter doendit "notifies about regular reply" do- user = Fabricate(:user)- topic = Fabricate(:topic)_post = Fabricate(:post, user: user, topic: topic)reply = Fabricate(:post, topic: topic, reply_to_post_number: 1)@@ -1114,10 +1109,6 @@ describe PostAlerter doendit "doesn't notify regular user about whispered reply" do- user = Fabricate(:user)- admin = Fabricate(:admin)-- topic = Fabricate(:topic)_post = Fabricate(:post, user: user, topic: topic)whispered_reply = Fabricate(:post, user: admin, topic: topic, post_type: Post.types[:whisper], reply_to_post_number: 1)@@ -1127,11 +1118,9 @@ describe PostAlerter doendit "notifies staff user about whispered reply" do- user = Fabricate(:user)admin1 = Fabricate(:admin)admin2 = Fabricate(:admin)- topic = Fabricate(:topic)_post = Fabricate(:post, user: user, topic: topic)whispered_reply1 = Fabricate(:post, user: admin1, topic: topic, post_type: Post.types[:whisper], reply_to_post_number: 1)@@ -1231,8 +1220,6 @@ describe PostAlerter docontext "category" docontext "watching" doit "triggers :before_create_notifications_for_users" do- user = Fabricate(:user)- category = Fabricate(:category)topic = Fabricate(:topic, category: category)post = Fabricate(:post, topic: topic)level = CategoryUser.notification_levels[:watching]@@ -1244,10 +1231,7 @@ describe PostAlerter doendit "notifies staff about whispered post" do- category = Fabricate(:category)topic = Fabricate(:topic, category: category)- admin = Fabricate(:admin)- user = Fabricate(:user)level = CategoryUser.notification_levels[:watching]CategoryUser.set_notification_level_for_category(admin, level, category.id)CategoryUser.set_notification_level_for_category(user, level, category.id)@@ -1263,7 +1247,6 @@ describe PostAlerter doit "notifies a staged user about a private post, but only if the user has access" dostaged_member = Fabricate(:staged)staged_non_member = Fabricate(:staged)- group = Fabricate(:group)group_member = Fabricate(:user)group.add(group_member)@@ -1289,7 +1272,6 @@ describe PostAlerter doendit "does not update existing unread notification" do- category = Fabricate(:category)CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:watching], category.id)topic = Fabricate(:topic, category: category)@@ -1313,7 +1295,6 @@ describe PostAlerter docontext "tags" docontext "watching" doit "triggers :before_create_notifications_for_users" do- user = Fabricate(:user)tag = Fabricate(:tag)topic = Fabricate(:topic, tags: [tag])post = Fabricate(:post, topic: topic)@@ -1350,7 +1331,6 @@ describe PostAlerter dotopic = Fabricate(:topic, tags: [tag])post = Fabricate(:post, topic: topic)tag_group = Fabricate(:tag_group, tags: [tag])- group = Fabricate(:group)Fabricate(:tag_group_permission, tag_group: tag_group, group: group)TagUser.change(user.id, tag.id, TagUser.notification_levels[:watching])@@ -1363,7 +1343,6 @@ describe PostAlerter dotopic = Fabricate(:topic, tags: [tag])post = Fabricate(:post, topic: topic)tag_group = Fabricate(:tag_group, tags: [tag])- group = Fabricate(:group)Fabricate(:group_user, group: group, user: user)Fabricate(:tag_group_permission, tag_group: tag_group, group: group)@@ -1377,7 +1356,6 @@ describe PostAlerter dofab!(:user) { Fabricate(:user) }fab!(:other_tag) { Fabricate(:tag) }fab!(:watched_tag) { Fabricate(:tag) }- fab!(:post) { Fabricate(:post) }before doSiteSetting.tagging_enabled = true@@ -1413,7 +1391,6 @@ describe PostAlerter dofab!(:other_tag3) { Fabricate(:tag) }fab!(:user) { Fabricate(:user) }fab!(:staged) { Fabricate(:staged) }- fab!(:admin) { Fabricate(:admin) }before doSiteSetting.tagging_enabled = true@@ -1440,7 +1417,6 @@ describe PostAlerter docontext "with tag groups" dofab!(:tag) { Fabricate(:tag) }- fab!(:group) { Fabricate(:group) }fab!(:user) { Fabricate(:user) }fab!(:topic) { Fabricate(:topic, tags: [tag]) }fab!(:post) { Fabricate(:post, topic: topic) }@@ -1498,7 +1474,6 @@ describe PostAlerter doenddescribe '#extract_linked_users' do- fab!(:topic) { Fabricate(:topic) }fab!(:post) { Fabricate(:post, topic: topic) }fab!(:post2) { Fabricate(:post) }@@ -1523,7 +1498,6 @@ describe PostAlerter doenddescribe '#notify_post_users' do- fab!(:topic) { Fabricate(:topic) }fab!(:post) { Fabricate(:post, topic: topic) }fab!(:last_editor) { Fabricate(:user) }fab!(:tag) { Fabricate(:tag) }@@ -1611,26 +1585,17 @@ describe PostAlerter doendit "does not error if SMTP is enabled and the topic has no incoming email or allowed groups" do- topic = Fabricate(:private_message_topic)- Fabricate(:post, topic: topic)- post = Fabricate(:post, topic: topic)expect { PostAlerter.new.after_save_post(post, true) }.not_to raise_errorendit "does not error if SMTP is enabled and the topic has no incoming email but does have an allowed group" do- topic = Fabricate(:private_message_topic)- Fabricate(:post, topic: topic)- post = Fabricate(:post, topic: topic)- TopicAllowedGroup.create(topic: topic, group: Fabricate(:group))+ TopicAllowedGroup.create(topic: private_message_topic, group: group)expect { PostAlerter.new.after_save_post(post, true) }.not_to raise_errorendit "does not error if SMTP is enabled and the topic has no incoming email but has multiple allowed groups" do- topic = Fabricate(:private_message_topic)- Fabricate(:post, topic: topic)- post = Fabricate(:post, topic: topic)- TopicAllowedGroup.create(topic: topic, group: Fabricate(:group))- TopicAllowedGroup.create(topic: topic, group: Fabricate(:group))+ TopicAllowedGroup.create(topic: private_message_topic, group: group)+ TopicAllowedGroup.create(topic: private_message_topic, group: Fabricate(:group))expect { PostAlerter.new.after_save_post(post, true) }.not_to raise_errorenddiff --git a/spec/services/user_merger_spec.rb b/spec/services/user_merger_spec.rbindex 3ffb7ef8479..a063d4e892e 100644--- a/spec/services/user_merger_spec.rb+++ b/spec/services/user_merger_spec.rb@@ -6,6 +6,7 @@ describe UserMerger dofab!(:target_user) { Fabricate(:user, username: 'alice', email: '[email protected]') }fab!(:source_user) { Fabricate(:user, username: 'alice1', email: '[email protected]') }fab!(:walter) { Fabricate(:walter_white) }+ fab!(:coding_horror) { Fabricate(:coding_horror) }fab!(:p1) { Fabricate(:post) }fab!(:p2) { Fabricate(:post) }@@ -271,7 +272,6 @@ describe UserMerger domuted1 = Fabricate(:user)muted2 = Fabricate(:user)muted3 = Fabricate(:user)- coding_horror = Fabricate(:coding_horror)MutedUser.create!(user_id: source_user.id, muted_user_id: muted1.id)MutedUser.create!(user_id: source_user.id, muted_user_id: muted2.id)@@ -297,7 +297,6 @@ describe UserMerger doignored1 = Fabricate(:user)ignored2 = Fabricate(:user)ignored3 = Fabricate(:user)- coding_horror = Fabricate(:coding_horror)Fabricate(:ignored_user, user: source_user, ignored_user: ignored1)Fabricate(:ignored_user, user: source_user, ignored_user: ignored2)@@ -705,8 +704,6 @@ describe UserMerger doendit "merges when acting_user is neither source_user nor target_user" do- coding_horror = Fabricate(:coding_horror)-pm_topic1 = Fabricate(:private_message_topic, topic_allowed_users: [Fabricate.build(:topic_allowed_user, user: walter),Fabricate.build(:topic_allowed_user, user: source_user),