debian-mirror-gitlab/spec/models/concerns/integrations/has_data_fields_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

160 lines
4.8 KiB
Ruby
Raw Permalink Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
require 'spec_helper'
2021-09-04 01:27:46 +05:30
RSpec.describe Integrations::HasDataFields do
2019-12-04 20:38:33 +05:30
let(:url) { 'http://url.com' }
let(:username) { 'username_one' }
let(:properties) do
2022-07-23 23:45:48 +05:30
{ url: url, username: username, jira_issue_transition_automatic: false }
2019-12-04 20:38:33 +05:30
end
shared_examples 'data fields' do
describe '#arg' do
2022-07-23 23:45:48 +05:30
it 'returns the expected values' do
expect(integration).to have_attributes(properties)
2019-12-04 20:38:33 +05:30
end
end
describe '{arg}_changed?' do
it 'returns false when the property has not been assigned a new value' do
2022-07-23 23:45:48 +05:30
integration.username = 'new_username'
integration.validate
expect(integration.url_changed?).to be_falsy
2019-12-04 20:38:33 +05:30
end
it 'returns true when the property has been assigned a different value' do
2022-07-23 23:45:48 +05:30
integration.url = "http://example.com"
integration.validate
expect(integration.url_changed?).to be_truthy
2019-12-04 20:38:33 +05:30
end
it 'returns true when the property has been assigned a different value twice' do
2022-07-23 23:45:48 +05:30
integration.url = "http://example.com"
integration.url = "http://example.com"
integration.validate
expect(integration.url_changed?).to be_truthy
2019-12-04 20:38:33 +05:30
end
it 'returns false when the property has been re-assigned the same value' do
2022-07-23 23:45:48 +05:30
integration.url = 'http://url.com'
integration.validate
expect(integration.url_changed?).to be_falsy
2019-12-04 20:38:33 +05:30
end
end
describe '{arg}_touched?' do
it 'returns false when the property has not been assigned a new value' do
2022-07-23 23:45:48 +05:30
integration.username = 'new_username'
integration.validate
expect(integration.url_changed?).to be_falsy
2019-12-04 20:38:33 +05:30
end
it 'returns true when the property has been assigned a different value' do
2022-07-23 23:45:48 +05:30
integration.url = "http://example.com"
integration.validate
expect(integration.url_changed?).to be_truthy
2019-12-04 20:38:33 +05:30
end
it 'returns true when the property has been assigned a different value twice' do
2022-07-23 23:45:48 +05:30
integration.url = "http://example.com"
integration.url = "http://example.com"
integration.validate
expect(integration.url_changed?).to be_truthy
2019-12-04 20:38:33 +05:30
end
it 'returns true when the property has been re-assigned the same value' do
2022-07-23 23:45:48 +05:30
integration.url = 'http://url.com'
expect(integration.url_touched?).to be_truthy
2019-12-04 20:38:33 +05:30
end
it 'returns false when the property has been re-assigned the same value' do
2022-07-23 23:45:48 +05:30
integration.url = 'http://url.com'
integration.validate
expect(integration.url_changed?).to be_falsy
2019-12-04 20:38:33 +05:30
end
end
2019-12-26 22:10:19 +05:30
describe 'data_fields_present?' do
2022-07-23 23:45:48 +05:30
it 'returns true from the issue tracker integration' do
expect(integration.data_fields_present?).to be true
2019-12-26 22:10:19 +05:30
end
end
2019-12-04 20:38:33 +05:30
end
context 'when data are stored in data_fields' do
2022-07-23 23:45:48 +05:30
let(:integration) do
2021-09-30 23:02:18 +05:30
create(:jira_integration, url: url, username: username)
2019-12-04 20:38:33 +05:30
end
it_behaves_like 'data fields'
describe '{arg}_was?' do
it 'returns nil' do
2022-07-23 23:45:48 +05:30
integration.url = 'http://example.com'
integration.validate
expect(integration.url_was).to be_nil
2019-12-04 20:38:33 +05:30
end
end
end
2022-07-23 23:45:48 +05:30
context 'when integration and data_fields are not persisted' do
let(:integration) do
2021-09-04 01:27:46 +05:30
Integrations::Jira.new
2019-12-26 22:10:19 +05:30
end
describe 'data_fields_present?' do
it 'returns true' do
2022-07-23 23:45:48 +05:30
expect(integration.data_fields_present?).to be true
2019-12-26 22:10:19 +05:30
end
end
end
2019-12-04 20:38:33 +05:30
context 'when data are stored in properties' do
2021-09-30 23:02:18 +05:30
let(:integration) { create(:jira_integration, :without_properties_callback, properties: properties) }
2019-12-04 20:38:33 +05:30
2022-07-23 23:45:48 +05:30
it_behaves_like 'data fields'
2019-12-04 20:38:33 +05:30
describe '{arg}_was?' do
it 'returns nil when the property has not been assigned a new value' do
2021-09-30 23:02:18 +05:30
integration.username = 'new_username'
integration.validate
expect(integration.url_was).to be_nil
2019-12-04 20:38:33 +05:30
end
it 'returns initial value when the property has been assigned a different value' do
2021-09-30 23:02:18 +05:30
integration.url = 'http://example.com'
integration.validate
expect(integration.url_was).to eq('http://url.com')
2019-12-04 20:38:33 +05:30
end
it 'returns initial value when the property has been re-assigned the same value' do
2021-09-30 23:02:18 +05:30
integration.url = 'http://url.com'
integration.validate
expect(integration.url_was).to eq('http://url.com')
2019-12-04 20:38:33 +05:30
end
end
end
context 'when data are stored in both properties and data_fields' do
2021-09-30 23:02:18 +05:30
let(:integration) do
create(:jira_integration, :without_properties_callback, active: false, properties: properties).tap do |integration|
2021-06-08 01:23:25 +05:30
create(:jira_tracker_data, properties.merge(integration: integration))
2019-12-04 20:38:33 +05:30
end
end
2022-07-23 23:45:48 +05:30
it_behaves_like 'data fields'
2019-12-04 20:38:33 +05:30
describe '{arg}_was?' do
it 'returns nil' do
2021-09-30 23:02:18 +05:30
integration.url = 'http://example.com'
integration.validate
expect(integration.url_was).to be_nil
2019-12-04 20:38:33 +05:30
end
end
end
end