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