diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-02-17 17:45:32 -0200 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-02-20 12:12:05 -0200 |
commit | 1d476b0656b3ec24e264d7a7c30bdca83704b3bd (patch) | |
tree | d1cdb1b22c0f1365efd80a0485e25b1ecfaf7735 /spec | |
parent | 14fc05ebfdfb6654859ee6f57aa462420a6bcb56 (diff) | |
download | gitlab-ce-1d476b0656b3ec24e264d7a7c30bdca83704b3bd.tar.gz |
Create a pending task when a user is mentioned on a note
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/note_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/task_spec.rb | 16 | ||||
-rw-r--r-- | spec/services/task_service_spec.rb | 11 |
3 files changed, 29 insertions, 0 deletions
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index e6da3724d33..e146f53c3f7 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -26,6 +26,8 @@ describe Note, models: true do it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:noteable) } it { is_expected.to belong_to(:author).class_name('User') } + + it { is_expected.to have_many(:tasks).dependent(:delete_all) } end describe 'validation' do diff --git a/spec/models/task_spec.rb b/spec/models/task_spec.rb index 86317626cc3..2f0b51ffc61 100644 --- a/spec/models/task_spec.rb +++ b/spec/models/task_spec.rb @@ -8,6 +8,7 @@ # target_id :integer not null # target_type :string not null # author_id :integer +# note_id :integer # action :integer # state :string not null # created_at :datetime @@ -19,6 +20,7 @@ require 'spec_helper' describe Task, models: true do describe 'relationships' do it { is_expected.to belong_to(:author).class_name("User") } + it { is_expected.to belong_to(:note) } it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:target).touch(true) } it { is_expected.to belong_to(:user) } @@ -48,6 +50,20 @@ describe Task, models: true do it 'returns false when target does not respond to title' end + describe '#note_text' do + it 'returns nil when note is blank' do + subject.note = nil + + expect(subject.note_text).to be_nil + end + + it 'returns note when note is present' do + subject.note = build(:note, note: 'quick fix') + + expect(subject.note_text).to eq 'quick fix' + end + end + describe '#target_iid' do it 'returns target.iid when target respond to iid' it 'returns target_id when target does not respond to iid' diff --git a/spec/services/task_service_spec.rb b/spec/services/task_service_spec.rb index b35715c8b7a..e373d3a4931 100644 --- a/spec/services/task_service_spec.rb +++ b/spec/services/task_service_spec.rb @@ -128,6 +128,17 @@ describe TaskService, services: true do expect(first_pending_task.reload).to be_pending expect(second_pending_task.reload).to be_pending end + + it 'creates a task for each valid mentioned user' do + note.update_attribute(:note, mentions) + + service.new_note(note) + + should_create_task(user: michael, target: issue, author: john_doe, action: Task::MENTIONED, note: note) + should_create_task(user: author, target: issue, author: john_doe, action: Task::MENTIONED, note: note) + should_not_create_task(user: john_doe, target: issue, author: john_doe, action: Task::MENTIONED, note: note) + should_not_create_task(user: stranger, target: issue, author: john_doe, action: Task::MENTIONED, note: note) + end end end |