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
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-30 12:09:35 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-30 12:09:35 +0300
commitbf774d67fc8a84f76f20494c318d7cfacb0c69ac (patch)
treeb991cad6b68560d19f8ce3075577aab2eb51fae6 /spec
parent50f0475ee134da9ea12e758a9f3250f2ab19cd65 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/members/components/members_tabs_spec.js14
-rw-r--r--spec/frontend/repository/components/blob_viewers/sketch_viewer_spec.js32
-rw-r--r--spec/lib/gitlab/checks/changes_access_spec.rb40
-rw-r--r--spec/lib/gitlab/checks/single_change_access_spec.rb16
-rw-r--r--spec/lib/gitlab/gitaly_client/commit_service_spec.rb115
-rw-r--r--spec/models/data_list_spec.rb2
-rw-r--r--spec/models/integration_spec.rb24
-rw-r--r--spec/models/integrations/issue_tracker_data_spec.rb8
-rw-r--r--spec/models/integrations/jira_tracker_data_spec.rb8
-rw-r--r--spec/models/integrations/zentao_tracker_data_spec.rb6
-rw-r--r--spec/models/repository_spec.rb47
-rw-r--r--spec/services/bulk_create_integration_service_spec.rb40
-rw-r--r--spec/services/bulk_update_integration_service_spec.rb28
-rw-r--r--spec/support/shared_examples/models/integrations/base_data_fields_shared_examples.rb17
14 files changed, 206 insertions, 191 deletions
diff --git a/spec/frontend/members/components/members_tabs_spec.js b/spec/frontend/members/components/members_tabs_spec.js
index 1d882e5ef09..1354b938d77 100644
--- a/spec/frontend/members/components/members_tabs_spec.js
+++ b/spec/frontend/members/components/members_tabs_spec.js
@@ -9,6 +9,7 @@ import {
MEMBER_TYPES,
TAB_QUERY_PARAM_VALUES,
ACTIVE_TAB_QUERY_PARAM_NAME,
+ FILTERED_SEARCH_TOKEN_GROUPS_WITH_INHERITED_PERMISSIONS,
} from '~/members/constants';
import { pagination } from '../mock_data';
@@ -42,6 +43,7 @@ describe('MembersTabs', () => {
},
filteredSearchBar: {
searchParam: 'search_groups',
+ tokens: [FILTERED_SEARCH_TOKEN_GROUPS_WITH_INHERITED_PERMISSIONS.type],
},
},
},
@@ -163,6 +165,18 @@ describe('MembersTabs', () => {
expect(findTabByText('Groups')).not.toBeUndefined();
});
});
+
+ describe('when url param matches `filteredSearchBar.tokens`', () => {
+ beforeEach(() => {
+ setWindowLocation('?groups_with_inherited_permissions=exclude');
+ });
+
+ it('shows tab that corresponds to filtered search token', async () => {
+ await createComponent({ totalItems: 0 });
+
+ expect(findTabByText('Groups')).not.toBeUndefined();
+ });
+ });
});
describe('when `canManageMembers` is `false`', () => {
diff --git a/spec/frontend/repository/components/blob_viewers/sketch_viewer_spec.js b/spec/frontend/repository/components/blob_viewers/sketch_viewer_spec.js
new file mode 100644
index 00000000000..b5c8c02c4a0
--- /dev/null
+++ b/spec/frontend/repository/components/blob_viewers/sketch_viewer_spec.js
@@ -0,0 +1,32 @@
+import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
+import SketchViewer from '~/repository/components/blob_viewers/sketch_viewer.vue';
+import SketchLoader from '~/blob/sketch';
+
+jest.mock('~/blob/sketch');
+
+describe('Sketch Viewer', () => {
+ let wrapper;
+
+ const DEFAULT_BLOB_DATA = {
+ rawPath: 'some/file.sketch',
+ };
+
+ const createComponent = () => {
+ wrapper = shallowMountExtended(SketchViewer, {
+ propsData: { blob: DEFAULT_BLOB_DATA },
+ });
+ };
+
+ const findSketchWrapper = () => wrapper.findByTestId('sketch');
+
+ beforeEach(() => createComponent());
+
+ it('inits the sketch loader', () => {
+ expect(SketchLoader).toHaveBeenCalledWith(wrapper.vm.$refs.viewer);
+ });
+
+ it('renders the sketch viewer', () => {
+ expect(findSketchWrapper().exists()).toBe(true);
+ expect(findSketchWrapper().attributes('data-endpoint')).toBe(DEFAULT_BLOB_DATA.rawPath);
+ });
+});
diff --git a/spec/lib/gitlab/checks/changes_access_spec.rb b/spec/lib/gitlab/checks/changes_access_spec.rb
index 41ec11c1055..60118823b5a 100644
--- a/spec/lib/gitlab/checks/changes_access_spec.rb
+++ b/spec/lib/gitlab/checks/changes_access_spec.rb
@@ -49,56 +49,26 @@ RSpec.describe Gitlab::Checks::ChangesAccess do
context 'when changes contain empty revisions' do
let(:expected_commit) { instance_double(Commit) }
- let(:expected_allow_quarantine) { allow_quarantine }
shared_examples 'returns only commits with non empty revisions' do
- before do
- stub_feature_flags(filter_quarantined_commits: filter_quarantined_commits)
- end
-
specify do
expect(project.repository)
.to receive(:new_commits)
- .with([newrev], allow_quarantine: expected_allow_quarantine) { [expected_commit] }
+ .with([newrev]) { [expected_commit] }
expect(subject.commits).to match_array([expected_commit])
end
end
- it_behaves_like 'returns only commits with non empty revisions' do
+ context 'with oldrev' do
let(:changes) { [{ oldrev: oldrev, newrev: newrev }, { newrev: '' }, { newrev: Gitlab::Git::BLANK_SHA }] }
- let(:allow_quarantine) { true }
- let(:filter_quarantined_commits) { true }
+
+ it_behaves_like 'returns only commits with non empty revisions'
end
context 'without oldrev' do
let(:changes) { [{ newrev: newrev }, { newrev: '' }, { newrev: Gitlab::Git::BLANK_SHA }] }
- context 'with disallowed quarantine' do
- # The quarantine directory should not be used because we're lacking
- # oldrev, and we're not filtering commits.
- let(:allow_quarantine) { false }
- let(:filter_quarantined_commits) { false }
-
- it_behaves_like 'returns only commits with non empty revisions'
- end
-
- context 'with allowed quarantine and :filter_quarantined_commits disabled' do
- # When we allow usage of the quarantine but have no oldrev and we're
- # not filtering commits then results returned by the quarantine aren't
- # accurate. We thus mustn't try using it.
- let(:allow_quarantine) { true }
- let(:filter_quarantined_commits) { false }
- let(:expected_allow_quarantine) { false }
-
- it_behaves_like 'returns only commits with non empty revisions'
- end
-
- context 'with allowed quarantine and :filter_quarantined_commits enabled' do
- let(:allow_quarantine) { true }
- let(:filter_quarantined_commits) { true }
-
- it_behaves_like 'returns only commits with non empty revisions'
- end
+ it_behaves_like 'returns only commits with non empty revisions'
end
end
end
diff --git a/spec/lib/gitlab/checks/single_change_access_spec.rb b/spec/lib/gitlab/checks/single_change_access_spec.rb
index 1b34e58797e..8d9f96dd2b4 100644
--- a/spec/lib/gitlab/checks/single_change_access_spec.rb
+++ b/spec/lib/gitlab/checks/single_change_access_spec.rb
@@ -96,26 +96,14 @@ RSpec.describe Gitlab::Checks::SingleChangeAccess do
let(:provided_commits) { nil }
before do
- stub_feature_flags(filter_quarantined_commits: filter_quarantined_commits)
-
expect(project.repository)
.to receive(:new_commits)
- .with(newrev, allow_quarantine: filter_quarantined_commits)
+ .with(newrev)
.once
.and_return(expected_commits)
end
- context 'with :filter_quarantined_commits disabled' do
- let(:filter_quarantined_commits) { false }
-
- it_behaves_like '#commits'
- end
-
- context 'with :filter_quarantined_commits enabled' do
- let(:filter_quarantined_commits) { true }
-
- it_behaves_like '#commits'
- end
+ it_behaves_like '#commits'
end
end
end
diff --git a/spec/lib/gitlab/gitaly_client/commit_service_spec.rb b/spec/lib/gitlab/gitaly_client/commit_service_spec.rb
index 92860c9232f..3a34d39c722 100644
--- a/spec/lib/gitlab/gitaly_client/commit_service_spec.rb
+++ b/spec/lib/gitlab/gitaly_client/commit_service_spec.rb
@@ -340,17 +340,12 @@ RSpec.describe Gitlab::GitalyClient::CommitService do
let(:revisions) { [revision] }
let(:gitaly_commits) { create_list(:gitaly_commit, 3) }
let(:expected_commits) { gitaly_commits.map { |c| Gitlab::Git::Commit.new(repository, c) }}
- let(:filter_quarantined_commits) { false }
subject do
- client.list_new_commits(revisions, allow_quarantine: allow_quarantine)
+ client.list_new_commits(revisions)
end
shared_examples 'a #list_all_commits message' do
- before do
- stub_feature_flags(filter_quarantined_commits: filter_quarantined_commits)
- end
-
it 'sends a list_all_commits message' do
expected_repository = repository.gitaly_repository.dup
expected_repository.git_alternate_object_directories = Google::Protobuf::RepeatedField.new(:string)
@@ -360,29 +355,25 @@ RSpec.describe Gitlab::GitalyClient::CommitService do
.with(gitaly_request_with_params(repository: expected_repository), kind_of(Hash))
.and_return([Gitaly::ListAllCommitsResponse.new(commits: gitaly_commits)])
- if filter_quarantined_commits
- # The object directory of the repository must not be set so that we
- # don't use the quarantine directory.
- objects_exist_repo = repository.gitaly_repository.dup
- objects_exist_repo.git_object_directory = ""
-
- # The first request contains the repository, the second request the
- # commit IDs we want to check for existence.
- objects_exist_request = [
- gitaly_request_with_params(repository: objects_exist_repo),
- gitaly_request_with_params(revisions: gitaly_commits.map(&:id))
- ]
-
- objects_exist_response = Gitaly::CheckObjectsExistResponse.new(revisions: revision_existence.map do
- |rev, exists| Gitaly::CheckObjectsExistResponse::RevisionExistence.new(name: rev, exists: exists)
- end)
-
- expect(service).to receive(:check_objects_exist)
- .with(objects_exist_request, kind_of(Hash))
- .and_return([objects_exist_response])
- else
- expect(service).not_to receive(:check_objects_exist)
- end
+ # The object directory of the repository must not be set so that we
+ # don't use the quarantine directory.
+ objects_exist_repo = repository.gitaly_repository.dup
+ objects_exist_repo.git_object_directory = ""
+
+ # The first request contains the repository, the second request the
+ # commit IDs we want to check for existence.
+ objects_exist_request = [
+ gitaly_request_with_params(repository: objects_exist_repo),
+ gitaly_request_with_params(revisions: gitaly_commits.map(&:id))
+ ]
+
+ objects_exist_response = Gitaly::CheckObjectsExistResponse.new(revisions: revision_existence.map do
+ |rev, exists| Gitaly::CheckObjectsExistResponse::RevisionExistence.new(name: rev, exists: exists)
+ end)
+
+ expect(service).to receive(:check_objects_exist)
+ .with(objects_exist_request, kind_of(Hash))
+ .and_return([objects_exist_response])
end
expect(subject).to eq(expected_commits)
@@ -418,49 +409,31 @@ RSpec.describe Gitlab::GitalyClient::CommitService do
}
end
- context 'with allowed quarantine' do
- let(:allow_quarantine) { true }
-
- context 'without commit filtering' do
- it_behaves_like 'a #list_all_commits message'
- end
-
- context 'with commit filtering' do
- let(:filter_quarantined_commits) { true }
-
- context 'reject commits which exist in target repository' do
- let(:revision_existence) { gitaly_commits.to_h { |c| [c.id, true] } }
- let(:expected_commits) { [] }
-
- it_behaves_like 'a #list_all_commits message'
- end
-
- context 'keep commits which do not exist in target repository' do
- let(:revision_existence) { gitaly_commits.to_h { |c| [c.id, false] } }
+ context 'reject commits which exist in target repository' do
+ let(:revision_existence) { gitaly_commits.to_h { |c| [c.id, true] } }
+ let(:expected_commits) { [] }
- it_behaves_like 'a #list_all_commits message'
- end
+ it_behaves_like 'a #list_all_commits message'
+ end
- context 'mixed existing and nonexisting commits' do
- let(:revision_existence) do
- {
- gitaly_commits[0].id => true,
- gitaly_commits[1].id => false,
- gitaly_commits[2].id => true
- }
- end
+ context 'keep commits which do not exist in target repository' do
+ let(:revision_existence) { gitaly_commits.to_h { |c| [c.id, false] } }
- let(:expected_commits) { [Gitlab::Git::Commit.new(repository, gitaly_commits[1])] }
+ it_behaves_like 'a #list_all_commits message'
+ end
- it_behaves_like 'a #list_all_commits message'
- end
+ context 'mixed existing and nonexisting commits' do
+ let(:revision_existence) do
+ {
+ gitaly_commits[0].id => true,
+ gitaly_commits[1].id => false,
+ gitaly_commits[2].id => true
+ }
end
- end
- context 'with disallowed quarantine' do
- let(:allow_quarantine) { false }
+ let(:expected_commits) { [Gitlab::Git::Commit.new(repository, gitaly_commits[1])] }
- it_behaves_like 'a #list_commits message'
+ it_behaves_like 'a #list_all_commits message'
end
end
@@ -472,17 +445,7 @@ RSpec.describe Gitlab::GitalyClient::CommitService do
}
end
- context 'with allowed quarantine' do
- let(:allow_quarantine) { true }
-
- it_behaves_like 'a #list_commits message'
- end
-
- context 'with disallowed quarantine' do
- let(:allow_quarantine) { false }
-
- it_behaves_like 'a #list_commits message'
- end
+ it_behaves_like 'a #list_commits message'
end
end
diff --git a/spec/models/data_list_spec.rb b/spec/models/data_list_spec.rb
index d2f15386808..67db2730a78 100644
--- a/spec/models/data_list_spec.rb
+++ b/spec/models/data_list_spec.rb
@@ -14,7 +14,7 @@ RSpec.describe DataList do
end
def data_list(integration)
- DataList.new([integration], integration.to_data_fields_hash, integration.data_fields.class).to_array
+ DataList.new([integration], integration.to_database_hash, integration.data_fields.class).to_array
end
it 'returns current data' do
diff --git a/spec/models/integration_spec.rb b/spec/models/integration_spec.rb
index 0567a8bd386..0d38e10c5e6 100644
--- a/spec/models/integration_spec.rb
+++ b/spec/models/integration_spec.rb
@@ -250,7 +250,7 @@ RSpec.describe Integration do
context 'with all existing instances' do
def integration_hash(type)
- Integration.new(instance: true, type: type).to_integration_hash
+ Integration.new(instance: true, type: type).to_database_hash
end
before do
@@ -977,19 +977,25 @@ RSpec.describe Integration do
end
end
- describe '#to_integration_hash' do
+ describe '#to_database_hash' do
let(:properties) { { foo: 1, bar: true } }
let(:db_props) { properties.stringify_keys }
let(:record) { create(:integration, :instance, properties: properties) }
it 'does not include the properties key' do
- hash = record.to_integration_hash
+ hash = record.to_database_hash
expect(hash).not_to have_key('properties')
end
+ it 'does not include certain attributes' do
+ hash = record.to_database_hash
+
+ expect(hash.keys).not_to include('id', 'instance', 'project_id', 'group_id', 'created_at', 'updated_at')
+ end
+
it 'saves correctly using insert_all' do
- hash = record.to_integration_hash
+ hash = record.to_database_hash
hash[:project_id] = project.id
expect do
@@ -999,8 +1005,8 @@ RSpec.describe Integration do
expect(described_class.last).to have_attributes(properties: db_props)
end
- it 'is part of the to_integration_hash' do
- hash = record.to_integration_hash
+ it 'decrypts encrypted properties correctly' do
+ hash = record.to_database_hash
expect(hash).to include('encrypted_properties' => be_present, 'encrypted_properties_iv' => be_present)
expect(hash['encrypted_properties']).not_to eq(record.encrypted_properties)
@@ -1016,14 +1022,14 @@ RSpec.describe Integration do
context 'when the properties are empty' do
let(:properties) { {} }
- it 'is part of the to_integration_hash' do
- hash = record.to_integration_hash
+ it 'is part of the to_database_hash' do
+ hash = record.to_database_hash
expect(hash).to include('encrypted_properties' => be_nil, 'encrypted_properties_iv' => be_nil)
end
it 'saves correctly using insert_all' do
- hash = record.to_integration_hash
+ hash = record.to_database_hash
hash[:project_id] = project
expect do
diff --git a/spec/models/integrations/issue_tracker_data_spec.rb b/spec/models/integrations/issue_tracker_data_spec.rb
index 597df237c67..233ed7b8475 100644
--- a/spec/models/integrations/issue_tracker_data_spec.rb
+++ b/spec/models/integrations/issue_tracker_data_spec.rb
@@ -3,7 +3,11 @@
require 'spec_helper'
RSpec.describe Integrations::IssueTrackerData do
- describe 'associations' do
- it { is_expected.to belong_to :integration }
+ it_behaves_like Integrations::BaseDataFields
+
+ describe 'encrypted attributes' do
+ subject { described_class.encrypted_attributes.keys }
+
+ it { is_expected.to contain_exactly(:issues_url, :new_issue_url, :project_url) }
end
end
diff --git a/spec/models/integrations/jira_tracker_data_spec.rb b/spec/models/integrations/jira_tracker_data_spec.rb
index 5430dd2eb52..d9f91527fbb 100644
--- a/spec/models/integrations/jira_tracker_data_spec.rb
+++ b/spec/models/integrations/jira_tracker_data_spec.rb
@@ -3,12 +3,12 @@
require 'spec_helper'
RSpec.describe Integrations::JiraTrackerData do
- describe 'associations' do
- it { is_expected.to belong_to(:integration) }
- end
+ it_behaves_like Integrations::BaseDataFields
describe 'deployment_type' do
- it { is_expected.to define_enum_for(:deployment_type).with_values([:unknown, :server, :cloud]).with_prefix(:deployment) }
+ specify do
+ is_expected.to define_enum_for(:deployment_type).with_values([:unknown, :server, :cloud]).with_prefix(:deployment)
+ end
end
describe 'encrypted attributes' do
diff --git a/spec/models/integrations/zentao_tracker_data_spec.rb b/spec/models/integrations/zentao_tracker_data_spec.rb
index b078c57830b..dca5c4d79ae 100644
--- a/spec/models/integrations/zentao_tracker_data_spec.rb
+++ b/spec/models/integrations/zentao_tracker_data_spec.rb
@@ -3,16 +3,14 @@
require 'spec_helper'
RSpec.describe Integrations::ZentaoTrackerData do
+ it_behaves_like Integrations::BaseDataFields
+
describe 'factory available' do
let(:zentao_tracker_data) { create(:zentao_tracker_data) }
it { expect(zentao_tracker_data.valid?).to eq true }
end
- describe 'associations' do
- it { is_expected.to belong_to(:integration) }
- end
-
describe 'encrypted attributes' do
subject { described_class.encrypted_attributes.keys }
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 215f83adf5d..e1d903a40cf 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -418,46 +418,31 @@ RSpec.describe Repository do
end
describe '#new_commits' do
- shared_examples '#new_commits' do
- let_it_be(:project) { create(:project, :repository) }
-
- let(:repository) { project.repository }
-
- subject { repository.new_commits(rev, allow_quarantine: allow_quarantine) }
-
- context 'when there are no new commits' do
- let(:rev) { repository.commit.id }
+ let_it_be(:project) { create(:project, :repository) }
- it 'returns an empty array' do
- expect(subject).to eq([])
- end
- end
+ let(:repository) { project.repository }
- context 'when new commits are found' do
- let(:branch) { 'orphaned-branch' }
- let!(:rev) { repository.commit(branch).id }
- let(:allow_quarantine) { false }
+ subject { repository.new_commits(rev) }
- it 'returns the commits' do
- repository.delete_branch(branch)
+ context 'when there are no new commits' do
+ let(:rev) { repository.commit.id }
- expect(subject).not_to be_empty
- expect(subject).to all( be_a(::Commit) )
- expect(subject.size).to eq(1)
- end
+ it 'returns an empty array' do
+ expect(subject).to eq([])
end
end
- context 'with quarantine' do
- let(:allow_quarantine) { true }
+ context 'when new commits are found' do
+ let(:branch) { 'orphaned-branch' }
+ let!(:rev) { repository.commit(branch).id }
- it_behaves_like '#new_commits'
- end
-
- context 'without quarantine' do
- let(:allow_quarantine) { false }
+ it 'returns the commits' do
+ repository.delete_branch(branch)
- it_behaves_like '#new_commits'
+ expect(subject).not_to be_empty
+ expect(subject).to all( be_a(::Commit) )
+ expect(subject.size).to eq(1)
+ end
end
end
diff --git a/spec/services/bulk_create_integration_service_spec.rb b/spec/services/bulk_create_integration_service_spec.rb
index 68c5af33fd8..ddc95ff92d5 100644
--- a/spec/services/bulk_create_integration_service_spec.rb
+++ b/spec/services/bulk_create_integration_service_spec.rb
@@ -21,7 +21,7 @@ RSpec.describe BulkCreateIntegrationService do
]
end
- shared_examples 'creates integration from batch ids' do
+ shared_examples 'creates integration successfully' do
def attributes(record)
record.reload.attributes.except(*excluded_attributes)
end
@@ -41,15 +41,31 @@ RSpec.describe BulkCreateIntegrationService do
expect(attributes(created_integration.data_fields))
.to eq attributes(integration.data_fields)
end
+
+ it 'sets created_at and updated_at timestamps', :freeze_time do
+ described_class.new(integration, batch, association).execute
+
+ expect(created_integration.data_fields.reload).to have_attributes(
+ created_at: eq(Time.current),
+ updated_at: eq(Time.current)
+ )
+ end
end
- end
- shared_examples 'updates inherit_from_id' do
it 'updates inherit_from_id attributes' do
described_class.new(integration, batch, association).execute
expect(created_integration.reload.inherit_from_id).to eq(inherit_from_id)
end
+
+ it 'sets created_at and updated_at timestamps', :freeze_time do
+ described_class.new(integration, batch, association).execute
+
+ expect(created_integration.reload).to have_attributes(
+ created_at: eq(Time.current),
+ updated_at: eq(Time.current)
+ )
+ end
end
context 'passing an instance-level integration' do
@@ -62,8 +78,7 @@ RSpec.describe BulkCreateIntegrationService do
let(:batch) { Project.where(id: project.id) }
let(:association) { 'project' }
- it_behaves_like 'creates integration from batch ids'
- it_behaves_like 'updates inherit_from_id'
+ it_behaves_like 'creates integration successfully'
end
context 'with a group association' do
@@ -72,8 +87,7 @@ RSpec.describe BulkCreateIntegrationService do
let(:batch) { Group.where(id: group.id) }
let(:association) { 'group' }
- it_behaves_like 'creates integration from batch ids'
- it_behaves_like 'updates inherit_from_id'
+ it_behaves_like 'creates integration successfully'
end
end
@@ -88,15 +102,13 @@ RSpec.describe BulkCreateIntegrationService do
let(:association) { 'project' }
let(:inherit_from_id) { integration.id }
- it_behaves_like 'creates integration from batch ids'
- it_behaves_like 'updates inherit_from_id'
+ it_behaves_like 'creates integration successfully'
context 'with different foreign key of data_fields' do
let(:integration) { create(:zentao_integration, :group, group: group) }
let(:created_integration) { project.zentao_integration }
- it_behaves_like 'creates integration from batch ids'
- it_behaves_like 'updates inherit_from_id'
+ it_behaves_like 'creates integration successfully'
end
end
@@ -108,14 +120,12 @@ RSpec.describe BulkCreateIntegrationService do
let(:association) { 'group' }
let(:inherit_from_id) { instance_integration.id }
- it_behaves_like 'creates integration from batch ids'
- it_behaves_like 'updates inherit_from_id'
+ it_behaves_like 'creates integration successfully'
context 'with different foreign key of data_fields' do
let(:integration) { create(:zentao_integration, :group, group: group, inherit_from_id: instance_integration.id) }
- it_behaves_like 'creates integration from batch ids'
- it_behaves_like 'updates inherit_from_id'
+ it_behaves_like 'creates integration successfully'
end
end
end
diff --git a/spec/services/bulk_update_integration_service_spec.rb b/spec/services/bulk_update_integration_service_spec.rb
index dcc8d2df36d..23e2a0ef0ff 100644
--- a/spec/services/bulk_update_integration_service_spec.rb
+++ b/spec/services/bulk_update_integration_service_spec.rb
@@ -55,6 +55,20 @@ RSpec.describe BulkUpdateIntegrationService do
.not_to eq(subgroup_integration.attributes.except(*excluded_attributes))
end
+ it 'does not change the created_at timestamp' do
+ subgroup_integration.update_column(:created_at, Time.utc('2022-01-01'))
+
+ expect do
+ described_class.new(subgroup_integration, batch).execute
+ end.not_to change { integration.reload.created_at }
+ end
+
+ it 'sets the updated_at timestamp to the current time', time_travel_to: Time.utc('2022-01-01') do
+ expect do
+ described_class.new(subgroup_integration, batch).execute
+ end.to change { integration.reload.updated_at }.to(Time.current)
+ end
+
context 'with integration with data fields' do
let(:excluded_attributes) do
%w[id service_id created_at updated_at encrypted_properties encrypted_properties_iv]
@@ -69,6 +83,20 @@ RSpec.describe BulkUpdateIntegrationService do
expect(integration.data_fields.attributes.except(*excluded_attributes))
.not_to eq(excluded_integration.data_fields.attributes.except(*excluded_attributes))
end
+
+ it 'does not change the created_at timestamp' do
+ subgroup_integration.data_fields.update_column(:created_at, Time.utc('2022-01-02'))
+
+ expect do
+ described_class.new(subgroup_integration, batch).execute
+ end.not_to change { integration.data_fields.reload.created_at }
+ end
+
+ it 'sets the updated_at timestamp to the current time', time_travel_to: Time.utc('2022-01-01') do
+ expect do
+ described_class.new(subgroup_integration, batch).execute
+ end.to change { integration.data_fields.reload.updated_at }.to(Time.current)
+ end
end
end
diff --git a/spec/support/shared_examples/models/integrations/base_data_fields_shared_examples.rb b/spec/support/shared_examples/models/integrations/base_data_fields_shared_examples.rb
new file mode 100644
index 00000000000..e15299bbdab
--- /dev/null
+++ b/spec/support/shared_examples/models/integrations/base_data_fields_shared_examples.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.shared_examples Integrations::BaseDataFields do
+ describe 'associations' do
+ it { is_expected.to belong_to :integration }
+ end
+
+ describe '#to_database_hash' do
+ it 'does not include certain attributes' do
+ hash = described_class.new.to_database_hash
+
+ expect(hash.keys).not_to include('id', 'service_id', 'integration_id', 'created_at', 'updated_at')
+ end
+ end
+end