2013-10-20 01:05:20 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe SearchHelper do
|
|
|
|
# Override simple_sanitize for our testing purposes
|
|
|
|
def simple_sanitize(str)
|
|
|
|
str
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'search_autocomplete_source' do
|
|
|
|
context "with no current user" do
|
2013-12-14 08:43:48 -05:00
|
|
|
before do
|
|
|
|
allow(self).to receive(:current_user).and_return(nil)
|
|
|
|
end
|
2013-10-20 01:05:20 -04:00
|
|
|
|
|
|
|
it "it returns nil" do
|
2014-01-18 08:02:53 -05:00
|
|
|
search_autocomplete_opts("q").should be_nil
|
2013-10-20 01:05:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a user" do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2013-12-14 08:43:48 -05:00
|
|
|
allow(self).to receive(:current_user).and_return(user)
|
2013-10-20 01:05:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "includes Help sections" do
|
2014-01-18 08:02:53 -05:00
|
|
|
search_autocomplete_opts("hel").size.should == 9
|
2013-10-20 01:05:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "includes default sections" do
|
2014-01-18 08:02:53 -05:00
|
|
|
search_autocomplete_opts("adm").size.should == 1
|
2013-10-20 01:05:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "includes the user's groups" do
|
|
|
|
create(:group).add_owner(user)
|
2014-01-18 08:02:53 -05:00
|
|
|
search_autocomplete_opts("gro").size.should == 1
|
2013-10-20 01:05:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "includes the user's projects" do
|
2014-01-18 08:02:53 -05:00
|
|
|
project = create(:project, namespace: create(:namespace, owner: user))
|
|
|
|
search_autocomplete_opts(project.name).size.should == 1
|
2013-10-20 01:05:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with a current project" do
|
2014-01-22 14:03:52 -05:00
|
|
|
before { @project = create(:project) }
|
2013-10-20 01:05:20 -04:00
|
|
|
|
|
|
|
it "includes project-specific sections" do
|
2014-01-18 08:02:53 -05:00
|
|
|
search_autocomplete_opts("Files").size.should == 1
|
|
|
|
search_autocomplete_opts("Commits").size.should == 1
|
2013-10-20 01:05:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|