summaryrefslogtreecommitdiff
path: root/spec/features/projects/files/project_owner_sees_link_to_create_license_file_in_empty_project_spec.rb
blob: 6c616bf045603db15cfadf8c9d63a565461a3876 (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
require 'spec_helper'

feature 'project owner sees a link to create a license file in empty project', :js do
  let(:project_master) { create(:user) }
  let(:project) { create(:project) }
  background do
    project.team << [project_master, :master]
    sign_in(project_master)
  end

  scenario 'project master creates a license file from a template' do
    visit project_path(project)
    click_link 'Create empty bare repository'
    click_on 'LICENSE'
    expect(page).to have_content('New file')

    expect(current_path).to eq(
      project_new_blob_path(project, 'master'))
    expect(find('#file_name').value).to eq('LICENSE')
    expect(page).to have_selector('.license-selector')

    select_template('MIT License')

    file_content = first('.file-editor')
    expect(file_content).to have_content('MIT License')
    expect(file_content).to have_content("Copyright (c) #{Time.now.year} #{project.namespace.human_name}")

    fill_in :commit_message, with: 'Add a LICENSE file', visible: true
    # Remove pre-receive hook so we can push without auth
    FileUtils.rm_f(File.join(project.repository.path, 'hooks', 'pre-receive'))
    click_button 'Commit changes'

    expect(current_path).to eq(
      project_blob_path(project, 'master/LICENSE'))
    expect(page).to have_content('MIT License')
    expect(page).to have_content("Copyright (c) #{Time.now.year} #{project.namespace.human_name}")
  end

  def select_template(template)
    page.within('.js-license-selector-wrap') do
      click_button 'Apply a license template'
      click_link template
      wait_for_requests
    end
  end
end