BigW Consortium Gitlab

project_owner_creates_license_file_spec.rb 2.52 KB
Newer Older
1 2
require 'spec_helper'

Rémy Coutable committed
3
feature 'project owner creates a license file', feature: true, js: true do
4 5 6
  let(:project_master) { create(:user) }
  let(:project) { create(:project) }
  background do
7
    project.repository.delete_file(project_master, 'LICENSE',
8
      message: 'Remove LICENSE', branch_name: 'master')
9 10 11 12 13 14 15 16 17 18 19 20 21 22
    project.team << [project_master, :master]
    login_as(project_master)
    visit namespace_project_path(project.namespace, project)
  end

  scenario 'project master creates a license file manually from a template' do
    visit namespace_project_tree_path(project.namespace, project, project.repository.root_ref)
    find('.add-to-tree').click
    click_link 'New file'

    fill_in :file_name, with: 'LICENSE'

    expect(page).to have_selector('.license-selector')

23
    select_template('MIT License')
24

Phil Hughes committed
25
    file_content = first('.file-editor')
26
    expect(file_content).to have_content('MIT License')
27
    expect(file_content).to have_content("Copyright (c) #{Time.now.year} #{project.namespace.human_name}")
28 29

    fill_in :commit_message, with: 'Add a LICENSE file', visible: true
30
    click_button 'Commit changes'
31 32 33

    expect(current_path).to eq(
      namespace_project_blob_path(project.namespace, project, 'master/LICENSE'))
34
    expect(page).to have_content('MIT License')
35
    expect(page).to have_content("Copyright (c) #{Time.now.year} #{project.namespace.human_name}")
36 37 38 39 40
  end

  scenario 'project master creates a license file from the "Add license" link' do
    click_link 'Add License'

41
    expect(page).to have_content('New file')
42 43 44 45 46
    expect(current_path).to eq(
      namespace_project_new_blob_path(project.namespace, project, 'master'))
    expect(find('#file_name').value).to eq('LICENSE')
    expect(page).to have_selector('.license-selector')

47
    select_template('MIT License')
48

Phil Hughes committed
49
    file_content = first('.file-editor')
50
    expect(file_content).to have_content('MIT License')
51
    expect(file_content).to have_content("Copyright (c) #{Time.now.year} #{project.namespace.human_name}")
52 53

    fill_in :commit_message, with: 'Add a LICENSE file', visible: true
Jose Ivan Vargas committed
54
    click_button 'Commit changes'
55 56 57

    expect(current_path).to eq(
      namespace_project_blob_path(project.namespace, project, 'master/LICENSE'))
58
    expect(page).to have_content('MIT License')
59
    expect(page).to have_content("Copyright (c) #{Time.now.year} #{project.namespace.human_name}")
60
  end
61 62 63

  def select_template(template)
    page.within('.js-license-selector-wrap') do
64
      click_button 'Apply a license template'
65 66 67 68
      click_link template
      wait_for_ajax
    end
  end
69
end