summaryrefslogtreecommitdiff
path: root/spec/features/projects/branches/user_creates_branch_spec.rb
blob: 156edb973cd5b5697d2e426874b696cd8b5ac834 (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
# frozen_string_literal: true

require "spec_helper"

describe "User creates branch", :js do
  include Spec::Support::Helpers::Features::BranchesHelpers

  let(:user) { create(:user) }
  let(:project) { create(:project, :repository) }

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

    visit(new_project_branch_path(project))
  end

  it "creates new branch" do
    BRANCH_NAME = "deploy_keys".freeze

    create_branch(BRANCH_NAME)

    expect(page).to have_content(BRANCH_NAME)
  end

  context "when branch name is invalid" do
    it "does not create new branch" do
      INVALID_BRANCH_NAME = "1.0 stable".freeze

      fill_in("branch_name", with: INVALID_BRANCH_NAME)
      page.find("body").click # defocus the branch_name input

      select_branch("master")
      click_button("Create branch")

      expect(page).to have_content("Branch name is invalid")
      expect(page).to have_content("can't contain spaces")
    end
  end

  context "when branch name already exists" do
    it "does not create new branch" do
      create_branch("master")

      expect(page).to have_content("Branch already exists")
    end
  end
end