2016-02-12 08:17:42 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Todo do
|
2016-03-16 19:31:30 -04:00
|
|
|
let(:issue) { create(:issue) }
|
|
|
|
|
2016-02-12 08:17:42 -05:00
|
|
|
describe 'relationships' do
|
|
|
|
it { is_expected.to belong_to(:author).class_name("User") }
|
2016-02-17 14:45:32 -05:00
|
|
|
it { is_expected.to belong_to(:note) }
|
2016-02-12 08:17:42 -05:00
|
|
|
it { is_expected.to belong_to(:project) }
|
2018-07-16 09:35:19 -04:00
|
|
|
it { is_expected.to belong_to(:group) }
|
2016-02-12 08:17:42 -05:00
|
|
|
it { is_expected.to belong_to(:target).touch(true) }
|
|
|
|
it { is_expected.to belong_to(:user) }
|
|
|
|
end
|
|
|
|
|
2016-02-12 13:45:44 -05:00
|
|
|
describe 'respond to' do
|
|
|
|
it { is_expected.to respond_to(:author_name) }
|
|
|
|
it { is_expected.to respond_to(:author_email) }
|
|
|
|
end
|
|
|
|
|
2016-02-12 08:17:42 -05:00
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:action) }
|
2016-03-16 19:31:30 -04:00
|
|
|
it { is_expected.to validate_presence_of(:target_type) }
|
2016-02-12 08:17:42 -05:00
|
|
|
it { is_expected.to validate_presence_of(:user) }
|
2018-02-04 14:46:14 -05:00
|
|
|
it { is_expected.to validate_presence_of(:author) }
|
2016-03-16 19:31:30 -04:00
|
|
|
|
|
|
|
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
|
2016-02-12 08:17:42 -05:00
|
|
|
end
|
2016-02-12 13:45:44 -05:00
|
|
|
|
2016-02-18 14:16:39 -05:00
|
|
|
describe '#body' do
|
2016-02-17 22:28:36 -05:00
|
|
|
before do
|
2016-02-18 14:16:39 -05:00
|
|
|
subject.target = build(:issue, title: 'Bugfix')
|
2016-02-17 22:28:36 -05:00
|
|
|
end
|
|
|
|
|
2016-02-18 14:16:39 -05:00
|
|
|
it 'returns target title when note is blank' do
|
2016-02-17 14:45:32 -05:00
|
|
|
subject.note = nil
|
|
|
|
|
2016-02-18 14:16:39 -05:00
|
|
|
expect(subject.body).to eq 'Bugfix'
|
2016-02-17 14:45:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns note when note is present' do
|
|
|
|
subject.note = build(:note, note: 'quick fix')
|
|
|
|
|
2016-02-18 14:16:39 -05:00
|
|
|
expect(subject.body).to eq 'quick fix'
|
2016-02-17 14:45:32 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-16 19:56:23 -04:00
|
|
|
describe '#done' do
|
2016-02-22 14:53:07 -05:00
|
|
|
it 'changes state to done' do
|
|
|
|
todo = create(:todo, state: :pending)
|
2016-03-16 19:56:23 -04:00
|
|
|
expect { todo.done }.to change(todo, :state).from('pending').to('done')
|
2016-02-17 22:28:36 -05:00
|
|
|
end
|
|
|
|
|
2016-02-22 14:53:07 -05:00
|
|
|
it 'does not raise error when is already done' do
|
|
|
|
todo = create(:todo, state: :done)
|
2016-03-16 19:56:23 -04:00
|
|
|
expect { todo.done }.not_to raise_error
|
2016-02-17 22:28:36 -05:00
|
|
|
end
|
2016-02-12 13:45:44 -05:00
|
|
|
end
|
2016-03-16 19:31:30 -04:00
|
|
|
|
|
|
|
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
|
2016-03-18 12:27:27 -04:00
|
|
|
context 'for commits' do
|
2017-01-26 17:44:58 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:commit) { project.commit }
|
|
|
|
|
2016-03-18 12:27:27 -04:00
|
|
|
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
|
|
|
|
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
|
2016-03-16 19:31:30 -04:00
|
|
|
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
|
|
|
|
|
2016-03-18 12:24:47 -04:00
|
|
|
describe '#target_reference' do
|
2017-01-10 18:53:51 -05:00
|
|
|
it 'returns commit full reference with short id' do
|
2017-01-26 17:44:58 -05:00
|
|
|
project = create(:project, :repository)
|
|
|
|
commit = project.commit
|
|
|
|
|
2016-03-18 09:32:22 -04:00
|
|
|
subject.project = project
|
2016-03-16 19:31:30 -04:00
|
|
|
subject.target_type = 'Commit'
|
|
|
|
subject.commit_id = commit.id
|
2016-03-18 09:32:22 -04:00
|
|
|
|
2017-01-10 18:53:51 -05:00
|
|
|
expect(subject.target_reference).to eq commit.reference_link_text(full: true)
|
2016-03-16 19:31:30 -04:00
|
|
|
end
|
|
|
|
|
2017-01-10 18:53:51 -05:00
|
|
|
it 'returns full reference for issuables' do
|
2016-03-16 19:31:30 -04:00
|
|
|
subject.target = issue
|
2017-01-10 18:53:51 -05:00
|
|
|
expect(subject.target_reference).to eq issue.to_reference(full: true)
|
2016-03-16 19:31:30 -04:00
|
|
|
end
|
|
|
|
end
|
2017-04-10 11:51:15 -04:00
|
|
|
|
|
|
|
describe '#self_added?' do
|
|
|
|
let(:user_1) { build(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject.user = user_1
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is true when the user is the author' do
|
|
|
|
subject.author = user_1
|
|
|
|
|
|
|
|
expect(subject).to be_self_added
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is false when the user is not the author' do
|
|
|
|
subject.author = build(:user)
|
|
|
|
|
|
|
|
expect(subject).not_to be_self_added
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#self_assigned?' do
|
|
|
|
let(:user_1) { build(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject.user = user_1
|
|
|
|
subject.author = user_1
|
|
|
|
subject.action = Todo::ASSIGNED
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is true when todo is ASSIGNED and self_added' do
|
|
|
|
expect(subject).to be_self_assigned
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is false when the todo is not ASSIGNED' do
|
|
|
|
subject.action = Todo::MENTIONED
|
|
|
|
|
|
|
|
expect(subject).not_to be_self_assigned
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is false when todo is not self_added' do
|
|
|
|
subject.author = build(:user)
|
|
|
|
|
|
|
|
expect(subject).not_to be_self_assigned
|
|
|
|
end
|
|
|
|
end
|
2016-02-12 08:17:42 -05:00
|
|
|
end
|