creating_a_file_spec.rb 1.29 KB
Newer Older
winniehell's avatar
winniehell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
require 'spec_helper'

feature 'User wants to create a file', feature: true do
  include WaitForAjax

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

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

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

    file_content = find('#file-content')
    file_content.set options[:file_content] || 'Some content'

22
    click_button 'Commit changes'
winniehell's avatar
winniehell committed
23 24 25 26 27 28 29 30 31
  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')
32
    expect(page).to have_content 'The file has been successfully created'
winniehell's avatar
winniehell committed
33 34 35 36
  end

  scenario 'file name contains invalid characters' do
    submit_new_file(file_name: '\\')
37
    expect(page).to have_content 'Path can contain only'
winniehell's avatar
winniehell committed
38 39 40 41
  end

  scenario 'file name contains directory traversal' do
    submit_new_file(file_name: '../README.md')
42
    expect(page).to have_content 'Path cannot include directory traversal'
winniehell's avatar
winniehell committed
43 44
  end
end