From 4447006832d8955f371e2430988e0c95b20f155d Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Mon, 19 Jun 2017 19:56:27 +0200 Subject: Split pipelines by origin on usage data When sending the usage data, it now includes all pipelines. This commit will split the pipelines in two; internal and external. This will lead to historical data being incorrectly marked this way. Fixes gitlab-org/gitlab-ce#33172 --- spec/models/ci/pipeline_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'spec/models') diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index dab8e8ca432..55d85a6e228 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -672,6 +672,12 @@ describe Ci::Pipeline, models: true do end end + describe '.internal_sources' do + subject { described_class.internal_sources } + + it { is_expected.to be_an(Array) } + end + describe '#status' do let(:build) do create(:ci_build, :created, pipeline: pipeline, name: 'test') -- cgit v1.2.1 From b4d325c80c63ee9ee2676a57a42fac472b5b20d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Wed, 21 Jun 2017 16:49:51 +0200 Subject: Allow the feature flags to be enabled/disabled with more granularity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows to enable/disable a feature flag for a given user, or a given Flipper group (must be declared statically in the `flipper.rb` initializer beforehand). Signed-off-by: Rémy Coutable --- spec/models/user_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'spec/models') diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 8e895ec6634..05ba887c51f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -430,6 +430,20 @@ describe User, models: true do end end + describe '#flipper_id' do + context 'when user is not persisted' do + let(:user) { build(:user) } + + it { expect(user.flipper_id).to be_nil } + end + + context 'when user is persisted' do + let(:user) { create(:user) } + + it { expect(user.flipper_id).to eq "User:#{user.id}" } + end + end + describe '#generate_password' do it "does not generate password by default" do user = create(:user, password: 'abcdefghe') -- cgit v1.2.1 From 5fa9d6a17dac86e9976946ded7857e1392403136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Tue, 27 Jun 2017 18:58:56 +0200 Subject: Rename FLippable to FeatureGate and make `flipper_group` and `user` mutually exclusive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- spec/models/concerns/feature_gate_spec.rb | 19 +++++++++++++++++++ spec/models/user_spec.rb | 14 -------------- 2 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 spec/models/concerns/feature_gate_spec.rb (limited to 'spec/models') diff --git a/spec/models/concerns/feature_gate_spec.rb b/spec/models/concerns/feature_gate_spec.rb new file mode 100644 index 00000000000..3f601243245 --- /dev/null +++ b/spec/models/concerns/feature_gate_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe FeatureGate do + describe 'User' do + describe '#flipper_id' do + context 'when user is not persisted' do + let(:user) { build(:user) } + + it { expect(user.flipper_id).to be_nil } + end + + context 'when user is persisted' do + let(:user) { create(:user) } + + it { expect(user.flipper_id).to eq "User:#{user.id}" } + end + end + end +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 05ba887c51f..8e895ec6634 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -430,20 +430,6 @@ describe User, models: true do end end - describe '#flipper_id' do - context 'when user is not persisted' do - let(:user) { build(:user) } - - it { expect(user.flipper_id).to be_nil } - end - - context 'when user is persisted' do - let(:user) { create(:user) } - - it { expect(user.flipper_id).to eq "User:#{user.id}" } - end - end - describe '#generate_password' do it "does not generate password by default" do user = create(:user, password: 'abcdefghe') -- cgit v1.2.1 From 963b374dc7ca077aeb97c6a3a79605e2646631d1 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Thu, 6 Apr 2017 14:09:58 -0700 Subject: update the specs to not require a set to be returned --- spec/models/ability_spec.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 090f9e70c50..dc7a0d80752 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' describe Ability, lib: true do context 'using a nil subject' do - it 'is always empty' do - expect(Ability.allowed(nil, nil).to_set).to be_empty + it 'has no permissions' do + expect(Ability.policy_for(nil, nil)).to be_banned end end @@ -255,12 +255,15 @@ describe Ability, lib: true do describe '.project_disabled_features_rules' do let(:project) { create(:empty_project, :wiki_disabled) } - subject { described_class.allowed(project.owner, project) } + subject { described_class.policy_for(project.owner, project) } context 'wiki named abilities' do it 'disables wiki abilities if the project has no wiki' do expect(project).to receive(:has_external_wiki?).and_return(false) - expect(subject).not_to include(:read_wiki, :create_wiki, :update_wiki, :admin_wiki) + expect(subject).not_to be_allowed(:read_wiki) + expect(subject).not_to be_allowed(:create_wiki) + expect(subject).not_to be_allowed(:update_wiki) + expect(subject).not_to be_allowed(:admin_wiki) end end end -- cgit v1.2.1 From 41aebaa103a8c9ef6ae5edef5cc500ba6ca24bb9 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Mon, 26 Jun 2017 22:03:34 +0900 Subject: Decuplin --- spec/models/ci/variable_spec.rb | 40 +-------------------------- spec/models/concerns/has_variable_spec.rb | 45 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 39 deletions(-) create mode 100644 spec/models/concerns/has_variable_spec.rb (limited to 'spec/models') diff --git a/spec/models/ci/variable_spec.rb b/spec/models/ci/variable_spec.rb index 83494af24ba..ade279cd16f 100644 --- a/spec/models/ci/variable_spec.rb +++ b/spec/models/ci/variable_spec.rb @@ -3,14 +3,8 @@ require 'spec_helper' describe Ci::Variable, models: true do subject { build(:ci_variable) } - let(:secret_value) { 'secret' } - - it { is_expected.to validate_presence_of(:key) } + it { is_expected.to be_kind_of(HasVariable) } it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id) } - it { is_expected.to validate_length_of(:key).is_at_most(255) } - it { is_expected.to allow_value('foo').for(:key) } - it { is_expected.not_to allow_value('foo bar').for(:key) } - it { is_expected.not_to allow_value('foo/bar').for(:key) } describe '.unprotected' do subject { described_class.unprotected } @@ -33,36 +27,4 @@ describe Ci::Variable, models: true do end end end - - describe '#value' do - before do - subject.value = secret_value - end - - it 'stores the encrypted value' do - expect(subject.encrypted_value).not_to be_nil - end - - it 'stores an iv for value' do - expect(subject.encrypted_value_iv).not_to be_nil - end - - it 'stores a salt for value' do - expect(subject.encrypted_value_salt).not_to be_nil - end - - it 'fails to decrypt if iv is incorrect' do - subject.encrypted_value_iv = SecureRandom.hex - subject.instance_variable_set(:@value, nil) - expect { subject.value } - .to raise_error(OpenSSL::Cipher::CipherError, 'bad decrypt') - end - end - - describe '#to_runner_variable' do - it 'returns a hash for the runner' do - expect(subject.to_runner_variable) - .to eq(key: subject.key, value: subject.value, public: false) - end - end end diff --git a/spec/models/concerns/has_variable_spec.rb b/spec/models/concerns/has_variable_spec.rb new file mode 100644 index 00000000000..3bb2d01e7c5 --- /dev/null +++ b/spec/models/concerns/has_variable_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +describe HasVariable do + subject { build(:ci_variable) } + + let(:secret_value) { 'secret' } + + it { is_expected.to validate_presence_of(:key) } + it { is_expected.to validate_length_of(:key).is_at_most(255) } + it { is_expected.to allow_value('foo').for(:key) } + it { is_expected.not_to allow_value('foo bar').for(:key) } + it { is_expected.not_to allow_value('foo/bar').for(:key) } + + describe '#value' do + before do + subject.value = secret_value + end + + it 'stores the encrypted value' do + expect(subject.encrypted_value).not_to be_nil + end + + it 'stores an iv for value' do + expect(subject.encrypted_value_iv).not_to be_nil + end + + it 'stores a salt for value' do + expect(subject.encrypted_value_salt).not_to be_nil + end + + it 'fails to decrypt if iv is incorrect' do + subject.encrypted_value_iv = SecureRandom.hex + subject.instance_variable_set(:@value, nil) + expect { subject.value } + .to raise_error(OpenSSL::Cipher::CipherError, 'bad decrypt') + end + end + + describe '#to_runner_variable' do + it 'returns a hash for the runner' do + expect(subject.to_runner_variable) + .to eq(key: subject.key, value: subject.value, public: false) + end + end +end -- cgit v1.2.1 From 083179e936dba669085cda7bb159c10be4d9312a Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Tue, 27 Jun 2017 00:12:52 +0900 Subject: Add a test for checking validates :key does not override by concern --- spec/models/ci/variable_spec.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'spec/models') diff --git a/spec/models/ci/variable_spec.rb b/spec/models/ci/variable_spec.rb index ade279cd16f..b7821afbdc9 100644 --- a/spec/models/ci/variable_spec.rb +++ b/spec/models/ci/variable_spec.rb @@ -6,6 +6,40 @@ describe Ci::Variable, models: true do it { is_expected.to be_kind_of(HasVariable) } it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id) } + describe 'validates :key' do + let(:project) { create(:project) } + + it 'be invalid if it exceeds maximum' do + expect do + create(:ci_variable, project: project, key: "A"*256) + end.to raise_error(ActiveRecord::RecordInvalid) + end + + it 'be invalid if violates constraints' do + expect do + create(:ci_variable, project: project, key: "*") + end.to raise_error(ActiveRecord::RecordInvalid) + end + + context 'when there is a variable' do + before do + create(:ci_variable, key: 'AAA', project: project) + end + + it 'be valid if it is unique' do + expect do + create(:ci_variable, project: project, key: 'CCC') + end.not_to raise_error + end + + it 'be invalid if it is duplicated' do + expect do + create(:ci_variable, project: project, key: 'AAA') + end.to raise_error(ActiveRecord::RecordInvalid) + end + end + end + describe '.unprotected' do subject { described_class.unprotected } -- cgit v1.2.1 From 2633a635311f60d15d9729dc770fdf2324a67927 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Tue, 27 Jun 2017 19:25:31 +0900 Subject: Remove PoC spec --- spec/models/ci/variable_spec.rb | 34 ---------------------------------- 1 file changed, 34 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/variable_spec.rb b/spec/models/ci/variable_spec.rb index b7821afbdc9..ade279cd16f 100644 --- a/spec/models/ci/variable_spec.rb +++ b/spec/models/ci/variable_spec.rb @@ -6,40 +6,6 @@ describe Ci::Variable, models: true do it { is_expected.to be_kind_of(HasVariable) } it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id) } - describe 'validates :key' do - let(:project) { create(:project) } - - it 'be invalid if it exceeds maximum' do - expect do - create(:ci_variable, project: project, key: "A"*256) - end.to raise_error(ActiveRecord::RecordInvalid) - end - - it 'be invalid if violates constraints' do - expect do - create(:ci_variable, project: project, key: "*") - end.to raise_error(ActiveRecord::RecordInvalid) - end - - context 'when there is a variable' do - before do - create(:ci_variable, key: 'AAA', project: project) - end - - it 'be valid if it is unique' do - expect do - create(:ci_variable, project: project, key: 'CCC') - end.not_to raise_error - end - - it 'be invalid if it is duplicated' do - expect do - create(:ci_variable, project: project, key: 'AAA') - end.to raise_error(ActiveRecord::RecordInvalid) - end - end - end - describe '.unprotected' do subject { described_class.unprotected } -- cgit v1.2.1 From de893b19c30acf83ce43dd42376783505d704763 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Wed, 28 Jun 2017 15:25:36 +0900 Subject: Improve small things --- spec/models/ci/variable_spec.rb | 2 +- spec/models/concerns/has_variable_spec.rb | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/variable_spec.rb b/spec/models/ci/variable_spec.rb index ade279cd16f..329682a0771 100644 --- a/spec/models/ci/variable_spec.rb +++ b/spec/models/ci/variable_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Ci::Variable, models: true do subject { build(:ci_variable) } - it { is_expected.to be_kind_of(HasVariable) } + it { is_expected.to include_module(HasVariable) } it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id) } describe '.unprotected' do diff --git a/spec/models/concerns/has_variable_spec.rb b/spec/models/concerns/has_variable_spec.rb index 3bb2d01e7c5..f4b24e6d1d9 100644 --- a/spec/models/concerns/has_variable_spec.rb +++ b/spec/models/concerns/has_variable_spec.rb @@ -3,8 +3,6 @@ require 'spec_helper' describe HasVariable do subject { build(:ci_variable) } - let(:secret_value) { 'secret' } - it { is_expected.to validate_presence_of(:key) } it { is_expected.to validate_length_of(:key).is_at_most(255) } it { is_expected.to allow_value('foo').for(:key) } @@ -13,7 +11,7 @@ describe HasVariable do describe '#value' do before do - subject.value = secret_value + subject.value = 'secret' end it 'stores the encrypted value' do -- cgit v1.2.1 From 34f57b462bc14ad194cf890a4585d403bdbde55c Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Thu, 15 Jun 2017 13:06:49 +0100 Subject: Fix current feature related specs --- spec/models/project_spec.rb | 9 --------- 1 file changed, 9 deletions(-) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index d7fcadb895e..1dbe901b004 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -284,15 +284,6 @@ describe Project, models: true do end end - describe 'default_scope' do - it 'excludes projects pending deletion from the results' do - project = create(:empty_project) - create(:empty_project, pending_delete: true) - - expect(Project.all).to eq [project] - end - end - describe 'project token' do it 'sets an random token if none provided' do project = FactoryGirl.create :empty_project, runners_token: '' -- cgit v1.2.1 From 2a64607b987add8747c4b9601aa01fe40064d15d Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Wed, 28 Jun 2017 10:42:51 -0300 Subject: Add Project#ensure_repository --- spec/models/project_spec.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index d7fcadb895e..cc22b8a4edc 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1327,6 +1327,37 @@ describe Project, models: true do end end + describe '#ensure_repository' do + let(:project) { create(:project, :repository) } + let(:shell) { Gitlab::Shell.new } + + before do + allow(project).to receive(:gitlab_shell).and_return(shell) + end + + it 'creates the repository if it not exist' do + allow(project).to receive(:repository_exists?) + .and_return(false) + + allow(shell).to receive(:add_repository) + .with(project.repository_storage_path, project.path_with_namespace) + .and_return(true) + + expect(project).to receive(:create_repository) + + project.ensure_repository + end + + it 'does not create the repository if it exists' do + allow(project).to receive(:repository_exists?) + .and_return(true) + + expect(project).not_to receive(:create_repository) + + project.ensure_repository + end + end + describe '#user_can_push_to_empty_repo?' do let(:project) { create(:empty_project) } let(:user) { create(:user) } -- cgit v1.2.1 From 26f3731021e8c5c6417fe874c53a5bf2065b8888 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Wed, 28 Jun 2017 10:42:59 -0300 Subject: Add ProjectWiki#ensure_repository --- spec/models/project_wiki_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'spec/models') diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb index bf74ac5ea25..1f314791479 100644 --- a/spec/models/project_wiki_spec.rb +++ b/spec/models/project_wiki_spec.rb @@ -278,6 +278,24 @@ describe ProjectWiki, models: true do end end + describe '#ensure_repository' do + it 'creates the repository if it not exist' do + allow(subject).to receive(:repository_exists?).and_return(false) + + expect(subject).to receive(:create_repo!) + + subject.ensure_repository + end + + it 'does not create the repository if it exists' do + allow(subject).to receive(:repository_exists?).and_return(true) + + expect(subject).not_to receive(:create_repo!) + + subject.ensure_repository + end + end + describe '#hook_attrs' do it 'returns a hash with values' do expect(subject.hook_attrs).to be_a Hash -- cgit v1.2.1 From da3e4f412846b754d31439da0d884181653bced0 Mon Sep 17 00:00:00 2001 From: Oswaldo Ferreira Date: Tue, 27 Jun 2017 17:35:35 -0300 Subject: Add "members_count" and "parent_id" data on namespaces API --- spec/models/namespace_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'spec/models') diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index e7c3acf19eb..d4f898f6d9f 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -323,6 +323,25 @@ describe Namespace, models: true do end end + describe '#users_with_descendants', :nested_groups do + let(:user_a) { create(:user) } + let(:user_b) { create(:user) } + + let(:group) { create(:group) } + let(:nested_group) { create(:group, parent: group) } + let(:deep_nested_group) { create(:group, parent: nested_group) } + + it 'returns member users on every nest level without duplication' do + group.add_developer(user_a) + nested_group.add_developer(user_b) + deep_nested_group.add_developer(user_a) + + expect(group.users_with_descendants).to contain_exactly(user_a, user_b) + expect(nested_group.users_with_descendants).to contain_exactly(user_a, user_b) + expect(deep_nested_group.users_with_descendants).to contain_exactly(user_a) + end + end + describe '#user_ids_for_project_authorizations' do it 'returns the user IDs for which to refresh authorizations' do expect(namespace.user_ids_for_project_authorizations) -- cgit v1.2.1 From 639639ef8a759c3956502a12df62c138022ee104 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Wed, 28 Jun 2017 15:58:26 -0300 Subject: Add tests for project import state transition: [:started] => [:finished] --- spec/models/project_spec.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index cc22b8a4edc..0d3494d9e58 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1509,6 +1509,40 @@ describe Project, models: true do end end + describe 'project import state transitions' do + context 'state transition: [:started] => [:finished]' do + let(:housekeeping_service) { spy } + + before do + allow(Projects::HousekeepingService).to receive(:new) { housekeeping_service } + end + + it 'performs housekeeping when an import of a fresh project is completed' do + project = create(:project_empty_repo, :import_started, import_type: :github) + + project.import_finish + + expect(housekeeping_service).to have_received(:execute) + end + + it 'does not perform housekeeping when project repository does not exist' do + project = create(:empty_project, :import_started, import_type: :github) + + project.import_finish + + expect(housekeeping_service).not_to have_received(:execute) + end + + it 'does not perform housekeeping when project does not have a valid import type' do + project = create(:empty_project, :import_started, import_type: nil) + + project.import_finish + + expect(housekeeping_service).not_to have_received(:execute) + end + end + end + describe '#latest_successful_builds_for' do def create_pipeline(status = 'success') create(:ci_pipeline, project: project, -- cgit v1.2.1 From 4d6ee98d861c98fe74340ae6263a866b6e36c9a1 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 27 Jun 2017 16:19:16 -0500 Subject: Drop default ORDER scope when calling a find method on a Sortable model --- spec/models/concerns/sortable_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 spec/models/concerns/sortable_spec.rb (limited to 'spec/models') diff --git a/spec/models/concerns/sortable_spec.rb b/spec/models/concerns/sortable_spec.rb new file mode 100644 index 00000000000..d1e17c4f684 --- /dev/null +++ b/spec/models/concerns/sortable_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe Sortable do + let(:relation) { Issue.all } + + describe '#where' do + it 'orders by id, descending' do + order_node = relation.where(iid: 1).order_values.first + expect(order_node).to be_a(Arel::Nodes::Descending) + expect(order_node.expr.name).to eq(:id) + end + end + + describe '#find_by' do + it 'does not order' do + expect(relation).to receive(:unscope).with(:order).and_call_original + + relation.find_by(iid: 1) + end + end +end -- cgit v1.2.1 From 7b77e2862ad1c294aeff5c0bf5f77ac3f0211801 Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Thu, 29 Jun 2017 07:56:48 +0100 Subject: Remove Namespace model default scope override and write additional test to Project search --- spec/models/project_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index ff4fe7f7e03..a807c3e6164 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1170,6 +1170,16 @@ describe Project, models: true do expect(relation.search(project.namespace.name)).to eq([project]) end + + describe 'with pending_delete project' do + let(:pending_delete_project) { create(:empty_project, pending_delete: true) } + + it 'shows pending deletion project' do + search_result = described_class.search(pending_delete_project.name) + + expect(search_result).to eq([pending_delete_project]) + end + end end describe '#rename_repo' do -- cgit v1.2.1 From 199425cee601733ef4f33ec5b76f5afe948cba61 Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Wed, 28 Jun 2017 16:05:02 +0100 Subject: Inserts exact matches of username, email and name to the top of the user search list --- spec/models/user_spec.rb | 57 +++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 25 deletions(-) (limited to 'spec/models') diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 8e895ec6634..448555d2190 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -754,42 +754,49 @@ describe User, models: true do end describe '.search' do - let(:user) { create(:user) } + let!(:user) { create(:user, name: 'user', username: 'usern', email: 'email@gmail.com') } + let!(:user2) { create(:user, name: 'user name', username: 'username', email: 'someemail@gmail.com') } - it 'returns users with a matching name' do - expect(described_class.search(user.name)).to eq([user]) - end + describe 'name matching' do + it 'returns users with a matching name with exact match first' do + expect(described_class.search(user.name)).to eq([user, user2]) + end - it 'returns users with a partially matching name' do - expect(described_class.search(user.name[0..2])).to eq([user]) - end + it 'returns users with a partially matching name' do + expect(described_class.search(user.name[0..2])).to eq([user2, user]) + end - it 'returns users with a matching name regardless of the casing' do - expect(described_class.search(user.name.upcase)).to eq([user]) + it 'returns users with a matching name regardless of the casing' do + expect(described_class.search(user2.name.upcase)).to eq([user2]) + end end - it 'returns users with a matching Email' do - expect(described_class.search(user.email)).to eq([user]) - end + describe 'email matching' do + it 'returns users with a matching Email' do + expect(described_class.search(user.email)).to eq([user, user2]) + end - it 'returns users with a partially matching Email' do - expect(described_class.search(user.email[0..2])).to eq([user]) - end + it 'returns users with a partially matching Email' do + expect(described_class.search(user.email[0..2])).to eq([user2, user]) + end - it 'returns users with a matching Email regardless of the casing' do - expect(described_class.search(user.email.upcase)).to eq([user]) + it 'returns users with a matching Email regardless of the casing' do + expect(described_class.search(user2.email.upcase)).to eq([user2]) + end end - it 'returns users with a matching username' do - expect(described_class.search(user.username)).to eq([user]) - end + describe 'username matching' do + it 'returns users with a matching username' do + expect(described_class.search(user.username)).to eq([user, user2]) + end - it 'returns users with a partially matching username' do - expect(described_class.search(user.username[0..2])).to eq([user]) - end + it 'returns users with a partially matching username' do + expect(described_class.search(user.username[0..2])).to eq([user2, user]) + end - it 'returns users with a matching username regardless of the casing' do - expect(described_class.search(user.username.upcase)).to eq([user]) + it 'returns users with a matching username regardless of the casing' do + expect(described_class.search(user2.username.upcase)).to eq([user2]) + end end end -- cgit v1.2.1 From af1f6844c98bfb4adda1c20dc75b808f031a4256 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 29 Jun 2017 15:37:37 +0200 Subject: Added code for defining SHA attributes These attributes are stored in binary in the database, but exposed as strings. This allows one to query/create data using plain SHA1 hashes as Strings, while storing them more efficiently as binary. --- spec/models/concerns/sha_attribute_spec.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 spec/models/concerns/sha_attribute_spec.rb (limited to 'spec/models') diff --git a/spec/models/concerns/sha_attribute_spec.rb b/spec/models/concerns/sha_attribute_spec.rb new file mode 100644 index 00000000000..9e37c2b20c4 --- /dev/null +++ b/spec/models/concerns/sha_attribute_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe ShaAttribute do + let(:model) { Class.new { include ShaAttribute } } + + before do + columns = [ + double(:column, name: 'name', type: :text), + double(:column, name: 'sha1', type: :binary) + ] + + allow(model).to receive(:columns).and_return(columns) + end + + describe '#sha_attribute' do + it 'defines a SHA attribute for a binary column' do + expect(model).to receive(:attribute) + .with(:sha1, an_instance_of(Gitlab::Database::ShaAttribute)) + + model.sha_attribute(:sha1) + end + + it 'raises ArgumentError when the column type is not :binary' do + expect { model.sha_attribute(:name) }.to raise_error(ArgumentError) + end + end +end -- cgit v1.2.1 From a3d7983b18cc81607c255f64b678da0ab7b9477d Mon Sep 17 00:00:00 2001 From: Adam Niedzielski Date: Thu, 29 Jun 2017 16:14:12 +0200 Subject: Revert "Merge branch 'dm-drop-default-scope-on-sortable-finders' into 'master'" This reverts commit b07c00032b038f40796a28e34b6dd4c622bad012, reversing changes made to 2b97d76d0b08a778710410df910a7601f6b8e9e7. --- spec/models/concerns/sortable_spec.rb | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 spec/models/concerns/sortable_spec.rb (limited to 'spec/models') diff --git a/spec/models/concerns/sortable_spec.rb b/spec/models/concerns/sortable_spec.rb deleted file mode 100644 index d1e17c4f684..00000000000 --- a/spec/models/concerns/sortable_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'spec_helper' - -describe Sortable do - let(:relation) { Issue.all } - - describe '#where' do - it 'orders by id, descending' do - order_node = relation.where(iid: 1).order_values.first - expect(order_node).to be_a(Arel::Nodes::Descending) - expect(order_node.expr.name).to eq(:id) - end - end - - describe '#find_by' do - it 'does not order' do - expect(relation).to receive(:unscope).with(:order).and_call_original - - relation.find_by(iid: 1) - end - end -end -- cgit v1.2.1 From fa93156528bca4306e040a1b73720b6411942fcf Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 23 Jun 2017 17:02:33 -0700 Subject: Defer project destroys within a namespace in Groups::DestroyService#async_execute Group#destroy would actually hard-delete all associated projects even though the acts_as_paranoia gem is used, preventing Projects::DestroyService from doing any work. We first noticed this while trying to log all projects deletion to the Geo log. --- spec/models/namespace_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'spec/models') diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index d4f898f6d9f..62c4ea01ce1 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -342,6 +342,17 @@ describe Namespace, models: true do end end + describe '#soft_delete_without_removing_associations' do + let(:project1) { create(:project_empty_repo, namespace: namespace) } + + it 'updates the deleted_at timestamp but preserves projects' do + namespace.soft_delete_without_removing_associations + + expect(Project.all).to include(project1) + expect(namespace.deleted_at).not_to be_nil + end + end + describe '#user_ids_for_project_authorizations' do it 'returns the user IDs for which to refresh authorizations' do expect(namespace.user_ids_for_project_authorizations) -- cgit v1.2.1 From f4e6aba1bbeca043a29b4903cef2f5b99a1faac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Thu, 29 Jun 2017 15:22:40 -0400 Subject: Set the GL_REPOSITORY env variable on Gitlab::Git::Hook --- spec/models/repository_spec.rb | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'spec/models') diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 3e984ec7588..c69f0a495db 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -780,7 +780,7 @@ describe Repository, models: true do context 'when pre hooks were successful' do it 'runs without errors' do expect_any_instance_of(GitHooksService).to receive(:execute) - .with(user, project.repository.path_to_repo, old_rev, blank_sha, 'refs/heads/feature') + .with(user, project, old_rev, blank_sha, 'refs/heads/feature') expect { repository.rm_branch(user, 'feature') }.not_to raise_error end @@ -823,12 +823,7 @@ describe Repository, models: true do service = GitHooksService.new expect(GitHooksService).to receive(:new).and_return(service) expect(service).to receive(:execute) - .with( - user, - repository.path_to_repo, - old_rev, - new_rev, - 'refs/heads/feature') + .with(user, project, old_rev, new_rev, 'refs/heads/feature') .and_yield(service).and_return(true) end @@ -1474,9 +1469,9 @@ describe Repository, models: true do it 'passes commit SHA to pre-receive and update hooks,\ and tag SHA to post-receive hook' do - pre_receive_hook = Gitlab::Git::Hook.new('pre-receive', repository.path_to_repo) - update_hook = Gitlab::Git::Hook.new('update', repository.path_to_repo) - post_receive_hook = Gitlab::Git::Hook.new('post-receive', repository.path_to_repo) + pre_receive_hook = Gitlab::Git::Hook.new('pre-receive', project) + update_hook = Gitlab::Git::Hook.new('update', project) + post_receive_hook = Gitlab::Git::Hook.new('post-receive', project) allow(Gitlab::Git::Hook).to receive(:new) .and_return(pre_receive_hook, update_hook, post_receive_hook) -- cgit v1.2.1