diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-06-08 17:03:51 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-06-10 15:33:05 +0200 |
commit | 24920bc52a5658dd1d16d38ba3dc46f92dfe7675 (patch) | |
tree | e1bb3003b7df81dec147e831334011e5f41cd1c2 /spec | |
parent | cea3cf177c68bb1fa9326d4e88631b7737ae8a98 (diff) | |
download | gitlab-ce-24920bc52a5658dd1d16d38ba3dc46f92dfe7675.tar.gz |
Add Project.where_paths_infinding-multiple-projects-by-paths
This method can be used to find multiple projects for multiple paths.
For example, take this snippet:
Project.where_paths_in(%w{gitlab-org/gitlab-ce gitlab-org/gitlab-ee})
This will return an ActiveRecord::Relation containing the GitLab CE and
GitLab EE projects.
This method takes care of matching rows both case-sensitively and
case-insensitively where needed.
Project.find_with_namespace in turn has been modified to use
Project.where_paths_in without nuking any scoping (instead it uses
reorder(nil)). This means that any default scopes (e.g. those used for
"pending_delete" stay intact).
The method Project.where_paths_in was added so the various Markdown
filters can use a single query to grab all the projects referenced in a
set of documents, something Project.find_with_namespace didn't allow.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/project_spec.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 553556ed326..f687e3171a7 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -859,4 +859,37 @@ describe Project, models: true do it { is_expected.to be_falsey } end end + + describe '.where_paths_in' do + context 'without any paths' do + it 'returns an empty relation' do + expect(Project.where_paths_in([])).to eq([]) + end + end + + context 'without any valid paths' do + it 'returns an empty relation' do + expect(Project.where_paths_in(%w[foo])).to eq([]) + end + end + + context 'with valid paths' do + let!(:project1) { create(:project) } + let!(:project2) { create(:project) } + + it 'returns the projects matching the paths' do + projects = Project.where_paths_in([project1.path_with_namespace, + project2.path_with_namespace]) + + expect(projects).to contain_exactly(project1, project2) + end + + it 'returns projects regardless of the casing of paths' do + projects = Project.where_paths_in([project1.path_with_namespace.upcase, + project2.path_with_namespace.upcase]) + + expect(projects).to contain_exactly(project1, project2) + end + end + end end |