2020-07-14 08:09:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-05-17 17:10:42 -04:00
|
|
|
RSpec.describe Integrations::Confluence do
|
2020-07-14 08:09:14 -04:00
|
|
|
describe 'Validations' do
|
|
|
|
before do
|
|
|
|
subject.active = active
|
|
|
|
end
|
|
|
|
|
2021-06-30 20:08:17 -04:00
|
|
|
context 'when integration is active' do
|
2020-07-14 08:09:14 -04:00
|
|
|
let(:active) { true }
|
|
|
|
|
|
|
|
it { is_expected.not_to allow_value('https://example.com').for(:confluence_url) }
|
|
|
|
it { is_expected.not_to allow_value('example.com').for(:confluence_url) }
|
|
|
|
it { is_expected.not_to allow_value('foo').for(:confluence_url) }
|
|
|
|
it { is_expected.not_to allow_value('ftp://example.atlassian.net/wiki').for(:confluence_url) }
|
|
|
|
it { is_expected.not_to allow_value('https://example.atlassian.net').for(:confluence_url) }
|
|
|
|
it { is_expected.not_to allow_value('https://.atlassian.net/wiki').for(:confluence_url) }
|
|
|
|
it { is_expected.not_to allow_value('https://example.atlassian.net/wikifoo').for(:confluence_url) }
|
|
|
|
it { is_expected.not_to allow_value('').for(:confluence_url) }
|
|
|
|
it { is_expected.not_to allow_value(nil).for(:confluence_url) }
|
|
|
|
it { is_expected.not_to allow_value('😊').for(:confluence_url) }
|
|
|
|
it { is_expected.to allow_value('https://example.atlassian.net/wiki').for(:confluence_url) }
|
|
|
|
it { is_expected.to allow_value('http://example.atlassian.net/wiki').for(:confluence_url) }
|
|
|
|
it { is_expected.to allow_value('https://example.atlassian.net/wiki/').for(:confluence_url) }
|
|
|
|
it { is_expected.to allow_value('http://example.atlassian.net/wiki/').for(:confluence_url) }
|
|
|
|
it { is_expected.to allow_value('https://example.atlassian.net/wiki/foo').for(:confluence_url) }
|
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:confluence_url) }
|
|
|
|
end
|
|
|
|
|
2021-06-30 20:08:17 -04:00
|
|
|
context 'when integration is inactive' do
|
2020-07-14 08:09:14 -04:00
|
|
|
let(:active) { false }
|
|
|
|
|
|
|
|
it { is_expected.not_to validate_presence_of(:confluence_url) }
|
|
|
|
it { is_expected.to allow_value('foo').for(:confluence_url) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-03 13:09:25 -05:00
|
|
|
describe '#help' do
|
2020-07-14 08:09:14 -04:00
|
|
|
it 'can correctly return a link to the project wiki when active' do
|
|
|
|
project = create(:project)
|
|
|
|
subject.project = project
|
|
|
|
subject.active = true
|
|
|
|
|
2021-02-03 13:09:25 -05:00
|
|
|
expect(subject.help).to include(Gitlab::Routing.url_helpers.project_wikis_url(project))
|
2020-07-14 08:09:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the project wiki is not enabled' do
|
|
|
|
it 'returns nil when both active or inactive', :aggregate_failures do
|
|
|
|
project = create(:project, :wiki_disabled)
|
|
|
|
subject.project = project
|
|
|
|
|
|
|
|
[true, false].each do |active|
|
|
|
|
subject.active = active
|
|
|
|
|
2021-02-03 13:09:25 -05:00
|
|
|
expect(subject.help).to be_nil
|
2020-07-14 08:09:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Caching has_confluence on project_settings' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
subject { project.project_setting.has_confluence? }
|
|
|
|
|
2021-06-30 20:08:17 -04:00
|
|
|
it 'sets the property to true when integration is active' do
|
2021-06-09 14:11:25 -04:00
|
|
|
create(:confluence_integration, project: project, active: true)
|
2020-07-14 08:09:14 -04:00
|
|
|
|
|
|
|
is_expected.to be(true)
|
|
|
|
end
|
|
|
|
|
2021-06-30 20:08:17 -04:00
|
|
|
it 'sets the property to false when integration is not active' do
|
2021-06-09 14:11:25 -04:00
|
|
|
create(:confluence_integration, project: project, active: false)
|
2020-07-14 08:09:14 -04:00
|
|
|
|
|
|
|
is_expected.to be(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a project_setting record if one was not already created' do
|
2021-06-09 14:11:25 -04:00
|
|
|
expect { create(:confluence_integration) }.to change(ProjectSetting, :count).by(1)
|
2020-07-14 08:09:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|