diff --git a/app/views/projects/merge_requests/_new_compare.html.haml b/app/views/projects/merge_requests/_new_compare.html.haml index 6f6f54ccecbec18dfe75a8d13f3c5d5e5c9b3d28..a8b774a3cd1ce58bcc497caaf951cb782ed0182b 100644 --- a/app/views/projects/merge_requests/_new_compare.html.haml +++ b/app/views/projects/merge_requests/_new_compare.html.haml @@ -2,11 +2,12 @@ %hr = form_for [@project, @merge_request], url: new_project_merge_request_path(@project), method: :get, html: { class: "merge-request-form form-inline" } do |f| + .hide.alert.alert-danger.mr-compare-errors .merge-request-branches.row .col-md-6 .panel.panel-default .panel-heading - From + %strong Source branch .panel-body = f.select(:source_project_id, [[@merge_request.source_project_path,@merge_request.source_project.id]] , {}, { class: 'source_project select2 span3', disabled: @merge_request.persisted? }) @@ -17,7 +18,7 @@ .col-md-6 .panel.panel-default .panel-heading - To + %strong Target branch .panel-body - projects = @project.forked_from_project.nil? ? [@project] : [@project, @project.forked_from_project] = f.select(:target_project_id, options_from_collection_for_select(projects, 'id', 'path_with_namespace', f.object.target_project_id), {}, { class: 'target_project select2 span3', disabled: @merge_request.persisted? }) @@ -45,8 +46,9 @@ %span.label-branch #{@merge_request.target_branch} are the same. + %hr - = f.submit 'Compare branches', class: "btn btn-primary" + = f.submit 'Compare branches', class: "btn btn-primary mr-compare-btn" :javascript var source_branch = $("#merge_request_source_branch") @@ -61,9 +63,22 @@ }); source_branch.on("change", function() { $.get("#{branch_from_project_merge_requests_path(@source_project)}", {ref: $(this).val() }); + $(".mr-compare-errors").fadeOut(); + $(".mr-compare-btn").enable(); }); target_branch.on("change", function() { $.get("#{branch_to_project_merge_requests_path(@source_project)}", {target_project_id: target_project.val(),ref: $(this).val() }); + $(".mr-compare-errors").fadeOut(); + $(".mr-compare-btn").enable(); }); +:coffeescript + + $(".merge-request-form").on 'submit', -> + if $("#merge_request_source_branch").val() is "" or $('#merge_request_target_branch').val() is "" + $(".mr-compare-errors").html("You must select source and target branch to proceed") + $(".mr-compare-errors").fadeIn() + event.preventDefault() + return + diff --git a/features/project/forked_merge_requests.feature b/features/project/forked_merge_requests.feature index 2d94b98c90b32d46a708654063f2cfc165f47f81..5832b729deb10af76680f873d56807994f18d76e 100644 --- a/features/project/forked_merge_requests.feature +++ b/features/project/forked_merge_requests.feature @@ -30,11 +30,10 @@ Feature: Project Forked Merge Requests Given I visit project "Forked Shop" merge requests page And I click link "New Merge Request" And I fill out an invalid "Merge Request On Forked Project" merge request - And I submit the merge request Then I should see validation errors @javascript Scenario: Merge request should target fork repository by default Given I visit project "Forked Shop" merge requests page And I click link "New Merge Request" - Then the target repository should be the original repository \ No newline at end of file + Then the target repository should be the original repository diff --git a/features/steps/project/forked_merge_requests.rb b/features/steps/project/forked_merge_requests.rb index df69cb7543768f4bd5c2c8aafd7b9018bc3d9d9c..3c497638d9cd3c6b339d695501739fce013738c9 100644 --- a/features/steps/project/forked_merge_requests.rb +++ b/features/steps/project/forked_merge_requests.rb @@ -53,6 +53,7 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps find(:select, "merge_request_source_branch", {}).value.should == 'master' find(:select, "merge_request_target_branch", {}).value.should == 'stable' + click_button "Compare branches" fill_in "merge_request_title", with: "Merge Request On Forked Project" end @@ -148,29 +149,19 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps current_path.should == edit_project_merge_request_path(@project, @merge_request) page.should have_content "Edit merge request ##{@merge_request.id}" find("#merge_request_title").value.should == "Merge Request On Forked Project" - find("#merge_request_source_project_id").value.should == @forked_project.id.to_s - find("#merge_request_target_project_id").value.should == @project.id.to_s - find("#merge_request_source_branch").value.should have_content "master" - verify_commit_link(".mr_source_commit",@forked_project) - find("#merge_request_target_branch").value.should have_content "stable" - verify_commit_link(".mr_target_commit",@project) end step 'I fill out an invalid "Merge Request On Forked Project" merge request' do - #If this isn't filled in the rest of the validations won't be triggered - fill_in "merge_request_title", with: "Merge Request On Forked Project" - select "Select branch", from: "merge_request_target_branch" - find(:select, "merge_request_source_project_id", {}).value.should == @forked_project.id.to_s find(:select, "merge_request_target_project_id", {}).value.should == project.id.to_s find(:select, "merge_request_source_branch", {}).value.should == "" find(:select, "merge_request_target_branch", {}).value.should == "" + click_button "Compare branches" end step 'I should see validation errors' do - page.should have_content "Source branch can't be blank" - page.should have_content "Target branch can't be blank" + page.should have_content "You must select source and target branch" end step 'the target repository should be the original repository' do