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
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/integration_spec.rb')
-rw-r--r--spec/models/integration_spec.rb202
1 files changed, 170 insertions, 32 deletions
diff --git a/spec/models/integration_spec.rb b/spec/models/integration_spec.rb
index 48d8ba975b6..0f596d3908d 100644
--- a/spec/models/integration_spec.rb
+++ b/spec/models/integration_spec.rb
@@ -60,6 +60,17 @@ RSpec.describe Integration do
end
describe 'Scopes' do
+ describe '.third_party_wikis' do
+ let!(:integration1) { create(:jira_integration) }
+ let!(:integration2) { create(:redmine_integration) }
+ let!(:integration3) { create(:confluence_integration) }
+ let!(:integration4) { create(:shimo_integration) }
+
+ it 'returns the right group integration' do
+ expect(described_class.third_party_wikis).to contain_exactly(integration3, integration4)
+ end
+ end
+
describe '.with_default_settings' do
it 'returns the correct integrations' do
instance_integration = create(:integration, :instance)
@@ -265,6 +276,20 @@ RSpec.describe Integration do
end
end
+ describe '#inheritable?' do
+ it 'is true for an instance integration' do
+ expect(create(:integration, :instance)).to be_inheritable
+ end
+
+ it 'is true for a group integration' do
+ expect(create(:integration, :group)).to be_inheritable
+ end
+
+ it 'is false for a project integration' do
+ expect(create(:integration)).not_to be_inheritable
+ end
+ end
+
describe '.build_from_integration' do
context 'when integration is invalid' do
let(:invalid_integration) do
@@ -462,6 +487,18 @@ RSpec.describe Integration do
expect(project.reload.integrations.first.inherit_from_id).to eq(group_integration.id)
end
+ context 'there are multiple inheritable integrations, and a duplicate' do
+ let!(:group_integration_2) { create(:jenkins_integration, :group, group: group) }
+ let!(:group_integration_3) { create(:datadog_integration, :instance) }
+ let!(:duplicate) { create(:jenkins_integration, project: project) }
+
+ it 'returns the number of successfully created integrations' do
+ expect(described_class.create_from_active_default_integrations(project, :project_id)).to eq 2
+
+ expect(project.reload.integrations.size).to eq(3)
+ end
+ end
+
context 'passing a group' do
let!(:subgroup) { create(:group, parent: group) }
@@ -621,6 +658,33 @@ RSpec.describe Integration do
end
end
+ describe '#properties=' do
+ let(:integration_type) do
+ Class.new(described_class) do
+ field :foo
+ field :bar
+ end
+ end
+
+ it 'supports indifferent access' do
+ integration = integration_type.new
+
+ integration.properties = { foo: 1, 'bar' => 2 }
+
+ expect(integration).to have_attributes(foo: 1, bar: 2)
+ end
+ end
+
+ describe '#properties' do
+ it 'is not mutable' do
+ integration = described_class.new
+
+ integration.properties = { foo: 1, bar: 2 }
+
+ expect { integration.properties[:foo] = 3 }.to raise_error
+ end
+ end
+
describe "{property}_touched?" do
let(:integration) do
Integrations::Bamboo.create!(
@@ -720,7 +784,7 @@ RSpec.describe Integration do
describe '#api_field_names' do
shared_examples 'api field names' do
- it 'filters out sensitive fields' do
+ it 'filters out secret fields' do
safe_fields = %w[some_safe_field safe_field url trojan_gift]
expect(fake_integration.new).to have_attributes(
@@ -857,7 +921,7 @@ RSpec.describe Integration do
end
end
- describe '#password_fields' do
+ describe '#secret_fields' do
it 'returns all fields with type `password`' do
allow(subject).to receive(:fields).and_return([
{ name: 'password', type: 'password' },
@@ -865,53 +929,34 @@ RSpec.describe Integration do
{ name: 'public', type: 'text' }
])
- expect(subject.password_fields).to match_array(%w[password secret])
+ expect(subject.secret_fields).to match_array(%w[password secret])
end
- it 'returns an empty array if no password fields exist' do
- expect(subject.password_fields).to eq([])
+ it 'returns an empty array if no secret fields exist' do
+ expect(subject.secret_fields).to eq([])
end
end
- describe 'encrypted_properties' do
+ describe '#to_integration_hash' do
let(:properties) { { foo: 1, bar: true } }
let(:db_props) { properties.stringify_keys }
let(:record) { create(:integration, :instance, properties: properties) }
- it 'contains the same data as properties' do
- expect(record).to have_attributes(
- properties: db_props,
- encrypted_properties_tmp: db_props
- )
- end
-
- it 'is persisted' do
- encrypted_properties = described_class.id_in(record.id)
-
- expect(encrypted_properties).to contain_exactly have_attributes(encrypted_properties_tmp: db_props)
- end
-
- it 'is updated when using prop_accessors' do
- some_integration = Class.new(described_class) do
- prop_accessor :foo
- end
-
- record = some_integration.new
-
- record.foo = 'the foo'
+ it 'does not include the properties key' do
+ hash = record.to_integration_hash
- expect(record.encrypted_properties_tmp).to eq({ 'foo' => 'the foo' })
+ expect(hash).not_to have_key('properties')
end
it 'saves correctly using insert_all' do
hash = record.to_integration_hash
- hash[:project_id] = project
+ hash[:project_id] = project.id
expect do
described_class.insert_all([hash])
end.to change(described_class, :count).by(1)
- expect(described_class.last).to have_attributes(encrypted_properties_tmp: db_props)
+ expect(described_class.last).to have_attributes(properties: db_props)
end
it 'is part of the to_integration_hash' do
@@ -921,7 +966,7 @@ RSpec.describe Integration do
expect(hash['encrypted_properties']).not_to eq(record.encrypted_properties)
expect(hash['encrypted_properties_iv']).not_to eq(record.encrypted_properties_iv)
- decrypted = described_class.decrypt(:encrypted_properties_tmp,
+ decrypted = described_class.decrypt(:properties,
hash['encrypted_properties'],
{ iv: hash['encrypted_properties_iv'] })
@@ -946,7 +991,7 @@ RSpec.describe Integration do
end.to change(described_class, :count).by(1)
expect(described_class.last).not_to eq record
- expect(described_class.last).to have_attributes(encrypted_properties_tmp: db_props)
+ expect(described_class.last).to have_attributes(properties: db_props)
end
end
end
@@ -1021,4 +1066,97 @@ RSpec.describe Integration do
)
end
end
+
+ describe 'boolean_accessor' do
+ let(:klass) do
+ Class.new(Integration) do
+ boolean_accessor :test_value
+ end
+ end
+
+ let(:integration) { klass.new(properties: { test_value: input }) }
+
+ where(:input, :method_result, :predicate_method_result) do
+ true | true | true
+ false | false | false
+ 1 | true | true
+ 0 | false | false
+ '1' | true | true
+ '0' | false | false
+ 'true' | true | true
+ 'false' | false | false
+ 'foobar' | nil | false
+ '' | nil | false
+ nil | nil | false
+ 'on' | true | true
+ 'off' | false | false
+ 'yes' | true | true
+ 'no' | false | false
+ 'n' | false | false
+ 'y' | true | true
+ 't' | true | true
+ 'f' | false | false
+ end
+
+ with_them do
+ it 'has the correct value' do
+ expect(integration).to have_attributes(
+ test_value: be(method_result),
+ test_value?: be(predicate_method_result)
+ )
+ end
+ end
+
+ it 'returns values when initialized without input' do
+ integration = klass.new
+
+ expect(integration).to have_attributes(
+ test_value: be(nil),
+ test_value?: be(false)
+ )
+ end
+ end
+
+ describe '#attributes' do
+ it 'does not include properties' do
+ expect(create(:integration).attributes).not_to have_key('properties')
+ end
+
+ it 'can be used in assign_attributes without nullifying properties' do
+ record = create(:integration, :instance, properties: { url: generate(:url) })
+
+ attrs = record.attributes
+
+ expect { record.assign_attributes(attrs) }.not_to change(record, :properties)
+ end
+ end
+
+ describe '#dup' do
+ let(:original) { create(:integration, properties: { one: 1, two: 2, three: 3 }) }
+
+ it 'results in distinct ciphertexts, but identical properties' do
+ copy = original.dup
+
+ expect(copy).to have_attributes(properties: eq(original.properties))
+
+ expect(copy).not_to have_attributes(
+ encrypted_properties: eq(original.encrypted_properties)
+ )
+ end
+
+ context 'when the model supports data-fields' do
+ let(:original) { create(:jira_integration, username: generate(:username), url: generate(:url)) }
+
+ it 'creates distinct but identical data-fields' do
+ copy = original.dup
+
+ expect(copy).to have_attributes(
+ username: original.username,
+ url: original.url
+ )
+
+ expect(copy.data_fields).not_to eq(original.data_fields)
+ end
+ end
+ end
end