summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-05-07 03:10:17 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-07 03:10:17 +0000
commit170765911848f0ad68e0f26f6413dd770d36f364 (patch)
treeb42a0750d6e17fc6d26357d3d97aad42bbb20462 /spec
parentfd6093f6f04702cecf75306a83beba837cfde8fb (diff)
downloadgitlab-ce-170765911848f0ad68e0f26f6413dd770d36f364.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/jobs/components/table/cells.vue/job_cell_spec.js23
-rw-r--r--spec/frontend/jobs/mock_data.js4
-rw-r--r--spec/models/concerns/bulk_insert_safe_spec.rb36
-rw-r--r--spec/support/shared_examples/models/concerns/bulk_insert_safe_shared_examples.rb4
4 files changed, 53 insertions, 14 deletions
diff --git a/spec/frontend/jobs/components/table/cells.vue/job_cell_spec.js b/spec/frontend/jobs/components/table/cells.vue/job_cell_spec.js
index cfe6e45332e..77c19162747 100644
--- a/spec/frontend/jobs/components/table/cells.vue/job_cell_spec.js
+++ b/spec/frontend/jobs/components/table/cells.vue/job_cell_spec.js
@@ -6,11 +6,13 @@ import { mockJobsInTable } from '../../../mock_data';
const mockJob = mockJobsInTable[0];
const mockJobCreatedByTag = mockJobsInTable[1];
+const mockJobLimitedAccess = mockJobsInTable[2];
describe('Job Cell', () => {
let wrapper;
- const findJobId = () => wrapper.findByTestId('job-id');
+ const findJobIdLink = () => wrapper.findByTestId('job-id-link');
+ const findJobIdNoLink = () => wrapper.findByTestId('job-id-limited-access');
const findJobRef = () => wrapper.findByTestId('job-ref');
const findJobSha = () => wrapper.findByTestId('job-sha');
const findLabelIcon = () => wrapper.findByTestId('label-icon');
@@ -34,15 +36,24 @@ describe('Job Cell', () => {
});
describe('Job Id', () => {
- beforeEach(() => {
+ it('displays the job id and links to the job', () => {
createComponent();
- });
- it('displays the job id and links to the job', () => {
const expectedJobId = `#${getIdFromGraphQLId(mockJob.id)}`;
- expect(findJobId().text()).toBe(expectedJobId);
- expect(findJobId().attributes('href')).toBe(mockJob.detailedStatus.detailsPath);
+ expect(findJobIdLink().text()).toBe(expectedJobId);
+ expect(findJobIdLink().attributes('href')).toBe(mockJob.detailedStatus.detailsPath);
+ expect(findJobIdNoLink().exists()).toBe(false);
+ });
+
+ it('display the job id with no link', () => {
+ createComponent(mockJobLimitedAccess);
+
+ const expectedJobId = `#${getIdFromGraphQLId(mockJobLimitedAccess.id)}`;
+
+ expect(findJobIdNoLink().text()).toBe(expectedJobId);
+ expect(findJobIdNoLink().exists()).toBe(true);
+ expect(findJobIdLink().exists()).toBe(false);
});
});
diff --git a/spec/frontend/jobs/mock_data.js b/spec/frontend/jobs/mock_data.js
index 85bdd87abc6..6d9a5b77f5a 100644
--- a/spec/frontend/jobs/mock_data.js
+++ b/spec/frontend/jobs/mock_data.js
@@ -1322,6 +1322,7 @@ export const mockJobsInTable = [
playable: true,
cancelable: false,
active: false,
+ userPermissions: { readBuild: true, __typename: 'JobPermissions' },
__typename: 'CiJob',
},
{
@@ -1360,6 +1361,7 @@ export const mockJobsInTable = [
playable: false,
cancelable: false,
active: false,
+ userPermissions: { readBuild: true, __typename: 'JobPermissions' },
__typename: 'CiJob',
},
{
@@ -1405,6 +1407,7 @@ export const mockJobsInTable = [
playable: false,
cancelable: false,
active: false,
+ userPermissions: { readBuild: false, __typename: 'JobPermissions' },
__typename: 'CiJob',
},
];
@@ -1492,6 +1495,7 @@ export const mockJobsQueryResponse = {
playable: false,
cancelable: false,
active: false,
+ userPermissions: { readBuild: true, __typename: 'JobPermissions' },
__typename: 'CiJob',
},
],
diff --git a/spec/models/concerns/bulk_insert_safe_spec.rb b/spec/models/concerns/bulk_insert_safe_spec.rb
index e40b0cf11ff..ca6df506ee8 100644
--- a/spec/models/concerns/bulk_insert_safe_spec.rb
+++ b/spec/models/concerns/bulk_insert_safe_spec.rb
@@ -5,6 +5,10 @@ require 'spec_helper'
RSpec.describe BulkInsertSafe do
before(:all) do
ActiveRecord::Schema.define do
+ create_table :bulk_insert_parent_items, force: true do |t|
+ t.string :name, null: false
+ end
+
create_table :bulk_insert_items, force: true do |t|
t.string :name, null: true
t.integer :enum_value, null: false
@@ -12,6 +16,7 @@ RSpec.describe BulkInsertSafe do
t.string :encrypted_secret_value_iv, null: false
t.binary :sha_value, null: false, limit: 20
t.jsonb :jsonb_value, null: false
+ t.belongs_to :bulk_insert_parent_item, foreign_key: true, null: true
t.index :name, unique: true
end
@@ -21,9 +26,23 @@ RSpec.describe BulkInsertSafe do
after(:all) do
ActiveRecord::Schema.define do
drop_table :bulk_insert_items, force: true
+ drop_table :bulk_insert_parent_items, force: true
end
end
+ BulkInsertParentItem = Class.new(ActiveRecord::Base) do
+ self.table_name = :bulk_insert_parent_items
+ self.inheritance_column = :_type_disabled
+
+ def self.name
+ table_name.singularize.camelcase
+ end
+ end
+
+ let_it_be(:bulk_insert_parent_item) do
+ BulkInsertParentItem.create!(name: 'parent')
+ end
+
let_it_be(:bulk_insert_item_class) do
Class.new(ActiveRecord::Base) do
self.table_name = 'bulk_insert_items'
@@ -33,6 +52,8 @@ RSpec.describe BulkInsertSafe do
validates :name, :enum_value, :secret_value, :sha_value, :jsonb_value, presence: true
+ belongs_to :bulk_insert_parent_item
+
sha_attribute :sha_value
enum enum_value: { case_1: 1 }
@@ -51,8 +72,8 @@ RSpec.describe BulkInsertSafe do
'BulkInsertItem'
end
- def self.valid_list(count)
- Array.new(count) { |n| new(name: "item-#{n}", secret_value: 'my-secret') }
+ def self.valid_list(count, bulk_insert_parent_item: nil)
+ Array.new(count) { |n| new(name: "item-#{n}", secret_value: 'my-secret', bulk_insert_parent_item: bulk_insert_parent_item) }
end
def self.invalid_list(count)
@@ -117,6 +138,14 @@ RSpec.describe BulkInsertSafe do
bulk_insert_item_class.bulk_insert!(items, batch_size: 5)
end
+ it 'inserts items with belongs_to association' do
+ items = bulk_insert_item_class.valid_list(10, bulk_insert_parent_item: bulk_insert_parent_item)
+
+ bulk_insert_item_class.bulk_insert!(items, batch_size: 5)
+
+ expect(bulk_insert_item_class.last(items.size).map(&:bulk_insert_parent_item)).to eq([bulk_insert_parent_item] * 10)
+ end
+
it 'items can be properly fetched from database' do
items = bulk_insert_item_class.valid_list(10)
@@ -129,8 +158,7 @@ RSpec.describe BulkInsertSafe do
it 'rolls back the transaction when any item is invalid' do
# second batch is bad
- all_items = bulk_insert_item_class.valid_list(10) +
- bulk_insert_item_class.invalid_list(10)
+ all_items = bulk_insert_item_class.valid_list(10) + bulk_insert_item_class.invalid_list(10)
expect do
bulk_insert_item_class.bulk_insert!(all_items, batch_size: 2) rescue nil
diff --git a/spec/support/shared_examples/models/concerns/bulk_insert_safe_shared_examples.rb b/spec/support/shared_examples/models/concerns/bulk_insert_safe_shared_examples.rb
index 3db5d7a8d7d..ec9756007f1 100644
--- a/spec/support/shared_examples/models/concerns/bulk_insert_safe_shared_examples.rb
+++ b/spec/support/shared_examples/models/concerns/bulk_insert_safe_shared_examples.rb
@@ -30,10 +30,6 @@ RSpec.shared_examples 'a BulkInsertSafe model' do |klass|
expect { target_class.set_callback(name) {} }.not_to raise_error
end
end
-
- it 'does not raise an error when the call is triggered by belongs_to' do
- expect { target_class.belongs_to(:other_record) }.not_to raise_error
- end
end
describe '.bulk_insert!' do