spec/ezmlm/list_spec.rb
author Michael Granger <mgranger@laika.com>
Fri, 09 May 2008 17:51:36 +0000
changeset 4 8c4ae0797d5f
parent 3 9b9e85ccf4f9
child 5 804e1c2b9a40
permissions -rw-r--r--
Added more archive-related functions: - Fetch the last post to the list - Fetch date/author/subject of the last post to the list - Fetch message count
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     1
#!/usr/bin/env ruby
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     2
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     3
BEGIN {
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     4
	require 'pathname'
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     5
	basedir = Pathname.new( __FILE__ ).dirname.parent.parent
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     6
	
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     7
	libdir = basedir + "lib"
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     8
	
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     9
	$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    10
}
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    11
4
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
    12
1
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    13
begin
4
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
    14
	require 'tmail'
1
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    15
	require 'spec/runner'
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    16
	require 'spec/lib/helpers'
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    17
	require 'ezmlm/list'
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    18
rescue LoadError
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    19
	unless Object.const_defined?( :Gem )
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    20
		require 'rubygems'
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    21
		retry
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    22
	end
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    23
	raise
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    24
end
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    25
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    26
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    27
describe Ezmlm::List do
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    28
	include Ezmlm::SpecHelpers
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    29
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    30
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    31
	LISTDIR = Pathname.new( 'list' )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    32
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    33
	TEST_SUBSCRIBERS = %w[
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    34
		pete.chaffee@toadsmackers.com
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    35
		dolphinzombie@alahalohamorra.com
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    36
		piratebanker@yahoo.com
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    37
	  ]
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    38
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    39
	TEST_MODERATORS = %w[
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    40
		dolphinzombie@alahalohamorra.com
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    41
	  ]
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    42
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    43
	TEST_OWNER = 'listowner@rumpus-the-whale.info'
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    44
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    45
	TEST_CUSTOM_MODERATORS_DIR = '/foo/bar/clowns'
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    46
		
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    47
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    48
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    49
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    50
	it "can create a new list"
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    51
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    52
	### 
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    53
	### List manager functions
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    54
	### 
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    55
	describe "list manager functions" do
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    56
		
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    57
		before( :each ) do
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    58
			@listpath = LISTDIR.dup
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    59
			@list = Ezmlm::List.new( @listpath )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    60
		end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    61
		
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    62
		
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    63
		it "can return a list of subscribers' email addresses" do
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    64
			subscribers_dir = LISTDIR + 'subscribers'
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    65
			
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    66
			expectation = Pathname.should_receive( :glob ).with( subscribers_dir + '*' )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    67
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    68
			TEST_SUBSCRIBERS.each do |email|
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    69
				mock_subfile = mock( "Mock subscribers file for '#{email}'" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    70
				mock_subfile.should_receive( :read ).and_return( "T#{email}\0" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    71
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    72
				expectation.and_yield( mock_subfile )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    73
			end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    74
				
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    75
			subscribers = @list.subscribers
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    76
			
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    77
			subscribers.should have(TEST_SUBSCRIBERS.length).members
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    78
			subscribers.should include( *TEST_SUBSCRIBERS )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    79
		end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    80
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    81
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    82
		### Subscriber moderation
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    83
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    84
		it "knows that subscription moderation is enabled if the dir/modsub file exists" do
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    85
			modsub_path_obj = mock( "Mock 'modsub' path object" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    86
			@listpath.should_receive( :+ ).with( 'modsub' ).and_return( modsub_path_obj )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    87
			modsub_path_obj.should_receive( :exist? ).and_return( true )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    88
			
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    89
			@list.should be_closed()
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    90
		end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    91
		
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    92
		it "knows that subscription moderation is enabled if the dir/remote file exists" do
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    93
			modsub_path_obj = mock( "Mock 'modsub' path object" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    94
			@listpath.should_receive( :+ ).with( 'modsub' ).and_return( modsub_path_obj )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    95
			modsub_path_obj.should_receive( :exist? ).and_return( false )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    96
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    97
			remote_path_obj = mock( "Mock 'remote' path object" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    98
			@listpath.should_receive( :+ ).with( 'remote' ).and_return( remote_path_obj )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    99
			remote_path_obj.should_receive( :exist? ).and_return( true )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   100
			
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   101
			@list.should be_closed()
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   102
		end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   103
		
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   104
		
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   105
		it "knows that subscription moderation is disabled if neither the dir/modsub nor " +
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   106
		   "dir/remote files exist" do
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   107
			modsub_path_obj = mock( "Mock 'modsub' path object" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   108
			@listpath.should_receive( :+ ).with( 'modsub' ).and_return( modsub_path_obj )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   109
			modsub_path_obj.should_receive( :exist? ).and_return( false )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   110
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   111
			remote_path_obj = mock( "Mock 'remote' path object" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   112
			@listpath.should_receive( :+ ).with( 'remote' ).and_return( remote_path_obj )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   113
			remote_path_obj.should_receive( :exist? ).and_return( false )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   114
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   115
			@list.should_not be_closed()
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   116
		end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   117
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   118
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   119
		it "returns an empty array of subscription moderators for an open list" do
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   120
			modsub_path_obj = mock( "Mock 'modsub' path object" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   121
			@listpath.should_receive( :+ ).with( 'modsub' ).and_return( modsub_path_obj )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   122
			modsub_path_obj.should_receive( :exist? ).and_return( false )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   123
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   124
			remote_path_obj = mock( "Mock 'remote' path object" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   125
			@listpath.should_receive( :+ ).with( 'remote' ).and_return( remote_path_obj )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   126
			remote_path_obj.should_receive( :exist? ).and_return( false )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   127
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   128
			@list.subscription_moderators.should be_empty()
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   129
		end
1
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   130
	
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   131
		it "can return a list of subscription moderators' email addresses" do
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   132
			# Test the moderation config files for existence
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   133
			modsub_path_obj = mock( "Mock 'modsub' path object" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   134
			@listpath.should_receive( :+ ).with( 'modsub' ).twice.and_return( modsub_path_obj )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   135
			modsub_path_obj.should_receive( :exist? ).twice.and_return( true )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   136
			remote_path_obj = mock( "Mock 'remote' path object" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   137
			@listpath.should_receive( :+ ).with( 'remote' ).and_return( remote_path_obj )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   138
			remote_path_obj.should_receive( :exist? ).once.and_return( true )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   139
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   140
			# Try to read directory names from both config files
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   141
			modsub_path_obj.should_receive( :read ).with( 1 ).and_return( nil )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   142
			remote_path_obj.should_receive( :read ).with( 1 ).and_return( nil )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   143
			
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   144
			# Read subscribers from the default directory
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   145
			subscribers_dir = mock( "Mock moderator subscribers directory" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   146
			@listpath.should_receive( :+ ).with( 'mod/subscribers' ).and_return( subscribers_dir )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   147
			subscribers_dir.should_receive( :+ ).with( '*' ).and_return( :mod_sub_dir )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   148
			expectation = Pathname.should_receive( :glob ).with( :mod_sub_dir )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   149
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   150
			TEST_MODERATORS.each do |email|
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   151
				mock_subfile = mock( "Mock subscribers file for '#{email}'" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   152
				mock_subfile.should_receive( :read ).and_return( "T#{email}\0" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   153
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   154
				expectation.and_yield( mock_subfile )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   155
			end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   156
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   157
			mods = @list.subscription_moderators
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   158
			mods.should have(TEST_MODERATORS.length).members
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   159
			mods.should include( *TEST_MODERATORS )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   160
		end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   161
		
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   162
		
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   163
		it "can return a list of subscription moderators' email addresses when the moderators " +
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   164
		   "directory has been customized" do
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   165
			# Test the moderation config files for existence
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   166
			modsub_path_obj = mock( "Mock 'modsub' path object" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   167
			@listpath.should_receive( :+ ).with( 'modsub' ).twice.and_return( modsub_path_obj )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   168
			modsub_path_obj.should_receive( :exist? ).twice.and_return( true )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   169
			@listpath.should_receive( :+ ).with( 'remote' )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   170
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   171
			# Try to read directory names from both config files
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   172
			modsub_path_obj.should_receive( :read ).with( 1 ).and_return( '/' )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   173
			modsub_path_obj.should_receive( :read ).with().and_return( TEST_CUSTOM_MODERATORS_DIR )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   174
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   175
			custom_mod_path = mock( "Mock path object for customized moderator dir" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   176
			Pathname.should_receive( :new ).with( TEST_CUSTOM_MODERATORS_DIR ).and_return( custom_mod_path )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   177
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   178
			# Read subscribers from the default file
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   179
			custom_mod_path.should_receive( :+ ).with( '*' ).and_return( :mod_sub_dir )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   180
			expectation = Pathname.should_receive( :glob ).with( :mod_sub_dir )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   181
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   182
			TEST_MODERATORS.each do |email|
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   183
				mock_subfile = mock( "Mock subscribers file for '#{email}'" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   184
				mock_subfile.should_receive( :read ).and_return( "T#{email}\0" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   185
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   186
				expectation.and_yield( mock_subfile )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   187
			end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   188
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   189
			mods = @list.subscription_moderators
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   190
			mods.should have(TEST_MODERATORS.length).members
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   191
			mods.should include( *TEST_MODERATORS )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   192
		end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   193
		
3
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   194
		it "can get a list of modererators when remote subscription moderation is enabled" +
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   195
           " and the modsub configuration is empty" do
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   196
			# Test the moderation config files for existence
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   197
			modsub_path_obj = mock( "Mock 'modsub' path object" )
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   198
			@listpath.should_receive( :+ ).with( 'modsub' ).twice.and_return( modsub_path_obj )
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   199
			modsub_path_obj.should_receive( :exist? ).twice.and_return( false )
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   200
            remote_path_obj = mock( "Mock 'remote' path object" )
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   201
			@listpath.should_receive( :+ ).with( 'remote' ).twice.and_return( remote_path_obj )
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   202
            remote_path_obj.should_receive( :exist? ).twice.and_return( true )
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   203
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   204
			# Try to read directory names from both config files
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   205
			remote_path_obj.should_receive( :read ).with( 1 ).and_return( '/' )
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   206
			remote_path_obj.should_receive( :read ).with().and_return( TEST_CUSTOM_MODERATORS_DIR )
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   207
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   208
			custom_mod_path = mock( "Mock path object for customized moderator dir" )
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   209
			Pathname.should_receive( :new ).with( TEST_CUSTOM_MODERATORS_DIR ).and_return( custom_mod_path )
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   210
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   211
			# Read subscribers from the default file
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   212
			custom_mod_path.should_receive( :+ ).with( '*' ).and_return( :mod_sub_dir )
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   213
			expectation = Pathname.should_receive( :glob ).with( :mod_sub_dir )
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   214
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   215
			TEST_MODERATORS.each do |email|
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   216
				mock_subfile = mock( "Mock subscribers file for '#{email}'" )
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   217
				mock_subfile.should_receive( :read ).and_return( "T#{email}\0" )
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   218
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   219
				expectation.and_yield( mock_subfile )
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   220
			end
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   221
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   222
			mods = @list.subscription_moderators
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   223
			mods.should have(TEST_MODERATORS.length).members
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   224
			mods.should include( *TEST_MODERATORS )
9b9e85ccf4f9 Add a test for a customized moderator's directory in the dir/remote file.
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   225
		end
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   226
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   227
		### Message moderation
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   228
		
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   229
		it "knows that subscription moderation is enabled if the dir/modpost file exists" do
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   230
			modpost_path_obj = mock( "Mock 'modpost' path object" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   231
			@listpath.should_receive( :+ ).with( 'modpost' ).and_return( modpost_path_obj )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   232
			modpost_path_obj.should_receive( :exist? ).and_return( true )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   233
			
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   234
			@list.should be_moderated()
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   235
		end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   236
		
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   237
		it "knows that subscription moderation is disabled if the dir/modpost file doesn't exist" do
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   238
			modpost_path_obj = mock( "Mock 'modpost' path object" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   239
			@listpath.should_receive( :+ ).with( 'modpost' ).and_return( modpost_path_obj )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   240
			modpost_path_obj.should_receive( :exist? ).and_return( false )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   241
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   242
			@list.should_not be_moderated()
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   243
		end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   244
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   245
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   246
		it "returns an empty array of message moderators for an open list" do
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   247
			modpost_path_obj = mock( "Mock 'modpost' path object" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   248
			@listpath.should_receive( :+ ).with( 'modpost' ).and_return( modpost_path_obj )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   249
			modpost_path_obj.should_receive( :exist? ).and_return( false )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   250
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   251
			@list.message_moderators.should be_empty()
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   252
		end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   253
	
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   254
	
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   255
		it "can return a list of message moderators' email addresses" do
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   256
			# Test the moderation config file for existence
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   257
			modpost_path_obj = mock( "Mock 'modpost' path object" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   258
			@listpath.should_receive( :+ ).with( 'modpost' ).twice.and_return( modpost_path_obj )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   259
			modpost_path_obj.should_receive( :exist? ).twice.and_return( true )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   260
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   261
			# Try to read directory names from the config file
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   262
			modpost_path_obj.should_receive( :read ).with( 1 ).and_return( nil )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   263
			
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   264
			# Read subscribers from the default directory
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   265
			subscribers_dir = mock( "Mock moderator subscribers directory" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   266
			@listpath.should_receive( :+ ).with( 'mod/subscribers' ).and_return( subscribers_dir )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   267
			subscribers_dir.should_receive( :+ ).with( '*' ).and_return( :mod_sub_dir )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   268
			expectation = Pathname.should_receive( :glob ).with( :mod_sub_dir )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   269
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   270
			TEST_MODERATORS.each do |email|
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   271
				mock_subfile = mock( "Mock subscribers file for '#{email}'" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   272
				mock_subfile.should_receive( :read ).and_return( "T#{email}\0" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   273
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   274
				expectation.and_yield( mock_subfile )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   275
			end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   276
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   277
			mods = @list.message_moderators
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   278
			mods.should have(TEST_MODERATORS.length).members
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   279
			mods.should include( *TEST_MODERATORS )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   280
		end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   281
		
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   282
		
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   283
		it "can return a list of message moderators' email addresses when the moderators " +
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   284
		   "directory has been customized" do
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   285
			# Test the moderation config files for existence
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   286
			modpost_path_obj = mock( "Mock 'modpost' path object" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   287
			@listpath.should_receive( :+ ).with( 'modpost' ).twice.and_return( modpost_path_obj )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   288
			modpost_path_obj.should_receive( :exist? ).twice.and_return( true )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   289
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   290
			# Try to read directory names from both config files
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   291
			modpost_path_obj.should_receive( :read ).with( 1 ).and_return( '/' )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   292
			modpost_path_obj.should_receive( :read ).with().and_return( TEST_CUSTOM_MODERATORS_DIR )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   293
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   294
			custom_mod_path = mock( "Mock path object for customized moderator dir" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   295
			Pathname.should_receive( :new ).with( TEST_CUSTOM_MODERATORS_DIR ).and_return( custom_mod_path )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   296
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   297
			# Read subscribers from the default file
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   298
			custom_mod_path.should_receive( :+ ).with( '*' ).and_return( :mod_sub_dir )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   299
			expectation = Pathname.should_receive( :glob ).with( :mod_sub_dir )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   300
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   301
			TEST_MODERATORS.each do |email|
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   302
				mock_subfile = mock( "Mock subscribers file for '#{email}'" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   303
				mock_subfile.should_receive( :read ).and_return( "T#{email}\0" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   304
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   305
				expectation.and_yield( mock_subfile )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   306
			end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   307
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   308
			mods = @list.message_moderators
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   309
			mods.should have(TEST_MODERATORS.length).members
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   310
			mods.should include( *TEST_MODERATORS )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   311
		end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   312
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   313
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   314
		### List owner
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   315
		
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   316
		TEST_CONFIG_WITHOUT_OWNER = <<-"EOF".gsub( /^\t+/, '' )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   317
		F:-aBCDeFGHijKlMnOpQrStUVWXYZ
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   318
		X:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   319
		D:/var/qmail/alias/lists/waffle-lovers/
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   320
		T:/var/qmail/alias/.qmail-waffle-lovers
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   321
		L:waffle-lovers
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   322
		H:lists.syrup.info
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   323
		C:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   324
		0:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   325
		3:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   326
		4:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   327
		5:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   328
		6:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   329
		7:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   330
		8:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   331
		9:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   332
		EOF
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   333
		
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   334
		it "returns nil when the list doesn't have an owner in its config" do
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   335
			config_path_obj = mock( "Config path object" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   336
			@listpath.should_receive( :+ ).with( 'config' ).and_return( config_path_obj )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   337
			config_path_obj.should_receive( :read ).and_return( TEST_CONFIG_WITHOUT_OWNER )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   338
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   339
			@list.owner.should == nil
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   340
		end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   341
		
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   342
			
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   343
		TEST_CONFIG_WITH_OWNER = <<-"EOF".gsub( /^\t+/, '' )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   344
		F:-aBCDeFGHijKlMnOpQrStUVWXYZ
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   345
		X:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   346
		D:/var/qmail/alias/lists/waffle-lovers/
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   347
		T:/var/qmail/alias/.qmail-waffle-lovers
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   348
		L:waffle-lovers
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   349
		H:lists.syrup.info
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   350
		C:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   351
		0:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   352
		3:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   353
		4:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   354
		5:#{TEST_OWNER}
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   355
		6:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   356
		7:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   357
		8:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   358
		9:
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   359
		EOF
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   360
		
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   361
		it "can return the email address of the list owner" do
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   362
			config_path_obj = mock( "Config path object" )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   363
			@listpath.should_receive( :+ ).with( 'config' ).and_return( config_path_obj )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   364
			config_path_obj.should_receive( :read ).and_return( TEST_CONFIG_WITH_OWNER )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   365
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   366
			@list.owner.should == TEST_OWNER
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   367
		end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   368
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   369
	end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   370
	
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   371
	### 
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   372
	### Archive functions
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   373
	### 
4
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   374
	describe "archive functions" do
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   375
	
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   376
		before( :each ) do
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   377
			@listpath = LISTDIR.dup
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   378
			@list = Ezmlm::List.new( @listpath )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   379
		end
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   380
		
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   381
		
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   382
		it "can return the count of archived posts" do
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   383
			numpath_obj = mock( "num file path object" )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   384
			@listpath.should_receive( :+ ).with( 'num' ).and_return( numpath_obj )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   385
			
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   386
			numpath_obj.should_receive( :exist? ).and_return( true )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   387
			numpath_obj.should_receive( :read ).and_return( "1723:123123123" )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   388
			
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   389
			@list.message_count.should == 1723
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   390
		end
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   391
	
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   392
		it "can return the count of archived posts to a list that hasn't been posted to" do
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   393
			numpath_obj = mock( "num file path object" )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   394
			@listpath.should_receive( :+ ).with( 'num' ).and_return( numpath_obj )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   395
			
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   396
			numpath_obj.should_receive( :exist? ).and_return( false )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   397
			
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   398
			@list.message_count.should == 0
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   399
		end
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   400
		
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   401
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   402
		
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   403
		TEST_ARCHIVE_DIR = LISTDIR + 'archive'
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   404
		TEST_ARCHIVE_SUBDIRS = %w[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 ]
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   405
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   406
		before( :each ) do
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   407
			@archive_dir = TEST_ARCHIVE_DIR.dup
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   408
			@archive_subdirs = TEST_ARCHIVE_SUBDIRS.dup
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   409
			@archive_subdir_paths = TEST_ARCHIVE_SUBDIRS.collect {|pn| TEST_ARCHIVE_DIR + pn }
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   410
			@archive_post_paths = TEST_ARCHIVE_SUBDIRS.collect {|pn|
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   411
				TEST_ARCHIVE_DIR + TEST_ARCHIVE_SUBDIRS.last + pn
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   412
			  }
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   413
		end
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   414
		
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   415
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   416
		it "can return a TMail::Mail object parsed from the last archived post" do
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   417
			# need to find the last message
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   418
			archive_path_obj = mock( "archive path" )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   419
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   420
			@listpath.should_receive( :+ ).with( 'archive' ).and_return( archive_path_obj )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   421
			archive_path_obj.should_receive( :exist? ).and_return( true )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   422
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   423
			# Find the last numbered directory under the archive dir
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   424
			archive_path_obj.should_receive( :+ ).with( '[0-9]*' ).
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   425
				and_return( :archive_dir_globpath )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   426
			Pathname.should_receive( :glob ).with( :archive_dir_globpath ).
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   427
				and_return( @archive_subdir_paths )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   428
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   429
			# Find the last numbered file under the last numbered directory we found
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   430
			# above.
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   431
			@archive_subdir_paths.last.should_receive( :+ ).with( '[0-9]*' ).
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   432
				and_return( :archive_post_pathglob )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   433
			Pathname.should_receive( :glob ).with( :archive_post_pathglob ).
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   434
				and_return( @archive_post_paths )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   435
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   436
			TMail::Mail.should_receive( :load ).with( @archive_post_paths.last.to_s ).
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   437
				and_return( :mail_object )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   438
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   439
			@list.last_post.should == :mail_object
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   440
		end
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   441
		
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   442
		
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   443
		it "returns nil for the last post if there is no archive directory for the list" do
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   444
			archive_path_obj = mock( "archive path" )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   445
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   446
			@listpath.should_receive( :+ ).with( 'archive' ).and_return( archive_path_obj )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   447
			archive_path_obj.should_receive( :exist? ).and_return( false )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   448
			@list.last_post.should == nil
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   449
		end
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   450
		
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   451
		
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   452
		it "returns nil for the last post if there haven't been any posts to the list" do
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   453
			archive_path_obj = mock( "archive path" )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   454
			mail_object = mock( "Mock TMail object" )
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   455
4
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   456
			@listpath.should_receive( :+ ).with( 'archive' ).and_return( archive_path_obj )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   457
			archive_path_obj.should_receive( :exist? ).and_return( true )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   458
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   459
			# Find the last numbered directory under the archive dir
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   460
			archive_path_obj.should_receive( :+ ).with( '[0-9]*' ).
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   461
				and_return( :archive_dir_globpath )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   462
			Pathname.should_receive( :glob ).with( :archive_dir_globpath ).and_return( [] )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   463
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   464
			@list.last_post.should == nil
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   465
		end
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   466
		
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   467
		
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   468
		it "raises a RuntimeError if the last archive directory doesn't have any messages in it" do
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   469
			archive_path_obj = mock( "archive path" )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   470
			mail_object = mock( "Mock TMail object" )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   471
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   472
			@listpath.should_receive( :+ ).with( 'archive' ).and_return( archive_path_obj )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   473
			archive_path_obj.should_receive( :exist? ).and_return( true )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   474
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   475
			# Find the last numbered directory under the archive dir
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   476
			archive_path_obj.should_receive( :+ ).with( '[0-9]*' ).
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   477
				and_return( :archive_dir_globpath )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   478
			Pathname.should_receive( :glob ).with( :archive_dir_globpath ).
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   479
				and_return( @archive_subdir_paths )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   480
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   481
			@archive_subdir_paths.last.should_receive( :+ ).with( '[0-9]*' ).
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   482
				and_return( :archive_post_pathglob )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   483
			Pathname.should_receive( :glob ).with( :archive_post_pathglob ).
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   484
				and_return( [] )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   485
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   486
			lambda {
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   487
				@list.last_post
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   488
			}.should raise_error( RuntimeError, /unexpectedly empty/i )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   489
		end
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   490
		
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   491
		
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   492
		it "can fetch the date of the last archived post" do
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   493
			mail_object = mock( "Mock TMail object" )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   494
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   495
			@list.should_receive( :last_post ).and_return( mail_object )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   496
			mail_object.should_receive( :date ).and_return( :the_message_date )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   497
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   498
			@list.last_message_date.should == :the_message_date
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   499
		end
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   500
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   501
		
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   502
		it "can fetch the date of the last archived post" do
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   503
			mail_object = mock( "Mock TMail object" )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   504
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   505
			@list.should_receive( :last_post ).and_return( mail_object )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   506
			mail_object.should_receive( :date ).and_return( :the_message_date )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   507
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   508
			@list.last_message_date.should == :the_message_date
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   509
		end
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   510
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   511
		
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   512
		it "can fetch the author of the last archived post" do
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   513
			mail_object = mock( "Mock TMail object" )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   514
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   515
			@list.should_receive( :last_post ).and_return( mail_object )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   516
			mail_object.should_receive( :from ).and_return( :the_message_author )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   517
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   518
			@list.last_message_author.should == :the_message_author
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   519
		end
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   520
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   521
		
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   522
		it "can fetch the subject of the last archived post" do
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   523
			mail_object = mock( "Mock TMail object" )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   524
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   525
			@list.should_receive( :last_post ).and_return( mail_object )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   526
			mail_object.should_receive( :from ).and_return( :the_message_author )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   527
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   528
			@list.last_message_author.should == :the_message_author
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   529
		end
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   530
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   531
	end
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   532
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   533
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   534
	it "can fetch the body of an archived post by message id"
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   535
	it "can fetch the header of an archived post by message id"
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   536
	
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 3
diff changeset
   537
	it "can return a hash of the subjects of all archived posts to message ids" 
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   538
	it "can return an Array of the subjects of all archived posts"
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   539
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   540
	it "can return a hash of the threads of all archived posts to message ids"
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   541
	it "can return an Array of the threads of all archived posts"
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   542
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   543
	it "can return a hash of the authors of all archived posts to message ids"
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   544
	it "can return an Array of the authors of all archived posts"
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   545
1
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   546
end
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   547
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   548