mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 19:46:55 +08:00
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
|
||||
)
|
||||
def check_interpolation_keys
|
||||
original_text = I18n.overrides_disabled do
|
||||
I18n.backend.send(:lookup, self.locale, self.translation_key)
|
||||
end
|
||||
|
||||
def check_interpolation_keys
|
||||
if original_text = lookup_original_text
|
||||
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,22 +363,21 @@ 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.suppress_welcome_message = true
|
||||
|
||||
FileHelper.stubs(:download).returns(file_from_fixtures("logo.png"))
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
|
@ -425,7 +425,6 @@ describe DiscourseSingleSignOn do
|
|||
# we better have the same avatar
|
||||
expect(user.uploaded_avatar_id).to eq(avatar_id)
|
||||
end
|
||||
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
Block a user