summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/security/ci_configuration/container_scanning_build_action_spec.rb10
-rw-r--r--spec/models/integrations/jira_spec.rb29
-rw-r--r--spec/models/user_preference_spec.rb157
-rw-r--r--spec/models/user_spec.rb17
-rw-r--r--spec/workers/namespaces/root_statistics_worker_spec.rb1
5 files changed, 178 insertions, 36 deletions
diff --git a/spec/lib/security/ci_configuration/container_scanning_build_action_spec.rb b/spec/lib/security/ci_configuration/container_scanning_build_action_spec.rb
index 38066e41c53..5b1db66beb0 100644
--- a/spec/lib/security/ci_configuration/container_scanning_build_action_spec.rb
+++ b/spec/lib/security/ci_configuration/container_scanning_build_action_spec.rb
@@ -33,7 +33,7 @@ RSpec.describe Security::CiConfiguration::ContainerScanningBuildAction do
RANDOM: make sure this persists
include:
- template: existing.yml
- - template: Security/Container-Scanning.gitlab-ci.yml
+ - template: Jobs/Container-Scanning.gitlab-ci.yml
CI_YML
end
@@ -85,7 +85,7 @@ RSpec.describe Security::CiConfiguration::ContainerScanningBuildAction do
variables:
RANDOM: make sure this persists
include:
- - template: Security/Container-Scanning.gitlab-ci.yml
+ - template: Jobs/Container-Scanning.gitlab-ci.yml
CI_YML
end
@@ -93,7 +93,7 @@ RSpec.describe Security::CiConfiguration::ContainerScanningBuildAction do
let(:gitlab_ci_content) do
{ "stages" => %w(test),
"variables" => { "RANDOM" => "make sure this persists" },
- "include" => [{ "template" => "Security/Container-Scanning.gitlab-ci.yml" }] }
+ "include" => [{ "template" => "Jobs/Container-Scanning.gitlab-ci.yml" }] }
end
it 'generates the correct YML' do
@@ -106,7 +106,7 @@ RSpec.describe Security::CiConfiguration::ContainerScanningBuildAction do
let(:gitlab_ci_content) do
{ "stages" => %w(test),
"variables" => { "RANDOM" => "make sure this persists" },
- "include" => { "template" => "Security/Container-Scanning.gitlab-ci.yml" } }
+ "include" => { "template" => "Jobs/Container-Scanning.gitlab-ci.yml" } }
end
it 'generates the correct YML' do
@@ -138,7 +138,7 @@ RSpec.describe Security::CiConfiguration::ContainerScanningBuildAction do
# DOCKER_USER: ...
# DOCKER_PASSWORD: ...
include:
- - template: Security/Container-Scanning.gitlab-ci.yml
+ - template: Jobs/Container-Scanning.gitlab-ci.yml
CI_YML
end
diff --git a/spec/models/integrations/jira_spec.rb b/spec/models/integrations/jira_spec.rb
index 819dad9d46d..6cc5222fa43 100644
--- a/spec/models/integrations/jira_spec.rb
+++ b/spec/models/integrations/jira_spec.rb
@@ -466,7 +466,8 @@ RSpec.describe Integrations::Jira do
end
describe '#client' do
- subject do
+ it 'uses the default GitLab::HTTP timeouts' do
+ timeouts = Gitlab::HTTP::DEFAULT_TIMEOUT_OPTIONS
stub_request(:get, 'http://jira.example.com/foo')
expect(Gitlab::HTTP).to receive(:httparty_perform_request)
@@ -474,32 +475,6 @@ RSpec.describe Integrations::Jira do
jira_integration.client.get('/foo')
end
-
- context 'when the FF :jira_raise_timeouts is enabled' do
- let(:timeouts) do
- {
- open_timeout: 2.minutes,
- read_timeout: 2.minutes,
- write_timeout: 2.minutes
- }
- end
-
- it 'uses custom timeouts' do
- subject
- end
- end
-
- context 'when the FF :jira_raise_timeouts is disabled' do
- before do
- stub_feature_flags(jira_raise_timeouts: false)
- end
-
- let(:timeouts) { Gitlab::HTTP::DEFAULT_TIMEOUT_OPTIONS }
-
- it 'uses the default GitLab::HTTP timeouts' do
- subject
- end
- end
end
describe '#find_issue' do
diff --git a/spec/models/user_preference_spec.rb b/spec/models/user_preference_spec.rb
index d76334d7c9e..a6f64c90657 100644
--- a/spec/models/user_preference_spec.rb
+++ b/spec/models/user_preference_spec.rb
@@ -3,7 +3,9 @@
require 'spec_helper'
RSpec.describe UserPreference do
- let(:user_preference) { create(:user_preference) }
+ let_it_be(:user) { create(:user) }
+
+ let(:user_preference) { create(:user_preference, user: user) }
describe 'validations' do
describe 'diffs_deletion_color and diffs_addition_color' do
@@ -132,10 +134,24 @@ RSpec.describe UserPreference do
describe '#tab_width' do
it 'is set to 8 by default' do
# Intentionally not using factory here to test the constructor.
- pref = UserPreference.new
+ pref = described_class.new
+
+ expect(pref.tab_width).to eq(8)
+ end
+
+ it 'returns default value when assigning nil' do
+ pref = described_class.new(tab_width: nil)
+
expect(pref.tab_width).to eq(8)
end
+ it 'returns default value when the value is NULL' do
+ pref = create(:user_preference, user: user)
+ pref.update_column(:tab_width, nil)
+
+ expect(pref.reload.tab_width).to eq(8)
+ end
+
it do
is_expected.to validate_numericality_of(:tab_width)
.only_integer
@@ -143,4 +159,141 @@ RSpec.describe UserPreference do
.is_less_than_or_equal_to(12)
end
end
+
+ describe '#tab_width=' do
+ it 'sets to default value when nil' do
+ pref = described_class.new(tab_width: nil)
+
+ expect(pref.read_attribute(:tab_width)).to eq(8)
+ end
+
+ it 'sets user values' do
+ pref = described_class.new(tab_width: 12)
+
+ expect(pref.read_attribute(:tab_width)).to eq(12)
+ end
+ end
+
+ describe '#time_display_relative' do
+ it 'is set to true by default' do
+ pref = described_class.new
+
+ expect(pref.time_display_relative).to eq(true)
+ end
+
+ it 'returns default value when assigning nil' do
+ pref = described_class.new(time_display_relative: nil)
+
+ expect(pref.time_display_relative).to eq(true)
+ end
+
+ it 'returns default value when the value is NULL' do
+ pref = create(:user_preference, user: user)
+ pref.update_column(:time_display_relative, nil)
+
+ expect(pref.reload.time_display_relative).to eq(true)
+ end
+
+ it 'returns assigned value' do
+ pref = described_class.new(time_display_relative: false)
+
+ expect(pref.time_display_relative).to eq(false)
+ end
+ end
+
+ describe '#time_display_relative=' do
+ it 'sets to default value when nil' do
+ pref = described_class.new(time_display_relative: nil)
+
+ expect(pref.read_attribute(:time_display_relative)).to eq(true)
+ end
+
+ it 'sets user values' do
+ pref = described_class.new(time_display_relative: false)
+
+ expect(pref.read_attribute(:time_display_relative)).to eq(false)
+ end
+ end
+
+ describe '#time_format_in_24h' do
+ it 'is set to false by default' do
+ pref = described_class.new
+
+ expect(pref.time_format_in_24h).to eq(false)
+ end
+
+ it 'returns default value when assigning nil' do
+ pref = described_class.new(time_format_in_24h: nil)
+
+ expect(pref.time_format_in_24h).to eq(false)
+ end
+
+ it 'returns default value when the value is NULL' do
+ pref = create(:user_preference, user: user)
+ pref.update_column(:time_format_in_24h, nil)
+
+ expect(pref.reload.time_format_in_24h).to eq(false)
+ end
+
+ it 'returns assigned value' do
+ pref = described_class.new(time_format_in_24h: true)
+
+ expect(pref.time_format_in_24h).to eq(true)
+ end
+ end
+
+ describe '#time_format_in_24h=' do
+ it 'sets to default value when nil' do
+ pref = described_class.new(time_format_in_24h: nil)
+
+ expect(pref.read_attribute(:time_format_in_24h)).to eq(false)
+ end
+
+ it 'sets user values' do
+ pref = described_class.new(time_format_in_24h: true)
+
+ expect(pref.read_attribute(:time_format_in_24h)).to eq(true)
+ end
+ end
+
+ describe '#render_whitespace_in_code' do
+ it 'is set to false by default' do
+ pref = described_class.new
+
+ expect(pref.render_whitespace_in_code).to eq(false)
+ end
+
+ it 'returns default value when assigning nil' do
+ pref = described_class.new(render_whitespace_in_code: nil)
+
+ expect(pref.render_whitespace_in_code).to eq(false)
+ end
+
+ it 'returns default value when the value is NULL' do
+ pref = create(:user_preference, user: user)
+ pref.update_column(:render_whitespace_in_code, nil)
+
+ expect(pref.reload.render_whitespace_in_code).to eq(false)
+ end
+
+ it 'returns assigned value' do
+ pref = described_class.new(render_whitespace_in_code: true)
+
+ expect(pref.render_whitespace_in_code).to eq(true)
+ end
+ end
+
+ describe '#render_whitespace_in_code=' do
+ it 'sets to default value when nil' do
+ pref = described_class.new(render_whitespace_in_code: nil)
+
+ expect(pref.read_attribute(:render_whitespace_in_code)).to eq(false)
+ end
+
+ it 'sets user values' do
+ pref = described_class.new(render_whitespace_in_code: true)
+
+ expect(pref.read_attribute(:render_whitespace_in_code)).to eq(true)
+ end
+ end
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 7207ee0b172..08fa4555fef 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -146,6 +146,21 @@ RSpec.describe User do
it { is_expected.to have_many(:project_callouts).class_name('Users::ProjectCallout') }
it { is_expected.to have_many(:created_projects).dependent(:nullify).class_name('Project') }
+ describe 'default values' do
+ let(:user) { described_class.new }
+
+ it { expect(user.admin).to be_falsey }
+ it { expect(user.external).to eq(Gitlab::CurrentSettings.user_default_external) }
+ it { expect(user.can_create_group).to eq(Gitlab::CurrentSettings.can_create_group) }
+ it { expect(user.can_create_team).to be_falsey }
+ it { expect(user.hide_no_ssh_key).to be_falsey }
+ it { expect(user.hide_no_password).to be_falsey }
+ it { expect(user.project_view).to eq('files') }
+ it { expect(user.notified_of_own_activity).to be_falsey }
+ it { expect(user.preferred_language).to eq(I18n.default_locale.to_s) }
+ it { expect(user.theme_id).to eq(described_class.gitlab_config.default_theme) }
+ end
+
describe '#user_detail' do
it 'does not persist `user_detail` by default' do
expect(create(:user).user_detail).not_to be_persisted
@@ -417,7 +432,7 @@ RSpec.describe User do
end
it 'falls back to english when I18n.default_locale is not an available language' do
- I18n.default_locale = :kl
+ allow(I18n).to receive(:default_locale) { :kl }
default_preferred_language = user.send(:default_preferred_language)
expect(user.preferred_language).to eq default_preferred_language
diff --git a/spec/workers/namespaces/root_statistics_worker_spec.rb b/spec/workers/namespaces/root_statistics_worker_spec.rb
index 30854415405..e047c94816f 100644
--- a/spec/workers/namespaces/root_statistics_worker_spec.rb
+++ b/spec/workers/namespaces/root_statistics_worker_spec.rb
@@ -92,7 +92,6 @@ RSpec.describe Namespaces::RootStatisticsWorker, '#perform' do
it_behaves_like 'worker with data consistency',
described_class,
- feature_flag: :root_statistics_worker_read_replica,
data_consistency: :sticky
it 'has the `until_executed` deduplicate strategy' do