Skip to content
Snippets Groups Projects
Verified Commit ffbbccb7 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Fix search autocomplete

parent 073a2698
No related branches found
No related tags found
No related merge requests found
Loading
@@ -13,52 +13,41 @@ describe SearchHelper do
Loading
@@ -13,52 +13,41 @@ describe SearchHelper do
end end
   
it "it returns nil" do it "it returns nil" do
search_autocomplete_source.should be_nil search_autocomplete_opts("q").should be_nil
end end
end end
   
context "with a user" do context "with a user" do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:result) { JSON.parse(search_autocomplete_source) }
   
before do before do
allow(self).to receive(:current_user).and_return(user) allow(self).to receive(:current_user).and_return(user)
end end
   
it "includes Help sections" do it "includes Help sections" do
result.select { |h| h['label'] =~ /^help:/ }.length.should == 9 search_autocomplete_opts("hel").size.should == 9
end end
   
it "includes default sections" do it "includes default sections" do
result.count { |h| h['label'] =~ /^(My|Admin)\s/ }.should == 4 search_autocomplete_opts("adm").size.should == 1
end end
   
it "includes the user's groups" do it "includes the user's groups" do
create(:group).add_owner(user) create(:group).add_owner(user)
result.count { |h| h['label'] =~ /^group:/ }.should == 1 search_autocomplete_opts("gro").size.should == 1
end end
   
it "includes the user's projects" do it "includes the user's projects" do
create(:project, namespace: create(:namespace, owner: user)) project = create(:project, namespace: create(:namespace, owner: user))
result.count { |h| h['label'] =~ /^project:/ }.should == 1 search_autocomplete_opts(project.name).size.should == 1
end end
   
context "with a current project" do context "with a current project" do
before { @project = create(:project_with_code) } before { @project = create(:project_with_code) }
   
it "includes project-specific sections" do it "includes project-specific sections" do
result.count { |h| h['label'] =~ /^#{@project.name_with_namespace} - / }.should == 11 search_autocomplete_opts("Files").size.should == 1
end search_autocomplete_opts("Commits").size.should == 1
it "uses @ref in urls if defined" do
@ref = "foo_bar"
result.count { |h| h['url'] == project_tree_path(@project, @ref) }.should == 1
end
end
context "with no current project" do
it "does not include project-specific sections" do
result.count { |h| h['label'] =~ /Files$/ }.should == 0
end end
end end
end end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment