spec/ezmlm/list/message_spec.rb
author Mahlon E. Smith <mahlon@laika.com>
Tue, 16 May 2017 13:58:34 -0700
changeset 17 23c7f5c8ee39
parent 15 a38e6916504c
permissions -rw-r--r--
Multiple changes. - Remove the runtime dependency on rake-compiler. - Use #rb_str_new instead of #rb_str_new2, the hash character array isn't null terminated. - Add various safeguards for object instantiations. - Remove the 'threaded' options for messages, folding them into 'archived'. If archiving is enabled, so is threading. - Return nil for lookups from the list object instead of raising exceptions. - Open subject indexes with the proper encodings (thanks Michael Granger!) - Allow touching and unlinking files to operate on multiple paths at once, within a single safety() wrap.

# vim: set nosta noet ts=4 sw=4 ft=rspec:

require_relative '../../spec_helpers'


describe Ezmlm::List::Message do

	before( :all ) do
		@listdir = make_listdir()
	end

	after( :all ) do
		rm_r( @listdir )
	end

	let( :list ) do
		Ezmlm::List.new( @listdir )
	end


	context 'instantiating' do

		it 'raises error if provided an unknown list object' do
			expect {
				described_class.new( true, 1 )
			}.to raise_error( ArgumentError, /unknown list/i )
		end

		it 'raises error if given a message number smaller than possible' do
			expect {
				described_class.new( list, -20 )
			}.to raise_error( ArgumentError, /invalid message number \(impossible/i )
			expect {
				described_class.new( list, 0 )
			}.to raise_error( ArgumentError, /invalid message number \(impossible/i )
		end

		it 'raises error if given a message higher than the list count' do
			expect {
				described_class.new( list, 200 )
			}.to raise_error( ArgumentError, /invalid message number \(out of list/i )
		end

		it 'raises error when unable to read message' do
			allow( list ).to receive( :listdir ).and_return( Pathname('/nope') )
			expect( list ).to receive( :message_count ).and_return( 1 )
			expect( list ).to receive( :archived? ).and_return( true )
			expect {
				described_class.new( list, 1 )
			}.to raise_error( RuntimeError, /unable to determine message path/i )
		end

		it 'parses a message from the archive' do
			message = described_class.new( list, 1 )
			expect( message ).to be_a( Ezmlm::List::Message )
		end


		context 'an instance of' do

			let( :message ) { described_class.new( list, 1 ) }

			it 'can be stringified' do
				expect( message.to_s ).to match( /need to copy the wireless/ )
			end

			it 'knows what thread it is a member of' do
				expect( message.thread ).to be_a( Ezmlm::List::Thread )
				expect( message.thread.id ).to eq( 'dipjdfoipmjmlcnacell' )
			end

			it 'knows the author' do
				expect( message.author ).to be_a( Ezmlm::List::Author )
				expect( message.author.id ).to eq( 'odhojfifmnbblilkmbfh' )
			end

			it 'passes all other method calls to the underlying Mail::Message' do
				expect( message.to.first ).to eq( 'testlist@lists.laika.com' )
				expect( message.body.to_s ).to match( /need to copy the wireless/ )
				expect( message.subject ).to match( /Trying to compress/ )
			end
		end
	end
end