Skip to content

Commit

Permalink
Feature/skip validation by domain (#41)
Browse files Browse the repository at this point in the history
* Add skip by domain feature
* Update tests
* Update version
* Update readme
  • Loading branch information
bestwebua authored May 23, 2019
1 parent ef26feb commit 37387d2
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
truemail (0.1.10)
truemail (0.2.0)

GEM
remote: https://rubygems.org/
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The Truemail gem helps you validate emails by regex pattern, presence of domain

- Configurable validator, validate only what you need
- Zero runtime dependencies
- Has simple SMTP debugger
- 100% test coverage

## Installation
Expand Down Expand Up @@ -73,10 +74,10 @@ Truemail.configure do |config|
config.connection_attempts = 3

# Optional parameter. You can predefine which type of validation will be used for domains.
# Available validation types: :regex, :mx, :smtp
# Also you can skip validation by domain. Available validation types: :regex, :mx, :smtp, :skip
# This configuration will be used over current or default validation type parameter
# All of validations for 'somedomain.com' will be processed with mx validation only
config.validation_type_for = { 'somedomain.com' => :mx }
config.validation_type_for = { 'somedomain.com' => :mx, 'otherdomain.com' => :skip }

# Optional parameter. This option will be parse bodies of SMTP errors. It will be helpful
# if SMTP server does not return an exact answer that the email does not exist
Expand Down
1 change: 1 addition & 0 deletions lib/truemail/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module Audit
end

module Validate
require 'truemail/validate/skip'
require 'truemail/validate/base'
require 'truemail/validate/regex'
require 'truemail/validate/mx'
Expand Down
11 changes: 11 additions & 0 deletions lib/truemail/validate/skip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Truemail
module Validate
class Skip < Truemail::Worker
def run
success(true)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/truemail/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Truemail
class Validator
RESULT_ATTRS = %i[success email domain mail_servers errors smtp_debug].freeze
VALIDATION_TYPES = %i[regex mx smtp].freeze
VALIDATION_TYPES = %i[regex mx smtp skip].freeze

Result = Struct.new(*RESULT_ATTRS, keyword_init: true) do
def initialize(errors: {}, mail_servers: [], **args)
Expand Down
2 changes: 1 addition & 1 deletion lib/truemail/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Truemail
VERSION = '0.1.10'
VERSION = '0.2.0'
end
9 changes: 5 additions & 4 deletions spec/truemail/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,14 @@

describe '#validation_type_for=' do
context 'with valid validation type attributes' do
let(:domain_1) { FFaker::Internet.domain_name }
let(:domain_2) { FFaker::Internet.domain_name }
let(:domains_config) do
(1..4).map { FFaker::Internet.unique.domain_name }.zip(%i[regex mx smtp skip]).to_h
end

it 'sets validation type for domain' do
expect { configuration_instance.validation_type_for = { domain_1 => :mx, domain_2 => :regex } }
expect { configuration_instance.validation_type_for = domains_config }
.to change(configuration_instance, :validation_type_by_domain)
.from({}).to({ domain_1 => :mx, domain_2 => :regex })
.from({}).to(domains_config)
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/truemail/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ module Truemail

RSpec.describe Truemail::Validate do
describe 'defined constants' do
specify { expect(described_class).to be_const_defined(:Skip) }
specify { expect(described_class).to be_const_defined(:Base) }
specify { expect(described_class).to be_const_defined(:Regex) }
specify { expect(described_class).to be_const_defined(:Mx) }
Expand Down
17 changes: 17 additions & 0 deletions spec/truemail/validate/skip_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

RSpec.describe Truemail::Validate::Skip do
describe '.check' do
subject(:skip_validator) { described_class.check(result_instance) }

let(:result_instance) { Truemail::Validator::Result.new(email: FFaker::Internet.email) }

specify do
expect { skip_validator }.to change(result_instance, :success).from(nil).to(true)
end

it 'returns true' do
expect(skip_validator).to be(true)
end
end
end

0 comments on commit 37387d2

Please sign in to comment.