Method `create_from_defaults` will never give nil
This commit is contained in:
parent
cc5099c5ce
commit
0ff27ce059
|
|
@ -311,7 +311,7 @@ class ApplicationSetting < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create_from_defaults
|
def self.create_from_defaults
|
||||||
create(defaults)
|
build_from_defaults.tap(&:save)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.human_attribute_name(attr, _options = {})
|
def self.human_attribute_name(attr, _options = {})
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,7 @@ module Gitlab
|
||||||
elsif current_settings.present?
|
elsif current_settings.present?
|
||||||
current_settings
|
current_settings
|
||||||
else
|
else
|
||||||
::ApplicationSetting.create_from_defaults ||
|
::ApplicationSetting.create_from_defaults
|
||||||
in_memory_application_settings
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ describe Gitlab::CurrentSettings do
|
||||||
expect(ApplicationSetting).not_to receive(:current)
|
expect(ApplicationSetting).not_to receive(:current)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns an in-memory ApplicationSetting object' do
|
it 'returns a FakeApplicationSettings object' do
|
||||||
expect(described_class.current_application_settings).to be_a(Gitlab::FakeApplicationSettings)
|
expect(described_class.current_application_settings).to be_a(Gitlab::FakeApplicationSettings)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -157,17 +157,12 @@ describe Gitlab::CurrentSettings do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the application_settings table does not exists' do
|
context 'when the application_settings table does not exist' do
|
||||||
it 'returns an in-memory ApplicationSetting object' do
|
it 'returns a FakeApplicationSettings object' do
|
||||||
expect(ApplicationSetting).to receive(:create_from_defaults).and_raise(ActiveRecord::StatementInvalid)
|
expect(Gitlab::Database)
|
||||||
|
.to receive(:cached_table_exists?)
|
||||||
expect(described_class.current_application_settings).to be_a(Gitlab::FakeApplicationSettings)
|
.with('application_settings')
|
||||||
end
|
.and_return(false)
|
||||||
end
|
|
||||||
|
|
||||||
context 'when the application_settings table is not fully migrated' do
|
|
||||||
it 'returns an in-memory ApplicationSetting object' do
|
|
||||||
expect(ApplicationSetting).to receive(:create_from_defaults).and_raise(ActiveRecord::UnknownAttributeError)
|
|
||||||
|
|
||||||
expect(described_class.current_application_settings).to be_a(Gitlab::FakeApplicationSettings)
|
expect(described_class.current_application_settings).to be_a(Gitlab::FakeApplicationSettings)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue