class TestMLProcessor

Public Instance Methods

ok_config(e) click to toggle source
# File vendor/qwik/lib/qwik/ml-processor.rb, line 481
def ok_config(e)
  dir = @config.sites_dir.path
  str = (dir + 'test/_GroupConfig.txt').path.read
  hash = QuickML::GroupConfig.parse_hash(str)
  ok_eq(e, hash)
end
ok_file(e, file) click to toggle source
# File vendor/qwik/lib/qwik/ml-processor.rb, line 475
def ok_file(e, file)
  dir = @config.sites_dir.path
  str = (dir + "test/#{file}").path.read
  ok_eq(e, str)
end
test_all() click to toggle source
# File vendor/qwik/lib/qwik/ml-processor.rb, line 488
    def test_all
      mail = QuickML::Mail.generate {
'From: "Test User" <user@e.com>
To: "Test Mailing List" <test@example.com>
Subject: Test Mail
Date: Mon, 3 Feb 2001 12:34:56 +0900

This is a test.
'
      }
      processor = QuickML::Processor.new(@ml_config, mail)
      processor.process

      ok_file("user@e.com\n", '_GroupMembers.txt')
      ok_config({
                  :auto_unsubscribe_count=>5,
                  :max_mail_length=>102400,
                  :max_members=>100,
                  :ml_alert_time=>2073600,
                  :ml_life_time=>2678400,
                  :forward=>false,
                  :permanent=>false,
                  :unlimited=>false,
                })
    end
test_class_method() click to toggle source
# File vendor/qwik/lib/qwik/ml-processor.rb, line 433
def test_class_method
  c = QuickML::Processor
  eq true, c.unsubscribe_requested?('')
  eq false, c.unsubscribe_requested?('unsubscribe'+' '*489)
  eq false, c.unsubscribe_requested?(' '*499)
  eq false, c.unsubscribe_requested?(' '*500)
  eq true, c.unsubscribe_requested?(' ')
  eq true, c.unsubscribe_requested?("\n")
  eq true, c.unsubscribe_requested?('unsubscribe')
  eq true, c.unsubscribe_requested?(' unsubscribe')
  eq true, c.unsubscribe_requested?('bye')
  eq true, c.unsubscribe_requested?('#bye')
  eq true, c.unsubscribe_requested?('# bye')
  eq true, c.unsubscribe_requested?('退会')
  eq true, c.unsubscribe_requested?('unsubscribe'+' '*488)
  eq false, c.unsubscribe_requested?('unsubscribe desu.')
  eq false, c.unsubscribe_requested?('I want to unsubscribe.')
end
test_ignore_list() click to toggle source
# File vendor/qwik/lib/qwik/ml-processor.rb, line 565
def test_ignore_list
  $test_rejection_ignore_list = ["test"]

  #
  # normal case
  #
  send_normal_mail('bob@example.net')               # Bob creates a new ML.

  sendmail('bob@example.net', 'test@q.example.com', 'test mail') {
    "This is a test."
  }
  eq true, @site.exist?('1')
  eq 'test mail', @site['1'].get_title
  eq "* test mail\n{{mail(bob@example.net,0)\nThis is a test.\n}}\n",
  @site['1'].load

  #
  # sent from alien
  #

  # clear probe
  $quickml_sendmail = nil

  # rejection message should be null
  expected = nil

  input = []
  input << 'alice@example.net' # from
  input << 'test@q.example.com' # to
  input << 'spam mail'      # subject
  inputBody =  'This is spam.'

  sendmail(*input) {
    inputBody
  }
  actual = $quickml_sendmail

  ok_eq(expected, actual)

  # clean up for test suite
  $test_rejection_ignore_list = nil
end
test_instance_method() click to toggle source
# File vendor/qwik/lib/qwik/ml-processor.rb, line 452
    def test_instance_method
      mail = QuickML::Mail.generate {
'From: "Test User" <user@e.com>
To: "Test Mailing List" <test@example.com>
Subject: Test Mail
Date: Mon, 3 Feb 2001 12:34:56 +0900

This is a test.
'
      }
      pro = QuickML::Processor.new(@ml_config, mail)

      # test_to_return_address
      t_make_public(QuickML::Processor, :to_return_address?)
      eq nil, pro.to_return_address?('t@example.com')
      assert pro.to_return_address?('t=return@example.com')

      # test_to_confirmation_address
      t_make_public(QuickML::Processor, :to_confirmation_address?)
      eq nil, pro.to_confirmation_address?('t@example.com')
      assert pro.to_confirmation_address?('confirm+t@example.com')
    end
test_invalid_mlname() click to toggle source
# File vendor/qwik/lib/qwik/ml-processor.rb, line 551
    def test_invalid_mlname
      message = 'From: user@e.com
To: invalid_mlname@example.com
Subject: Test Mail
Date: Mon, 3 Feb 2001 12:34:56 +0900

This is a test.
'
      mail = QuickML::Mail.generate { message }
      processor = QuickML::Processor.new(@ml_config, mail)
      processor.process
      eq "To: user@e.com\nFrom: postmaster@q.example.com\nSubject: [QuickML] Error: Test Mail\nContent-Type: text/plain\n\nInvalid mailing list name: <invalid_mlname@example.com>\nYou can only use 0-9, a-z, A-Z,  `-' for mailing list name\n\n-- \nInfo: http://example.com/\n", $quickml_sendmail[4]
    end
test_with_confirm() click to toggle source
# File vendor/qwik/lib/qwik/ml-processor.rb, line 514
    def test_with_confirm
      message = 'From: "Test User" <user@e.com>
To: "Test Mailing List" <test@example.com>
Subject: Test Mail
Date: Mon, 3 Feb 2001 12:34:56 +0900

This is a test.
'
      mail = QuickML::Mail.generate { message }
      org_confirm_ml_creation = @ml_config[:confirm_ml_creation]
      @ml_config[:confirm_ml_creation] = true

      ".test/data/test".path.rmtree

      processor = QuickML::Processor.new(@ml_config, mail)
      processor.process

      eq "ply to this mail to create ML <test@example.com>.\n",
        $quickml_sendmail[4][-50..9999]

      ok_file('', '_GroupMembers.txt')
      ok_file("user@e.com\n", '_GroupWaitingMembers.txt')
      ok_file(message, '_GroupWaitingMessage.txt')
      h = {
        :auto_unsubscribe_count=>5,
        :max_mail_length=>102400,
        :max_members=>100,
        :ml_alert_time=>2073600,
        :ml_life_time=>2678400,
        :forward=>false,
        :permanent=>false,
        :unlimited=>false,
      }
      ok_config(h)
      @ml_config[:confirm_ml_creation] = org_confirm_ml_creation
    end