BigW Consortium Gitlab

creating_a_file_spec.rb 1.1 KB
Newer Older
1 2
require 'spec_helper'

3
feature 'User wants to create a file' do
4
  let(:project) { create(:project, :repository) }
5 6 7 8
  let(:user) { create(:user) }

  background do
    project.team << [user, :master]
9
    sign_in user
10
    visit project_new_blob_path(project, project.default_branch)
11 12 13 14 15 16
  end

  def submit_new_file(options)
    file_name = find('#file_name')
    file_name.set options[:file_name] || 'README.md'

17
    file_content = find('#file-content', visible: false)
18 19
    file_content.set options[:file_content] || 'Some content'

20
    click_button 'Commit changes'
21 22 23 24 25 26 27 28 29
  end

  scenario 'file name contains Chinese characters' do
    submit_new_file(file_name: '测试.md')
    expect(page).to have_content 'The file has been successfully created.'
  end

  scenario 'directory name contains Chinese characters' do
    submit_new_file(file_name: '中文/测试.md')
30
    expect(page).to have_content 'The file has been successfully created'
31 32 33 34
  end

  scenario 'file name contains directory traversal' do
    submit_new_file(file_name: '../README.md')
35
    expect(page).to have_content 'Path cannot include directory traversal'
36 37
  end
end