user_searches_for_code_spec.rb 1.64 KB
Newer Older
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
require 'spec_helper'

describe 'User searches for code' do
  let(:user) { create(:user) }
  let(:project) { create(:project, :repository, namespace: user.namespace) }

  context 'when signed in' do
    before do
      project.add_master(user)
      sign_in(user)
    end

    it 'finds a file' do
      visit(project_path(project))

      page.within('.search') do
        fill_in('search', with: 'application.js')
        click_button('Go')
      end

      click_link('Code')

      expect(page).to have_selector('.file-content .code')
      expect(page).to have_selector("span.line[lang='javascript']")
    end

    context 'when on a project page', :js do
      before do
        visit(search_path)
      end

      include_examples 'top right search form'

      it 'finds code' do
        find('.js-search-project-dropdown').trigger('click')

        page.within('.project-filter') do
          click_link(project.name_with_namespace)
        end

        fill_in('dashboard_search', with: 'rspec')
        find('.btn-search').trigger('click')

        page.within('.results') do
          expect(find(:css, '.search-results')).to have_content('Update capybara, rspec-rails, poltergeist to recent versions')
        end
      end
    end
  end

  context 'when signed out' do
    let(:project) { create(:project, :public, :repository) }

    before do
      visit(project_path(project))
    end

    it 'finds code' do
      fill_in('search', with: 'rspec')
      click_button('Go')

      page.within('.results') do
        expect(find(:css, '.search-results')).to have_content('Update capybara, rspec-rails, poltergeist to recent versions')
      end
    end
  end
end