Commit ffbbccb7ea3e3c667b4cfdeaeeedfbef0a5f190a
1 parent
073a2698
Exists in
spb-stable
and in
3 other branches
Fix search autocomplete
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
1 changed file
with
8 additions
and
19 deletions
Show diff stats
spec/helpers/search_helper_spec.rb
@@ -13,52 +13,41 @@ describe SearchHelper do | @@ -13,52 +13,41 @@ describe SearchHelper do | ||
13 | end | 13 | end |
14 | 14 | ||
15 | it "it returns nil" do | 15 | it "it returns nil" do |
16 | - search_autocomplete_source.should be_nil | 16 | + search_autocomplete_opts("q").should be_nil |
17 | end | 17 | end |
18 | end | 18 | end |
19 | 19 | ||
20 | context "with a user" do | 20 | context "with a user" do |
21 | let(:user) { create(:user) } | 21 | let(:user) { create(:user) } |
22 | - let(:result) { JSON.parse(search_autocomplete_source) } | ||
23 | 22 | ||
24 | before do | 23 | before do |
25 | allow(self).to receive(:current_user).and_return(user) | 24 | allow(self).to receive(:current_user).and_return(user) |
26 | end | 25 | end |
27 | 26 | ||
28 | it "includes Help sections" do | 27 | it "includes Help sections" do |
29 | - result.select { |h| h['label'] =~ /^help:/ }.length.should == 9 | 28 | + search_autocomplete_opts("hel").size.should == 9 |
30 | end | 29 | end |
31 | 30 | ||
32 | it "includes default sections" do | 31 | it "includes default sections" do |
33 | - result.count { |h| h['label'] =~ /^(My|Admin)\s/ }.should == 4 | 32 | + search_autocomplete_opts("adm").size.should == 1 |
34 | end | 33 | end |
35 | 34 | ||
36 | it "includes the user's groups" do | 35 | it "includes the user's groups" do |
37 | create(:group).add_owner(user) | 36 | create(:group).add_owner(user) |
38 | - result.count { |h| h['label'] =~ /^group:/ }.should == 1 | 37 | + search_autocomplete_opts("gro").size.should == 1 |
39 | end | 38 | end |
40 | 39 | ||
41 | it "includes the user's projects" do | 40 | it "includes the user's projects" do |
42 | - create(:project, namespace: create(:namespace, owner: user)) | ||
43 | - result.count { |h| h['label'] =~ /^project:/ }.should == 1 | 41 | + project = create(:project, namespace: create(:namespace, owner: user)) |
42 | + search_autocomplete_opts(project.name).size.should == 1 | ||
44 | end | 43 | end |
45 | 44 | ||
46 | context "with a current project" do | 45 | context "with a current project" do |
47 | before { @project = create(:project_with_code) } | 46 | before { @project = create(:project_with_code) } |
48 | 47 | ||
49 | it "includes project-specific sections" do | 48 | it "includes project-specific sections" do |
50 | - result.count { |h| h['label'] =~ /^#{@project.name_with_namespace} - / }.should == 11 | ||
51 | - end | ||
52 | - | ||
53 | - it "uses @ref in urls if defined" do | ||
54 | - @ref = "foo_bar" | ||
55 | - result.count { |h| h['url'] == project_tree_path(@project, @ref) }.should == 1 | ||
56 | - end | ||
57 | - end | ||
58 | - | ||
59 | - context "with no current project" do | ||
60 | - it "does not include project-specific sections" do | ||
61 | - result.count { |h| h['label'] =~ /Files$/ }.should == 0 | 49 | + search_autocomplete_opts("Files").size.should == 1 |
50 | + search_autocomplete_opts("Commits").size.should == 1 | ||
62 | end | 51 | end |
63 | end | 52 | end |
64 | end | 53 | end |