diff options
author | Robert Speicher <rspeicher@gmail.com> | 2013-10-20 01:05:20 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2013-10-20 01:05:20 -0400 |
commit | cb9cf077de8bf315842a7f357b65ec7e5b5ce0de (patch) | |
tree | 8a99800ab820e46a3d8084e773e8770022dd1b7a /spec/helpers | |
parent | bb494203d263104e9f2ac13d18c438798f7a99f8 (diff) | |
download | gitlab-ce-cb9cf077de8bf315842a7f357b65ec7e5b5ce0de.tar.gz |
Refactor and cover search_autocomplete_source
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/search_helper_spec.rb | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb new file mode 100644 index 00000000000..55b6b6b4dad --- /dev/null +++ b/spec/helpers/search_helper_spec.rb @@ -0,0 +1,64 @@ +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 + before { stub!(:current_user).and_return(nil) } + + it "it returns nil" do + search_autocomplete_source.should be_nil + end + end + + context "with a user" do + let(:user) { create(:user) } + let(:result) { JSON.parse(search_autocomplete_source) } + + before do + stub!(:current_user).and_return(user) + end + + it "includes Help sections" do + result.select { |h| h['label'] =~ /^help:/ }.length.should == 9 + end + + it "includes default sections" do + result.count { |h| h['label'] =~ /^(My|Admin)\s/ }.should == 4 + end + + it "includes the user's groups" do + create(:group).add_owner(user) + result.count { |h| h['label'] =~ /^group:/ }.should == 1 + end + + it "includes the user's projects" do + create(:project, namespace: create(:namespace, owner: user)) + result.count { |h| h['label'] =~ /^project:/ }.should == 1 + end + + context "with a current project" do + before { @project = create(:project_with_code) } + + it "includes project-specific sections" do + result.count { |h| h['label'] =~ /^#{@project.name_with_namespace} - / }.should == 11 + end + + 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 |