spec/ezmlm/list_spec.rb
changeset 4 8c4ae0797d5f
parent 3 9b9e85ccf4f9
child 5 804e1c2b9a40
equal deleted inserted replaced
3:9b9e85ccf4f9 4:8c4ae0797d5f
     7 	libdir = basedir + "lib"
     7 	libdir = basedir + "lib"
     8 	
     8 	
     9 	$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
     9 	$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
    10 }
    10 }
    11 
    11 
       
    12 
    12 begin
    13 begin
       
    14 	require 'tmail'
    13 	require 'spec/runner'
    15 	require 'spec/runner'
    14 	require 'spec/lib/helpers'
    16 	require 'spec/lib/helpers'
    15 	require 'ezmlm/list'
    17 	require 'ezmlm/list'
    16 rescue LoadError
    18 rescue LoadError
    17 	unless Object.const_defined?( :Gem )
    19 	unless Object.const_defined?( :Gem )
   367 	end
   369 	end
   368 	
   370 	
   369 	### 
   371 	### 
   370 	### Archive functions
   372 	### Archive functions
   371 	### 
   373 	### 
   372 	it "can return the count of archived posts"
   374 	describe "archive functions" do
   373 
   375 	
   374 	it "can return a hash of the subjects of all archived posts to message ids"
   376 		before( :each ) do
       
   377 			@listpath = LISTDIR.dup
       
   378 			@list = Ezmlm::List.new( @listpath )
       
   379 		end
       
   380 		
       
   381 		
       
   382 		it "can return the count of archived posts" do
       
   383 			numpath_obj = mock( "num file path object" )
       
   384 			@listpath.should_receive( :+ ).with( 'num' ).and_return( numpath_obj )
       
   385 			
       
   386 			numpath_obj.should_receive( :exist? ).and_return( true )
       
   387 			numpath_obj.should_receive( :read ).and_return( "1723:123123123" )
       
   388 			
       
   389 			@list.message_count.should == 1723
       
   390 		end
       
   391 	
       
   392 		it "can return the count of archived posts to a list that hasn't been posted to" do
       
   393 			numpath_obj = mock( "num file path object" )
       
   394 			@listpath.should_receive( :+ ).with( 'num' ).and_return( numpath_obj )
       
   395 			
       
   396 			numpath_obj.should_receive( :exist? ).and_return( false )
       
   397 			
       
   398 			@list.message_count.should == 0
       
   399 		end
       
   400 		
       
   401 
       
   402 		
       
   403 		TEST_ARCHIVE_DIR = LISTDIR + 'archive'
       
   404 		TEST_ARCHIVE_SUBDIRS = %w[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 ]
       
   405 
       
   406 		before( :each ) do
       
   407 			@archive_dir = TEST_ARCHIVE_DIR.dup
       
   408 			@archive_subdirs = TEST_ARCHIVE_SUBDIRS.dup
       
   409 			@archive_subdir_paths = TEST_ARCHIVE_SUBDIRS.collect {|pn| TEST_ARCHIVE_DIR + pn }
       
   410 			@archive_post_paths = TEST_ARCHIVE_SUBDIRS.collect {|pn|
       
   411 				TEST_ARCHIVE_DIR + TEST_ARCHIVE_SUBDIRS.last + pn
       
   412 			  }
       
   413 		end
       
   414 		
       
   415 
       
   416 		it "can return a TMail::Mail object parsed from the last archived post" do
       
   417 			# need to find the last message
       
   418 			archive_path_obj = mock( "archive path" )
       
   419 
       
   420 			@listpath.should_receive( :+ ).with( 'archive' ).and_return( archive_path_obj )
       
   421 			archive_path_obj.should_receive( :exist? ).and_return( true )
       
   422 
       
   423 			# Find the last numbered directory under the archive dir
       
   424 			archive_path_obj.should_receive( :+ ).with( '[0-9]*' ).
       
   425 				and_return( :archive_dir_globpath )
       
   426 			Pathname.should_receive( :glob ).with( :archive_dir_globpath ).
       
   427 				and_return( @archive_subdir_paths )
       
   428 
       
   429 			# Find the last numbered file under the last numbered directory we found
       
   430 			# above.
       
   431 			@archive_subdir_paths.last.should_receive( :+ ).with( '[0-9]*' ).
       
   432 				and_return( :archive_post_pathglob )
       
   433 			Pathname.should_receive( :glob ).with( :archive_post_pathglob ).
       
   434 				and_return( @archive_post_paths )
       
   435 
       
   436 			TMail::Mail.should_receive( :load ).with( @archive_post_paths.last.to_s ).
       
   437 				and_return( :mail_object )
       
   438 
       
   439 			@list.last_post.should == :mail_object
       
   440 		end
       
   441 		
       
   442 		
       
   443 		it "returns nil for the last post if there is no archive directory for the list" do
       
   444 			archive_path_obj = mock( "archive path" )
       
   445 
       
   446 			@listpath.should_receive( :+ ).with( 'archive' ).and_return( archive_path_obj )
       
   447 			archive_path_obj.should_receive( :exist? ).and_return( false )
       
   448 			@list.last_post.should == nil
       
   449 		end
       
   450 		
       
   451 		
       
   452 		it "returns nil for the last post if there haven't been any posts to the list" do
       
   453 			archive_path_obj = mock( "archive path" )
       
   454 			mail_object = mock( "Mock TMail object" )
       
   455 
       
   456 			@listpath.should_receive( :+ ).with( 'archive' ).and_return( archive_path_obj )
       
   457 			archive_path_obj.should_receive( :exist? ).and_return( true )
       
   458 
       
   459 			# Find the last numbered directory under the archive dir
       
   460 			archive_path_obj.should_receive( :+ ).with( '[0-9]*' ).
       
   461 				and_return( :archive_dir_globpath )
       
   462 			Pathname.should_receive( :glob ).with( :archive_dir_globpath ).and_return( [] )
       
   463 
       
   464 			@list.last_post.should == nil
       
   465 		end
       
   466 		
       
   467 		
       
   468 		it "raises a RuntimeError if the last archive directory doesn't have any messages in it" do
       
   469 			archive_path_obj = mock( "archive path" )
       
   470 			mail_object = mock( "Mock TMail object" )
       
   471 
       
   472 			@listpath.should_receive( :+ ).with( 'archive' ).and_return( archive_path_obj )
       
   473 			archive_path_obj.should_receive( :exist? ).and_return( true )
       
   474 
       
   475 			# Find the last numbered directory under the archive dir
       
   476 			archive_path_obj.should_receive( :+ ).with( '[0-9]*' ).
       
   477 				and_return( :archive_dir_globpath )
       
   478 			Pathname.should_receive( :glob ).with( :archive_dir_globpath ).
       
   479 				and_return( @archive_subdir_paths )
       
   480 
       
   481 			@archive_subdir_paths.last.should_receive( :+ ).with( '[0-9]*' ).
       
   482 				and_return( :archive_post_pathglob )
       
   483 			Pathname.should_receive( :glob ).with( :archive_post_pathglob ).
       
   484 				and_return( [] )
       
   485 
       
   486 			lambda {
       
   487 				@list.last_post
       
   488 			}.should raise_error( RuntimeError, /unexpectedly empty/i )
       
   489 		end
       
   490 		
       
   491 		
       
   492 		it "can fetch the date of the last archived post" do
       
   493 			mail_object = mock( "Mock TMail object" )
       
   494 
       
   495 			@list.should_receive( :last_post ).and_return( mail_object )
       
   496 			mail_object.should_receive( :date ).and_return( :the_message_date )
       
   497 
       
   498 			@list.last_message_date.should == :the_message_date
       
   499 		end
       
   500 
       
   501 		
       
   502 		it "can fetch the date of the last archived post" do
       
   503 			mail_object = mock( "Mock TMail object" )
       
   504 
       
   505 			@list.should_receive( :last_post ).and_return( mail_object )
       
   506 			mail_object.should_receive( :date ).and_return( :the_message_date )
       
   507 
       
   508 			@list.last_message_date.should == :the_message_date
       
   509 		end
       
   510 
       
   511 		
       
   512 		it "can fetch the author of the last archived post" do
       
   513 			mail_object = mock( "Mock TMail object" )
       
   514 
       
   515 			@list.should_receive( :last_post ).and_return( mail_object )
       
   516 			mail_object.should_receive( :from ).and_return( :the_message_author )
       
   517 
       
   518 			@list.last_message_author.should == :the_message_author
       
   519 		end
       
   520 
       
   521 		
       
   522 		it "can fetch the subject of the last archived post" do
       
   523 			mail_object = mock( "Mock TMail object" )
       
   524 
       
   525 			@list.should_receive( :last_post ).and_return( mail_object )
       
   526 			mail_object.should_receive( :from ).and_return( :the_message_author )
       
   527 
       
   528 			@list.last_message_author.should == :the_message_author
       
   529 		end
       
   530 
       
   531 	end
       
   532 
       
   533 
       
   534 	it "can fetch the body of an archived post by message id"
       
   535 	it "can fetch the header of an archived post by message id"
       
   536 	
       
   537 	it "can return a hash of the subjects of all archived posts to message ids" 
   375 	it "can return an Array of the subjects of all archived posts"
   538 	it "can return an Array of the subjects of all archived posts"
   376 
   539 
   377 	it "can return a hash of the threads of all archived posts to message ids"
   540 	it "can return a hash of the threads of all archived posts to message ids"
   378 	it "can return an Array of the threads of all archived posts"
   541 	it "can return an Array of the threads of all archived posts"
   379 
   542 
   380 	it "can return a hash of the authors of all archived posts to message ids"
   543 	it "can return a hash of the authors of all archived posts to message ids"
   381 	it "can return an Array of the authors of all archived posts"
   544 	it "can return an Array of the authors of all archived posts"
   382 
   545 
   383 
       
   384 	it "can fetch the body of an archived post by message id"
       
   385 	it "can fetch the header of an archived post by message id"
       
   386 
       
   387 	it "can fetch the date of the last archived post"
       
   388 	it "can fetch the author of the last archived post"
       
   389 	it "can fetch the subject of the last archived post"
       
   390 
       
   391 end
   546 end
   392 
   547 
   393 
   548