2015-04-27 02:42:29 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::CompareController do
|
2017-01-25 16:44:33 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
2015-04-27 02:42:29 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:ref_from) { "improve%2Fawesome" }
|
|
|
|
let(:ref_to) { "feature" }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
project.team << [user, :master]
|
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'compare shows some diffs' do
|
2015-06-23 01:24:39 -04:00
|
|
|
get(:show,
|
2017-02-23 18:55:01 -05:00
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
2015-06-23 01:24:39 -04:00
|
|
|
from: ref_from,
|
|
|
|
to: ref_to)
|
2015-04-27 02:42:29 -04:00
|
|
|
|
|
|
|
expect(response).to be_success
|
2016-07-20 12:25:36 -04:00
|
|
|
expect(assigns(:diffs).diff_files.first).not_to be_nil
|
2015-04-27 02:42:29 -04:00
|
|
|
expect(assigns(:commits).length).to be >= 1
|
|
|
|
end
|
2015-09-18 15:02:01 -04:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'compare shows some diffs with ignore whitespace change option' do
|
2015-10-21 20:55:35 -04:00
|
|
|
get(:show,
|
2017-02-23 18:55:01 -05:00
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
2015-10-21 20:55:35 -04:00
|
|
|
from: '08f22f25',
|
|
|
|
to: '66eceea0',
|
|
|
|
w: 1)
|
|
|
|
|
|
|
|
expect(response).to be_success
|
2016-07-26 03:21:42 -04:00
|
|
|
diff_file = assigns(:diffs).diff_files.first
|
|
|
|
expect(diff_file).not_to be_nil
|
2015-10-21 20:55:35 -04:00
|
|
|
expect(assigns(:commits).length).to be >= 1
|
|
|
|
# without whitespace option, there are more than 2 diff_splits
|
2016-07-26 03:21:42 -04:00
|
|
|
diff_splits = diff_file.diff.diff.split("\n")
|
2015-10-21 20:55:35 -04:00
|
|
|
expect(diff_splits.length).to be <= 2
|
|
|
|
end
|
|
|
|
|
2015-09-18 15:02:01 -04:00
|
|
|
describe 'non-existent refs' do
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'uses invalid source ref' do
|
2015-09-18 15:02:01 -04:00
|
|
|
get(:show,
|
2017-02-23 18:55:01 -05:00
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
2015-09-18 15:02:01 -04:00
|
|
|
from: 'non-existent',
|
|
|
|
to: ref_to)
|
|
|
|
|
|
|
|
expect(response).to be_success
|
2016-07-20 12:25:36 -04:00
|
|
|
expect(assigns(:diffs).diff_files.to_a).to eq([])
|
2015-09-18 15:02:01 -04:00
|
|
|
expect(assigns(:commits)).to eq([])
|
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'uses invalid target ref' do
|
2015-09-18 15:02:01 -04:00
|
|
|
get(:show,
|
2017-02-23 18:55:01 -05:00
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
2015-09-18 15:02:01 -04:00
|
|
|
from: ref_from,
|
|
|
|
to: 'non-existent')
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
expect(assigns(:diffs)).to eq(nil)
|
|
|
|
expect(assigns(:commits)).to eq(nil)
|
|
|
|
end
|
2017-01-10 17:46:32 -05:00
|
|
|
|
2017-01-14 20:28:01 -05:00
|
|
|
it 'redirects back to index when params[:from] is empty and preserves params[:to]' do
|
|
|
|
post(:create,
|
2017-02-23 18:55:01 -05:00
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
2017-01-14 20:28:01 -05:00
|
|
|
from: '',
|
|
|
|
to: 'master')
|
|
|
|
|
|
|
|
expect(response).to redirect_to(namespace_project_compare_index_path(project.namespace, project, to: 'master'))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects back to index when params[:to] is empty and preserves params[:from]' do
|
|
|
|
post(:create,
|
2017-02-23 18:55:01 -05:00
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
2017-01-14 20:28:01 -05:00
|
|
|
from: 'master',
|
|
|
|
to: '')
|
|
|
|
|
|
|
|
expect(response).to redirect_to(namespace_project_compare_index_path(project.namespace, project, from: 'master'))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects back to index when params[:from] and params[:to] are empty' do
|
2017-01-10 17:46:32 -05:00
|
|
|
post(:create,
|
2017-02-23 18:55:01 -05:00
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
2017-01-10 17:46:32 -05:00
|
|
|
from: '',
|
|
|
|
to: '')
|
|
|
|
|
|
|
|
expect(response).to redirect_to(namespace_project_compare_index_path)
|
|
|
|
end
|
2015-09-18 15:02:01 -04:00
|
|
|
end
|
2016-06-28 12:25:32 -04:00
|
|
|
|
2016-07-08 13:11:47 -04:00
|
|
|
describe 'GET diff_for_path' do
|
2016-06-28 12:25:32 -04:00
|
|
|
def diff_for_path(extra_params = {})
|
|
|
|
params = {
|
2017-02-23 18:55:01 -05:00
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project
|
2016-06-28 12:25:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
get :diff_for_path, params.merge(extra_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:existing_path) { 'files/ruby/feature.rb' }
|
|
|
|
|
|
|
|
context 'when the from and to refs exist' do
|
|
|
|
context 'when the user has access to the project' do
|
|
|
|
context 'when the path exists in the diff' do
|
|
|
|
it 'disables diff notes' do
|
2016-07-08 17:50:06 -04:00
|
|
|
diff_for_path(from: ref_from, to: ref_to, old_path: existing_path, new_path: existing_path)
|
2016-06-28 12:25:32 -04:00
|
|
|
|
|
|
|
expect(assigns(:diff_notes_disabled)).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'only renders the diffs for the path given' do
|
2016-07-26 03:21:42 -04:00
|
|
|
expect(controller).to receive(:render_diff_for_path).and_wrap_original do |meth, diffs|
|
|
|
|
expect(diffs.diff_files.map(&:new_path)).to contain_exactly(existing_path)
|
|
|
|
meth.call(diffs)
|
2016-06-28 12:25:32 -04:00
|
|
|
end
|
|
|
|
|
2016-07-08 17:50:06 -04:00
|
|
|
diff_for_path(from: ref_from, to: ref_to, old_path: existing_path, new_path: existing_path)
|
2016-06-28 12:25:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the path does not exist in the diff' do
|
2016-07-08 17:50:06 -04:00
|
|
|
before { diff_for_path(from: ref_from, to: ref_to, old_path: existing_path.succ, new_path: existing_path.succ) }
|
2016-06-28 12:25:32 -04:00
|
|
|
|
|
|
|
it 'returns a 404' do
|
|
|
|
expect(response).to have_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user does not have access to the project' do
|
|
|
|
before do
|
|
|
|
project.team.truncate
|
2016-07-08 17:50:06 -04:00
|
|
|
diff_for_path(from: ref_from, to: ref_to, old_path: existing_path, new_path: existing_path)
|
2016-06-28 12:25:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a 404' do
|
|
|
|
expect(response).to have_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the from ref does not exist' do
|
2016-07-08 17:50:06 -04:00
|
|
|
before { diff_for_path(from: ref_from.succ, to: ref_to, old_path: existing_path, new_path: existing_path) }
|
2016-06-28 12:25:32 -04:00
|
|
|
|
|
|
|
it 'returns a 404' do
|
|
|
|
expect(response).to have_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the to ref does not exist' do
|
2016-07-08 17:50:06 -04:00
|
|
|
before { diff_for_path(from: ref_from, to: ref_to.succ, old_path: existing_path, new_path: existing_path) }
|
2016-06-28 12:25:32 -04:00
|
|
|
|
|
|
|
it 'returns a 404' do
|
|
|
|
expect(response).to have_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-04-27 02:42:29 -04:00
|
|
|
end
|