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>2020-02-01 06:09:04 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-01 06:09:04 +0300
commitd0356412dfc91d02585f0a177c65677dbe2944a3 (patch)
tree5a2ac806b6ea6113475bb2a759f6b15c186fb482 /spec
parent72817fd7c07d1b812623f8d5e27fc7bcecb4eed5 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap13
-rw-r--r--spec/frontend/monitoring/components/dashboard_spec.js3
-rw-r--r--spec/graphql/mutations/todos/restore_many_spec.rb114
-rw-r--r--spec/lib/gitlab/diff/highlight_cache_spec.rb6
-rw-r--r--spec/lib/gitlab/graphql/connections/keyset/conditions/not_null_condition_spec.rb75
-rw-r--r--spec/lib/gitlab/graphql/connections/keyset/conditions/null_condition_spec.rb70
-rw-r--r--spec/lib/gitlab/graphql/connections/keyset/query_builder_spec.rb5
-rw-r--r--spec/models/todo_spec.rb30
8 files changed, 252 insertions, 64 deletions
diff --git a/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap b/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap
index 2b2ff074f83..c705270343b 100644
--- a/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap
+++ b/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap
@@ -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>
diff --git a/spec/frontend/monitoring/components/dashboard_spec.js b/spec/frontend/monitoring/components/dashboard_spec.js
index 29338ee204e..31266b4f6d4 100644
--- a/spec/frontend/monitoring/components/dashboard_spec.js
+++ b/spec/frontend/monitoring/components/dashboard_spec.js
@@ -255,9 +255,6 @@ describe('Dashboard', () => {
{
attachToDocument: true,
stubs: ['graph-group', 'panel-type'],
- provide: {
- glFeatures: { searchableEnvironmentsDropdown: true },
- },
},
);
diff --git a/spec/graphql/mutations/todos/restore_many_spec.rb b/spec/graphql/mutations/todos/restore_many_spec.rb
new file mode 100644
index 00000000000..7821ce35a08
--- /dev/null
+++ b/spec/graphql/mutations/todos/restore_many_spec.rb
@@ -0,0 +1,114 @@
+# 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
diff --git a/spec/lib/gitlab/diff/highlight_cache_spec.rb b/spec/lib/gitlab/diff/highlight_cache_spec.rb
index bff51709c40..218c393c409 100644
--- a/spec/lib/gitlab/diff/highlight_cache_spec.rb
+++ b/spec/lib/gitlab/diff/highlight_cache_spec.rb
@@ -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
diff --git a/spec/lib/gitlab/graphql/connections/keyset/conditions/not_null_condition_spec.rb b/spec/lib/gitlab/graphql/connections/keyset/conditions/not_null_condition_spec.rb
index d943540fe1f..5e215be4dfb 100644
--- a/spec/lib/gitlab/graphql/connections/keyset/conditions/not_null_condition_spec.rb
+++ b/spec/lib/gitlab/graphql/connections/keyset/conditions/not_null_condition_spec.rb
@@ -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
@@ -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
diff --git a/spec/lib/gitlab/graphql/connections/keyset/conditions/null_condition_spec.rb b/spec/lib/gitlab/graphql/connections/keyset/conditions/null_condition_spec.rb
index 7fce94adb81..1049890a079 100644
--- a/spec/lib/gitlab/graphql/connections/keyset/conditions/null_condition_spec.rb
+++ b/spec/lib/gitlab/graphql/connections/keyset/conditions/null_condition_spec.rb
@@ -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
diff --git a/spec/lib/gitlab/graphql/connections/keyset/query_builder_spec.rb b/spec/lib/gitlab/graphql/connections/keyset/query_builder_spec.rb
index 59e153d9e07..7ebf5da264d 100644
--- a/spec/lib/gitlab/graphql/connections/keyset/query_builder_spec.rb
+++ b/spec/lib/gitlab/graphql/connections/keyset/query_builder_spec.rb
@@ -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 }
@@ -101,8 +102,4 @@ describe Gitlab::Graphql::Connections::Keyset::QueryBuilder do
end
end
end
-
- def arel_table
- Issue.arel_table
- end
end
diff --git a/spec/models/todo_spec.rb b/spec/models/todo_spec.rb
index ea09c6caed3..3f0c95b2513 100644
--- a/spec/models/todo_spec.rb
+++ b/spec/models/todo_spec.rb
@@ -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)