|
1 # vim: set nosta noet ts=4 sw=4 ft=rspec: |
|
2 |
|
3 require_relative '../../spec_helpers' |
|
4 |
|
5 |
|
6 describe Ezmlm::List::Author 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 ( :author_id ) { "idijebinbeadbfecldlb" } |
|
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 |
|
32 expect( list ).to receive( :threaded? ).and_return( false ) |
|
33 expect { |
|
34 described_class.new( list, author_id ) |
|
35 }.to raise_error( RuntimeError, /indexing is not enabled/i ) |
|
36 end |
|
37 |
|
38 it 'raises error if passed a malformed author 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 index file' do |
|
45 allow( list ).to receive( :listdir ).and_return( Pathname('/nope') ) |
|
46 expect( list ).to receive( :threaded? ).and_return( true ) |
|
47 expect { |
|
48 described_class.new( list, author_id ) |
|
49 }.to raise_error( RuntimeError, /unknown author/i ) |
|
50 end |
|
51 |
|
52 it 'parses an author index from the archive' do |
|
53 author = described_class.new( list, author_id ) |
|
54 expect( author ).to be_a( Ezmlm::List::Author ) |
|
55 end |
|
56 |
|
57 context 'an instance of' do |
|
58 |
|
59 let( :author ) { described_class.new( list, author_id ) } |
|
60 |
|
61 it 'knows the author name' do |
|
62 expect( author.name ).to match( /Jessy Labadie/i ) |
|
63 end |
|
64 |
|
65 it 'holds messages that belong to the author' do |
|
66 expect( author.messages.size ).to be( 1 ) |
|
67 expect( author.first.subject ).to match( /interface/i ) |
|
68 expect( author.first.body.to_s ).to match( /protocol/i ) |
|
69 expect( author.first.from.first ).to match( /karianne@example.net/i ) |
|
70 end |
|
71 |
|
72 it 'holds threads that the author has participated in' do |
|
73 expect( author.threads.size ).to be( 1 ) |
|
74 expect( author.threads.first ).to eq( 'caaabjkbghlcbokpfpeg' ) |
|
75 end |
|
76 |
|
77 it 'is enumerable' do |
|
78 expect( author.any?{|m| m.id == 111 }).to be_truthy |
|
79 end |
|
80 end |
|
81 end |
|
82 end |
|
83 |