Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 18:09:30 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 18:09:30 +0300
commitc6b3ec3f56fa32a0e0ed3de0d0878d25f1adaddf (patch)
tree967afee9a510ff9dd503ebd83706dc760ec2e3ed /spec/models
parent903ccf7c93eb9490c76857bffe744249cc07de09 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/member_spec.rb34
-rw-r--r--spec/models/project_wiki_spec.rb25
-rw-r--r--spec/models/snippet_spec.rb16
-rw-r--r--spec/models/user_spec.rb34
4 files changed, 38 insertions, 71 deletions
diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb
index e922542a984..eeb2350359c 100644
--- a/spec/models/member_spec.rb
+++ b/spec/models/member_spec.rb
@@ -3,6 +3,8 @@
require 'spec_helper'
describe Member do
+ include ExclusiveLeaseHelpers
+
using RSpec::Parameterized::TableSyntax
describe "Associations" do
@@ -593,6 +595,9 @@ describe Member do
end
context 'when after_commit :update_highest_role' do
+ let!(:user) { create(:user) }
+ let(:user_id) { user.id }
+
where(:member_type, :source_type) do
:project_member | :project
:group_member | :group
@@ -600,43 +605,34 @@ describe Member do
with_them do
describe 'create member' do
- it 'initializes a new Members::UpdateHighestRoleService object' do
- source = create(source_type) # source owner initializes a new service object too
- user = create(:user)
+ let!(:source) { create(source_type) }
- expect(Members::UpdateHighestRoleService).to receive(:new).with(user.id).and_call_original
+ subject { create(member_type, :guest, user: user, source_type => source) }
- create(member_type, :guest, user: user, source_type => source)
- end
+ include_examples 'update highest role with exclusive lease'
end
context 'when member exists' do
- let!(:member) { create(member_type) }
+ let!(:member) { create(member_type, user: user) }
describe 'update member' do
context 'when access level was changed' do
- it 'initializes a new Members::UpdateHighestRoleService object' do
- expect(Members::UpdateHighestRoleService).to receive(:new).with(member.user_id).and_call_original
+ subject { member.update(access_level: Gitlab::Access::GUEST) }
- member.update(access_level: Gitlab::Access::GUEST)
- end
+ include_examples 'update highest role with exclusive lease'
end
context 'when access level was not changed' do
- it 'does not initialize a new Members::UpdateHighestRoleService object' do
- expect(Members::UpdateHighestRoleService).not_to receive(:new).with(member.user_id)
+ subject { member.update(notification_level: NotificationSetting.levels[:disabled]) }
- member.update(notification_level: NotificationSetting.levels[:disabled])
- end
+ include_examples 'does not update the highest role'
end
end
describe 'destroy member' do
- it 'initializes a new Members::UpdateHighestRoleService object' do
- expect(Members::UpdateHighestRoleService).to receive(:new).with(member.user_id).and_call_original
+ subject { member.destroy }
- member.destroy
- end
+ include_examples 'update highest role with exclusive lease'
end
end
end
diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb
index 9f5fd3a9495..1b121b7dee1 100644
--- a/spec/models/project_wiki_spec.rb
+++ b/spec/models/project_wiki_spec.rb
@@ -34,7 +34,7 @@ describe ProjectWiki do
describe "#url_to_repo" do
it "returns the correct ssh url to the repo" do
- expect(subject.url_to_repo).to eq(Gitlab::Shell.url_to_repo(subject.full_path))
+ expect(subject.url_to_repo).to eq(Gitlab::RepositoryUrlBuilder.build(subject.repository.full_path, protocol: :ssh))
end
end
@@ -45,27 +45,8 @@ describe ProjectWiki do
end
describe "#http_url_to_repo" do
- let(:project) { create :project }
-
- context 'when a custom HTTP clone URL root is not set' do
- it 'returns the full http url to the repo' do
- expected_url = "#{Gitlab.config.gitlab.url}/#{subject.full_path}.git"
-
- expect(project_wiki.http_url_to_repo).to eq(expected_url)
- expect(project_wiki.http_url_to_repo).not_to include('@')
- end
- end
-
- context 'when a custom HTTP clone URL root is set' do
- before do
- stub_application_setting(custom_http_clone_url_root: 'https://git.example.com:51234')
- end
-
- it 'returns the full http url to the repo, with the root replaced with the custom one' do
- expected_url = "https://git.example.com:51234/#{subject.full_path}.git"
-
- expect(project_wiki.http_url_to_repo).to eq(expected_url)
- end
+ it "returns the correct http url to the repo" do
+ expect(subject.http_url_to_repo).to eq(Gitlab::RepositoryUrlBuilder.build(subject.repository.full_path, protocol: :http))
end
end
diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb
index 9cced1f24ab..8c4d1951697 100644
--- a/spec/models/snippet_spec.rb
+++ b/spec/models/snippet_spec.rb
@@ -735,22 +735,6 @@ describe Snippet do
end
end
- describe '#url_to_repo' do
- subject { snippet.url_to_repo }
-
- context 'with personal snippet' do
- let(:snippet) { create(:personal_snippet) }
-
- it { is_expected.to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + "snippets/#{snippet.id}.git") }
- end
-
- context 'with project snippet' do
- let(:snippet) { create(:project_snippet) }
-
- it { is_expected.to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + "#{snippet.project.full_path}/snippets/#{snippet.id}.git") }
- end
- end
-
describe '#versioned_enabled_for?' do
let_it_be(:user) { create(:user) }
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 679f4a19f5b..5a3e16baa87 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -5,6 +5,7 @@ require 'spec_helper'
describe User, :do_not_mock_admin_mode do
include ProjectForksHelper
include TermsHelper
+ include ExclusiveLeaseHelpers
it_behaves_like 'having unique enum values'
@@ -4535,17 +4536,22 @@ describe User, :do_not_mock_admin_mode do
context 'when after_commit :update_highest_role' do
describe 'create user' do
- it 'initializes a new Members::UpdateHighestRoleService object' do
- expect_next_instance_of(Members::UpdateHighestRoleService) do |service|
- expect(service).to receive(:execute)
+ subject { create(:user) }
+
+ it 'schedules a job in the future', :aggregate_failures, :clean_gitlab_redis_shared_state do
+ allow_next_instance_of(Gitlab::ExclusiveLease) do |instance|
+ allow(instance).to receive(:try_obtain).and_return('uuid')
end
- create(:user)
+ expect(UpdateHighestRoleWorker).to receive(:perform_in).and_call_original
+
+ expect { subject }.to change(UpdateHighestRoleWorker.jobs, :size).by(1)
end
end
context 'when user already exists' do
let!(:user) { create(:user) }
+ let(:user_id) { user.id }
describe 'update user' do
using RSpec::Parameterized::TableSyntax
@@ -4560,24 +4566,24 @@ describe User, :do_not_mock_admin_mode do
with_them do
context 'when state was changed' do
- it 'initializes a new Members::UpdateHighestRoleService object' do
- expect_next_instance_of(Members::UpdateHighestRoleService) do |service|
- expect(service).to receive(:execute)
- end
+ subject { user.update(attributes) }
- user.update(attributes)
- end
+ include_examples 'update highest role with exclusive lease'
end
end
context 'when state was not changed' do
- it 'does not initialize a new Members::UpdateHighestRoleService object' do
- expect(Members::UpdateHighestRoleService).not_to receive(:new)
+ subject { user.update(email: 'newmail@example.com') }
- user.update(email: 'newmail@example.com')
- end
+ include_examples 'does not update the highest role'
end
end
+
+ describe 'destroy user' do
+ subject { user.destroy }
+
+ include_examples 'does not update the highest role'
+ end
end
end