summaryrefslogtreecommitdiff
path: root/spec/features/projects/services/user_activates_bugzilla_spec.rb
blob: e49bd469aebdc1201f72f0d3e81025a4be8b696e (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
84
85
86
require 'spec_helper'

describe 'User activates Bugzilla', :js do
  let(:user) { create(:user) }
  let(:project) { create(:project) }

  let(:url) { 'http://bugzilla.example.com' }

  def fill_form(active = true)
    check 'Active' if active

    fill_in 'service_project_url', with: url
    fill_in 'service_issues_url', with: "#{url}/:id"
    fill_in 'service_new_issue_url', with: url
  end

  before do
    project.add_master(user)
    sign_in(user)

    visit project_settings_integrations_path(project)
  end

  describe 'user sets and activates Bugzilla Service' do
    context 'when Bugzilla connection test succeeds' do
      before do
        stub_request(:head, url).to_return(headers: { 'Content-Type' => 'application/json' })

        click_link('Bugzilla')
        fill_form
        click_button('Test settings and save changes')
        wait_for_requests
      end

      it 'activates the Bugzilla service' do
        expect(page).to have_content('Bugzilla activated.')
        expect(current_path).to eq(project_settings_integrations_path(project))
      end

      it 'shows the Bugzilla link in the menu' do
        page.within('.nav-sidebar') do
          expect(page).to have_link('Bugzilla', href: url)
        end
      end
    end

    context 'when Bugzilla connection test fails' do
      it 'activates the Bugzilla service' do
        stub_request(:head, url).to_raise(HTTParty::Error)

        click_link('Bugzilla')
        fill_form
        click_button('Test settings and save changes')
        wait_for_requests

        expect(find('.flash-container-page')).to have_content 'Test failed.'
        expect(find('.flash-container-page')).to have_content 'Save anyway'

        find('.flash-alert .flash-action').click
        wait_for_requests

        expect(page).to have_content('Bugzilla activated.')
        expect(current_path).to eq(project_settings_integrations_path(project))
      end
    end
  end

  describe 'user sets Bugzilla Service but keeps it disabled' do
    before do
      click_link('Bugzilla')
      fill_form(false)
      click_button('Save changes')
    end

    it 'saves but does not activate the Bugzilla service' do
      expect(page).to have_content('Bugzilla settings saved, but not activated.')
      expect(current_path).to eq(project_settings_integrations_path(project))
    end

    it 'does not show the Bugzilla link in the menu' do
      page.within('.nav-sidebar') do
        expect(page).not_to have_link('Bugzilla', href: url)
      end
    end
  end
end