user_create_spec.rb 2.46 KB
Newer Older
1 2 3 4
require 'spec_helper'

feature 'New blob creation', feature: true, js: true do
  include WaitForAjax
5
  include TargetBranchHelpers
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

  given(:user) { create(:user) }
  given(:role) { :developer }
  given(:project) { create(:project) }
  given(:content) { 'class NextFeature\nend\n' }

  background do
    login_as(user)
    project.team << [user, role]
    visit namespace_project_new_blob_path(project.namespace, project, 'master')
  end

  def edit_file
    wait_for_ajax
    fill_in 'file_name', with: 'feature.rb'
    execute_script("ace.edit('editor').setValue('#{content}')")
  end

  def commit_file
25
    click_button 'Commit changes'
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
  end

  context 'with default target branch' do
    background do
      edit_file
      commit_file
    end

    scenario 'creates the blob in the default branch' do
      expect(page).to have_content 'master'
      expect(page).to have_content 'successfully created'
      expect(page).to have_content 'NextFeature'
    end
  end

  context 'with different target branch' do
    background do
      edit_file
44
      select_branch('feature')
45 46 47 48
      commit_file
    end

    scenario 'creates the blob in the different branch' do
49
      expect(page).to have_content 'feature'
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 87 88 89 90
      expect(page).to have_content 'successfully created'
    end
  end

  context 'with a new target branch' do
    given(:new_branch_name) { 'new-feature' }

    background do
      edit_file
      create_new_branch(new_branch_name)
      commit_file
    end

    scenario 'creates the blob in the new branch' do
      expect(page).to have_content new_branch_name
      expect(page).to have_content 'successfully created'
    end
    scenario 'returns you to the mr' do
      expect(page).to have_content 'New Merge Request'
      expect(page).to have_content "From #{new_branch_name} into master"
      expect(page).to have_content 'Add new file'
    end
  end

  context 'the file already exist in the source branch' do
    background do
      Files::CreateService.new(
        project,
        user,
        start_branch: 'master',
        target_branch: 'master',
        commit_message: 'Create file',
        file_path: 'feature.rb',
        file_content: content
      ).execute
      edit_file
      commit_file
    end

    scenario 'shows error message' do
      expect(page).to have_content('Your changes could not be committed because a file with the same name already exists')
91
      expect(page).to have_content('New file')
92 93 94 95
      expect(page).to have_content('NextFeature')
    end
  end
end