<commit_before># frozen_string_literal: true

require "spec_helper"
require "fileutils"

class TestUser < TestModel
  validates :email, 'valid_email_2/email': true
end

class TestUserDotted < TestModel
  validates :email, 'valid_email_2/email': { disallow_dotted: true }
end

class TestUserSubaddressing < TestModel
  validates :email, 'valid_email_2/email': { disallow_subaddressing: true }
end

class TestUserMX < TestModel
  validates :email, 'valid_email_2/email': { mx: true }
end

class TestUserDisallowDisposable < TestModel
  validates :email, 'valid_email_2/email': { disposable: true }
end

class TestUserDisallowDisposableDomain < TestModel
  validates :email, 'valid_email_2/email': { disposable_domain: true }
end

class TestUserDisallowDisposableWithWhitelist < TestModel
  validates :email, 'valid_email_2/email': { disposable_with_whitelist: true }
end

class TestUserDisallowBlacklisted < TestModel
  validates :email, 'valid_email_2/email': { blacklist: true }
end

class TestUserMessage < TestModel
  validates :email, 'valid_email_2/email': { message: "custom message" }
end

class TestUserMultiple < TestModel
  validates :email, 'valid_email_2/email': { multiple: true }
end

describe ValidEmail2 do

  let(:disposable_domain) { ValidEmail2.disposable_emails.first }

  describe "basic validation" do
    subject(:user) { TestUser.new(email: "") }

    it "is valid" do
      user = TestUser.new(email: "<EMAIL>")
      expect(user.valid?).to be_truthy
    end

    it "is invalid if email is empty" do
      expect(user.valid?).to be_truthy
    end

    it "is invalid if domain is missing" do
      user = TestUser.new(email: "foo@.com")
      expect(user.valid?).to be_falsey
    end

    %w[+ _ ! / \  ' `].each do |invalid_character|
      it "is invalid if email contains a \"#{invalid_character}\" character" do
        user = TestUser.new(email: "<EMAIL>#{invalid_character}yahoo.com")
        expect(user.valid?).to be_falsey
      end
    end

    it "is invalid if address is malformed" do
      user = TestUser.new(email: "foo@bar")
      expect(user.valid?).to be_falsey
    end

    it "is invalid if Mail::AddressListsParser raises exception" do
      user = TestUser.new(email: "<EMAIL>")
      expect(Mail::Address).to receive(:new).and_raise(Mail::Field::ParseError.new(nil, nil, nil))
      expect(user.valid?).to be_falsey
    end

    it "is invalid if the domain contains consecutive dots" do
      user = TestUser.new(email: "foo@bar..com")
      expect(user.valid?).to be_falsey
    end

    it "is invalid if the address contains consecutive dots" do
      user = TestUser.new(email: "<EMAIL>")
      expect(user.valid?).to be_falsey
    end

    it "is invalid if the address starts with a dot" do
      user = TestUser.new(email: ".<EMAIL>")
      expect(user.valid?).to be_falsey
    end

    it "is invalid if the email contains emoticons" do
      user = TestUser.new(email: "foo🙈<EMAIL>")
      expect(user.valid?).to be_falsy
    end

    it "is invalid if the domain contains spaces" do
      user = TestUser.new(email: "user@gmail .com")
      expect(user.valid?).to be_falsy
    end

    it "is invalid if the domain contains a forward slash" do
      user = TestUser.new(email: "user@gm/ail.com")
      expect(user.valid?).to be_falsy
    end

    it "is invalid if the domain begins with a dash" do
      user = TestUser.new(email: "<EMAIL>")
      expect(user.valid?).to be_falsy
    end

    it "is invalid if the domain name ends with a dash" do
      user = TestUser.new(email: "<EMAIL>")
      expect(user.valid?).to be_falsy
    end
  end
<commit_msg>test: add missing spec<commit_after># frozen_string_literal: true

require "spec_helper"
require "fileutils"

class TestUser < TestModel
  validates :email, 'valid_email_2/email': true
end

class TestUserDotted < TestModel
  validates :email, 'valid_email_2/email': { disallow_dotted: true }
end

class TestUserSubaddressing < TestModel
  validates :email, 'valid_email_2/email': { disallow_subaddressing: true }
end

class TestUserMX < TestModel
  validates :email, 'valid_email_2/email': { mx: true }
end

class TestUserDisallowDisposable < TestModel
  validates :email, 'valid_email_2/email': { disposable: true }
end

class TestUserDisallowDisposableDomain < TestModel
  validates :email, 'valid_email_2/email': { disposable_domain: true }
end

class TestUserDisallowDisposableWithWhitelist < TestModel
  validates :email, 'valid_email_2/email': { disposable_with_whitelist: true }
end

class TestUserDisallowBlacklisted < TestModel
  validates :email, 'valid_email_2/email': { blacklist: true }
end

class TestUserMessage < TestModel
  validates :email, 'valid_email_2/email': { message: "custom message" }
end

class TestUserMultiple < TestModel
  validates :email, 'valid_email_2/email': { multiple: true }
end

describe ValidEmail2 do

  let(:disposable_domain) { ValidEmail2.disposable_emails.first }

  describe "basic validation" do
    subject(:user) { TestUser.new(email: "") }

    it "is valid" do
      user = TestUser.new(email: "<EMAIL>")
      expect(user.valid?).to be_truthy
    end

    it "is invalid if email is empty" do
      expect(user.valid?).to be_truthy
    end

    it "is invalid if domain is missing" do
      user = TestUser.new(email: "foo<EMAIL>")
      expect(user.valid?).to be_falsey
    end

    %w[+ _ ! / \  ' `].each do |invalid_character|
      it "is invalid if email contains a \"#{invalid_character}\" character" do
        user = TestUser.new(email: "foo@google#{invalid_character}yahoo.com")
        expect(user.valid?).to be_falsey
      end
    end

    it "is invalid if address is malformed" do
      user = TestUser.new(email: "foo@bar")
      expect(user.valid?).to be_falsey
    end

    it "is invalid if Mail::AddressListsParser raises exception" do
      user = TestUser.new(email: "<EMAIL>")
      expect(Mail::Address).to receive(:new).and_raise(Mail::Field::ParseError.new(nil, nil, nil))
      expect(user.valid?).to be_falsey
    end

    it "is invalid if the domain contains consecutive dots" do
      user = TestUser.new(email: "foo@bar..com")
      expect(user.valid?).to be_falsey
    end

    it "is invalid if the address contains consecutive dots" do
      user = TestUser.new(email: "<EMAIL>")
      expect(user.valid?).to be_falsey
    end

    it "is invalid if the address starts with a dot" do
      user = TestUser.new(email: ".<EMAIL>")
      expect(user.valid?).to be_falsey
    end

    it "is invalid if the local part of the address ends with a dot" do
      user = TestUser.new(email: "<EMAIL>")
      expect(user.valid?).to be_falsey
    end

    it "is invalid if the email contains emoticons" do
      user = TestUser.new(email: "<EMAIL>")
      expect(user.valid?).to be_falsy
    end

    it "is invalid if the domain contains spaces" do
      user = TestUser.new(email: "<EMAIL>")
      expect(user.valid?).to be_falsy
    end

    it "is invalid if the domain contains a forward slash" do
      user = TestUser.new(email: "user@gm/ail.com")
      expect(user.valid?).to be_falsy
    end

    it "is invalid if the domain begins with a dash" do
      user = TestUser.new(email: "<EMAIL>")
      expect(user.valid?).to be_falsy
    end

    it "is invalid if the domain name ends with a dash" do
      user = TestUser.new(email: "<EMAIL>")
      expect(user.valid?).to be_falsy
    end
  end

{'fraction_non_alphanumeric': 0.10773181941065153, 'fraction_numerical': 0.0032441200324412004, 'mean_word_length': 3.4652987326493663, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3276350', 'n_tokens_mistral': 2442, 'n_tokens_neox': 2369, 'n_words': 681}