15
|
1 |
# vim: set nosta noet ts=4 sw=4 ft=rspec:
|
|
2 |
|
|
3 |
require_relative '../../spec_helpers'
|
|
4 |
|
|
5 |
|
|
6 |
describe Ezmlm::List::Thread do
|
|
7 |
|
|
8 |
before( :all ) do
|
|
9 |
@listdir = make_listdir()
|
|
10 |
end
|
|
11 |
|
|
12 |
after( :all ) do
|
|
13 |
rm_r( @listdir )
|
|
14 |
end
|
|
15 |
|
|
16 |
let( :list ) do
|
|
17 |
Ezmlm::List.new( @listdir )
|
|
18 |
end
|
|
19 |
|
|
20 |
let ( :thread_id ) { "hdohjgmgfakappbhjnkp" }
|
|
21 |
|
|
22 |
|
|
23 |
context 'instantiating' do
|
|
24 |
|
|
25 |
it 'raises error if provided an unknown list object' do
|
|
26 |
expect {
|
|
27 |
described_class.new( true, 1 )
|
|
28 |
}.to raise_error( ArgumentError, /unknown list/i )
|
|
29 |
end
|
|
30 |
|
|
31 |
it 'raises error if thread indexing is disabled' do
|
17
|
32 |
expect( list ).to receive( :archived? ).and_return( false )
|
15
|
33 |
expect {
|
|
34 |
described_class.new( list, thread_id )
|
17
|
35 |
}.to raise_error( RuntimeError, /archiving is not enabled/i )
|
15
|
36 |
end
|
|
37 |
|
|
38 |
it 'raises error if passed a malformed thread ID' do
|
|
39 |
expect {
|
|
40 |
described_class.new( list, 'whatever' )
|
|
41 |
}.to raise_error( ArgumentError, /malformed/i )
|
|
42 |
end
|
|
43 |
|
|
44 |
it 'raises error when unable to read thread file' do
|
|
45 |
allow( list ).to receive( :listdir ).and_return( Pathname('/nope') )
|
17
|
46 |
expect( list ).to receive( :archived? ).and_return( true )
|
15
|
47 |
expect {
|
|
48 |
described_class.new( list, thread_id )
|
|
49 |
}.to raise_error( RuntimeError, /unknown thread/i )
|
|
50 |
end
|
|
51 |
|
|
52 |
it 'parses a thread index from the archive' do
|
|
53 |
thread = described_class.new( list, thread_id )
|
|
54 |
expect( thread ).to be_a( Ezmlm::List::Thread )
|
|
55 |
end
|
|
56 |
|
|
57 |
|
|
58 |
context 'an instance of' do
|
|
59 |
|
|
60 |
let( :thread ) { described_class.new( list, thread_id ) }
|
|
61 |
|
|
62 |
it 'knows its subject' do
|
|
63 |
expect( thread.subject ).to match( /ai on the microchip/i )
|
|
64 |
end
|
|
65 |
|
|
66 |
it 'contains a list of message ids' do
|
|
67 |
expect( thread.messages ).to eq( [20, 108] )
|
|
68 |
end
|
|
69 |
|
|
70 |
it 'contains a list of author ids' do
|
|
71 |
expect( thread.authors ).to eq( ["mdncdmmkeffdjkopffbj", "ffcambaeljjifcodfjoc"] )
|
|
72 |
end
|
|
73 |
|
|
74 |
it 'holds messages that belong to the thread' do
|
|
75 |
expect( thread.messages.size ).to be( 2 )
|
|
76 |
expect( thread.first.subject ).to match( /microchip/i )
|
|
77 |
expect( thread.first.body.to_s ).to match( /protocol/i )
|
|
78 |
expect( thread.first.from.first ).to match( /block@example.net/i )
|
|
79 |
end
|
|
80 |
|
|
81 |
it 'is enumerable' do
|
|
82 |
expect( thread.any?{|m| m.id == 20 }).to be_truthy
|
|
83 |
end
|
|
84 |
end
|
|
85 |
end
|
|
86 |
end
|
|
87 |
|