summaryrefslogtreecommitdiff
path: root/spec/controllers/jira_connect/branches_controller_spec.rb
blob: 45daf3b5309c2e52236090275d048d9f767dcf10 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe JiraConnect::BranchesController do
  describe '#new' do
    context 'when logged in' do
      let_it_be(:user) { create(:user) }

      before do
        sign_in(user)
      end

      it 'assigns the suggested branch name' do
        get :new, params: { issue_key: 'ACME-123', issue_summary: 'My Issue !@#$%' }

        expect(response).to be_successful
        expect(assigns(:new_branch_data)).to include(
          initial_branch_name: 'ACME-123-my-issue',
          success_state_svg_path: start_with('/assets/illustrations/merge_requests-')
        )
      end

      it 'ignores missing summary' do
        get :new, params: { issue_key: 'ACME-123' }

        expect(response).to be_successful
        expect(assigns(:new_branch_data)).to include(initial_branch_name: 'ACME-123')
      end

      it 'does not set a branch name if key is not passed' do
        get :new, params: { issue_summary: 'My issue' }

        expect(response).to be_successful
        expect(assigns(:new_branch_data)).to include('initial_branch_name': nil)
      end
    end

    context 'when not logged in' do
      it 'redirects to the login page' do
        get :new

        expect(response).to redirect_to(new_user_session_path)
      end
    end
  end
end