2020-01-23 16:08:35 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
require Rails.root.join('db', 'post_migrate', '20200123155929_remove_invalid_jira_data.rb')
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe RemoveInvalidJiraData do
|
2020-01-23 16:08:35 -05:00
|
|
|
let(:jira_tracker_data) { table(:jira_tracker_data) }
|
|
|
|
let(:services) { table(:services) }
|
|
|
|
|
2020-12-10 16:10:15 -05:00
|
|
|
let(:service) { services.create!(id: 1) }
|
2020-01-23 16:08:35 -05:00
|
|
|
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
|
|
|
|
|
2020-12-10 16:10:15 -05:00
|
|
|
let!(:valid_data) { jira_tracker_data.create!(data) }
|
|
|
|
let!(:empty_data) { jira_tracker_data.create!(service_id: service.id) }
|
2020-01-23 16:08:35 -05:00
|
|
|
let!(:invalid_api_url) do
|
|
|
|
data[:encrypted_api_url_iv] = nil
|
2020-12-10 16:10:15 -05:00
|
|
|
jira_tracker_data.create!(data)
|
2020-01-23 16:08:35 -05:00
|
|
|
end
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2020-01-23 16:08:35 -05:00
|
|
|
let!(:missing_api_url) do
|
|
|
|
data[:encrypted_api_url] = ''
|
|
|
|
data[:encrypted_api_url_iv] = nil
|
2020-12-10 16:10:15 -05:00
|
|
|
jira_tracker_data.create!(data)
|
2020-01-23 16:08:35 -05:00
|
|
|
end
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2020-01-23 16:08:35 -05:00
|
|
|
let!(:invalid_url) do
|
|
|
|
data[:encrypted_url_iv] = nil
|
2020-12-10 16:10:15 -05:00
|
|
|
jira_tracker_data.create!(data)
|
2020-01-23 16:08:35 -05:00
|
|
|
end
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2020-01-23 16:08:35 -05:00
|
|
|
let!(:missing_url) do
|
|
|
|
data[:encrypted_url] = ''
|
2020-12-10 16:10:15 -05:00
|
|
|
jira_tracker_data.create!(data)
|
2020-01-23 16:08:35 -05:00
|
|
|
end
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2020-01-23 16:08:35 -05:00
|
|
|
let!(:invalid_username) do
|
|
|
|
data[:encrypted_username_iv] = nil
|
2020-12-10 16:10:15 -05:00
|
|
|
jira_tracker_data.create!(data)
|
2020-01-23 16:08:35 -05:00
|
|
|
end
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2020-01-23 16:08:35 -05:00
|
|
|
let!(:missing_username) do
|
|
|
|
data[:encrypted_username] = nil
|
|
|
|
data[:encrypted_username_iv] = nil
|
2020-12-10 16:10:15 -05:00
|
|
|
jira_tracker_data.create!(data)
|
2020-01-23 16:08:35 -05:00
|
|
|
end
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2020-01-23 16:08:35 -05:00
|
|
|
let!(:invalid_password) do
|
|
|
|
data[:encrypted_password_iv] = nil
|
2020-12-10 16:10:15 -05:00
|
|
|
jira_tracker_data.create!(data)
|
2020-01-23 16:08:35 -05:00
|
|
|
end
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2020-01-23 16:08:35 -05:00
|
|
|
let!(:missing_password) do
|
|
|
|
data[:encrypted_password] = nil
|
|
|
|
data[:encrypted_username_iv] = nil
|
2020-12-10 16:10:15 -05:00
|
|
|
jira_tracker_data.create!(data)
|
2020-01-23 16:08:35 -05:00
|
|
|
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
|