diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 050dc4910f2..b5d1a34ec31 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -105,11 +105,11 @@ class MergeRequest < ActiveRecord::Base end if opened? || reopened? - similar_mrs = self.project.merge_requests.where(source_branch: source_branch, target_branch: target_branch).opened + similar_mrs = self.target_project.merge_requests.where(source_branch: source_branch, target_branch: target_branch, source_project_id: source_project.id).opened similar_mrs = similar_mrs.where('id not in (?)', self.id) if self.id if similar_mrs.any? - errors.add :base, "There is already an open merge request for this branches" + errors.add :base, "Cannot Create: This merge request already exists: #{similar_mrs.pluck(:title)}" end end end diff --git a/app/observers/merge_request_observer.rb b/app/observers/merge_request_observer.rb index 6260b79593a..2c6cfd2de7f 100644 --- a/app/observers/merge_request_observer.rb +++ b/app/observers/merge_request_observer.rb @@ -1,6 +1,5 @@ class MergeRequestObserver < ActivityObserver observe :merge_request - cattr_accessor :current_user def after_create(merge_request) event_author_id = merge_request.author_id diff --git a/features/steps/project/project_merge_requests.rb b/features/steps/project/project_merge_requests.rb index 0ebfe961392..64dde145a89 100644 --- a/features/steps/project/project_merge_requests.rb +++ b/features/steps/project/project_merge_requests.rb @@ -57,11 +57,17 @@ class ProjectMergeRequests < Spinach::FeatureSteps end And 'I submit new merge request "Wiki Feature"' do - fill_in "merge_request_title", :with => "Wiki Feature" + #this must come first, so that the target branch is set by the time the "select" for "notes_refactoring" is executed select project.path_with_namespace, :from => "merge_request_target_project_id" + fill_in "merge_request_title", :with => "Wiki Feature" select "master", :from => "merge_request_source_branch" - select "stable", :from => "merge_request_target_branch" - find(:select, "merge_request_target_branch", {}).find(:option, "stable", {}).value.should == "stable" + find(:select, "merge_request_target_project_id", {}).value.should == project.id.to_s + find(:select, "merge_request_source_project_id", {}).value.should == project.id.to_s + + #using "notes_refactoring" because "Bug NS-04" uses master/stable, this will fail merge_request validation if the branches are the same + find(:select, "merge_request_target_branch", {}).find(:option, "notes_refactoring", {}).value.should == "notes_refactoring" + select "notes_refactoring", :from => "merge_request_target_branch" + click_button "Submit merge request" end diff --git a/spec/contexts/filter_context_spec.rb b/spec/contexts/filter_context_spec.rb index 1732353dd76..0ecdb7416e5 100644 --- a/spec/contexts/filter_context_spec.rb +++ b/spec/contexts/filter_context_spec.rb @@ -9,7 +9,7 @@ describe FilterContext do let(:merge_request1) { create(:merge_request, author_id: user.id, source_project: project1, target_project: project2) } let(:merge_request2) { create(:merge_request, author_id: user.id, source_project: project2, target_project: project1) } let(:merge_request3) { create(:merge_request, author_id: user.id, source_project: project2, target_project: project2) } - let(:merge_request4) { create(:merge_request, author_id: user2.id, source_project: project2, target_project: project2) } + let(:merge_request4) { create(:merge_request, author_id: user2.id, source_project: project2, target_project: project2, target_branch:"notes_refactoring") } let(:issue1) { create(:issue, assignee_id: user.id, project: project1) } let(:issue2) { create(:issue, assignee_id: user.id, project: project2) } let(:issue3) { create(:issue, assignee_id: user2.id, project: project2) } diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index 1a7a866307b..8428326e018 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -232,11 +232,16 @@ describe NotificationService do end end + let(:u_watcher) { create(:user, notification_level: Notification::N_WATCH) } + let(:u_participating) { create(:user, notification_level: Notification::N_PARTICIPATING) } + let(:u_disabled) { create(:user, notification_level: Notification::N_DISABLED) } + let(:u_mentioned) { create(:user, username: 'mention', notification_level: Notification::N_WATCH) } + def build_team(project) - @u_watcher = create(:user, notification_level: Notification::N_WATCH) - @u_participating = create(:user, notification_level: Notification::N_PARTICIPATING) - @u_disabled = create(:user, notification_level: Notification::N_DISABLED) - @u_mentioned = create(:user, username: 'mention', notification_level: Notification::N_WATCH) + @u_watcher = u_watcher + @u_participating = u_participating + @u_disabled = u_disabled + @u_mentioned = u_mentioned project.team << [@u_watcher, :master] project.team << [@u_participating, :master]