DEV: Fix flaky specs (#13226)

Some specs failed when `LOAD_PLUGINS=1` was set while migrating the test DB and the narrative-bot plugin disabled the `send_welcome_message` site setting.
This commit is contained in:
Gerhard Schlager 2021-06-01 14:38:55 +02:00 committed by GitHub
parent fb4dc2f35c
commit 3df928d609
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 6 deletions

View File

@ -31,16 +31,15 @@ describe Onebox::Engine::InstagramOnebox do
stub_request(:get, api_link).to_return(status: 200, body: onebox_response("instagram")) stub_request(:get, api_link).to_return(status: 200, body: onebox_response("instagram"))
stub_request(:get, "https://api.instagram.com/oembed/?url=https://www.instagram.com/p/CARbvuYDm3Q") stub_request(:get, "https://api.instagram.com/oembed/?url=https://www.instagram.com/p/CARbvuYDm3Q")
.to_return(status: 200, body: onebox_response("instagram")) .to_return(status: 200, body: onebox_response("instagram"))
@previous_options = Onebox.options.to_h
Onebox.options = { facebook_app_access_token: access_token }
end end
around do |example| after do
previous_options = Onebox.options.to_h Onebox.options = @previous_options
example.run
Onebox.options = previous_options
end end
it "includes title" do it "includes title" do
Onebox.options = { facebook_app_access_token: access_token }
onebox = described_class.new(link) onebox = described_class.new(link)
html = onebox.to_html html = onebox.to_html
@ -48,7 +47,6 @@ describe Onebox::Engine::InstagramOnebox do
end end
it "includes image" do it "includes image" do
Onebox.options = { facebook_app_access_token: access_token }
onebox = described_class.new(link) onebox = described_class.new(link)
html = onebox.to_html html = onebox.to_html
@ -62,6 +60,12 @@ describe Onebox::Engine::InstagramOnebox do
before do before do
stub_request(:get, api_link).to_return(status: 200, body: onebox_response("instagram_old_onebox")) stub_request(:get, api_link).to_return(status: 200, body: onebox_response("instagram_old_onebox"))
@previous_options = Onebox.options.to_h
Onebox.options = {}
end
after do
Onebox.options = @previous_options
end end
it "includes title" do it "includes title" do

View File

@ -153,6 +153,8 @@ describe User do
let(:user) { Fabricate(:user) } let(:user) { Fabricate(:user) }
it 'enqueues the system message' do it 'enqueues the system message' do
SiteSetting.send_welcome_message = true
expect_enqueued_with(job: :send_system_message, args: { user_id: user.id, message_type: 'welcome_user' }) do expect_enqueued_with(job: :send_system_message, args: { user_id: user.id, message_type: 'welcome_user' }) do
user.enqueue_welcome_message('welcome_user') user.enqueue_welcome_message('welcome_user')
end end

View File

@ -64,6 +64,7 @@ describe UsersController do
context 'valid token' do context 'valid token' do
context 'welcome message' do context 'welcome message' do
it 'enqueues a welcome message if the user object indicates so' do it 'enqueues a welcome message if the user object indicates so' do
SiteSetting.send_welcome_message = true
user.update(active: false) user.update(active: false)
put "/u/activate-account/#{token}" put "/u/activate-account/#{token}"
expect(response.status).to eq(200) expect(response.status).to eq(200)