From 56e9ff6853d9ecd6500bee2a8d1ab86dd619413a Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 31 May 2018 15:34:46 +0800 Subject: [PATCH] Revert "DEV: Queue jobs in tests by default." Too risky for now This reverts commit be28154d3b9289a249d413d462705cd075375888. --- .../integration/discobot_welcome_post_spec.rb | 1 + .../discourse-narrative-bot/spec/user_spec.rb | 1 + .../auth/github_authenticator_spec.rb | 2 ++ spec/components/email/receiver_spec.rb | 2 ++ spec/components/post_creator_spec.rb | 7 +++-- spec/components/post_destroyer_spec.rb | 1 - spec/components/post_revisor_spec.rb | 4 --- .../admin/email_controller_spec.rb | 1 + .../controllers/categories_controller_spec.rb | 6 ++--- spec/integration/topic_auto_close_spec.rb | 1 + spec/integration/watched_words_spec.rb | 1 - spec/jobs/delete_topic_spec.rb | 4 +++ spec/jobs/jobs_spec.rb | 2 ++ spec/jobs/publish_topic_to_category_spec.rb | 4 +++ spec/jobs/pull_hotlinked_images_spec.rb | 2 +- spec/jobs/toggle_topic_closed_spec.rb | 4 +++ spec/jobs/topic_reminder_spec.rb | 4 +++ spec/models/category_user_spec.rb | 1 - spec/models/discourse_single_sign_on_spec.rb | 1 - spec/models/post_action_spec.rb | 2 +- spec/models/post_mover_spec.rb | 1 - spec/models/quoted_post_spec.rb | 2 -- spec/models/tag_user_spec.rb | 3 --- spec/models/topic_spec.rb | 5 +--- spec/models/topic_timer_spec.rb | 12 +++------ spec/models/topic_user_spec.rb | 1 - spec/models/user_spec.rb | 2 +- spec/models/web_hook_spec.rb | 5 ++++ spec/rails_helper.rb | 4 --- spec/requests/admin/flags_controller_spec.rb | 4 +-- spec/requests/admin/groups_controller_spec.rb | 2 -- spec/requests/admin/users_controller_spec.rb | 2 ++ spec/requests/embed_controller_spec.rb | 4 --- spec/requests/groups_controller_spec.rb | 1 + spec/requests/posts_controller_spec.rb | 3 ++- spec/requests/session_controller_spec.rb | 5 ++++ spec/requests/topics_controller_spec.rb | 2 ++ spec/requests/users_controller_spec.rb | 27 +++++++++++++------ spec/services/group_mentions_updater_spec.rb | 4 --- spec/services/post_alerter_spec.rb | 10 +------ spec/services/user_anonymizer_spec.rb | 1 - spec/services/username_changer_spec.rb | 3 --- 42 files changed, 79 insertions(+), 75 deletions(-) diff --git a/plugins/discourse-narrative-bot/spec/integration/discobot_welcome_post_spec.rb b/plugins/discourse-narrative-bot/spec/integration/discobot_welcome_post_spec.rb index f9087b74597..9ada964d7ab 100644 --- a/plugins/discourse-narrative-bot/spec/integration/discobot_welcome_post_spec.rb +++ b/plugins/discourse-narrative-bot/spec/integration/discobot_welcome_post_spec.rb @@ -4,6 +4,7 @@ describe "Discobot welcome post" do let(:user) { Fabricate(:user) } before do + SiteSetting.queue_jobs = true SiteSetting.discourse_narrative_bot_enabled = true end diff --git a/plugins/discourse-narrative-bot/spec/user_spec.rb b/plugins/discourse-narrative-bot/spec/user_spec.rb index 7fa5cab5477..d0dba54a7ee 100644 --- a/plugins/discourse-narrative-bot/spec/user_spec.rb +++ b/plugins/discourse-narrative-bot/spec/user_spec.rb @@ -78,6 +78,7 @@ describe User do describe 'when welcome message is configured to be delayed' do before do SiteSetting.discourse_narrative_bot_welcome_post_delay = 100 + SiteSetting.queue_jobs = true end it 'should delay the welcome post until user logs in' do diff --git a/spec/components/auth/github_authenticator_spec.rb b/spec/components/auth/github_authenticator_spec.rb index 17fff987cdf..011c440971b 100644 --- a/spec/components/auth/github_authenticator_spec.rb +++ b/spec/components/auth/github_authenticator_spec.rb @@ -207,6 +207,8 @@ describe Auth::GithubAuthenticator do describe 'avatar retrieval' do let(:job_klass) { Jobs::DownloadAvatarFromUrl } + before { SiteSetting.queue_jobs = true } + context 'when user has a custom avatar' do let(:user_avatar) { Fabricate(:user_avatar, custom_upload: Fabricate(:upload)) } let(:user_with_custom_avatar) { Fabricate(:user, user_avatar: user_avatar) } diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb index a6525afce8c..d0d2048edc7 100644 --- a/spec/components/email/receiver_spec.rb +++ b/spec/components/email/receiver_spec.rb @@ -389,6 +389,7 @@ describe Email::Receiver do it "supports attached images in TEXT part" do SiteSetting.incoming_email_prefer_html = false + SiteSetting.queue_jobs = true expect { process(:no_body_with_image) }.to change { topic.posts.count } expect(topic.posts.last.raw).to match(/ embed_url } } - before do - SiteSetting.queue_jobs = false - end - after do expect(response).to be_success expect(response.headers['X-Frame-Options']).to eq("ALLOWALL") diff --git a/spec/requests/groups_controller_spec.rb b/spec/requests/groups_controller_spec.rb index b268542391c..8a25aea5fd1 100644 --- a/spec/requests/groups_controller_spec.rb +++ b/spec/requests/groups_controller_spec.rb @@ -496,6 +496,7 @@ describe GroupsController do before do user.update_attributes!(admin: true) sign_in(user) + SiteSetting.queue_jobs = true end it 'should be able to update the group' do diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rb index f43a5b511f5..6ad5f32dd90 100644 --- a/spec/requests/posts_controller_spec.rb +++ b/spec/requests/posts_controller_spec.rb @@ -568,7 +568,6 @@ describe PostsController do end it 'allows to create posts in import_mode' do - SiteSetting.queue_jobs = false NotificationEmailer.enable post_1 = Fabricate(:post) user = Fabricate(:user) @@ -783,6 +782,8 @@ describe PostsController do end it 'can create a reply to a post' do + SiteSetting.queue_jobs = true + topic = Fabricate(:private_message_post, user: user).topic post_2 = Fabricate(:private_message_post, user: user, topic: topic) diff --git a/spec/requests/session_controller_spec.rb b/spec/requests/session_controller_spec.rb index 3dfb07c5833..3005b10a702 100644 --- a/spec/requests/session_controller_spec.rb +++ b/spec/requests/session_controller_spec.rb @@ -435,6 +435,7 @@ RSpec.describe SessionController do end it 'sends an activation email' do + SiteSetting.queue_jobs = true sso = get_sso('/a/') sso.external_id = '666' # the number of the beast sso.email = 'bob@bob.com' @@ -1199,6 +1200,7 @@ RSpec.describe SessionController do context 'for a non existant username' do it "doesn't generate a new token for a made up username" do + SiteSetting.queue_jobs = true expect do post "/session/forgot_password.json", params: { login: 'made_up' } end.not_to change(EmailToken, :count) @@ -1236,6 +1238,7 @@ RSpec.describe SessionController do end it "enqueues an email" do + SiteSetting.queue_jobs = true post "/session/forgot_password.json", params: { login: user.username } expect(Jobs::CriticalUserEmail.jobs.size).to eq(1) end @@ -1251,6 +1254,7 @@ RSpec.describe SessionController do end it 'enqueues no email' do + SiteSetting.queue_jobs = true post "/session/forgot_password.json", params: { login: system.username } expect(Jobs::CriticalUserEmail.jobs.size).to eq(0) end @@ -1266,6 +1270,7 @@ RSpec.describe SessionController do end it 'enqueues no email' do + SiteSetting.queue_jobs = true post "/session/forgot_password.json", params: { login: staged.username } expect(Jobs::CriticalUserEmail.jobs.size).to eq(0) end diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index 3be410083cd..64d11da2c43 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -258,6 +258,8 @@ RSpec.describe TopicsController do describe 'publishing topic to category in the future' do it 'should be able to create the topic status update' do + SiteSetting.queue_jobs = true + post "/t/#{topic.id}/timer.json", params: { time: 24, status_type: TopicTimer.types[3], diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 5b7e588c528..6712de39ac5 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -25,6 +25,10 @@ describe UsersController do context 'valid token' do context 'welcome message' do + before do + SiteSetting.queue_jobs = true + end + it 'enqueues a welcome message if the user object indicates so' do user.update(active: false) put "/u/activate-account/#{token}" @@ -349,6 +353,7 @@ describe UsersController do context 'enqueues mail' do it 'enqueues mail with admin email and sso enabled' do + SiteSetting.queue_jobs = true put "/u/admin-login", params: { email: admin.email } expect(response.status).to eq(200) expect(Jobs::CriticalUserEmail.jobs.size).to eq(1) @@ -464,7 +469,8 @@ describe UsersController do UsersController.any_instance.stubs(:honeypot_value).returns(nil) UsersController.any_instance.stubs(:challenge_value).returns(nil) SiteSetting.allow_new_registrations = true - @user = Fabricate.build(:user, password: "strongpassword") + @user = Fabricate.build(:user) + @user.password = "strongpassword" end let(:post_user_params) do @@ -518,6 +524,8 @@ describe UsersController do end it 'creates a user correctly' do + SiteSetting.queue_jobs = true + post_user expect(response.status).to eq(200) expect(JSON.parse(response.body)['active']).to be_falsey @@ -537,6 +545,8 @@ describe UsersController do before { SiteSetting.must_approve_users = true } it 'creates a user correctly' do + SiteSetting.queue_jobs = true + post_user expect(response.status).to eq(200) @@ -609,6 +619,7 @@ describe UsersController do let(:api_key) { Fabricate(:api_key, user: admin) } it "creates the user as active with a regular key" do + SiteSetting.queue_jobs = true SiteSetting.send_welcome_message = true SiteSetting.must_approve_users = true @@ -689,6 +700,7 @@ describe UsersController do before { User.any_instance.stubs(:active?).returns(true) } it 'enqueues a welcome email' do + SiteSetting.queue_jobs = true User.any_instance.expects(:enqueue_welcome_message).with('welcome_user') post_user @@ -1586,8 +1598,7 @@ describe UsersController do password: "strongpassword", email: "dsdsds@sasa.com" } - - User.find_by(username: "osamatest") + User.where(username: "osamatest").first end context 'for an existing user' do @@ -1687,12 +1698,10 @@ describe UsersController do end it 'should send an email' do - expect do - post "/u/action/send_activation_email.json", params: { - username: user.username - } - end.to change { Jobs::CriticalUserEmail.jobs.size }.by(1) + SiteSetting.queue_jobs = true + post "/u/action/send_activation_email.json", params: { username: user.username } + expect(Jobs::CriticalUserEmail.jobs.size).to eq(1) expect(session[SessionController::ACTIVATE_USER_KEY]).to eq(nil) end end @@ -1700,6 +1709,7 @@ describe UsersController do context 'when username does not exist' do it 'should not send an email' do + SiteSetting.queue_jobs = true post "/u/action/send_activation_email.json", params: { username: 'nopenopenopenope' } expect(response.status).to eq(404) expect(Jobs::CriticalUserEmail.jobs.size).to eq(0) @@ -2681,6 +2691,7 @@ describe UsersController do describe '#email_login' do before do + SiteSetting.queue_jobs = true SiteSetting.enable_local_logins_via_email = true end diff --git a/spec/services/group_mentions_updater_spec.rb b/spec/services/group_mentions_updater_spec.rb index 7bdfce7cde3..301fa134d50 100644 --- a/spec/services/group_mentions_updater_spec.rb +++ b/spec/services/group_mentions_updater_spec.rb @@ -3,10 +3,6 @@ require 'rails_helper' RSpec.describe GroupMentionsUpdater do let(:post) { Fabricate(:post) } - before do - SiteSetting.queue_jobs = false - end - describe '.update' do it 'should update valid group mentions' do new_group_name = 'awesome_team' diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rb index 87408d112f9..c7abefee984 100644 --- a/spec/services/post_alerter_spec.rb +++ b/spec/services/post_alerter_spec.rb @@ -307,10 +307,6 @@ describe PostAlerter do let(:user) { post1.user } let(:linking_post) { create_post(raw: "my magic topic\n##{Discourse.base_url}#{post1.url}") } - before do - SiteSetting.queue_jobs = false - end - it "will notify correctly on linking" do linking_post @@ -383,10 +379,6 @@ describe PostAlerter do let(:mention_post) { create_post_with_alerts(user: user, raw: 'Hello @eviltrout') } let(:topic) { mention_post.topic } - before do - SiteSetting.queue_jobs = false - end - it 'notifies a user' do expect { mention_post @@ -637,6 +629,7 @@ describe PostAlerter do let(:topic) { mention_post.topic } it "pushes nothing to suspended users" do + SiteSetting.queue_jobs = true SiteSetting.allowed_user_api_push_urls = "https://site.com/push|https://site2.com/push" evil_trout.update_columns(suspended_till: 1.year.from_now) @@ -654,7 +647,6 @@ describe PostAlerter do end it "correctly pushes notifications if configured correctly" do - SiteSetting.queue_jobs = false 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 f397bc930bb..58eefd90edf 100644 --- a/spec/services/user_anonymizer_spec.rb +++ b/spec/services/user_anonymizer_spec.rb @@ -120,7 +120,6 @@ describe UserAnonymizer do end it "updates the avatar in posts" do - SiteSetting.queue_jobs = false 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 diff --git a/spec/services/username_changer_spec.rb b/spec/services/username_changer_spec.rb index 87e5da2b0c9..15b41d5f8b2 100644 --- a/spec/services/username_changer_spec.rb +++ b/spec/services/username_changer_spec.rb @@ -1,9 +1,6 @@ require 'rails_helper' describe UsernameChanger do - before do - SiteSetting.queue_jobs = false - end describe '#change' do let(:user) { Fabricate(:user) }