A platform for community discussion. Free, open, simple.
PERF: Make tests faster by prefabricating more things (#15392)
Daniel Waterworth5ff0b86b5758
diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rbindex b07746a6d42..4634ff0226c 100644--- a/spec/components/guardian_spec.rb+++ b/spec/components/guardian_spec.rb@@ -1884,7 +1884,6 @@ describe Guardian doit 'returns true for a group member with reviewable status' doSiteSetting.enable_category_group_moderation = true- group = Fabricate(:group)GroupUser.create!(group_id: group.id, user_id: user.id)topic.category.update!(reviewable_by_group_id: group.id)expect(Guardian.new(user).can_review_topic?(topic)).to eq(true)@@ -1906,7 +1905,6 @@ describe Guardian doit 'returns true for a group member with reviewable status' doSiteSetting.enable_category_group_moderation = true- group = Fabricate(:group)GroupUser.create!(group_id: group.id, user_id: user.id)topic.category.update!(reviewable_by_group_id: group.id)expect(Guardian.new(user).can_close_topic?(topic)).to eq(true)@@ -1928,7 +1926,6 @@ describe Guardian doit 'returns true for a group member with reviewable status' doSiteSetting.enable_category_group_moderation = true- group = Fabricate(:group)GroupUser.create!(group_id: group.id, user_id: user.id)topic.category.update!(reviewable_by_group_id: group.id)expect(Guardian.new(user).can_archive_topic?(topic)).to eq(true)@@ -1950,7 +1947,6 @@ describe Guardian doit 'returns true for a group member with reviewable status' doSiteSetting.enable_category_group_moderation = true- group = Fabricate(:group)GroupUser.create!(group_id: group.id, user_id: user.id)topic.category.update!(reviewable_by_group_id: group.id)expect(Guardian.new(user).can_edit_staff_notes?(topic)).to eq(true)@@ -2156,7 +2152,6 @@ describe Guardian doit "returns true for category moderators" doSiteSetting.enable_category_group_moderation = true- group = Fabricate(:group)GroupUser.create(group: group, user: user)category = Fabricate(:category, reviewable_by_group_id: group.id)post.topic.update!(category: category)diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rbindex 0e723088f25..484ff8140aa 100644--- a/spec/components/post_creator_spec.rb+++ b/spec/components/post_creator_spec.rb@@ -7,6 +7,7 @@ require 'topic_subtype'describe PostCreator dofab!(:user) { Fabricate(:user) }+ fab!(:admin) { Fabricate(:admin) }fab!(:coding_horror) { Fabricate(:coding_horror) }fab!(:evil_trout) { Fabricate(:evil_trout) }let(:topic) { Fabricate(:topic, user: user) }@@ -119,7 +120,6 @@ describe PostCreator doendit "does not notify on system messages" do- admin = Fabricate(:admin)messages = MessageBus.track_publish dop = PostCreator.create(admin, basic_topic_params.merge(post_type: Post.types[:moderator_action]))PostCreator.create(admin, basic_topic_params.merge(topic_id: p.topic_id, post_type: Post.types[:moderator_action]))@@ -866,7 +866,6 @@ describe PostCreator doendit 'creates the topic if the user is a staff member' do- admin = Fabricate(:admin)post_creator = PostCreator.new(admin, raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4)TopicUser.create!(user: admin, topic: topic, last_posted_at: 10.minutes.ago)@@ -961,7 +960,6 @@ describe PostCreator doUserArchivedMessage.create(user_id: target_user2.id, topic_id: post.topic_id)# if an admin replies they should be added to the allowed user list- admin = Fabricate(:admin)PostCreator.create!(admin,raw: 'hi there welcome topic, I am a mod',topic_id: post.topic_id@@ -1064,8 +1062,6 @@ describe PostCreator doit 'closes private messages that have more than N posts' doSiteSetting.auto_close_messages_post_count = 2- admin = Fabricate(:admin)-post1 = create_post(archetype: Archetype.private_message,target_usernames: [admin.username])@@ -1325,7 +1321,6 @@ describe PostCreator doit "automatically watches topic based on preference" douser.user_option.notification_level_when_replying = 3- admin = Fabricate(:admin)topic = PostCreator.create(admin,title: "this is the title of a topic created by an admin for watching notification",raw: "this is the content of a topic created by an admin for keeping a watching notification state on a topic ;)"@@ -1342,7 +1337,6 @@ describe PostCreator doit "topic notification level remains tracking based on preference" douser.user_option.notification_level_when_replying = 2- admin = Fabricate(:admin)topic = PostCreator.create(admin,title: "this is the title of a topic created by an admin for tracking notification",raw: "this is the content of a topic created by an admin for keeping a tracking notification state on a topic ;)"@@ -1359,7 +1353,6 @@ describe PostCreator doit "topic notification level is normal based on preference" douser.user_option.notification_level_when_replying = 1- admin = Fabricate(:admin)topic = PostCreator.create(admin,title: "this is the title of a topic created by an admin for tracking notification",raw: "this is the content of a topic created by an admin for keeping a tracking notification state on a topic ;)"@@ -1376,7 +1369,6 @@ describe PostCreator doit "user preferences for notification level when replying doesn't affect PMs" douser.user_option.update!(notification_level_when_replying: 1)- admin = Fabricate(:admin)pm = Fabricate(:private_message_topic, user: admin)pm.invite(admin, user.username)diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rbindex d3c61aacbbf..34947fbc24f 100644--- a/spec/components/search_spec.rb+++ b/spec/components/search_spec.rb@@ -5,6 +5,7 @@ require 'rails_helper'describe Search dofab!(:admin) { Fabricate(:admin) }+ fab!(:topic) { Fabricate(:topic) }before doSearchIndexer.enable@@ -671,7 +672,6 @@ describe Search doendit 'displays multiple results within a topic' do- topic = Fabricate(:topic)topic2 = Fabricate(:topic)new_post('this is the other post I am posting', topic2, created_at: 6.minutes.ago)@@ -1086,7 +1086,6 @@ describe Search doit 'can use tag as a search context' dotag = Fabricate(:tag, name: 'important-stuff')- topic = Fabricate(:topic)topic_no_tag = Fabricate(:topic)Fabricate(:topic_tag, tag: tag, topic: topic)@@ -1151,7 +1150,6 @@ describe Search dodescribe 'Advanced search' doit 'supports pinned' do- topic = Fabricate(:topic)Fabricate(:post, raw: 'hi this is a test 123 123', topic: topic)_post = Fabricate(:post, raw: 'boom boom shake the room', topic: topic)@@ -1162,7 +1160,6 @@ describe Search doendit 'supports wiki' do- topic = Fabricate(:topic)topic_2 = Fabricate(:topic)post = Fabricate(:post, raw: 'this is a test 248', wiki: true, topic: topic)Fabricate(:post, raw: 'this is a test 248', wiki: false, topic: topic_2)@@ -1173,7 +1170,6 @@ describe Search doendit 'supports searching for posts that the user has seen/unseen' do- topic = Fabricate(:topic)topic_2 = Fabricate(:topic)post = Fabricate(:post, raw: 'logan is longan', topic: topic)post_2 = Fabricate(:post, raw: 'longan is logan', topic: topic_2)@@ -1231,7 +1227,6 @@ describe Search doendit 'supports in:first, user:, @username' do- topic = Fabricate(:topic)post_1 = Fabricate(:post, raw: 'hi this is a test 123 123', topic: topic)post_2 = Fabricate(:post, raw: 'boom boom shake the room test', topic: topic)@@ -1569,7 +1564,6 @@ describe Search doendit 'can find posts with non-latin tag' do- topic = Fabricate(:topic)topic.tags = [Fabricate(:tag, name: 'さようなら')]post = Fabricate(:post, raw: 'Testing post', topic: topic)@@ -1577,7 +1571,6 @@ describe Search doendit 'can find posts with thai tag' do- topic = Fabricate(:topic)topic.tags = [Fabricate(:tag, name: 'เรซิ่น')]post = Fabricate(:post, raw: 'Testing post', topic: topic)diff --git a/spec/components/svg_sprite/svg_sprite_spec.rb b/spec/components/svg_sprite/svg_sprite_spec.rbindex e3d1ccd3bf6..11cb9aee9e9 100644--- a/spec/components/svg_sprite/svg_sprite_spec.rb+++ b/spec/components/svg_sprite/svg_sprite_spec.rb@@ -3,6 +3,7 @@require 'rails_helper'describe SvgSprite do+ fab!(:theme) { Fabricate(:theme) }before doSvgSprite.expire_cache@@ -50,7 +51,6 @@ describe SvgSprite doendit 'version should be based on bundled output, not requested icons' do- theme = Fabricate(:theme)fname = "custom-theme-icon-sprite.svg"upload = UploadCreator.new(file_from_fixtures(fname), fname, for_theme: true).create_for(-1)@@ -92,8 +92,6 @@ describe SvgSprite doendit 'includes icons defined in theme settings' do- theme = Fabricate(:theme)-# Works for default settings:theme.set_field(target: :settings, name: :yaml, value: "custom_icon: dragon")theme.save!@@ -138,7 +136,6 @@ describe SvgSprite doendit 'includes icons defined in theme modifiers' do- theme = Fabricate(:theme)child_theme = Fabricate(:theme, component: true)theme.add_relative_theme!(:child, child_theme)@@ -173,7 +170,6 @@ describe SvgSprite doendit 'includes svg sprites in themes stored in s3' do- theme = Fabricate(:theme)theme.set_field(target: :common, name: SvgSprite.theme_sprite_variable_name, upload_id: upload_s3.id, type: :theme_upload_var)theme.save!@@ -253,7 +249,6 @@ describe SvgSprite doendit 'includes custom icons in a theme' do- theme = Fabricate(:theme)fname = "custom-theme-icon-sprite.svg"upload = UploadCreator.new(file_from_fixtures(fname), fname, for_theme: true).create_for(-1)@@ -266,7 +261,6 @@ describe SvgSprite doendit 'does not fail on bad XML in custom icon sprite' do- theme = Fabricate(:theme)fname = "bad-xml-icon-sprite.svg"upload = UploadCreator.new(file_from_fixtures(fname), fname, for_theme: true).create_for(-1)@@ -279,7 +273,6 @@ describe SvgSprite doendit 'includes custom icons in a child theme' do- theme = Fabricate(:theme)fname = "custom-theme-icon-sprite.svg"child_theme = Fabricate(:theme, component: true)theme.add_relative_theme!(:child, child_theme)diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rbindex 449a5c10433..9153981f5b9 100644--- a/spec/models/notification_spec.rb+++ b/spec/models/notification_spec.rb@@ -3,6 +3,7 @@require 'rails_helper'describe Notification do+ fab!(:user) { Fabricate(:user) }fab!(:coding_horror) { Fabricate(:coding_horror) }before do@@ -269,8 +270,6 @@ describe Notification dodescribe 'saw_regular_notification_id' doit 'correctly updates the read state' do- user = Fabricate(:user)-t = Fabricate(:topic)Notification.create!(read: false,@@ -308,8 +307,6 @@ describe Notification dodescribe 'mark_posts_read' doit "marks multiple posts as read if needed" do- user = Fabricate(:user)-(1..3).map do |i|Notification.create!(read: false, user_id: user.id, topic_id: 2, post_number: i, data: '{}', notification_type: 1)end@@ -345,7 +342,6 @@ describe Notification doendit 'does not delete chat_message notifications' do- user = Fabricate(:user)Notification.create!(read: false, user_id: user.id, topic_id: nil, post_number: nil, data: '[]',notification_type: Notification.types[:chat_mention])@@ -357,7 +353,6 @@ describe Notification dodescribe "do not disturb" doit "calls NotificationEmailer.process_notification when user is not in 'do not disturb'" do- user = Fabricate(:user)notification = Notification.new(read: false, user_id: user.id, topic_id: 2, post_number: 1, data: '{}', notification_type: 1)NotificationEmailer.expects(:process_notification).with(notification)notification.save!@@ -365,7 +360,6 @@ describe Notification doit "doesn't call NotificationEmailer.process_notification when user is in 'do not disturb'" dofreeze_time- user = Fabricate(:user)Fabricate(:do_not_disturb_timing, user: user, starts_at: Time.zone.now, ends_at: 1.day.from_now)notification = Notification.new(read: false, user_id: user.id, topic_id: 2, post_number: 1, data: '{}', notification_type: 1)diff --git a/spec/models/post_timing_spec.rb b/spec/models/post_timing_spec.rbindex f00c0f65b14..ecdf9c00293 100644--- a/spec/models/post_timing_spec.rb+++ b/spec/models/post_timing_spec.rb@@ -3,6 +3,7 @@require 'rails_helper'describe PostTiming do+ fab!(:post) { Fabricate(:post) }it { is_expected.to validate_presence_of :post_number }it { is_expected.to validate_presence_of :msecs }@@ -61,7 +62,6 @@ describe PostTiming dodescribe 'safeguard' doit "doesn't store timings that are larger than the account lifetime" douser = Fabricate(:user, created_at: 3.minutes.ago)- post = Fabricate(:post)PostTiming.process_timings(user, post.topic_id, 1, [[post.post_number, 123]])msecs = PostTiming.where(post_number: post.post_number, user_id: user.id).pluck(:msecs)[0]@@ -81,7 +81,6 @@ describe PostTiming doit 'processes timings correctly' doPostActionNotifier.enable- post = Fabricate(:post)(2..5).each do |i|Fabricate(:post, topic: post.topic, post_number: i)end@@ -131,17 +130,16 @@ describe PostTiming dodescribe 'recording' dobefore do- @post = Fabricate(:post)- @topic = @post.topic+ @topic = post.topic@coding_horror = Fabricate(:coding_horror)- @timing_attrs = { msecs: 1234, topic_id: @post.topic_id, user_id: @coding_horror.id, post_number: @post.post_number }+ @timing_attrs = { msecs: 1234, topic_id: post.topic_id, user_id: @coding_horror.id, post_number: post.post_number }endit 'adds a view to the post' doexpect {PostTiming.record_timing(@timing_attrs)- @post.reload- }.to change(@post, :reads).by(1)+ post.reload+ }.to change(post, :reads).by(1)endit "doesn't update the posts read count if the topic is a PM" do@@ -157,7 +155,7 @@ describe PostTiming doit 'correctly works' doPostTiming.record_timing(@timing_attrs)PostTiming.record_timing(@timing_attrs)- timing = PostTiming.find_by(topic_id: @post.topic_id, user_id: @coding_horror.id, post_number: @post.post_number)+ timing = PostTiming.find_by(topic_id: post.topic_id, user_id: @coding_horror.id, post_number: post.post_number)expect(timing).to be_presentexpect(timing.msecs).to eq(2468)@@ -192,7 +190,6 @@ describe PostTiming dodescribe '.destroy_last_for' doit 'updates first unread for a user correctly when topic is public' do- post = Fabricate(:post)post.topic.update!(updated_at: 10.minutes.ago)PostTiming.process_timings(post.user, post.topic_id, 1, [[post.post_number, 100]])diff --git a/spec/models/theme_field_spec.rb b/spec/models/theme_field_spec.rbindex 5ebc77dc478..63b2cc2b67a 100644--- a/spec/models/theme_field_spec.rb+++ b/spec/models/theme_field_spec.rb@@ -4,13 +4,10 @@require 'rails_helper'describe ThemeField do- after do- ThemeField.destroy_all- end+ fab!(:theme) { Fabricate(:theme) }describe "scope: find_by_theme_ids" doit "returns result in the specified order" do- theme = Fabricate(:theme)theme2 = Fabricate(:theme)theme3 = Fabricate(:theme)@@ -159,7 +156,6 @@ HTMLendit "allows importing scss files" do- theme = Fabricate(:theme)main_field = theme.set_field(target: :common, name: :scss, value: ".class1{color: red}\n@import 'rootfile1';\n@import 'rootfile3';")theme.set_field(target: :extra_scss, name: "rootfile1", value: ".class2{color:green}\n@import 'foldername/subfile1';")theme.set_field(target: :extra_scss, name: "rootfile2", value: ".class3{color:green} ")@@ -179,7 +175,6 @@ HTMLendit "correctly handles extra JS fields" do- theme = Fabricate(:theme)js_field = theme.set_field(target: :extra_js, name: "discourse/controllers/discovery.js.es6", value: "import 'discourse/lib/ajax'; console.log('hello from .js.es6');")js_2_field = theme.set_field(target: :extra_js, name: "discourse/controllers/discovery-2.js", value: "import 'discourse/lib/ajax'; console.log('hello from .js');")hbs_field = theme.set_field(target: :extra_js, name: "discourse/templates/discovery.hbs", value: "{{hello-world}}")@@ -235,7 +230,6 @@ HTMLlet(:key) { "themes.settings_errors" }it "forces re-transpilation of theme JS when settings YAML changes" do- theme = Fabricate(:theme)settings_field = ThemeField.create!(theme: theme, target_id: Theme.targets[:settings], name: "yaml", value: "setting: 5")html = <<~HTMLdiff --git a/spec/models/topic_tracking_state_spec.rb b/spec/models/topic_tracking_state_spec.rbindex 6f7cfd5e913..947b16615e4 100644--- a/spec/models/topic_tracking_state_spec.rb+++ b/spec/models/topic_tracking_state_spec.rb@@ -4,9 +4,7 @@ require 'rails_helper'describe TopicTrackingState do- fab!(:user) do- Fabricate(:user)- end+ fab!(:user) { Fabricate(:user) }let(:post) docreate_post@@ -335,8 +333,6 @@ describe TopicTrackingState doendit "correctly handles muted categories" do-- user = Fabricate(:user)postreport = TopicTrackingState.report(user)@@ -359,7 +355,6 @@ describe TopicTrackingState doendit "correctly handles category_users with null notification level" do- user = Fabricate(:user)postreport = TopicTrackingState.report(user)@@ -374,7 +369,6 @@ describe TopicTrackingState doit "works when categories are default muted" doSiteSetting.mute_all_categories_by_default = true- user = Fabricate(:user)postreport = TopicTrackingState.report(user)@@ -394,7 +388,6 @@ describe TopicTrackingState docontext 'muted tags' doit "remove_muted_tags_from_latest is set to always" doSiteSetting.remove_muted_tags_from_latest = 'always'- user = Fabricate(:user)tag1 = Fabricate(:tag)tag2 = Fabricate(:tag)Fabricate(:topic_tag, tag: tag1, topic: topic)@@ -420,7 +413,6 @@ describe TopicTrackingState doit "remove_muted_tags_from_latest is set to only_muted" doSiteSetting.remove_muted_tags_from_latest = 'only_muted'- user = Fabricate(:user)tag1 = Fabricate(:tag)tag2 = Fabricate(:tag)Fabricate(:topic_tag, tag: tag1, topic: topic)@@ -454,7 +446,6 @@ describe TopicTrackingState doit "remove_muted_tags_from_latest is set to never" doSiteSetting.remove_muted_tags_from_latest = 'never'- user = Fabricate(:user)tag1 = Fabricate(:tag)Fabricate(:topic_tag, tag: tag1, topic: topic)post@@ -474,7 +465,7 @@ describe TopicTrackingState doit "correctly handles dismissed topics" dofreeze_time 1.minute.ago- user = Fabricate(:user)+ user.update!(created_at: Time.now)postreport = TopicTrackingState.report(user)@@ -492,8 +483,6 @@ describe TopicTrackingState doendit "correctly handles capping" do- user = Fabricate(:user)-post1 = create_postFabricate(:post, topic: post1.topic)diff --git a/spec/models/user_auth_token_spec.rb b/spec/models/user_auth_token_spec.rbindex 27448880b4a..39872ae2697 100644--- a/spec/models/user_auth_token_spec.rb+++ b/spec/models/user_auth_token_spec.rb@@ -4,6 +4,7 @@ require 'rails_helper'require 'discourse_ip_info'describe UserAuthToken do+ fab!(:user) { Fabricate(:user) }it "can remove old expired tokens" do@@ -12,7 +13,6 @@ describe UserAuthToken dofreeze_time Time.zone.nowSiteSetting.maximum_session_age = 1- user = Fabricate(:user)token = UserAuthToken.generate!(user_id: user.id,user_agent: "some user agent 2",client_ip: "1.1.2.3")@@ -35,8 +35,6 @@ describe UserAuthToken doendit "can lookup hashed" do- user = Fabricate(:user)-token = UserAuthToken.generate!(user_id: user.id,user_agent: "some user agent 2",client_ip: "1.1.2.3")@@ -51,9 +49,6 @@ describe UserAuthToken doendit "can validate token was seen at lookup time" do-- user = Fabricate(:user)-user_token = UserAuthToken.generate!(user_id: user.id,user_agent: "some user agent 2",client_ip: "1.1.2.3")@@ -68,9 +63,6 @@ describe UserAuthToken doendit "can rotate with no params maintaining data" do-- user = Fabricate(:user)-user_token = UserAuthToken.generate!(user_id: user.id,user_agent: "some user agent 2",client_ip: "1.1.2.3")@@ -84,7 +76,6 @@ describe UserAuthToken doit "expires correctly" dofreeze_time Time.zone.now- user = Fabricate(:user)user_token = UserAuthToken.generate!(user_id: user.id,user_agent: "some user agent 2",client_ip: "1.1.2.3")@@ -110,7 +101,6 @@ describe UserAuthToken doit "can properly rotate tokens" dofreeze_time 3.days.ago- user = Fabricate(:user)user_token = UserAuthToken.generate!(user_id: user.id,user_agent: "some user agent 2",@@ -164,9 +154,6 @@ describe UserAuthToken doendit "keeps prev token valid for 1 minute after it is confirmed" do-- user = Fabricate(:user)-token = UserAuthToken.generate!(user_id: user.id,user_agent: "some user agent",client_ip: "1.1.2.3")@@ -189,8 +176,6 @@ describe UserAuthToken doit "can correctly log auth tokens" doSiteSetting.verbose_auth_token_logging = true- user = Fabricate(:user)-token = UserAuthToken.generate!(user_id: user.id,user_agent: "some user agent",client_ip: "1.1.2.3")@@ -256,8 +241,6 @@ describe UserAuthToken doit "calls before_destroy" doSiteSetting.verbose_auth_token_logging = true- user = Fabricate(:user)-token = UserAuthToken.generate!(user_id: user.id,user_agent: "some user agent",client_ip: "1.1.2.3")@@ -273,8 +256,6 @@ describe UserAuthToken doendit "will not mark token unseen when prev and current are the same" do- user = Fabricate(:user)-token = UserAuthToken.generate!(user_id: user.id,user_agent: "some user agent",client_ip: "1.1.2.3")@@ -286,8 +267,6 @@ describe UserAuthToken doendcontext "suspicious login" do-- fab!(:user) { Fabricate(:user) }fab!(:admin) { Fabricate(:admin) }it "is not checked when generated for non-staff" dodiff --git a/spec/requests/groups_controller_spec.rb b/spec/requests/groups_controller_spec.rbindex 7dc0d1cb59c..a9146846423 100644--- a/spec/requests/groups_controller_spec.rb+++ b/spec/requests/groups_controller_spec.rb@@ -4,6 +4,7 @@ require 'rails_helper'describe GroupsController dofab!(:user) { Fabricate(:user) }+ fab!(:user2) { Fabricate(:user) }fab!(:other_user) { Fabricate(:user) }let(:group) { Fabricate(:group, users: [user]) }let(:moderator_group_id) { Group::AUTO_GROUPS[:moderators] }@@ -877,7 +878,6 @@ describe GroupsController doit "should update default notification preference for existing users" dogroup.update!(default_notification_level: NotificationLevels.all[:watching])user1 = Fabricate(:user)- user2 = Fabricate(:user)group.add(user1)group.add(user2)group_user1 = user1.group_users.first@@ -937,7 +937,6 @@ describe GroupsController doit "should update category & tag notification preferences for existing users" douser1 = Fabricate(:user)- user2 = Fabricate(:user)CategoryUser.create!(user: user1, category: category, notification_level: 4)TagUser.create!(user: user1, tag: tag, notification_level: 4)TagUser.create!(user: user2, tag: tag, notification_level: 4)@@ -1317,8 +1316,6 @@ describe GroupsController doendit "can make incremental adds" do- user2 = Fabricate(:user)-expect doput "/groups/#{group.id}/members.json", params: { usernames: user2.username }end.to change { group.users.count }.by(1)@@ -1340,8 +1337,6 @@ describe GroupsController doendit "does not notify users when the param is not present" do- user2 = Fabricate(:user)-expect {put "/groups/#{group.id}/members.json", params: { usernames: user2.username }}.to change { Topic.where(archetype: "private_message").count }.by(0)@@ -1350,8 +1345,6 @@ describe GroupsController doendit "notifies users when the param is present" do- user2 = Fabricate(:user)-expect {put "/groups/#{group.id}/members.json", params: { usernames: user2.username, notify_users: true }}.to change { Topic.where(archetype: "private_message").count }.by(1)diff --git a/spec/requests/user_badges_controller_spec.rb b/spec/requests/user_badges_controller_spec.rbindex 4154f5ba982..c14e3aea672 100644--- a/spec/requests/user_badges_controller_spec.rb+++ b/spec/requests/user_badges_controller_spec.rb@@ -4,6 +4,7 @@ require 'rails_helper'describe UserBadgesController dofab!(:user) { Fabricate(:user) }+ fab!(:admin) { Fabricate(:admin) }fab!(:badge) { Fabricate(:badge) }context 'index' do@@ -107,7 +108,6 @@ describe UserBadgesController doendit 'grants badges from staff' do- admin = Fabricate(:admin)post_1 = create_postsign_in(admin)@@ -169,7 +169,6 @@ describe UserBadgesController doendit 'does not grant badge when external link is used in reason' do- admin = Fabricate(:admin)post = create_postsign_in(admin)@@ -184,7 +183,6 @@ describe UserBadgesController doendit 'does not grant badge if invalid discourse post/topic link is used in reason' do- admin = Fabricate(:admin)post = create_postsign_in(admin)@@ -199,7 +197,6 @@ describe UserBadgesController doendit 'grants badge when valid post/topic link is given in reason' do- admin = Fabricate(:admin)post = create_postsign_in(admin)@@ -217,7 +214,6 @@ describe UserBadgesController doit 'grants badge when valid post/topic link is given in reason' doset_subfolder "/discuss"- admin = Fabricate(:admin)post = create_postsign_in(admin)@@ -248,7 +244,6 @@ describe UserBadgesController doendit 'revokes the badge' do- admin = Fabricate(:admin)sign_in(admin)delete "/user_badges/#{user_badge.id}.json"diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rbindex a8ad3d4cdb6..b9149740e6b 100644--- a/spec/requests/users_controller_spec.rb+++ b/spec/requests/users_controller_spec.rb@@ -4,6 +4,7 @@ require 'rails_helper'require 'rotp'describe UsersController do+ fab!(:user) { Fabricate(:user) }fab!(:user1) { Fabricate(:user) }fab!(:another_user) { Fabricate(:user) }fab!(:invitee) { Fabricate(:user) }@@ -1930,7 +1931,6 @@ describe UsersController doit "allows staff to edit the field" dosign_in(admin)- user = Fabricate(:user)put "/u/#{user.username}.json", params: {name: 'Jim Tom',title: "foobar",@@ -2346,7 +2346,6 @@ describe UsersController dodescribe 'when user does not have a valid session' doit 'should not be valid' do- user = Fabricate(:user)post "/u/action/send_activation_email.json", params: {username: user.username}@@ -2867,7 +2866,6 @@ describe UsersController doendit "returns emails and associated_accounts for self" do- user = Fabricate(:user)Fabricate(:email_change_request, user: user1)sign_in(user)@@ -2882,7 +2880,6 @@ describe UsersController doendit "returns emails and associated_accounts when you're allowed to see them" do- user = Fabricate(:user)Fabricate(:email_change_request, user: user1)sign_in_admin@@ -3189,7 +3186,6 @@ describe UsersController dodescribe '#summary' doit "generates summary info" do- user = Fabricate(:user)create_post(user: user)get "/u/#{user.username_lower}/summary.json"@@ -3467,8 +3463,6 @@ describe UsersController doendit "raises an error when the new email is taken" do- user = Fabricate(:user)-put "/u/update-activation-email.json", params: {username: inactive_user.username,password: 'qwerqwer123',diff --git a/spec/services/user_updater_spec.rb b/spec/services/user_updater_spec.rbindex 9d52d1c1317..04f94040663 100644--- a/spec/services/user_updater_spec.rb+++ b/spec/services/user_updater_spec.rb@@ -3,15 +3,15 @@require 'rails_helper'describe UserUpdater do+ fab!(:user) { Fabricate(:user) }+ fab!(:u1) { Fabricate(:user) }+ fab!(:u2) { Fabricate(:user) }+ fab!(:u3) { Fabricate(:user) }let(:acting_user) { Fabricate.build(:user) }describe '#update_muted_users' doit 'has no cross talk' do- u1 = Fabricate(:user)- u2 = Fabricate(:user)- u3 = Fabricate(:user)-updater = UserUpdater.new(u1, u1)updater.update_muted_users("#{u2.username},#{u3.username}")@@ -27,8 +27,6 @@ describe UserUpdater doendit 'excludes acting user' do- u1 = Fabricate(:user)- u2 = Fabricate(:user)updater = UserUpdater.new(u1, u1)updater.update_muted_users("#{u1.username},#{u2.username}")@@ -51,7 +49,6 @@ describe UserUpdater doendit 'can update categories and tags' do- user = Fabricate(:user)updater = UserUpdater.new(user, user)updater.update(watched_tags: "#{tag.name},#{tag2.name}", muted_category_ids: [category.id])@@ -110,7 +107,6 @@ describe UserUpdater doendit "doesn't remove notification prefs when updating something else" do- user = Fabricate(:user)TagUser.create!(user: user, tag: tag, notification_level: TagUser.notification_levels[:watching])CategoryUser.create!(user: user, category: category, notification_level: CategoryUser.notification_levels[:muted])@@ -122,7 +118,6 @@ describe UserUpdater doendit 'updates various fields' do- user = Fabricate(:user)updater = UserUpdater.new(acting_user, user)date_of_birth = Time.zone.nowSiteSetting.disable_mailing_list_mode = false@@ -194,7 +189,6 @@ describe UserUpdater doendit "disables email_digests when enabling mailing_list_mode" do- user = Fabricate(:user)updater = UserUpdater.new(acting_user, user)SiteSetting.disable_mailing_list_mode = false@@ -208,7 +202,6 @@ describe UserUpdater doendit "filters theme_ids blank values before updating preferences" do- user = Fabricate(:user)user.user_option.update!(theme_ids: [1])updater = UserUpdater.new(acting_user, user)@@ -251,8 +244,6 @@ describe UserUpdater do}context 'with user_notification_schedule' do- fab!(:user) { Fabricate(:user) }-it "allows users to create their notification schedule when it doesn't exist previously" doexpect(user.user_notification_schedule).to be_nilupdater = UserUpdater.new(acting_user, user)@@ -307,7 +298,6 @@ describe UserUpdater doSiteSetting.enable_discourse_connect = trueSiteSetting.discourse_connect_overrides_bio = true- user = Fabricate(:user)updater = UserUpdater.new(acting_user, user)expect(updater.update(bio_raw: "new bio")).to be_truthy@@ -323,7 +313,6 @@ describe UserUpdater doSiteSetting.enable_discourse_connect = trueSiteSetting.discourse_connect_overrides_location = true- user = Fabricate(:user)updater = UserUpdater.new(acting_user, user)expect(updater.update(location: "new location")).to be_truthy@@ -339,7 +328,6 @@ describe UserUpdater doSiteSetting.enable_discourse_connect = trueSiteSetting.discourse_connect_overrides_website = true- user = Fabricate(:user)updater = UserUpdater.new(acting_user, user)expect(updater.update(website: "https://google.com")).to be_truthy@@ -351,7 +339,6 @@ describe UserUpdater docontext 'when updating primary group' dolet(:new_group) { Group.create(name: 'new_group') }- let(:user) { Fabricate(:user) }it 'updates when setting is enabled' doSiteSetting.user_selected_primary_groups = true@@ -406,7 +393,6 @@ describe UserUpdater docontext 'when updating flair group' dolet(:group) { Fabricate(:group, name: "Group", flair_bg_color: "#111111", flair_color: "#999999", flair_icon: "icon") }- let(:user) { Fabricate(:user) }it 'updates when setting is enabled' dogroup.add(user)@@ -421,7 +407,6 @@ describe UserUpdater docontext 'when update fails' doit 'returns false' do- user = Fabricate(:user)user.stubs(save: false)updater = UserUpdater.new(acting_user, user)@@ -505,7 +490,6 @@ describe UserUpdater docontext 'when website includes http' doit 'does not add http before updating' do- user = Fabricate(:user)updater = UserUpdater.new(acting_user, user)updater.update(website: 'http://example.com')@@ -516,7 +500,6 @@ describe UserUpdater docontext 'when website does not include http' doit 'adds http before updating' do- user = Fabricate(:user)updater = UserUpdater.new(acting_user, user)updater.update(website: 'example.com')@@ -527,7 +510,6 @@ describe UserUpdater docontext 'when website is invalid' doit 'returns an error' do- user = Fabricate(:user)updater = UserUpdater.new(acting_user, user)expect(updater.update(website: 'ʔ<')).to eq nil@@ -536,7 +518,6 @@ describe UserUpdater docontext 'when custom_fields is empty string' doit "update is successful" do- user = Fabricate(:user)user.custom_fields = { 'import_username' => 'my_old_username' }user.saveupdater = UserUpdater.new(acting_user, user)