Refactor Todo#target

This commit is contained in:
Douglas Barbosa Alexandre 2016-03-18 13:27:27 -03:00
parent 2a8858ca8a
commit 02b0c37cab
2 changed files with 17 additions and 11 deletions

View file

@ -61,14 +61,10 @@ class Todo < ActiveRecord::Base
# override to return commits, which are not active record
def target
if for_commit?
project.commit(commit_id)
project.commit(commit_id) rescue nil
else
super
end
# Temp fix to prevent app crash
# if note commit id doesn't exist
rescue
nil
end
def target_reference

View file

@ -99,13 +99,23 @@ describe Todo, models: true do
end
describe '#target' do
it 'returns an instance of Commit for commits' do
subject.project = project
subject.target_type = 'Commit'
subject.commit_id = commit.id
context 'for commits' do
it 'returns an instance of Commit when exists' do
subject.project = project
subject.target_type = 'Commit'
subject.commit_id = commit.id
expect(subject.target).to be_a(Commit)
expect(subject.target).to eq commit
expect(subject.target).to be_a(Commit)
expect(subject.target).to eq commit
end
it 'returns nil when does not exists' do
subject.project = project
subject.target_type = 'Commit'
subject.commit_id = 'xxxx'
expect(subject.target).to be_nil
end
end
it 'returns the issuable for issuables' do