2016-02-12 08:17:42 -05:00
|
|
|
# == Schema Information
|
|
|
|
#
|
2016-02-20 08:59:59 -05:00
|
|
|
# Table name: todos
|
2016-02-12 08:17:42 -05: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
|
2016-02-17 14:45:32 -05:00
|
|
|
# note_id :integer
|
2016-02-18 08:51:53 -05:00
|
|
|
# action :integer not null
|
2016-02-12 08:17:42 -05:00
|
|
|
# state :string not null
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
#
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
describe Todo, models: true do
|
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) }
|
|
|
|
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) }
|
|
|
|
it { is_expected.to validate_presence_of(:target) }
|
|
|
|
it { is_expected.to validate_presence_of(:user) }
|
|
|
|
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-02-22 14:53:07 -05:00
|
|
|
describe '#done!' do
|
|
|
|
it 'changes state to done' do
|
|
|
|
todo = create(:todo, state: :pending)
|
|
|
|
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)
|
|
|
|
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-02-12 08:17:42 -05:00
|
|
|
end
|