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
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/projects/lfs_pointers/lfs_link_service_spec.rb30
-rw-r--r--spec/services/users/signup_service_spec.rb64
2 files changed, 93 insertions, 1 deletions
diff --git a/spec/services/projects/lfs_pointers/lfs_link_service_spec.rb b/spec/services/projects/lfs_pointers/lfs_link_service_spec.rb
index 66233787d3a..aca59079b3c 100644
--- a/spec/services/projects/lfs_pointers/lfs_link_service_spec.rb
+++ b/spec/services/projects/lfs_pointers/lfs_link_service_spec.rb
@@ -16,6 +16,13 @@ describe Projects::LfsPointers::LfsLinkService do
end
describe '#execute' do
+ it 'raises an error when trying to link too many objects at once' do
+ oids = Array.new(described_class::MAX_OIDS) { |i| "oid-#{i}" }
+ oids << 'the straw'
+
+ expect { subject.execute(oids) }.to raise_error(described_class::TooManyOidsError)
+ end
+
it 'links existing lfs objects to the project' do
expect(project.all_lfs_objects.count).to eq 2
@@ -28,7 +35,7 @@ describe Projects::LfsPointers::LfsLinkService do
it 'returns linked oids' do
linked = lfs_objects_project.map(&:lfs_object).map(&:oid) << new_lfs_object.oid
- expect(subject.execute(new_oid_list.keys)).to eq linked
+ expect(subject.execute(new_oid_list.keys)).to contain_exactly(*linked)
end
it 'links in batches' do
@@ -48,5 +55,26 @@ describe Projects::LfsPointers::LfsLinkService do
expect(project.all_lfs_objects.count).to eq 9
expect(linked.size).to eq 7
end
+
+ it 'only queries for the batch that will be processed', :aggregate_failures do
+ stub_const("#{described_class}::BATCH_SIZE", 1)
+ oids = %w(one two)
+
+ expect(LfsObject).to receive(:where).with(oid: %w(one)).once.and_call_original
+ expect(LfsObject).to receive(:where).with(oid: %w(two)).once.and_call_original
+
+ subject.execute(oids)
+ end
+
+ it 'only queries 3 times' do
+ # make sure that we don't count the queries in the setup
+ new_oid_list
+
+ # These are repeated for each batch of oids: maximum (MAX_OIDS / BATCH_SIZE) times
+ # 1. Load the batch of lfs object ids that we might know already
+ # 2. Load the objects that have not been linked to the project yet
+ # 3. Insert the lfs_objects_projects for that batch
+ expect { subject.execute(new_oid_list.keys) }.not_to exceed_query_limit(3)
+ end
end
end
diff --git a/spec/services/users/signup_service_spec.rb b/spec/services/users/signup_service_spec.rb
new file mode 100644
index 00000000000..7d3cd614142
--- /dev/null
+++ b/spec/services/users/signup_service_spec.rb
@@ -0,0 +1,64 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Users::SignupService do
+ let(:user) { create(:user, setup_for_company: true) }
+
+ describe '#execute' do
+ context 'when updating name' do
+ it 'updates the name attribute' do
+ result = update_user(user, name: 'New Name')
+
+ expect(result).to eq(status: :success)
+ expect(user.reload.name).to eq('New Name')
+ end
+
+ it 'returns an error result when name is missing' do
+ result = update_user(user, name: '')
+
+ expect(user.reload.name).not_to be_blank
+ expect(result[:status]).to eq(:error)
+ expect(result[:message]).to include("Name can't be blank")
+ end
+ end
+
+ context 'when updating role' do
+ it 'updates the role attribute' do
+ result = update_user(user, role: 'development_team_lead')
+
+ expect(result).to eq(status: :success)
+ expect(user.reload.role).to eq('development_team_lead')
+ end
+
+ it 'returns an error result when role is missing' do
+ result = update_user(user, role: '')
+
+ expect(user.reload.role).not_to be_blank
+ expect(result[:status]).to eq(:error)
+ expect(result[:message]).to eq("Role can't be blank")
+ end
+ end
+
+ context 'when updating setup_for_company' do
+ it 'updates the setup_for_company attribute' do
+ result = update_user(user, setup_for_company: 'false')
+
+ expect(result).to eq(status: :success)
+ expect(user.reload.setup_for_company).to be(false)
+ end
+
+ it 'returns an error result when setup_for_company is missing' do
+ result = update_user(user, setup_for_company: '')
+
+ expect(user.reload.setup_for_company).not_to be_blank
+ expect(result[:status]).to eq(:error)
+ expect(result[:message]).to eq("Setup for company can't be blank")
+ end
+ end
+
+ def update_user(user, opts)
+ described_class.new(user, opts).execute
+ end
+ end
+end