gitlab-org--gitlab-foss/spec/models/todo_spec.rb.rb

90 lines
2.3 KiB
Ruby
Raw Normal View History

2016-02-12 13:17:42 +00:00
# == Schema Information
#
2016-02-20 13:59:59 +00:00
# Table name: todos
2016-02-12 13:17:42 +00:00
#
# id :integer not null, primary key
# user_id :integer not null
# project_id :integer not null
# target_id :integer not null
# target_type :string not null
# author_id :integer
# note_id :integer
2016-02-18 13:51:53 +00:00
# action :integer not null
2016-02-12 13:17:42 +00:00
# state :string not null
# created_at :datetime
# updated_at :datetime
#
require 'spec_helper'
2016-02-20 13:59:59 +00:00
describe Todo, models: true do
2016-02-12 13:17:42 +00:00
describe 'relationships' do
it { is_expected.to belong_to(:author).class_name("User") }
it { is_expected.to belong_to(:note) }
2016-02-12 13:17:42 +00:00
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:target).touch(true) }
it { is_expected.to belong_to(:user) }
end
2016-02-12 18:45:44 +00: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 13:17:42 +00:00
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(:user) }
end
2016-02-12 18:45:44 +00:00
describe '#action_name' do
it 'returns proper message when action is an assigment' do
2016-02-20 13:59:59 +00:00
subject.action = Todo::ASSIGNED
2016-02-12 18:45:44 +00:00
expect(subject.action_name).to eq 'assigned'
end
it 'returns proper message when action is a mention' do
2016-02-20 13:59:59 +00:00
subject.action = Todo::MENTIONED
expect(subject.action_name).to eq 'mentioned you on'
end
2016-02-12 18:45:44 +00:00
end
2016-02-18 19:16:39 +00:00
describe '#body' do
before do
2016-02-18 19:16:39 +00:00
subject.target = build(:issue, title: 'Bugfix')
end
2016-02-18 19:16:39 +00:00
it 'returns target title when note is blank' do
subject.note = nil
2016-02-18 19:16:39 +00:00
expect(subject.body).to eq 'Bugfix'
end
it 'returns note when note is present' do
subject.note = build(:note, note: 'quick fix')
2016-02-18 19:16:39 +00:00
expect(subject.body).to eq 'quick fix'
end
end
2016-02-12 18:45:44 +00:00
describe '#target_iid' do
let(:issue) { build(:issue, id: 1, iid: 5) }
before do
subject.target = issue
end
it 'returns target.iid when target respond to iid' do
expect(subject.target_iid).to eq 5
end
it 'returns target_id when target does not respond to iid' do
allow(issue).to receive(:respond_to?).with(:iid).and_return(false)
expect(subject.target_iid).to eq 1
end
2016-02-12 18:45:44 +00:00
end
2016-02-12 13:17:42 +00:00
end