blob: fe9ea7e7d1ec4b2d9ae4366a2eb0acab8291329f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# == Schema Information
#
# Table name: todos
#
# 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
# action :integer not null
# state :string not null
# created_at :datetime
# updated_at :datetime
#
require 'spec_helper'
describe Todo, 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) }
end
describe 'respond to' do
it { is_expected.to respond_to(:author_name) }
it { is_expected.to respond_to(:author_email) }
end
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
describe '#body' do
before do
subject.target = build(:issue, title: 'Bugfix')
end
it 'returns target title when note is blank' do
subject.note = nil
expect(subject.body).to eq 'Bugfix'
end
it 'returns note when note is present' do
subject.note = build(:note, note: 'quick fix')
expect(subject.body).to eq 'quick fix'
end
end
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')
end
it 'does not raise error when is already done' do
todo = create(:todo, state: :done)
expect { todo.done! }.not_to raise_error
end
end
end
|