Commit f8aeb8cd authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Change merge request diff creation from callback to part of the service

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 3c1dca03
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment