summaryrefslogtreecommitdiff
path: root/spec/models/todo_spec.rb
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-03-16 20:31:30 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-03-18 11:00:53 -0300
commitc29da3f8ca1d759b8cbecb91b6e0529b18cc5c85 (patch)
treeb60d38cea7b271f52307ec48df1a14327915edda /spec/models/todo_spec.rb
parent1e76245d4e8c5ecbd915c517b6c8923e9c4bbd2d (diff)
downloadgitlab-ce-c29da3f8ca1d759b8cbecb91b6e0529b18cc5c85.tar.gz
Trigger a todo for mentions on commits page
Diffstat (limited to 'spec/models/todo_spec.rb')
-rw-r--r--spec/models/todo_spec.rb62
1 files changed, 61 insertions, 1 deletions
diff --git a/spec/models/todo_spec.rb b/spec/models/todo_spec.rb
index fe9ea7e7d1e..3e59443589c 100644
--- a/spec/models/todo_spec.rb
+++ b/spec/models/todo_spec.rb
@@ -18,6 +18,10 @@
require 'spec_helper'
describe Todo, models: true do
+ let(:project) { create(:project) }
+ let(:commit) { project.commit }
+ let(:issue) { create(:issue) }
+
describe 'relationships' do
it { is_expected.to belong_to(:author).class_name("User") }
it { is_expected.to belong_to(:note) }
@@ -33,8 +37,22 @@ describe Todo, models: true do
describe 'validations' do
it { is_expected.to validate_presence_of(:action) }
- it { is_expected.to validate_presence_of(:target) }
+ it { is_expected.to validate_presence_of(:target_type) }
it { is_expected.to validate_presence_of(:user) }
+
+ context 'for commits' do
+ subject { described_class.new(target_type: 'Commit') }
+
+ it { is_expected.to validate_presence_of(:commit_id) }
+ it { is_expected.not_to validate_presence_of(:target_id) }
+ end
+
+ context 'for issuables' do
+ subject { described_class.new(target: issue) }
+
+ it { is_expected.to validate_presence_of(:target_id) }
+ it { is_expected.not_to validate_presence_of(:commit_id) }
+ end
end
describe '#body' do
@@ -66,4 +84,46 @@ describe Todo, models: true do
expect { todo.done! }.not_to raise_error
end
end
+
+ describe '#for_commit?' do
+ it 'returns true when target is a commit' do
+ subject.target_type = 'Commit'
+ expect(subject.for_commit?).to eq true
+ end
+
+ it 'returns false when target is an issuable' do
+ subject.target_type = 'Issue'
+ expect(subject.for_commit?).to eq false
+ end
+ 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
+
+ expect(subject.target).to be_a(Commit)
+ expect(subject.target).to eq commit
+ end
+
+ it 'returns the issuable for issuables' do
+ subject.target_id = issue.id
+ subject.target_type = issue.class.name
+ expect(subject.target).to eq issue
+ end
+ end
+
+ describe '#to_reference' do
+ it 'returns the short commit id for commits' do
+ subject.target_type = 'Commit'
+ subject.commit_id = commit.id
+ expect(subject.to_reference).to eq Commit.truncate_sha(commit.id)
+ end
+
+ it 'returns reference for issuables' do
+ subject.target = issue
+ expect(subject.to_reference).to eq issue.to_reference
+ end
+ end
end