diff options
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/application_setting_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 16 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 1 | ||||
-rw-r--r-- | spec/models/clusters/cluster_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/concerns/group_descendant_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/namespace_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/upload_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 75 |
8 files changed, 102 insertions, 6 deletions
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 9a76be5b6f1..a403aa296d4 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -68,6 +68,12 @@ describe ApplicationSetting do it { is_expected.to validate_numericality_of(:snippet_size_limit).only_integer.is_greater_than(0) } + it { is_expected.not_to allow_value(7).for(:minimum_password_length) } + it { is_expected.not_to allow_value(129).for(:minimum_password_length) } + it { is_expected.not_to allow_value(nil).for(:minimum_password_length) } + it { is_expected.not_to allow_value('abc').for(:minimum_password_length) } + it { is_expected.to allow_value(10).for(:minimum_password_length) } + context 'when snowplow is enabled' do before do setting.snowplow_enabled = true diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index dde37e62e6c..371982df2bb 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2366,6 +2366,7 @@ describe Ci::Build do { key: 'CI_COMMIT_BEFORE_SHA', value: build.before_sha, public: true, masked: false }, { key: 'CI_COMMIT_REF_NAME', value: build.ref, public: true, masked: false }, { key: 'CI_COMMIT_REF_SLUG', value: build.ref_slug, public: true, masked: false }, + { key: 'CI_COMMIT_BRANCH', value: build.ref, public: true, masked: false }, { key: 'CI_COMMIT_MESSAGE', value: pipeline.git_commit_message, public: true, masked: false }, { key: 'CI_COMMIT_TITLE', value: pipeline.git_commit_title, public: true, masked: false }, { key: 'CI_COMMIT_DESCRIPTION', value: pipeline.git_commit_description, public: true, masked: false }, @@ -2589,6 +2590,19 @@ describe Ci::Build do it { is_expected.to include(job_variable) } end + context 'when build is for branch' do + let(:branch_variable) do + { key: 'CI_COMMIT_BRANCH', value: 'master', public: true, masked: false } + end + + before do + build.update(tag: false) + pipeline.update(tag: false) + end + + it { is_expected.to include(branch_variable) } + end + context 'when build is for tag' do let(:tag_variable) do { key: 'CI_COMMIT_TAG', value: 'master', public: true, masked: false } @@ -3522,7 +3536,7 @@ describe Ci::Build do end it 'can drop the build' do - expect(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception) + expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception) expect { build.drop! }.not_to raise_error diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index b60e240d596..3f9e882ea52 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -599,6 +599,7 @@ describe Ci::Pipeline, :mailer do CI_COMMIT_BEFORE_SHA CI_COMMIT_REF_NAME CI_COMMIT_REF_SLUG + CI_COMMIT_BRANCH CI_COMMIT_MESSAGE CI_COMMIT_TITLE CI_COMMIT_DESCRIPTION diff --git a/spec/models/clusters/cluster_spec.rb b/spec/models/clusters/cluster_spec.rb index 036b6c7902f..44ca4a06e2d 100644 --- a/spec/models/clusters/cluster_spec.rb +++ b/spec/models/clusters/cluster_spec.rb @@ -1004,7 +1004,7 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do it { is_expected.to eq(connection_status: :unknown_failure) } it 'notifies Sentry' do - expect(Gitlab::Sentry).to receive(:track_exception) + expect(Gitlab::ErrorTracking).to receive(:track_exception) .with(instance_of(StandardError), hash_including(cluster_id: cluster.id)) subject diff --git a/spec/models/concerns/group_descendant_spec.rb b/spec/models/concerns/group_descendant_spec.rb index 6af57283a2a..47419770d0f 100644 --- a/spec/models/concerns/group_descendant_spec.rb +++ b/spec/models/concerns/group_descendant_spec.rb @@ -82,7 +82,7 @@ describe GroupDescendant do end it 'tracks the exception when a parent was not preloaded' do - expect(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception).and_call_original + expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).and_call_original expect { described_class.build_hierarchy([subsub_group]) }.to raise_error(ArgumentError) end @@ -91,7 +91,7 @@ describe GroupDescendant do expected_hierarchy = { parent => { subgroup => subsub_group } } # this does not raise in production, so stubbing it here. - allow(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception) + allow(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception) expect(described_class.build_hierarchy([subsub_group])).to eq(expected_hierarchy) end diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index 3089afd8d8a..2ba0d97792b 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -281,7 +281,7 @@ describe Namespace do move_dir_result end - expect(Gitlab::Sentry).to receive(:should_raise_for_dev?).and_return(false) # like prod + expect(Gitlab::ErrorTracking).to receive(:should_raise_for_dev?).and_return(false) # like prod namespace.update(path: namespace.full_path + '_new') end diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb index 6128e7d2a24..7138305d7b1 100644 --- a/spec/models/upload_spec.rb +++ b/spec/models/upload_spec.rb @@ -171,7 +171,7 @@ describe Upload do it 'sends a message to Sentry' do upload = create(:upload, :issuable_upload) - expect(Gitlab::Sentry).to receive(:track_exception).with(instance_of(RuntimeError), upload.attributes) + expect(Gitlab::ErrorTracking).to receive(:track_exception).with(instance_of(RuntimeError), upload.attributes) upload.exist? end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 49991dbd2d4..db26b872045 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -98,6 +98,53 @@ describe User, :do_not_mock_admin_mode do end describe 'validations' do + describe 'password' do + let!(:user) { create(:user) } + + before do + allow(Devise).to receive(:password_length).and_return(8..128) + allow(described_class).to receive(:password_length).and_return(10..130) + end + + context 'length' do + it { is_expected.to validate_length_of(:password).is_at_least(10).is_at_most(130) } + end + + context 'length validator' do + context 'for a short password' do + before do + user.password = user.password_confirmation = 'abc' + end + + it 'does not run the default Devise password length validation' do + expect(user).to be_invalid + expect(user.errors.full_messages.join).not_to include('is too short (minimum is 8 characters)') + end + + it 'runs the custom password length validator' do + expect(user).to be_invalid + expect(user.errors.full_messages.join).to include('is too short (minimum is 10 characters)') + end + end + + context 'for a long password' do + before do + user.password = user.password_confirmation = 'a' * 140 + end + + it 'does not run the default Devise password length validation' do + expect(user).to be_invalid + expect(user.errors.full_messages.join).not_to include('is too long (maximum is 128 characters)') + end + + it 'runs the custom password length validator' do + expect(user).to be_invalid + expect(user.errors.full_messages.join).to include('is too long (maximum is 130 characters)') + end + end + end + end + describe 'name' do it { is_expected.to validate_presence_of(:name) } it { is_expected.to validate_length_of(:name).is_at_most(128) } @@ -461,6 +508,34 @@ describe User, :do_not_mock_admin_mode do end end + describe '.password_length' do + let(:password_length) { described_class.password_length } + + it 'is expected to be a Range' do + expect(password_length).to be_a(Range) + end + + context 'minimum value' do + before do + stub_application_setting(minimum_password_length: 101) + end + + it 'is determined by the current value of `minimum_password_length` attribute of application_setting' do + expect(password_length.min).to eq(101) + end + end + + context 'maximum value' do + before do + allow(Devise.password_length).to receive(:max).and_return(201) + end + + it 'is determined by the current value of `Devise.password_length.max`' do + expect(password_length.max).to eq(201) + end + end + end + describe '.limit_to_todo_authors' do context 'when filtering by todo authors' do let(:user1) { create(:user) } |