summaryrefslogtreecommitdiff
path: root/spec/frontend/fixtures/search.rb
blob: db1ef67998f8691fed321276bebbdffffdfbeb93 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe SearchController, '(JavaScript fixtures)', type: :controller do
  include JavaScriptFixturesHelpers

  render_views

  let_it_be(:user) { create(:user) }

  before do
    sign_in(user)
  end

  it 'search/show.html' do
    get :show

    expect(response).to be_successful
  end

  context 'search within a project' do
    let(:namespace) { create(:namespace, name: 'frontend-fixtures') }
    let(:project) { create(:project, :public, :repository, namespace: namespace, path: 'search-project') }
    let(:blobs) do
      Kaminari.paginate_array([
        Gitlab::Search::FoundBlob.new(
          path: 'CHANGELOG',
          basename: 'CHANGELOG',
          ref: 'master',
          data: "hello\nworld\nfoo\nSend # this is the highligh\nbaz\nboo\nbat",
          project: project,
          project_id: project.id,
          startline: 2),
        Gitlab::Search::FoundBlob.new(
          path: 'CONTRIBUTING',
          basename: 'CONTRIBUTING',
          ref: 'master',
          data: "hello\nworld\nfoo\nSend # this is the highligh\nbaz\nboo\nbat",
          project: project,
          project_id: project.id,
          startline: 2),
        Gitlab::Search::FoundBlob.new(
          path: 'README',
          basename: 'README',
          ref: 'master',
          data: "foo\nSend # this is the highlight\nbaz\nboo\nbat",
          project: project,
          project_id: project.id,
          startline: 2),
        Gitlab::Search::FoundBlob.new(
          path: 'test',
          basename: 'test',
          ref: 'master',
          data: "foo\nSend # this is the highlight\nbaz\nboo\nbat",
          project: project,
          project_id: project.id,
          startline: 2)
     ],
     total_count: 4,
     limit: 4,
     offset: 0)
    end

    before do
      project.add_developer(user)
    end

    it 'search/blob_search_result.html' do
      allow_next_instance_of(SearchServicePresenter) do |search_service|
        allow(search_service).to receive(:search_objects).and_return(blobs)
      end

      get :show, params: {
        search: 'Send',
        project_id: project.id,
        scope: :blobs
      }

      expect(response).to be_successful
    end
  end
end