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
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-02 06:08:01 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-02 06:08:01 +0300
commit796b00a98a82fcbe082c9343fd4efcccc77478dc (patch)
tree257bcb124f57cb91a8dff75e69649e8a2f91c51d /spec
parent93dcf45d441bc884b167f4338380c8c888e9b86f (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/db/schema_spec.rb2
-rw-r--r--spec/migrations/20200313203550_remove_orphaned_chat_names_spec.rb27
-rw-r--r--spec/models/chat_name_spec.rb6
-rw-r--r--spec/models/project_spec.rb14
4 files changed, 48 insertions, 1 deletions
diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb
index 08e4920b020..2e22e67f4e2 100644
--- a/spec/db/schema_spec.rb
+++ b/spec/db/schema_spec.rb
@@ -21,7 +21,7 @@ describe 'Database schema' do
award_emoji: %w[awardable_id user_id],
aws_roles: %w[role_external_id],
boards: %w[milestone_id],
- chat_names: %w[chat_id service_id team_id user_id],
+ chat_names: %w[chat_id team_id user_id],
chat_teams: %w[team_id],
ci_builds: %w[erased_by_id runner_id trigger_request_id user_id],
ci_pipelines: %w[user_id],
diff --git a/spec/migrations/20200313203550_remove_orphaned_chat_names_spec.rb b/spec/migrations/20200313203550_remove_orphaned_chat_names_spec.rb
new file mode 100644
index 00000000000..fd30ebaa66f
--- /dev/null
+++ b/spec/migrations/20200313203550_remove_orphaned_chat_names_spec.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20200313203550_remove_orphaned_chat_names.rb')
+
+describe RemoveOrphanedChatNames, schema: 20200313202430 do
+ let(:projects) { table(:projects) }
+ let(:namespaces) { table(:namespaces) }
+ let(:services) { table(:services) }
+ let(:chat_names) { table(:chat_names) }
+
+ let(:namespace) { namespaces.create(name: 'foo', path: 'foo') }
+ let(:project) { projects.create(namespace_id: namespace.id) }
+ let(:service) { services.create(project_id: project.id, type: 'chat') }
+ let(:chat_name) { chat_names.create!(service_id: service.id, team_id: 'TEAM', user_id: 12345, chat_id: 12345) }
+ let(:orphaned_chat_name) { chat_names.create!(team_id: 'TEAM', service_id: 0, user_id: 12345, chat_id: 12345) }
+
+ it 'removes the orphaned chat_name' do
+ expect(chat_name).to be_present
+ expect(orphaned_chat_name).to be_present
+
+ migrate!
+
+ expect(chat_names.where(id: orphaned_chat_name.id)).to be_empty
+ expect(chat_name.reload).to be_present
+ end
+end
diff --git a/spec/models/chat_name_spec.rb b/spec/models/chat_name_spec.rb
index 863c28a86fb..02594b98665 100644
--- a/spec/models/chat_name_spec.rb
+++ b/spec/models/chat_name_spec.rb
@@ -17,6 +17,12 @@ describe ChatName do
it { is_expected.to validate_uniqueness_of(:user_id).scoped_to(:service_id) }
it { is_expected.to validate_uniqueness_of(:chat_id).scoped_to(:service_id, :team_id) }
+ it 'is removed when the project is deleted' do
+ expect { subject.reload.service.project.delete }.to change { ChatName.count }.by(-1)
+
+ expect(ChatName.where(id: subject.id)).not_to exist
+ end
+
describe '#update_last_used_at', :clean_gitlab_redis_shared_state do
it 'updates the last_used_at timestamp' do
expect(subject.last_used_at).to be_nil
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 508098bfc39..1b12550ebac 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -5729,6 +5729,20 @@ describe Project do
end
end
+ describe 'with services and chat names' do
+ subject { create(:project) }
+
+ let(:service) { create(:service, project: subject) }
+
+ before do
+ create_list(:chat_name, 5, service: service)
+ end
+
+ it 'removes chat names on removal' do
+ expect { subject.destroy }.to change { ChatName.count }.by(-5)
+ end
+ end
+
describe 'with_issues_or_mrs_available_for_user' do
before do
Project.delete_all