Sha256: 85b53c55e49d9910f5cc728b8c8bf3c0a63adff0e5ebcdbdf6eda679c1d8ec22

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

require 'test_helper'

class EmailValidatorTest < ActiveSupport::TestCase

  test "validating single address" do
    email = Email.new({
      from: "some invalid email address",
      to: "foo@bar.com",
      body: "body",
      subject: "subject"
    })

    assert_equal("some invalid email address", email.from)
    assert_equal(false, email.save)
    assert email.errors[:from].present?
    assert email.errors[:from].first.match("custom message")
  end

  test "validating list addresses" do
    email = Email.new({
      from: "sender@foo.com",
      to: "some invalid email address",
      body: "body",
      subject: "subject"
    })

    assert_equal(1, email.to.length)
    assert_equal(["some invalid email address"], email.to.addresses)
    assert_equal(false, email.save)
    assert email.errors[:to].present?
    assert email.errors[:to].first.match("another message")
  end

  test "validating several addresses" do
    email = Email.new({
      from: "sender@foo.com",
      to: "some invalid email address, valid@foo.com",
      body: "body",
      subject: "subject"
    })

    assert_equal(2, email.to.length)
    assert_equal(false, email.save)
    assert email.errors[:to].present?
    assert email.errors[:to].first.match("another message")
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
email_attribute-0.0.2 test/unit/email_validator_test.rb
email_attribute-0.0.1 test/unit/email_validator_test.rb