Change merge request diff creation from callback to part of the service
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
3c1dca0301
commit
f8aeb8cdac
5 changed files with 9 additions and 7 deletions
|
@ -88,7 +88,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
|
|||
@merge_request.merge_request_diff
|
||||
end
|
||||
|
||||
|
||||
respond_to do |format|
|
||||
format.html { define_discussion_vars }
|
||||
format.json { render json: { html: view_to_html_string("projects/merge_requests/show/_diffs") } }
|
||||
|
|
|
@ -15,7 +15,6 @@ class MergeRequest < ActiveRecord::Base
|
|||
|
||||
serialize :merge_params, Hash
|
||||
|
||||
before_validation :ensure_merge_request_diff, on: :create, unless: :importing?
|
||||
after_update :update_merge_request_diff
|
||||
|
||||
delegate :commits, :real_size, to: :merge_request_diff, prefix: nil
|
||||
|
@ -283,10 +282,6 @@ class MergeRequest < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def ensure_merge_request_diff
|
||||
merge_request_diff || merge_request_diffs.build
|
||||
end
|
||||
|
||||
def create_merge_request_diff
|
||||
merge_request_diffs.create
|
||||
end
|
||||
|
|
|
@ -16,6 +16,7 @@ module MergeRequests
|
|||
merge_request.target_project ||= source_project
|
||||
merge_request.author = current_user
|
||||
merge_request.merge_params['force_remove_source_branch'] = force_remove_source_branch
|
||||
merge_request.merge_request_diffs.build
|
||||
|
||||
if merge_request.save
|
||||
merge_request.update_attributes(label_ids: label_params)
|
||||
|
|
|
@ -68,5 +68,11 @@ FactoryGirl.define do
|
|||
factory :closed_merge_request, traits: [:closed]
|
||||
factory :reopened_merge_request, traits: [:reopened]
|
||||
factory :merge_request_with_diffs, traits: [:with_diffs]
|
||||
|
||||
after :create do |merge_request|
|
||||
unless merge_request.merge_request_diff
|
||||
merge_request.create_merge_request_diff
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,9 +11,10 @@ describe MergeRequestDiff, models: true do
|
|||
end
|
||||
|
||||
describe 'create new record' do
|
||||
subject { create(:merge_request) }
|
||||
subject { create(:merge_request).merge_request_diff }
|
||||
|
||||
it { expect(subject).to be_valid }
|
||||
it { expect(subject).to be_persisted }
|
||||
it { expect(subject.commits.count).to eq(5) }
|
||||
it { expect(subject.diffs.count).to eq(8) }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue