Commit 0e974b52 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor MergeRequestDiff initialize method

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent b0a02384
...@@ -25,22 +25,18 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -25,22 +25,18 @@ class MergeRequestDiff < ActiveRecord::Base
validates :start_commit_sha, presence: true, unless: :importing? validates :start_commit_sha, presence: true, unless: :importing?
validates :head_commit_sha, presence: true, unless: :importing? validates :head_commit_sha, presence: true, unless: :importing?
after_initialize :set_diff_range, unless: :importing? after_initialize :initialize_commits_sha, unless: :importing?
after_create :save_git_content, unless: :importing? after_create :save_git_content, unless: :importing?
after_save :keep_around_commits, unless: :importing? after_save :keep_around_commits, unless: :importing?
def set_diff_range # Those variables are used for collecting commits and diff from git repository.
if persisted? # After object is created those sha are stored in the database.
# Workaround for old MergeRequestDiff object # However some old MergeRequestDiff records don't
# that does not have head_commit_sha in the database # have those variables in the database so we try to initialize it
self.start_commit_sha ||= merge_request.target_branch_sha def initialize_commits_sha
self.head_commit_sha ||= last_commit.sha self.start_commit_sha ||= merge_request.target_branch_sha
self.base_commit_sha ||= find_base_sha self.head_commit_sha ||= last_commit.try(:sha) || merge_request.source_branch_sha
else self.base_commit_sha ||= find_base_sha
self.start_commit_sha ||= merge_request.target_branch_sha
self.head_commit_sha ||= merge_request.source_branch_sha
self.base_commit_sha ||= find_base_sha
end
end end
# Collect information about commits and diff from repository # Collect information about commits and diff from repository
......
...@@ -22,7 +22,6 @@ feature 'Merge Request versions', js: true, feature: true do ...@@ -22,7 +22,6 @@ feature 'Merge Request versions', js: true, feature: true do
before do before do
page.within '.mr-version-switch' do page.within '.mr-version-switch' do
find('.btn-link').click find('.btn-link').click
#find('a', text: '6f6d7e7e').click
click_link '6f6d7e7e' click_link '6f6d7e7e'
end end
end 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