Refactor MR code reload

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
Dmitriy Zaporozhets 2014-02-18 20:17:26 +02:00
parent e1c93a6bca
commit 1c61ac1c64
No known key found for this signature in database
GPG key ID: 627C5F589F467F17
3 changed files with 9 additions and 5 deletions

View file

@ -106,9 +106,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
params[:merge_request].delete(:target_project_id)
if @merge_request.update_attributes(params[:merge_request].merge(author_id_of_changes: current_user.id))
@merge_request.reload_code
@merge_request.mark_as_unchecked
@merge_request.reset_events_cache
respond_to do |format|

View file

@ -32,7 +32,9 @@ class MergeRequest < ActiveRecord::Base
belongs_to :source_project, foreign_key: :source_project_id, class_name: "Project"
has_one :merge_request_diff, dependent: :destroy
after_create :create_merge_request_diff
after_update :update_merge_request_diff
delegate :commits, :diffs, :last_commit, :last_commit_short_sha, to: :merge_request_diff, prefix: nil
@ -125,6 +127,13 @@ class MergeRequest < ActiveRecord::Base
end
end
def update_merge_request_diff
if source_branch_changed? || target_branch_changed?
reload_code
mark_as_unchecked
end
end
def reload_code
if merge_request_diff && opened?
merge_request_diff.reload_content

View file

@ -116,8 +116,6 @@ module API
authorize! :modify_merge_request, merge_request
if merge_request.update_attributes attrs
merge_request.reload_code
merge_request.mark_as_unchecked
present merge_request, with: Entities::MergeRequest
else
handle_merge_request_errors! merge_request.errors