Welcome to mirror list, hosted at ThFree Co, Russian Federation.

search_helper_spec.rb « helpers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 55b6b6b4dad56cef85b0571c19464e3dd196e545 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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