diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-01-09 14:23:07 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-01-09 14:23:07 +0200 |
commit | 768d21654a135130a28278c46cf413dbe65f8c81 (patch) | |
tree | 40eddc6791e2f377c1eaa51683d2396744137019 /spec | |
parent | fc60c391ae93e0a9ef9a5123ee7d71cd504e4366 (diff) | |
download | gitlab-ce-768d21654a135130a28278c46cf413dbe65f8c81.tar.gz |
Better search login for global context. Improved tests
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/contexts/search_context_spec.rb | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/spec/contexts/search_context_spec.rb b/spec/contexts/search_context_spec.rb index c25743e0032..38a6b55383a 100644 --- a/spec/contexts/search_context_spec.rb +++ b/spec/contexts/search_context_spec.rb @@ -1,43 +1,54 @@ require 'spec_helper' -describe SearchContext do +describe 'Search::GlobalContext' do let(:found_namespace) { create(:namespace, name: 'searchable namespace', path:'another_thing') } let(:user) { create(:user, namespace: found_namespace) } let!(:found_project) { create(:project, name: 'searchable_project', creator_id: user.id, namespace: found_namespace, visibility_level: Gitlab::VisibilityLevel::PRIVATE) } let(:unfound_namespace) { create(:namespace, name: 'unfound namespace', path: 'yet_something_else') } let!(:unfound_project) { create(:project, name: 'unfound_project', creator_id: user.id, namespace: unfound_namespace, visibility_level: Gitlab::VisibilityLevel::PRIVATE) } - + let(:internal_namespace) { create(:namespace, path: 'something_internal',name: 'searchable internal namespace') } let(:internal_user) { create(:user, namespace: internal_namespace) } let!(:internal_project) { create(:project, name: 'searchable_internal_project', creator_id: internal_user.id, namespace: internal_namespace, visibility_level: Gitlab::VisibilityLevel::INTERNAL) } - + let(:public_namespace) { create(:namespace, path: 'something_public',name: 'searchable public namespace') } let(:public_user) { create(:user, namespace: public_namespace) } let!(:public_project) { create(:project, name: 'searchable_public_project', creator_id: public_user.id, namespace: public_namespace, visibility_level: Gitlab::VisibilityLevel::PUBLIC) } describe '#execute' do - it 'public projects should be searchable' do - context = SearchContext.new([found_project.id], nil, {search_code: false, search: "searchable"}) - results = context.execute - results[:projects].should == [found_project, public_project] + context 'unauthenticated' do + it 'should return public projects only' do + context = Search::GlobalContext.new(nil, search: "searchable") + results = context.execute + results[:projects].should have(1).items + results[:projects].should include(public_project) + end end - it 'internal projects should be searchable' do - context = SearchContext.new([found_project.id], user, {search_code: false, search: "searchable"}) - results = context.execute - # can't seem to rely on the return order, so check this way - #subject { results[:projects] } - results[:projects].should have(3).items - results[:projects].should include(found_project) - results[:projects].should include(internal_project) - results[:projects].should include(public_project) - end + context 'authenticated' do + it 'should return public, internal and private projects' do + context = Search::GlobalContext.new(user, search: "searchable") + results = context.execute + results[:projects].should have(3).items + results[:projects].should include(public_project) + results[:projects].should include(found_project) + results[:projects].should include(internal_project) + end + + it 'should return only public & internal projects' do + context = Search::GlobalContext.new(internal_user, search: "searchable") + results = context.execute + results[:projects].should have(2).items + results[:projects].should include(internal_project) + results[:projects].should include(public_project) + end - it 'namespace name should be searchable' do - context = SearchContext.new([found_project.id], user, {search_code: false, search: "searchable namespace"}) - results = context.execute - results[:projects].should == [found_project] + it 'namespace name should be searchable' do + context = Search::GlobalContext.new(user, search: "searchable namespace") + results = context.execute + results[:projects].should == [found_project] + end end end end |