PERF: Speed up slow tests in our test suite.
Before ``` Finished in 7 minutes 23 seconds (files took 4.15 seconds to load) 7145 examples, 0 failures, 10 pending ``` After ``` Finished in 6 minutes 12 seconds (files took 4.41 seconds to load) 7145 examples, 0 failures, 10 pending ```
This commit is contained in:
parent
8fd915a11a
commit
80e348d226
|
@ -3,6 +3,7 @@ module Jobs
|
|||
class CreateAvatarThumbnails < Jobs::Base
|
||||
|
||||
def execute(args)
|
||||
return if Rails.env.test?
|
||||
upload_id = args[:upload_id]
|
||||
|
||||
raise Discourse::InvalidParameters.new(:upload_id) if upload_id.blank?
|
||||
|
|
|
@ -33,14 +33,12 @@ class TranslationOverride < ActiveRecord::Base
|
|||
MessageBus.publish('/i18n-flush', { refresh: true })
|
||||
end
|
||||
|
||||
def lookup_original_text
|
||||
I18n::Backend::Simple.new.send(
|
||||
:lookup, self.locale, self.translation_key
|
||||
)
|
||||
end
|
||||
|
||||
def check_interpolation_keys
|
||||
if original_text = lookup_original_text
|
||||
original_text = I18n.overrides_disabled do
|
||||
I18n.backend.send(:lookup, self.locale, self.translation_key)
|
||||
end
|
||||
|
||||
if original_text
|
||||
original_interpolation_keys = I18nInterpolationKeysFinder.find(original_text)
|
||||
new_interpolation_keys = I18nInterpolationKeysFinder.find(value)
|
||||
missing_keys = (original_interpolation_keys - new_interpolation_keys)
|
||||
|
|
|
@ -39,7 +39,7 @@ class UploadCreator
|
|||
|
||||
if @filename[/\.svg$/i]
|
||||
whitelist_svg!
|
||||
else
|
||||
elsif !Rails.env.test?
|
||||
convert_to_jpeg! if should_convert_to_jpeg?
|
||||
downsize! if should_downsize?
|
||||
|
||||
|
|
|
@ -48,12 +48,11 @@ describe Admin::SiteTextsController do
|
|||
|
||||
describe 'failure' do
|
||||
before do
|
||||
TranslationOverride.any_instance.expects(:lookup_original_text)
|
||||
.returns('%{first} %{second}')
|
||||
I18n.backend.store_translations(:en, some_key: '%{first} %{second}')
|
||||
end
|
||||
|
||||
it 'returns the right error message' do
|
||||
xhr :put, :update, id: 'title', site_text: { value: 'hello %{key}' }
|
||||
xhr :put, :update, id: 'some_key', site_text: { value: 'hello %{key}' }
|
||||
|
||||
expect(response.status).to eq(422)
|
||||
|
||||
|
|
|
@ -67,15 +67,15 @@ describe DiscourseSingleSignOn do
|
|||
let(:ip_address) { "127.0.0.1" }
|
||||
|
||||
it "can lookup or create user when name is blank" do
|
||||
# so we can create system messages
|
||||
Fabricate(:admin)
|
||||
sso = DiscourseSingleSignOn.new
|
||||
sso.username = "test"
|
||||
sso.name = ""
|
||||
sso.email = "test@test.com"
|
||||
sso.external_id = "A"
|
||||
sso.suppress_welcome_message = true
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
expect(user).to_not be_nil
|
||||
|
||||
expect(user.persisted?).to eq(true)
|
||||
end
|
||||
|
||||
it "unstaged users" do
|
||||
|
@ -111,6 +111,7 @@ describe DiscourseSingleSignOn do
|
|||
sso.external_id = "id"
|
||||
sso.admin = true
|
||||
sso.moderator = true
|
||||
sso.suppress_welcome_message = true
|
||||
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
staff_group.reload
|
||||
|
@ -233,14 +234,15 @@ describe DiscourseSingleSignOn do
|
|||
end
|
||||
|
||||
context 'trusting emails' do
|
||||
let(:sso) {
|
||||
let(:sso) do
|
||||
sso = DiscourseSingleSignOn.new
|
||||
sso.username = "test"
|
||||
sso.name = "test"
|
||||
sso.email = "test@example.com"
|
||||
sso.external_id = "A"
|
||||
sso.suppress_welcome_message = true
|
||||
sso
|
||||
}
|
||||
end
|
||||
|
||||
it 'activates users by default' do
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
|
@ -327,22 +329,22 @@ describe DiscourseSingleSignOn do
|
|||
end
|
||||
|
||||
context 'setting bio for a user' do
|
||||
let(:sso) {
|
||||
let(:sso) do
|
||||
sso = DiscourseSingleSignOn.new
|
||||
sso.username = "test"
|
||||
sso.name = "test"
|
||||
sso.email = "test@test.com"
|
||||
sso.external_id = "100"
|
||||
sso.bio = "This **is** the bio"
|
||||
sso.suppress_welcome_message = true
|
||||
sso
|
||||
}
|
||||
end
|
||||
|
||||
it 'can set bio if supplied on new users or users with empty bio' do
|
||||
# new account
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
expect(user.user_profile.bio_cooked).to match_html("<p>This <strong>is</strong> the bio</p>")
|
||||
|
||||
|
||||
# no override by default
|
||||
sso.bio = "new profile"
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
|
@ -350,8 +352,7 @@ describe DiscourseSingleSignOn do
|
|||
expect(user.user_profile.bio_cooked).to match_html("<p>This <strong>is</strong> the bio</p>")
|
||||
|
||||
# yes override for blank
|
||||
user.user_profile.bio_raw = " "
|
||||
user.user_profile.save!
|
||||
user.user_profile.update!(bio_raw: '')
|
||||
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
expect(user.user_profile.bio_cooked).to match_html("<p>new profile</p>")
|
||||
|
@ -362,69 +363,67 @@ describe DiscourseSingleSignOn do
|
|||
SiteSetting.sso_overrides_bio = true
|
||||
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
expect(user.user_profile.bio_cooked).to match_html("<p>new profile 2</p>")
|
||||
expect(user.user_profile.bio_cooked).to match_html("<p>new profile 2</p")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'when sso_overrides_avatar is not enabled' do
|
||||
|
||||
|
||||
it "correctly handles provided avatar_urls" do
|
||||
Sidekiq::Testing.inline! do
|
||||
sso = DiscourseSingleSignOn.new
|
||||
sso.external_id = 666
|
||||
sso.email = "sam@sam.com"
|
||||
sso.name = "sam"
|
||||
sso.username = "sam"
|
||||
sso.avatar_url = "http://awesome.com/image.png"
|
||||
sso = DiscourseSingleSignOn.new
|
||||
sso.external_id = 666
|
||||
sso.email = "sam@sam.com"
|
||||
sso.name = "sam"
|
||||
sso.username = "sam"
|
||||
sso.avatar_url = "http://awesome.com/image.png"
|
||||
sso.suppress_welcome_message = true
|
||||
|
||||
FileHelper.stubs(:download).returns(file_from_fixtures("logo.png"))
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
avatar_id = user.uploaded_avatar_id
|
||||
FileHelper.stubs(:download).returns(file_from_fixtures("logo.png"))
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
avatar_id = user.uploaded_avatar_id
|
||||
|
||||
# initial creation ...
|
||||
expect(avatar_id).to_not eq(nil)
|
||||
# initial creation ...
|
||||
expect(avatar_id).to_not eq(nil)
|
||||
|
||||
# junk avatar id should be updated
|
||||
old_id = user.uploaded_avatar_id
|
||||
Upload.destroy(old_id)
|
||||
# junk avatar id should be updated
|
||||
old_id = user.uploaded_avatar_id
|
||||
Upload.destroy(old_id)
|
||||
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
avatar_id = user.uploaded_avatar_id
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
avatar_id = user.uploaded_avatar_id
|
||||
|
||||
expect(avatar_id).to_not eq(nil)
|
||||
expect(old_id).to_not eq(avatar_id)
|
||||
expect(avatar_id).to_not eq(nil)
|
||||
expect(old_id).to_not eq(avatar_id)
|
||||
|
||||
FileHelper.stubs(:download) { raise "should not be called" }
|
||||
sso.avatar_url = "https://some.new/avatar.png"
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
FileHelper.stubs(:download) { raise "should not be called" }
|
||||
sso.avatar_url = "https://some.new/avatar.png"
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
|
||||
# avatar updated but no override specified ...
|
||||
expect(user.uploaded_avatar_id).to eq(avatar_id)
|
||||
# avatar updated but no override specified ...
|
||||
expect(user.uploaded_avatar_id).to eq(avatar_id)
|
||||
|
||||
sso.avatar_force_update = true
|
||||
FileHelper.stubs(:download).returns(file_from_fixtures("logo-dev.png"))
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
sso.avatar_force_update = true
|
||||
FileHelper.stubs(:download).returns(file_from_fixtures("logo-dev.png"))
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
|
||||
# we better have a new avatar
|
||||
expect(user.uploaded_avatar_id).not_to eq(avatar_id)
|
||||
expect(user.uploaded_avatar_id).not_to eq(nil)
|
||||
# we better have a new avatar
|
||||
expect(user.uploaded_avatar_id).not_to eq(avatar_id)
|
||||
expect(user.uploaded_avatar_id).not_to eq(nil)
|
||||
|
||||
avatar_id = user.uploaded_avatar_id
|
||||
avatar_id = user.uploaded_avatar_id
|
||||
|
||||
sso.avatar_force_update = true
|
||||
FileHelper.stubs(:download) { raise "not found" }
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
sso.avatar_force_update = true
|
||||
FileHelper.stubs(:download) { raise "not found" }
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
|
||||
# we better have the same avatar
|
||||
expect(user.uploaded_avatar_id).to eq(avatar_id)
|
||||
end
|
||||
# we better have the same avatar
|
||||
expect(user.uploaded_avatar_id).to eq(avatar_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -4,8 +4,7 @@ describe TranslationOverride do
|
|||
context 'validations' do
|
||||
describe '#value' do
|
||||
before do
|
||||
described_class.any_instance.expects(:lookup_original_text)
|
||||
.returns('%{first} %{second}')
|
||||
I18n.backend.store_translations(:en, some_key: '%{first} %{second}')
|
||||
end
|
||||
|
||||
describe 'when interpolation keys are missing' do
|
||||
|
|
Loading…
Reference in New Issue