Skip to content

A platform for community discussion. Free, open, simple.

Add new `run_jobs_synchronously!` helper for tests

Robin Wardd1d9a4f1289e
diff --git a/lib/generators/plugin/templates/controller_spec.rb.erb b/lib/generators/plugin/templates/controller_spec.rb.erb
index 88935a5dfe2..c73e0a87e9b 100644
--- a/lib/generators/plugin/templates/controller_spec.rb.erb
+++ b/lib/generators/plugin/templates/controller_spec.rb.erb
@@ -2,7 +2,7 @@ require 'rails_helper'
describe <%= name %>::ActionsController do
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
end
it 'can list' do
diff --git a/plugins/discourse-local-dates/spec/models/post_spec.rb b/plugins/discourse-local-dates/spec/models/post_spec.rb
index 13e7e9a5ac2..9591607cc93 100644
--- a/plugins/discourse-local-dates/spec/models/post_spec.rb
+++ b/plugins/discourse-local-dates/spec/models/post_spec.rb
@@ -3,7 +3,7 @@ require 'rails_helper'
describe Post do
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
end
describe '#local_dates' do
diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb
index 32a5a4e3f43..91b0c15255c 100644
--- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb
+++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb
@@ -22,7 +22,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
let(:reset_trigger) { DiscourseNarrativeBot::TrackSelector.reset_trigger }
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
SiteSetting.discourse_narrative_bot_enabled = true
end
diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb
index 3a7e5d8aa32..7ecc7270765 100644
--- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb
+++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb
@@ -25,7 +25,7 @@ describe DiscourseNarrativeBot::NewUserNarrative do
let(:reset_trigger) { DiscourseNarrativeBot::TrackSelector.reset_trigger }
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
SiteSetting.discourse_narrative_bot_enabled = true
end
diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb
index 0e6cb7a43ff..4d76b065669 100644
--- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb
+++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb
@@ -37,7 +37,7 @@ describe DiscourseNarrativeBot::TrackSelector do
end
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
end
describe '#select' do
diff --git a/plugins/discourse-narrative-bot/spec/user_spec.rb b/plugins/discourse-narrative-bot/spec/user_spec.rb
index 9779c2414fa..de52f0eafec 100644
--- a/plugins/discourse-narrative-bot/spec/user_spec.rb
+++ b/plugins/discourse-narrative-bot/spec/user_spec.rb
@@ -13,7 +13,7 @@ describe User do
end
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
SiteSetting.discourse_narrative_bot_enabled = true
end
diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb
index 78b2d6437fd..0e609c93588 100644
--- a/spec/components/post_creator_spec.rb
+++ b/spec/components/post_creator_spec.rb
@@ -902,7 +902,7 @@ describe PostCreator do
end
it 'can post to a group correctly' do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
expect(post.topic.archetype).to eq(Archetype.private_message)
expect(post.topic.topic_allowed_users.count).to eq(1)
diff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rb
index ba12c82f9c4..d5da412659b 100644
--- a/spec/components/post_destroyer_spec.rb
+++ b/spec/components/post_destroyer_spec.rb
@@ -617,7 +617,7 @@ describe PostDestroyer do
context '@mentions' do
it 'removes notifications when deleted' do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
user = Fabricate(:evil_trout)
post = create_post(raw: 'Hello @eviltrout')
expect {
diff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rb
index 4f5df63762b..d721692f261 100644
--- a/spec/components/post_revisor_spec.rb
+++ b/spec/components/post_revisor_spec.rb
@@ -608,7 +608,7 @@ describe PostRevisor do
let(:mentioned_user) { Fabricate(:user) }
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
end
it "generates a notification for a mention" do
diff --git a/spec/integration/watched_words_spec.rb b/spec/integration/watched_words_spec.rb
index b165b175a26..7620237b1c5 100644
--- a/spec/integration/watched_words_spec.rb
+++ b/spec/integration/watched_words_spec.rb
@@ -163,7 +163,7 @@ describe WatchedWord do
end
it "flags on revisions" do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
post = Fabricate(:post, topic: Fabricate(:topic, user: tl2_user), user: tl2_user)
expect {
PostRevisor.new(post).revise!(post.user, { raw: "Want some #{flag_word.word} for cheap?" }, revised_at: post.updated_at + 10.seconds)
diff --git a/spec/jobs/pull_hotlinked_images_spec.rb b/spec/jobs/pull_hotlinked_images_spec.rb
index fc258ada1eb..2415696ff00 100644
--- a/spec/jobs/pull_hotlinked_images_spec.rb
+++ b/spec/jobs/pull_hotlinked_images_spec.rb
@@ -32,7 +32,7 @@ describe Jobs::PullHotlinkedImages do
describe '#execute' do
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
FastImage.expects(:size).returns([100, 100]).at_least_once
end
diff --git a/spec/lib/upload_recovery_spec.rb b/spec/lib/upload_recovery_spec.rb
index 5e8e4500a92..b9a6b911ee7 100644
--- a/spec/lib/upload_recovery_spec.rb
+++ b/spec/lib/upload_recovery_spec.rb
@@ -31,7 +31,7 @@ RSpec.describe UploadRecovery do
before do
SiteSetting.authorized_extensions = 'png|pdf'
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
end
after do
diff --git a/spec/models/category_user_spec.rb b/spec/models/category_user_spec.rb
index 8313c0b7157..048a19a2d09 100644
--- a/spec/models/category_user_spec.rb
+++ b/spec/models/category_user_spec.rb
@@ -68,7 +68,7 @@ describe CategoryUser do
context 'integration' do
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
NotificationEmailer.enable
end
diff --git a/spec/models/discourse_single_sign_on_spec.rb b/spec/models/discourse_single_sign_on_spec.rb
index 68c72d11935..95f71d0f417 100644
--- a/spec/models/discourse_single_sign_on_spec.rb
+++ b/spec/models/discourse_single_sign_on_spec.rb
@@ -8,7 +8,7 @@ describe DiscourseSingleSignOn do
SiteSetting.sso_url = @sso_url
SiteSetting.enable_sso = true
SiteSetting.sso_secret = @sso_secret
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
end
def make_sso
diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb
index 0de0efd6bc5..37392835283 100644
--- a/spec/models/post_action_spec.rb
+++ b/spec/models/post_action_spec.rb
@@ -1072,7 +1072,7 @@ describe PostAction do
end
it "should create a notification in the related topic" do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
post = Fabricate(:post)
user = Fabricate(:user)
action = PostAction.act(user, post, PostActionType.types[:spam], message: "WAT")
@@ -1089,7 +1089,7 @@ describe PostAction do
end
it "should not add a moderator post when post is flagged via private message" do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
post = Fabricate(:post)
user = Fabricate(:user)
action = PostAction.act(user, post, PostActionType.types[:notify_user], message: "WAT")
diff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rb
index 80e707b25fe..4e117d9dc84 100644
--- a/spec/models/post_mover_spec.rb
+++ b/spec/models/post_mover_spec.rb
@@ -41,7 +41,7 @@ describe PostMover do
before do
SiteSetting.tagging_enabled = true
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
p1.replies << p3
p2.replies << p4
UserActionCreator.enable
@@ -570,7 +570,7 @@ describe PostMover do
before do
SiteSetting.tagging_enabled = true
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
p1.replies << p3
p2.replies << p4
UserActionCreator.enable
diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb
index 93eaf3600f4..fe827d16b89 100644
--- a/spec/models/post_spec.rb
+++ b/spec/models/post_spec.rb
@@ -995,7 +995,7 @@ describe Post do
end
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
end
describe 'when user can not mention a group' do
diff --git a/spec/models/quoted_post_spec.rb b/spec/models/quoted_post_spec.rb
index 7636a29d052..538a3f21ca4 100644
--- a/spec/models/quoted_post_spec.rb
+++ b/spec/models/quoted_post_spec.rb
@@ -2,7 +2,7 @@ require 'rails_helper'
describe QuotedPost do
it 'correctly extracts quotes' do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
topic = Fabricate(:topic)
post1 = create_post(topic: topic, post_number: 1, raw: "foo bar")
@@ -34,7 +34,7 @@ describe QuotedPost do
end
it "doesn't count quotes from the same post" do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
topic = Fabricate(:topic)
post = create_post(topic: topic, post_number: 1, raw: "foo bar")
diff --git a/spec/models/tag_user_spec.rb b/spec/models/tag_user_spec.rb
index 9a120f28901..a57373ddbc9 100644
--- a/spec/models/tag_user_spec.rb
+++ b/spec/models/tag_user_spec.rb
@@ -75,7 +75,7 @@ describe TagUser do
context "with some tag notification settings" do
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
end
let :watched_post do
diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb
index 82b850788c3..d0ecd98a432 100644
--- a/spec/models/topic_spec.rb
+++ b/spec/models/topic_spec.rb
@@ -1280,7 +1280,7 @@ describe Topic do
describe 'user that is watching the new category' do
it 'should generate the notification for the topic' do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
topic.posts << Fabricate(:post)
@@ -1602,7 +1602,7 @@ describe Topic do
let(:topic) { Fabricate(:topic, category: category) }
it "should be able to override category's default auto close" do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
expect(topic.topic_timers.first.duration).to eq(4)
diff --git a/spec/models/topic_timer_spec.rb b/spec/models/topic_timer_spec.rb
index cd6f2e2b703..e49d51a3b00 100644
--- a/spec/models/topic_timer_spec.rb
+++ b/spec/models/topic_timer_spec.rb
@@ -190,7 +190,7 @@ RSpec.describe TopicTimer, type: :model do
end
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
end
it 'should close the topic' do
@@ -219,7 +219,7 @@ RSpec.describe TopicTimer, type: :model do
end
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
end
it 'should open the topic' do
diff --git a/spec/models/topic_user_spec.rb b/spec/models/topic_user_spec.rb
index fca57e78047..ebe3e561f8d 100644
--- a/spec/models/topic_user_spec.rb
+++ b/spec/models/topic_user_spec.rb
@@ -451,7 +451,7 @@ describe TopicUser do
it "will receive email notification for every topic" do
user1 = Fabricate(:user)
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
SiteSetting.default_email_mailing_list_mode = true
SiteSetting.default_email_mailing_list_mode_frequency = 1
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index a1fbdcc0192..dfce0b76ef1 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -1088,7 +1088,7 @@ describe User do
context "with a reply" do
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
PostCreator.new(Fabricate(:user),
raw: 'whatever this is a raw post',
topic_id: topic.id,
diff --git a/spec/requests/admin/flags_controller_spec.rb b/spec/requests/admin/flags_controller_spec.rb
index 1c572fe7650..cba8d017e66 100644
--- a/spec/requests/admin/flags_controller_spec.rb
+++ b/spec/requests/admin/flags_controller_spec.rb
@@ -37,7 +37,7 @@ RSpec.describe Admin::FlagsController do
context '#agree' do
it 'should raise a reasonable error if a flag was deferred and then someone else agreed' do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
_post_action = PostAction.act(user, post_1, PostActionType.types[:spam], message: 'bad')
@@ -52,7 +52,7 @@ RSpec.describe Admin::FlagsController do
end
it 'should be able to agree and keep content' do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
post_action = PostAction.act(user, post_1, PostActionType.types[:spam], message: 'bad')
@@ -69,7 +69,7 @@ RSpec.describe Admin::FlagsController do
it 'should be able to hide spam' do
SiteSetting.allow_user_locale = true
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
post_action = PostAction.act(user, post_1, PostActionType.types[:spam], message: 'bad')
admin.update!(locale: 'ja')
@@ -90,7 +90,7 @@ RSpec.describe Admin::FlagsController do
end
it 'should not delete category topic' do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
category.update_column(:topic_id, first_post.topic_id)
PostAction.act(user, first_post, PostActionType.types[:spam], message: 'bad')
diff --git a/spec/requests/admin/groups_controller_spec.rb b/spec/requests/admin/groups_controller_spec.rb
index 32ff704d454..326a3012905 100644
--- a/spec/requests/admin/groups_controller_spec.rb
+++ b/spec/requests/admin/groups_controller_spec.rb
@@ -78,7 +78,7 @@ RSpec.describe Admin::GroupsController do
let(:user2) { Fabricate(:user, trust_level: 4) }
it "can assign users to a group by email or username" do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
put "/admin/groups/bulk.json", params: {
group_id: group.id, users: [user.username.upcase, user2.email, 'doesnt_exist']
diff --git a/spec/requests/categories_controller_spec.rb b/spec/requests/categories_controller_spec.rb
index df387c56abb..92f0a6dc534 100644
--- a/spec/requests/categories_controller_spec.rb
+++ b/spec/requests/categories_controller_spec.rb
@@ -78,7 +78,7 @@ describe CategoriesController do
describe "logged in" do
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
sign_in(admin)
end
@@ -226,7 +226,7 @@ describe CategoriesController do
context '#update' do
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
end
it "requires the user to be logged in" do
diff --git a/spec/requests/embed_controller_spec.rb b/spec/requests/embed_controller_spec.rb
index 85601b0b107..6c79ab98403 100644
--- a/spec/requests/embed_controller_spec.rb
+++ b/spec/requests/embed_controller_spec.rb
@@ -74,7 +74,7 @@ describe EmbedController do
let(:headers) { { 'REFERER' => embed_url } }
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
end
it "raises an error with no referer" do
diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rb
index 0829f3ee0ec..20a58b3a868 100644
--- a/spec/requests/posts_controller_spec.rb
+++ b/spec/requests/posts_controller_spec.rb
@@ -730,7 +730,7 @@ describe PostsController do
end
it 'allows to create posts in import_mode' do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
NotificationEmailer.enable
post_1 = Fabricate(:post)
user = Fabricate(:user)
diff --git a/spec/services/group_mentions_updater_spec.rb b/spec/services/group_mentions_updater_spec.rb
index 5487bd18867..0491dbdbe84 100644
--- a/spec/services/group_mentions_updater_spec.rb
+++ b/spec/services/group_mentions_updater_spec.rb
@@ -4,7 +4,7 @@ RSpec.describe GroupMentionsUpdater do
let(:post) { Fabricate(:post) }
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
end
describe '.update' do
diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rb
index f4888711b7d..c2f414041ca 100644
--- a/spec/services/post_alerter_spec.rb
+++ b/spec/services/post_alerter_spec.rb
@@ -213,7 +213,7 @@ describe PostAlerter do
let(:linking_post) { create_post(raw: "my magic topic\n##{Discourse.base_url}#{post1.url}") }
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
end
it "will notify correctly on linking" do
@@ -289,7 +289,7 @@ describe PostAlerter do
let(:topic) { mention_post.topic }
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
end
it 'notifies a user' do
@@ -591,7 +591,7 @@ describe PostAlerter do
end
it "correctly pushes notifications if configured correctly" do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
SiteSetting.allowed_user_api_push_urls = "https://site.com/push|https://site2.com/push"
2.times do |i|
diff --git a/spec/services/user_anonymizer_spec.rb b/spec/services/user_anonymizer_spec.rb
index 87a652925e7..8e3048b953d 100644
--- a/spec/services/user_anonymizer_spec.rb
+++ b/spec/services/user_anonymizer_spec.rb
@@ -136,7 +136,7 @@ describe UserAnonymizer do
end
it "updates the avatar in posts" do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
upload = Fabricate(:upload, user: user)
user.user_avatar = UserAvatar.new(user_id: user.id, custom_upload_id: upload.id)
user.uploaded_avatar_id = upload.id # chosen in user preferences
@@ -214,7 +214,7 @@ describe UserAnonymizer do
context "executes job" do
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
end
it "removes invites" do
@@ -302,7 +302,7 @@ describe UserAnonymizer do
end
it "exhaustively replaces all user ips" do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
link = IncomingLink.create!(current_user_id: user.id, ip_address: old_ip, post_id: post.id)
screened_email = ScreenedEmail.create!(email: user.email, ip_address: old_ip)
diff --git a/spec/services/username_changer_spec.rb b/spec/services/username_changer_spec.rb
index c4281a403a3..8ae83f191dc 100644
--- a/spec/services/username_changer_spec.rb
+++ b/spec/services/username_changer_spec.rb
@@ -2,7 +2,7 @@ require 'rails_helper'
describe UsernameChanger do
before do
- SiteSetting.queue_jobs = false
+ run_jobs_synchronously!
end
describe '#change' do
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index 455230e1b48..9d709d3e1dd 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -5,6 +5,12 @@ module Helpers
@next_seq = (@next_seq || 0) + 1
end
+ # If you don't `queue_jobs` it means you want to run them synchronously. This method
+ # makes that more clear in tests. It is automatically reset after every test.
+ def run_jobs_synchronously!
+ SiteSetting.queue_jobs = false
+ end
+
def log_in(fabricator = nil)
user = Fabricate(fabricator || :user)
log_in_user(user)