Add more tests to merge_request_diff and improve initialize
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
0e974b52d8
commit
3c1dca0301
|
@ -246,8 +246,10 @@ class MergeRequest < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def diff_refs
|
def diff_refs
|
||||||
|
if merge_request_diff
|
||||||
merge_request_diff.diff_refs
|
merge_request_diff.diff_refs
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def validate_branches
|
def validate_branches
|
||||||
if target_project == source_project && target_branch == source_branch
|
if target_project == source_project && target_branch == source_branch
|
||||||
|
|
|
@ -35,7 +35,7 @@ class MergeRequestDiff < ActiveRecord::Base
|
||||||
# have those variables in the database so we try to initialize it
|
# have those variables in the database so we try to initialize it
|
||||||
def initialize_commits_sha
|
def initialize_commits_sha
|
||||||
self.start_commit_sha ||= merge_request.target_branch_sha
|
self.start_commit_sha ||= merge_request.target_branch_sha
|
||||||
self.head_commit_sha ||= last_commit.try(:sha) || merge_request.source_branch_sha
|
self.head_commit_sha ||= persisted? ? last_commit.sha : merge_request.source_branch_sha
|
||||||
self.base_commit_sha ||= find_base_sha
|
self.base_commit_sha ||= find_base_sha
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -191,9 +191,7 @@ class MergeRequestDiff < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
new_attributes[:st_diffs] = new_diffs
|
new_attributes[:st_diffs] = new_diffs
|
||||||
|
|
||||||
update_columns_serialized(new_attributes)
|
update_columns_serialized(new_attributes)
|
||||||
|
|
||||||
keep_around_commits
|
keep_around_commits
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,23 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe MergeRequestDiff, models: true do
|
describe MergeRequestDiff, models: true do
|
||||||
|
describe 'initialize new object' do
|
||||||
|
subject { build(:merge_request).merge_request_diffs.build }
|
||||||
|
|
||||||
|
it { expect(subject).to be_valid }
|
||||||
|
it { expect(subject.head_commit_sha).to eq('5937ac0a7beb003549fc5fd26fc247adbce4a52e') }
|
||||||
|
it { expect(subject.base_commit_sha).to eq('ae73cb07c9eeaf35924a10f713b364d32b2dd34f') }
|
||||||
|
it { expect(subject.start_commit_sha).to eq('0b4bc9a49b562e85de7cc9e834518ea6828729b9') }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'create new record' do
|
||||||
|
subject { create(:merge_request) }
|
||||||
|
|
||||||
|
it { expect(subject).to be_valid }
|
||||||
|
it { expect(subject.commits.count).to eq(5) }
|
||||||
|
it { expect(subject.diffs.count).to eq(8) }
|
||||||
|
end
|
||||||
|
|
||||||
describe '#diffs' do
|
describe '#diffs' do
|
||||||
let(:mr) { create(:merge_request, :with_diffs) }
|
let(:mr) { create(:merge_request, :with_diffs) }
|
||||||
let(:mr_diff) { mr.merge_request_diff }
|
let(:mr_diff) { mr.merge_request_diff }
|
||||||
|
|
Loading…
Reference in New Issue