summaryrefslogtreecommitdiff
path: root/spec/migrations
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-23 21:08:35 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-23 21:08:35 +0000
commit24256212ea84e6fb6509f6fb317a2d2bac3d0d06 (patch)
treee4300d70d8e724179d9de657a68d88462aaaf04a /spec/migrations
parentd933bc5a8738d24898c5a82cc72ee9bd050425e6 (diff)
downloadgitlab-ce-24256212ea84e6fb6509f6fb317a2d2bac3d0d06.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r--spec/migrations/20200123155929_remove_invalid_jira_data_spec.rb70
1 files changed, 70 insertions, 0 deletions
diff --git a/spec/migrations/20200123155929_remove_invalid_jira_data_spec.rb b/spec/migrations/20200123155929_remove_invalid_jira_data_spec.rb
new file mode 100644
index 00000000000..0e640623ea9
--- /dev/null
+++ b/spec/migrations/20200123155929_remove_invalid_jira_data_spec.rb
@@ -0,0 +1,70 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20200123155929_remove_invalid_jira_data.rb')
+
+describe RemoveInvalidJiraData, :migration do
+ let(:jira_tracker_data) { table(:jira_tracker_data) }
+ let(:services) { table(:services) }
+
+ let(:service) { services.create(id: 1) }
+ let(:data) do
+ {
+ service_id: service.id,
+ encrypted_api_url: 'http:url.com',
+ encrypted_api_url_iv: 'somevalue',
+ encrypted_url: 'http:url.com',
+ encrypted_url_iv: 'somevalue',
+ encrypted_username: 'username',
+ encrypted_username_iv: 'somevalue',
+ encrypted_password: 'username',
+ encrypted_password_iv: 'somevalue'
+ }
+ end
+
+ let!(:valid_data) { jira_tracker_data.create(data) }
+ let!(:empty_data) { jira_tracker_data.create(service_id: service.id) }
+ let!(:invalid_api_url) do
+ data[:encrypted_api_url_iv] = nil
+ jira_tracker_data.create(data)
+ end
+ let!(:missing_api_url) do
+ data[:encrypted_api_url] = ''
+ data[:encrypted_api_url_iv] = nil
+ jira_tracker_data.create(data)
+ end
+ let!(:invalid_url) do
+ data[:encrypted_url_iv] = nil
+ jira_tracker_data.create(data)
+ end
+ let!(:missing_url) do
+ data[:encrypted_url] = ''
+ jira_tracker_data.create(data)
+ end
+ let!(:invalid_username) do
+ data[:encrypted_username_iv] = nil
+ jira_tracker_data.create(data)
+ end
+ let!(:missing_username) do
+ data[:encrypted_username] = nil
+ data[:encrypted_username_iv] = nil
+ jira_tracker_data.create(data)
+ end
+ let!(:invalid_password) do
+ data[:encrypted_password_iv] = nil
+ jira_tracker_data.create(data)
+ end
+ let!(:missing_password) do
+ data[:encrypted_password] = nil
+ data[:encrypted_username_iv] = nil
+ jira_tracker_data.create(data)
+ end
+
+ it 'removes the invalid data' do
+ valid_data_records = [valid_data, empty_data, missing_api_url, missing_url, missing_username, missing_password]
+
+ expect { migrate! }.to change { jira_tracker_data.count }.from(10).to(6)
+
+ expect(jira_tracker_data.all).to match_array(valid_data_records)
+ end
+end