summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Rose <sam@gitlab.com>2016-12-27 12:03:44 -0500
committerSam Rose <sam@gitlab.com>2016-12-31 08:00:40 -0500
commit139ff5783b2eb2ff4b63a2f6c30695830a3984ff (patch)
treefe2d6384516cd64de01c78c9eae0a776b371175a
parent8dc2163ce580f1d71be1cf45e5dfcb2b4763d7bb (diff)
downloadgitlab-ce-139ff5783b2eb2ff4b63a2f6c30695830a3984ff.tar.gz
Preserve selected versions when comparing MR changes25836-changing-from-version-in-diff-comparison-does-not-preserve-to-version
-rw-r--r--app/controllers/projects/merge_requests_controller.rb3
-rw-r--r--app/views/projects/merge_requests/show/_versions.html.haml2
-rw-r--r--spec/features/merge_requests/merge_request_versions_spec.rb48
3 files changed, 51 insertions, 2 deletions
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index fc8a289d49d..6004e7d7115 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -98,7 +98,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@start_version = @comparable_diffs.find { |diff| diff.head_commit_sha == @start_sha }
unless @start_version
- render_404
+ @start_sha = @merge_request_diff.head_commit_sha
+ @start_version = @merge_request_diff
end
end
diff --git a/app/views/projects/merge_requests/show/_versions.html.haml b/app/views/projects/merge_requests/show/_versions.html.haml
index ac4a03220b9..b0f3c86fd21 100644
--- a/app/views/projects/merge_requests/show/_versions.html.haml
+++ b/app/views/projects/merge_requests/show/_versions.html.haml
@@ -19,7 +19,7 @@
%ul
- @merge_request_diffs.each do |merge_request_diff|
%li
- = link_to merge_request_version_path(@project, @merge_request, merge_request_diff), class: ('is-active' if merge_request_diff == @merge_request_diff) do
+ = link_to merge_request_version_path(@project, @merge_request, merge_request_diff, @start_sha), class: ('is-active' if merge_request_diff == @merge_request_diff) do
%strong
- if merge_request_diff.latest?
latest version
diff --git a/spec/features/merge_requests/merge_request_versions_spec.rb b/spec/features/merge_requests/merge_request_versions_spec.rb
index cd2272dd38f..04e85ed3f73 100644
--- a/spec/features/merge_requests/merge_request_versions_spec.rb
+++ b/spec/features/merge_requests/merge_request_versions_spec.rb
@@ -81,4 +81,52 @@ feature 'Merge Request versions', js: true, feature: true do
expect(page).to have_content '8 changed files'
end
end
+
+ describe 'compare with same version' do
+ before do
+ page.within '.mr-version-compare-dropdown' do
+ find('.btn-default').click
+ click_link 'version 1'
+ end
+ end
+
+ it 'should have 0 chages between versions' do
+ page.within '.mr-version-compare-dropdown' do
+ expect(page).to have_content 'version 1'
+ end
+
+ page.within '.mr-version-dropdown' do
+ find('.btn-default').click
+ find(:link, 'version 1').trigger('click')
+ end
+
+ expect(page).to have_content '0 changed files'
+ end
+ end
+
+ describe 'compare with newer version' do
+ before do
+ page.within '.mr-version-compare-dropdown' do
+ find('.btn-default').click
+ click_link 'version 2'
+ end
+ end
+
+ it 'should set the compared versions to be the same' do
+ page.within '.mr-version-compare-dropdown' do
+ expect(page).to have_content 'version 2'
+ end
+
+ page.within '.mr-version-dropdown' do
+ find('.btn-default').click
+ find(:link, 'version 1').trigger('click')
+ end
+
+ page.within '.mr-version-compare-dropdown' do
+ expect(page).to have_content 'version 1'
+ end
+
+ expect(page).to have_content '0 changed files'
+ end
+ end
end