Skip to content
Snippets Groups Projects
Commit d0356412 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent 72817fd7
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -8,12 +8,12 @@ module Gitlab
attr_reader :attribute_name, :sort_direction
 
def initialize(order_value)
if order_value.is_a?(String)
@attribute_name, @sort_direction = extract_nulls_last_order(order_value)
else
@attribute_name = order_value.expr.name
@sort_direction = order_value.direction
end
@attribute_name, @sort_direction =
if order_value.is_a?(String)
extract_nulls_last_order(order_value)
else
extract_attribute_values(order_value)
end
end
 
def operator_for(before_or_after)
Loading
Loading
@@ -71,6 +71,10 @@ module Gitlab
 
[tokens.first, (tokens[1] == 'asc' ? :asc : :desc)]
end
def extract_attribute_values(order_value)
[order_value.expr.name, order_value.direction]
end
end
end
end
Loading
Loading
Loading
Loading
@@ -51,13 +51,22 @@ exports[`Dashboard template matches the default snapshot 1`] = `
<gl-dropdown-divider-stub />
<!---->
<gl-search-box-by-type-stub
class="m-2"
value=""
/>
<div
class="flex-fill overflow-auto"
/>
<!---->
<div
class="text-secondary no-matches-message"
>
No matching results
</div>
</div>
</gl-dropdown-stub>
</gl-form-group-stub>
Loading
Loading
Loading
Loading
@@ -255,9 +255,6 @@ describe('Dashboard', () => {
{
attachToDocument: true,
stubs: ['graph-group', 'panel-type'],
provide: {
glFeatures: { searchableEnvironmentsDropdown: true },
},
},
);
 
Loading
Loading
# frozen_string_literal: true
require 'spec_helper'
describe Mutations::Todos::RestoreMany do
let_it_be(:current_user) { create(:user) }
let_it_be(:author) { create(:user) }
let_it_be(:other_user) { create(:user) }
let_it_be(:todo1) { create(:todo, user: current_user, author: author, state: :done) }
let_it_be(:todo2) { create(:todo, user: current_user, author: author, state: :pending) }
let_it_be(:other_user_todo) { create(:todo, user: other_user, author: author, state: :done) }
let(:mutation) { described_class.new(object: nil, context: { current_user: current_user }) }
describe '#resolve' do
it 'restores a single todo' do
result = restore_mutation([todo1])
expect(todo1.reload.state).to eq('pending')
expect(todo2.reload.state).to eq('pending')
expect(other_user_todo.reload.state).to eq('done')
todo_ids = result[:updated_ids]
expect(todo_ids.size).to eq(1)
expect(todo_ids.first).to eq(todo1.to_global_id.to_s)
end
it 'handles a todo which is already pending as expected' do
result = restore_mutation([todo2])
expect_states_were_not_changed
expect(result[:updated_ids]).to eq([])
end
it 'ignores requests for todos which do not belong to the current user' do
restore_mutation([other_user_todo])
expect_states_were_not_changed
end
it 'ignores invalid GIDs' do
expect { mutation.resolve(ids: ['invalid_gid']) }.to raise_error(URI::BadURIError)
expect_states_were_not_changed
end
it 'restores multiple todos' do
todo4 = create(:todo, user: current_user, author: author, state: :done)
result = restore_mutation([todo1, todo4, todo2])
expect(result[:updated_ids].size).to eq(2)
returned_todo_ids = result[:updated_ids]
expect(returned_todo_ids).to contain_exactly(todo1.to_global_id.to_s, todo4.to_global_id.to_s)
expect(todo1.reload.state).to eq('pending')
expect(todo2.reload.state).to eq('pending')
expect(todo4.reload.state).to eq('pending')
expect(other_user_todo.reload.state).to eq('done')
end
it 'fails if one todo does not belong to the current user' do
restore_mutation([todo1, todo2, other_user_todo])
expect(todo1.reload.state).to eq('pending')
expect(todo2.reload.state).to eq('pending')
expect(other_user_todo.reload.state).to eq('done')
end
it 'fails if too many todos are requested for update' do
expect { restore_mutation([todo1] * 51) }.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
end
it 'does not update todos from another app' do
todo4 = create(:todo)
todo4_gid = ::URI::GID.parse("gid://otherapp/Todo/#{todo4.id}")
result = mutation.resolve(ids: [todo4_gid.to_s])
expect(result[:updated_ids]).to be_empty
expect_states_were_not_changed
end
it 'does not update todos from another model' do
todo4 = create(:todo)
todo4_gid = ::URI::GID.parse("gid://#{GlobalID.app}/Project/#{todo4.id}")
result = mutation.resolve(ids: [todo4_gid.to_s])
expect(result[:updated_ids]).to be_empty
expect_states_were_not_changed
end
end
def restore_mutation(todos)
mutation.resolve(ids: todos.map { |todo| global_id_of(todo) } )
end
def global_id_of(todo)
todo.to_global_id.to_s
end
def expect_states_were_not_changed
expect(todo1.reload.state).to eq('done')
expect(todo2.reload.state).to eq('pending')
expect(other_user_todo.reload.state).to eq('done')
end
end
Loading
Loading
@@ -144,4 +144,10 @@ describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do
cache.clear
end
end
describe 'metrics' do
it 'defines :gitlab_redis_diff_caching_memory_usage_bytes histogram' do
expect(described_class).to respond_to(:gitlab_redis_diff_caching_memory_usage_bytes)
end
end
end
Loading
Loading
@@ -4,10 +4,15 @@ require 'spec_helper'
 
describe Gitlab::Graphql::Connections::Keyset::Conditions::NotNullCondition do
describe '#build' do
let(:condition) { described_class.new(Issue.arel_table, %w(relative_position id), [1500, 500], ['>', '>'], before_or_after) }
let(:operators) { ['>', '>'] }
let(:before_or_after) { :after }
let(:condition) { described_class.new(arel_table, order_list, values, operators, before_or_after) }
 
context 'when there is only one ordering field' do
let(:condition) { described_class.new(Issue.arel_table, ['id'], [500], ['>'], :after) }
let(:arel_table) { Issue.arel_table }
let(:order_list) { ['id'] }
let(:values) { [500] }
let(:operators) { ['>'] }
 
it 'generates a single condition sql' do
expected_sql = <<~SQL
Loading
Loading
@@ -18,38 +23,52 @@ describe Gitlab::Graphql::Connections::Keyset::Conditions::NotNullCondition do
end
end
 
context 'when :after' do
let(:before_or_after) { :after }
context 'when ordering by a column attribute' do
let(:arel_table) { Issue.arel_table }
let(:order_list) { %w(relative_position id) }
let(:values) { [1500, 500] }
 
it 'generates :after sql' do
expected_sql = <<~SQL
("issues"."relative_position" > 1500)
OR (
"issues"."relative_position" = 1500
AND
"issues"."id" > 500
)
OR ("issues"."relative_position" IS NULL)
SQL
shared_examples ':after condition' do
it 'generates :after sql' do
expected_sql = <<~SQL
("issues"."relative_position" > 1500)
OR (
"issues"."relative_position" = 1500
AND
"issues"."id" > 500
)
OR ("issues"."relative_position" IS NULL)
SQL
 
expect(condition.build.squish).to eq expected_sql.squish
expect(condition.build.squish).to eq expected_sql.squish
end
end
end
 
context 'when :before' do
let(:before_or_after) { :before }
context 'when :after' do
it_behaves_like ':after condition'
end
 
it 'generates :before sql' do
expected_sql = <<~SQL
("issues"."relative_position" > 1500)
OR (
"issues"."relative_position" = 1500
AND
"issues"."id" > 500
)
SQL
context 'when :before' do
let(:before_or_after) { :before }
 
expect(condition.build.squish).to eq expected_sql.squish
it 'generates :before sql' do
expected_sql = <<~SQL
("issues"."relative_position" > 1500)
OR (
"issues"."relative_position" = 1500
AND
"issues"."id" > 500
)
SQL
expect(condition.build.squish).to eq expected_sql.squish
end
end
context 'when :foo' do
let(:before_or_after) { :foo }
it_behaves_like ':after condition'
end
end
end
Loading
Loading
Loading
Loading
@@ -4,38 +4,54 @@ require 'spec_helper'
 
describe Gitlab::Graphql::Connections::Keyset::Conditions::NullCondition do
describe '#build' do
let(:condition) { described_class.new(Issue.arel_table, %w(relative_position id), [nil, 500], [nil, '>'], before_or_after) }
context 'when :after' do
let(:before_or_after) { :after }
it 'generates sql' do
expected_sql = <<~SQL
(
"issues"."relative_position" IS NULL
AND
"issues"."id" > 500
)
SQL
let(:values) { [nil, 500] }
let(:operators) { [nil, '>'] }
let(:before_or_after) { :after }
let(:condition) { described_class.new(arel_table, order_list, values, operators, before_or_after) }
context 'when ordering by a column attribute' do
let(:arel_table) { Issue.arel_table }
let(:order_list) { %w(relative_position id) }
shared_examples ':after condition' do
it 'generates sql' do
expected_sql = <<~SQL
(
"issues"."relative_position" IS NULL
AND
"issues"."id" > 500
)
SQL
expect(condition.build.squish).to eq expected_sql.squish
end
end
 
expect(condition.build.squish).to eq expected_sql.squish
context 'when :after' do
it_behaves_like ':after condition'
end
end
 
context 'when :before' do
let(:before_or_after) { :before }
context 'when :before' do
let(:before_or_after) { :before }
it 'generates :before sql' do
expected_sql = <<~SQL
(
"issues"."relative_position" IS NULL
AND
"issues"."id" > 500
)
OR ("issues"."relative_position" IS NOT NULL)
SQL
expect(condition.build.squish).to eq expected_sql.squish
end
end
 
it 'generates :before sql' do
expected_sql = <<~SQL
(
"issues"."relative_position" IS NULL
AND
"issues"."id" > 500
)
OR ("issues"."relative_position" IS NOT NULL)
SQL
context 'when :foo' do
let(:before_or_after) { :foo }
 
expect(condition.build.squish).to eq expected_sql.squish
it_behaves_like ':after condition'
end
end
end
Loading
Loading
Loading
Loading
@@ -13,6 +13,7 @@ describe Gitlab::Graphql::Connections::Keyset::QueryBuilder do
describe '#conditions' do
let(:relation) { Issue.order(relative_position: :desc).order(:id) }
let(:order_list) { Gitlab::Graphql::Connections::Keyset::OrderInfo.build_order_list(relation) }
let(:arel_table) { Issue.arel_table }
let(:builder) { described_class.new(arel_table, order_list, decoded_cursor, before_or_after) }
let(:before_or_after) { :after }
 
Loading
Loading
@@ -101,8 +102,4 @@ describe Gitlab::Graphql::Connections::Keyset::QueryBuilder do
end
end
end
def arel_table
Issue.arel_table
end
end
Loading
Loading
@@ -313,6 +313,36 @@ describe Todo do
end
end
 
describe '.for_ids' do
it 'returns the expected todos' do
todo1 = create(:todo)
todo2 = create(:todo)
todo3 = create(:todo)
create(:todo)
expect(described_class.for_ids([todo2.id, todo1.id, todo3.id])).to contain_exactly(todo1, todo2, todo3)
end
it 'returns an empty collection when no ids are given' do
create(:todo)
expect(described_class.for_ids([])).to be_empty
end
end
describe '.for_user' do
it 'returns the expected todos' do
user1 = create(:user)
user2 = create(:user)
todo1 = create(:todo, user: user1)
todo2 = create(:todo, user: user1)
create(:todo, user: user2)
expect(described_class.for_user(user1)).to contain_exactly(todo1, todo2)
end
end
describe '.any_for_target?' do
it 'returns true if there are todos for a given target' do
todo = create(:todo)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment