blob: 8994216cab3c5c862760d5a6e4f0061d42916614 (
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
|
# frozen_string_literal: true
require 'rspec'
require_relative '../../lib/chotto/message'
require_relative '../../lib/chotto/helpers'
RSpec.describe Chotto::Message do
let(:tags) { [] }
let(:msg) { double('Notmuch::Message', tags: tags) }
let(:db_double) { double('Chotto::Database') }
let(:subject) { Chotto::Message.new(msg: msg, db: db_double) }
it 'reads headers' do
expect(msg).to receive(:header).with('A-Header')
subject.a_header
end
describe 'tags' do
it 'keeps tags state in memory' do
subject.tags << 'tag'
expect(subject.tags).to match ['tag']
subject.tags << 'tag2'
expect(subject.tags).to match %w[tag tag2]
end
it 'allows to overwritte entire tags array' do
subject.tags = [1, 2, 3, 4]
expect(subject.tags).to match [1, 2, 3, 4]
end
end
describe 'save!' do
let(:tags) { [1, 2, 3] }
it 'saves current tag array to db' do
expect(msg).to receive(:remove_all_tags)
tags.each do |tag|
expect(msg).to receive(:add_tag).with(tag.to_s)
end
subject.tags = tags
subject.save!
end
end
describe 'thread' do
let(:thread_id) { '1' }
let(:tester) { double }
let(:msg_in_thread) { double('Chotto:Message') }
it 'fetches messages for thread' do
expect(msg).to receive(:thread_id).and_return(thread_id)
expect(db_double).to receive(:search_messages).with("thread:#{thread_id}").and_return([msg_in_thread])
expect(msg_in_thread).to receive(:tags)
expect(tester).to receive(:test).with(an_instance_of(Chotto::Message))
subject.thread.each do |msg|
tester.test(msg)
end
end
end
end
|