2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'projects/edit' do
|
|
|
|
include Devise::Test::ControllerHelpers
|
2019-12-04 20:38:33 +05:30
|
|
|
include ProjectForksHelper
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:user) { create(:admin) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
assign(:project, project)
|
|
|
|
|
|
|
|
allow(controller).to receive(:current_user).and_return(user)
|
2018-03-17 18:26:18 +05:30
|
|
|
allow(view).to receive_messages(current_user: user,
|
|
|
|
can?: true,
|
|
|
|
current_application_settings: Gitlab::CurrentSettings.current_application_settings)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'project export disabled' do
|
|
|
|
it 'does not display the project export option' do
|
|
|
|
stub_application_setting(project_export_enabled?: false)
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
render
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
expect(rendered).not_to have_content('Export project')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
context 'merge suggestions settings' do
|
|
|
|
it 'displays all possible variables' do
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).to have_content('%{branch_name}')
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(rendered).to have_content('%{files_count}')
|
|
|
|
expect(rendered).to have_content('%{file_paths}')
|
|
|
|
expect(rendered).to have_content('%{project_name}')
|
|
|
|
expect(rendered).to have_content('%{project_path}')
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(rendered).to have_content('%{user_full_name}')
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(rendered).to have_content('%{username}')
|
|
|
|
expect(rendered).to have_content('%{suggestions_count}')
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'displays a placeholder if none is set' do
|
|
|
|
render
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(rendered).to have_field('project[suggestion_commit_message]', placeholder: "Apply %{suggestions_count} suggestion(s) to %{files_count} file(s)")
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'displays the user entered value' do
|
2020-06-23 00:09:42 +05:30
|
|
|
project.update!(suggestion_commit_message: 'refactor: changed %{file_paths}')
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
render
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(rendered).to have_field('project[suggestion_commit_message]', with: 'refactor: changed %{file_paths}')
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
context 'forking' do
|
|
|
|
before do
|
|
|
|
assign(:project, project)
|
|
|
|
|
|
|
|
allow(view).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'project is not a fork' do
|
|
|
|
it 'hides the remove fork relationship settings' do
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).not_to have_content('Remove fork relationship')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'project is a fork' do
|
|
|
|
let(:source_project) { create(:project) }
|
|
|
|
let(:project) { fork_project(source_project) }
|
|
|
|
|
|
|
|
it 'shows the remove fork relationship settings to an authorized user' do
|
|
|
|
allow(view).to receive(:can?).with(user, :remove_fork_project, project).and_return(true)
|
|
|
|
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).to have_content('Remove fork relationship')
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(rendered).to have_link(source_project.full_name, href: project_path(source_project))
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'hides the fork relationship settings from an unauthorized user' do
|
|
|
|
allow(view).to receive(:can?).with(user, :remove_fork_project, project).and_return(false)
|
|
|
|
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).not_to have_content('Remove fork relationship')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'hides the fork source from an unauthorized user' do
|
|
|
|
allow(view).to receive(:can?).with(user, :read_project, source_project).and_return(false)
|
|
|
|
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).to have_content('Remove fork relationship')
|
|
|
|
expect(rendered).not_to have_content(source_project.full_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows the fork source to an authorized user' do
|
|
|
|
allow(view).to receive(:can?).with(user, :read_project, source_project).and_return(true)
|
|
|
|
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).to have_content('Remove fork relationship')
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(rendered).to have_link(source_project.full_name, href: project_path(source_project))
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|