diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-23 12:10:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-23 12:10:07 +0300 |
commit | 8f2b51af416f4f4451632f6b3c2ada52c52eb44f (patch) | |
tree | 5e134df670cf056f300b887c3999f4aa84ec6f24 /spec | |
parent | 86fa823611b3ab5701d144aca1c57c51b4af25d5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/fixtures/api/schemas/feature_flags_client_token.json | 10 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb | 24 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_spec.rb | 6 | ||||
-rw-r--r-- | spec/serializers/feature_flag_entity_spec.rb | 22 | ||||
-rw-r--r-- | spec/serializers/feature_flag_serializer_spec.rb | 23 | ||||
-rw-r--r-- | spec/serializers/feature_flag_summary_entity_spec.rb | 21 | ||||
-rw-r--r-- | spec/serializers/feature_flag_summary_serializer_spec.rb | 22 | ||||
-rw-r--r-- | spec/serializers/feature_flags_client_serializer_spec.rb | 17 | ||||
-rw-r--r-- | spec/services/snippets/update_service_spec.rb | 95 |
9 files changed, 200 insertions, 40 deletions
diff --git a/spec/fixtures/api/schemas/feature_flags_client_token.json b/spec/fixtures/api/schemas/feature_flags_client_token.json new file mode 100644 index 00000000000..115db422d12 --- /dev/null +++ b/spec/fixtures/api/schemas/feature_flags_client_token.json @@ -0,0 +1,10 @@ +{ + "type": "object", + "required" : [ + "token" + ], + "properties" : { + "token": { "type": ["string"] } + }, + "additionalProperties": false +} diff --git a/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb index f881da71251..6d4f52974aa 100644 --- a/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb @@ -238,16 +238,20 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s it 'returns the number of unique events for all known events' do results = { - 'category1' => { - 'event1_slot' => 1, - 'event2_slot' => 1, - 'category1_total_unique_counts_weekly' => 2, - 'category1_total_unique_counts_monthly' => 3 - }, - 'category2' => { - 'event3' => 1, - 'event4' => 1 - } + "category1" => { + "event1_slot_weekly" => 1, + "event1_slot_monthly" => 1, + "event2_slot_weekly" => 1, + "event2_slot_monthly" => 2, + "category1_total_unique_counts_weekly" => 2, + "category1_total_unique_counts_monthly" => 3 + }, + "category2" => { + "event3_weekly" => 1, + "event3_monthly" => 1, + "event4_weekly" => 1, + "event4_monthly" => 1 + } } expect(subject.unique_events_data).to eq(results) diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index d3fb26c0a0a..5a54b29edc3 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -1186,11 +1186,13 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do categories.each do |category| keys = ::Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category(category) + metrics = keys.map { |key| "#{key}_weekly" } + keys.map { |key| "#{key}_monthly" } + if ineligible_total_categories.exclude?(category) - keys.append("#{category}_total_unique_counts_weekly", "#{category}_total_unique_counts_monthly") + metrics.append("#{category}_total_unique_counts_weekly", "#{category}_total_unique_counts_monthly") end - expect(subject[:redis_hll_counters][category].keys).to match_array(keys) + expect(subject[:redis_hll_counters][category].keys).to match_array(metrics) end end end diff --git a/spec/serializers/feature_flag_entity_spec.rb b/spec/serializers/feature_flag_entity_spec.rb new file mode 100644 index 00000000000..21ecfe59c31 --- /dev/null +++ b/spec/serializers/feature_flag_entity_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe FeatureFlagEntity do + let(:feature_flag) { create(:operations_feature_flag, project: project) } + let(:project) { create(:project) } + let(:request) { double('request', current_user: user) } + let(:user) { create(:user) } + let(:entity) { described_class.new(feature_flag, request: request) } + + before do + project.add_developer(user) + end + + subject { entity.as_json } + + it 'has feature flag attributes' do + expect(subject).to include(:id, :active, :created_at, :updated_at, + :description, :name, :edit_path, :destroy_path) + end +end diff --git a/spec/serializers/feature_flag_serializer_spec.rb b/spec/serializers/feature_flag_serializer_spec.rb new file mode 100644 index 00000000000..fab8ca93b1b --- /dev/null +++ b/spec/serializers/feature_flag_serializer_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe FeatureFlagSerializer do + let(:serializer) { described_class.new(project: project, current_user: user) } + let(:user) { create(:user) } + let(:project) { create(:project) } + let(:feature_flags) { create_list(:operations_feature_flag, 3) } + + before do + project.add_developer(user) + end + + describe '#represent' do + subject { serializer.represent(feature_flags) } + + it 'includes feature flag attributes' do + is_expected.to all(include(:id, :active, :created_at, :updated_at, + :description, :name)) + end + end +end diff --git a/spec/serializers/feature_flag_summary_entity_spec.rb b/spec/serializers/feature_flag_summary_entity_spec.rb new file mode 100644 index 00000000000..385a9deb2d7 --- /dev/null +++ b/spec/serializers/feature_flag_summary_entity_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe FeatureFlagSummaryEntity do + let!(:feature_flag) { create(:operations_feature_flag, project: project) } + let(:project) { create(:project) } + let(:request) { double('request', current_user: user) } + let(:user) { create(:user) } + let(:entity) { described_class.new(project, request: request) } + + before do + project.add_developer(user) + end + + subject { entity.as_json } + + it 'has summary information' do + expect(subject).to include(:count) + end +end diff --git a/spec/serializers/feature_flag_summary_serializer_spec.rb b/spec/serializers/feature_flag_summary_serializer_spec.rb new file mode 100644 index 00000000000..79cef6765f7 --- /dev/null +++ b/spec/serializers/feature_flag_summary_serializer_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe FeatureFlagSummarySerializer do + let(:serializer) { described_class.new(project: project, current_user: user) } + let(:user) { create(:user) } + let(:project) { create(:project) } + let!(:feature_flags) { create(:operations_feature_flag, project: project) } + + before do + project.add_developer(user) + end + + describe '#represent' do + subject { serializer.represent(project) } + + it 'has summary information' do + expect(subject).to include(:count) + end + end +end diff --git a/spec/serializers/feature_flags_client_serializer_spec.rb b/spec/serializers/feature_flags_client_serializer_spec.rb new file mode 100644 index 00000000000..3746142a3f1 --- /dev/null +++ b/spec/serializers/feature_flags_client_serializer_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe FeatureFlagsClientSerializer do + let(:project) { create(:project) } + let(:feature_flags_client) { project.create_operations_feature_flags_client! } + let(:serializer) { described_class.new } + + describe '#represent_token' do + subject { serializer.represent_token(feature_flags_client).to_json } + + it 'includes feature flags client token' do + expect(subject).to match_schema('feature_flags_client_token') + end + end +end diff --git a/spec/services/snippets/update_service_spec.rb b/spec/services/snippets/update_service_spec.rb index 641fc56294a..406ece30bd7 100644 --- a/spec/services/snippets/update_service_spec.rb +++ b/spec/services/snippets/update_service_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe Snippets::UpdateService do - describe '#execute' do + describe '#execute', :aggregate_failures do let_it_be(:user) { create(:user) } let_it_be(:admin) { create :user, admin: true } let(:visibility_level) { Gitlab::VisibilityLevel::PRIVATE } @@ -97,40 +97,81 @@ RSpec.describe Snippets::UpdateService do end shared_examples 'creates repository and creates file' do - it 'creates repository' do - expect(snippet.repository).not_to exist + context 'when file_name and content params are used' do + it 'creates repository' do + expect(snippet.repository).not_to exist - subject + subject - expect(snippet.repository).to exist - end + expect(snippet.repository).to exist + end - it 'commits the files to the repository' do - subject + it 'commits the files to the repository' do + subject - expect(snippet.blobs.count).to eq 1 + expect(snippet.blobs.count).to eq 1 - blob = snippet.repository.blob_at('master', options[:file_name]) + blob = snippet.repository.blob_at('master', options[:file_name]) - expect(blob.data).to eq options[:content] + expect(blob.data).to eq options[:content] + end + + context 'when the repository creation fails' do + before do + allow(snippet).to receive(:repository_exists?).and_return(false) + end + + it 'raise an error' do + expect(subject).to be_error + expect(subject.payload[:snippet].errors[:repository].to_sentence).to eq 'Error updating the snippet - Repository could not be created' + end + + it 'does not try to commit file' do + expect(service).not_to receive(:create_commit) + + subject + end + end end - context 'when the repository creation fails' do - before do - allow(snippet).to receive(:repository_exists?).and_return(false) + context 'when snippet_actions param is used' do + let(:file_path) { 'CHANGELOG' } + let(:created_file_path) { 'New file'} + let(:content) { 'foobar' } + let(:snippet_actions) { [{ action: :move, previous_path: snippet.file_name, file_path: file_path }, { action: :create, file_path: created_file_path, content: content }] } + let(:base_opts) do + { + snippet_actions: snippet_actions + } end - it 'raise an error' do - response = subject + it 'performs operation without raising errors' do + db_content = snippet.content - expect(response).to be_error - expect(response.payload[:snippet].errors[:repository].to_sentence).to eq 'Error updating the snippet - Repository could not be created' + expect(subject).to be_success + + new_blob = snippet.repository.blob_at('master', file_path) + created_file = snippet.repository.blob_at('master', created_file_path) + + expect(new_blob.data).to eq db_content + expect(created_file.data).to eq content end - it 'does not try to commit file' do - expect(service).not_to receive(:create_commit) + context 'when the repository is not created' do + it 'keeps snippet database data' do + old_file_name = snippet.file_name + old_file_content = snippet.content - subject + expect_next_instance_of(described_class) do |instance| + expect(instance).to receive(:create_repository_for).and_raise(StandardError) + end + + snippet = subject.payload[:snippet] + + expect(subject).to be_error + expect(snippet.file_name).to eq(old_file_name) + expect(snippet.content).to eq(old_file_content) + end end end end @@ -366,10 +407,9 @@ RSpec.describe Snippets::UpdateService do let(:snippet_actions) { [{ action: 'invalid_action' }] } it 'raises a validation error' do - response = subject - snippet = response.payload[:snippet] + snippet = subject.payload[:snippet] - expect(response).to be_error + expect(subject).to be_error expect(snippet.errors.full_messages_for(:snippet_actions)).to eq ['Snippet actions have invalid data'] end end @@ -377,13 +417,12 @@ RSpec.describe Snippets::UpdateService do context 'when an error is raised committing the file' do it 'keeps any snippet modifications' do expect_next_instance_of(described_class) do |instance| - expect(instance).to receive(:create_repository_for).and_raise(StandardError) + expect(instance).to receive(:create_commit).and_raise(StandardError) end - response = subject - snippet = response.payload[:snippet] + snippet = subject.payload[:snippet] - expect(response).to be_error + expect(subject).to be_error expect(snippet.title).to eq(new_title) expect(snippet.file_name).to eq(file_path) expect(snippet.content).to eq(content) |