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 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 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 From 2446252cfd1f5a7d7329099e8d6371fcffa99971 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Thu, 29 Jun 2017 18:53:32 -0300 Subject: Expires full_path cache after project is renamed --- spec/models/concerns/routable_spec.rb | 12 ++++++++++++ spec/models/project_spec.rb | 2 ++ 2 files changed, 14 insertions(+) (limited to 'spec/models') diff --git a/spec/models/concerns/routable_spec.rb b/spec/models/concerns/routable_spec.rb index 65f05121b40..be82a601b36 100644 --- a/spec/models/concerns/routable_spec.rb +++ b/spec/models/concerns/routable_spec.rb @@ -132,6 +132,18 @@ describe Group, 'Routable' do end end + describe '#expires_full_path_cache' do + context 'with RequestStore active', :request_store do + it 'expires the full_path cache' do + expect(group).to receive(:uncached_full_path).twice.and_call_original + + 3.times { group.full_path } + group.expires_full_path_cache + 3.times { group.full_path } + end + end + end + describe '#full_name' do let(:group) { create(:group) } let(:nested_group) { create(:group, parent: group) } diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 1390848ff4a..6ff4ec3d417 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1216,6 +1216,8 @@ describe Project, models: true do expect(project).to receive(:expire_caches_before_rename) + expect(project).to receive(:expires_full_path_cache) + project.rename_repo end -- cgit v1.2.1 From 9da3076944146444cb864d5db066a766c76b1935 Mon Sep 17 00:00:00 2001 From: Adam Niedzielski Date: Fri, 30 Jun 2017 14:47:53 +0200 Subject: Improve support for external issue references --- spec/models/project_services/jira_service_spec.rb | 6 +++--- spec/models/project_services/redmine_service_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/models') diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index c86f56c55eb..4a1de76f099 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -64,12 +64,12 @@ describe JiraService, models: true do end end - describe '#reference_pattern' do + describe '.reference_pattern' do it_behaves_like 'allows project key on reference pattern' it 'does not allow # on the code' do - expect(subject.reference_pattern.match('#123')).to be_nil - expect(subject.reference_pattern.match('1#23#12')).to be_nil + expect(described_class.reference_pattern.match('#123')).to be_nil + expect(described_class.reference_pattern.match('1#23#12')).to be_nil end end diff --git a/spec/models/project_services/redmine_service_spec.rb b/spec/models/project_services/redmine_service_spec.rb index 6631d9040b1..441b3f896ca 100644 --- a/spec/models/project_services/redmine_service_spec.rb +++ b/spec/models/project_services/redmine_service_spec.rb @@ -31,11 +31,11 @@ describe RedmineService, models: true do end end - describe '#reference_pattern' do + describe '.reference_pattern' do it_behaves_like 'allows project key on reference pattern' it 'does allow # on the reference' do - expect(subject.reference_pattern.match('#123')[:issue]).to eq('123') + expect(described_class.reference_pattern.match('#123')[:issue]).to eq('123') end end end -- cgit v1.2.1 From ea9dd29a76477e73104764d2e7f937bb2ccce8c0 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 3 Jul 2017 12:38:01 -0300 Subject: Reset @full_path to nil when cache expires --- spec/models/concerns/routable_spec.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'spec/models') diff --git a/spec/models/concerns/routable_spec.rb b/spec/models/concerns/routable_spec.rb index be82a601b36..36aedd2f701 100644 --- a/spec/models/concerns/routable_spec.rb +++ b/spec/models/concerns/routable_spec.rb @@ -135,11 +135,12 @@ describe Group, 'Routable' do describe '#expires_full_path_cache' do context 'with RequestStore active', :request_store do it 'expires the full_path cache' do - expect(group).to receive(:uncached_full_path).twice.and_call_original + expect(group.full_path).to eq('foo') - 3.times { group.full_path } + group.route.update(path: 'bar', name: 'bar') group.expires_full_path_cache - 3.times { group.full_path } + + expect(group.full_path).to eq('bar') end end end -- cgit v1.2.1