BigW Consortium Gitlab

search_helper_spec.rb 1.59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
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
skv committed
11 12 13
      before do
        allow(self).to receive(:current_user).and_return(nil)
      end
14 15

      it "it returns nil" do
16
        expect(search_autocomplete_opts("q")).to be_nil
17 18 19 20 21 22 23
      end
    end

    context "with a user" do
      let(:user)   { create(:user) }

      before do
skv committed
24
        allow(self).to receive(:current_user).and_return(user)
25 26 27
      end

      it "includes Help sections" do
28
        expect(search_autocomplete_opts("hel").size).to eq(9)
29 30 31
      end

      it "includes default sections" do
32
        expect(search_autocomplete_opts("adm").size).to eq(1)
33 34 35 36
      end

      it "includes the user's groups" do
        create(:group).add_owner(user)
37
        expect(search_autocomplete_opts("gro").size).to eq(1)
38 39 40
      end

      it "includes the user's projects" do
41
        project = create(:project, namespace: create(:namespace, owner: user))
42
        expect(search_autocomplete_opts(project.name).size).to eq(1)
43 44
      end

Dmitriy Zaporozhets committed
45
      it "should not include the public group" do
46
        group = create(:group)
Dmitriy Zaporozhets committed
47
        expect(search_autocomplete_opts(group.name).size).to eq(0)
48 49
      end

50
      context "with a current project" do
51
        before { @project = create(:project) }
52 53

        it "includes project-specific sections" do
54 55
          expect(search_autocomplete_opts("Files").size).to eq(1)
          expect(search_autocomplete_opts("Commits").size).to eq(1)
56 57 58 59 60
        end
      end
    end
  end
end