Skip to content

Commit

Permalink
Feature/Ability to create ListMatch validation instances (#47)
Browse files Browse the repository at this point in the history
* Added support for ListMatch validation layer
* Updated runtime/development dependencies
* Updated circleci/codeclimate configs
* Updated gem readme, version, changelog
  • Loading branch information
bestwebua authored Oct 25, 2022
1 parent 69cc5b9 commit 9683dda
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
- checkout
- <<: *use_compatible_gemspec
- ruby/install-deps:
bundler-version: "2.3.23"
bundler-version: "2.3.24"
with-cache: false
path: './vendor/custom_bundle'
- run:
Expand Down
2 changes: 1 addition & 1 deletion .circleci/gemspec_compatible
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Gem::Specification.new do |spec|

spec.add_runtime_dependency 'ffaker', '~> 2.21'
spec.add_runtime_dependency 'rspec', '~> 3.11'
spec.add_runtime_dependency 'truemail', '~> 2.7', '>= 2.7.4'
spec.add_runtime_dependency 'truemail', '~> 3.0'

spec.add_development_dependency 'ffaker', '~> 2.21'
spec.add_development_dependency 'pry-byebug', '~> 3.9'
Expand Down
4 changes: 2 additions & 2 deletions .circleci/gemspec_latest
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'ffaker', '~> 2.21'
spec.add_runtime_dependency 'net-smtp', '~> 0.3.2'
spec.add_runtime_dependency 'rspec', '~> 3.11'
spec.add_runtime_dependency 'truemail', '~> 2.7', '>= 2.7.4'
spec.add_runtime_dependency 'truemail', '~> 3.0'

spec.add_development_dependency 'bundler-audit', '~> 0.9.1'
spec.add_development_dependency 'fasterer', '~> 0.10.0'
Expand All @@ -42,7 +42,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
spec.add_development_dependency 'reek', '~> 6.1', '>= 6.1.1'
spec.add_development_dependency 'rspec', '~> 3.11'
spec.add_development_dependency 'rubocop', '~> 1.36'
spec.add_development_dependency 'rubocop', '~> 1.37'
spec.add_development_dependency 'rubocop-performance', '~> 1.15'
spec.add_development_dependency 'rubocop-rspec', '~> 2.13', '>= 2.13.2'
spec.add_development_dependency 'simplecov', '~> 0.21.2'
Expand Down
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ checks:
plugins:
rubocop:
enabled: true
channel: rubocop-1-36
channel: rubocop-1-37

reek:
enabled: true
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 2022-10-25

### Added

- Ability to create `Truemail::Validator` instance for `Whitelist/Blacklist` validation layer

### Updated

- Updated `Truemail::RSpec::ValidatorHelper::ValidatorFactory#process_validator_params`, tests
- Updated gem runtime dependencies
- Updated gem development dependencies
- Updated gem readme, gem version

## [0.9.2] - 2022-10-09

### Updated
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ create_servers_list(42) # => returns array with 42 random ip addresses

```ruby
create_validator(
validation_type, # optional, type:Symbol, can be :whitelist, :regex, :mx, :mx_blacklist or :smtp, by default creates :smtp validation
validation_type, # optional, type:Symbol, can be :emails_list, :domains_list, :regex, :mx, :mx_blacklist or :smtp, by default creates :smtp validation
email, # optional, type:String, by default random email
mail_servers, # optional, type:Array(String), by default array with random ip addresses
success: true, # optional, type:Bool, by default true
Expand Down
14 changes: 9 additions & 5 deletions lib/truemail/rspec/validator_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Truemail
module RSpec
module ValidatorHelper
VALIDATION_LIST_TYPE_REGEX_PATTERN = /(emails|domains)(_list)/.freeze

def create_servers_list(size = nil)
::Array.new(size || ::Random.rand(1..4)) { ::FFaker::Internet.ip_v4_address }
end
Expand Down Expand Up @@ -122,13 +124,15 @@ def build
attr_reader :success, :email, :mail_servers, :configuration
attr_accessor :validation_type

def process_validator_params
def process_validator_params # rubocop:disable Metrics/AbcSize
case validation_type
when :whitelist
when Truemail::RSpec::ValidatorHelper::VALIDATION_LIST_TYPE_REGEX_PATTERN
list_type = validation_type[Truemail::RSpec::ValidatorHelper::VALIDATION_LIST_TYPE_REGEX_PATTERN, 1]
self.validation_type = nil
method = success ? :whitelisted_domains : :blacklisted_domains
domain = email[Truemail::RegexConstant::REGEX_EMAIL_PATTERN, 3]
configuration.tap { |config| config.public_send(method) << domain }
method = success ? :"whitelisted_#{list_type}" : :"blacklisted_#{list_type}"
configuration.tap do |config|
config.public_send(method) << (list_type.eql?('emails') ? email : email[Truemail::RegexConstant::REGEX_EMAIL_PATTERN, 3])
end
when :mx_blacklist
configuration.blacklisted_mx_ip_addresses.push(*mail_servers) unless success
end
Expand Down
2 changes: 1 addition & 1 deletion lib/truemail/rspec/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Truemail
module RSpec
VERSION = '0.9.2'
VERSION = '1.0.0'
end
end
73 changes: 55 additions & 18 deletions spec/truemail/rspec/validator_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# frozen_string_literal: true

RSpec.describe Truemail::RSpec::ValidatorHelper, type: :helper do
describe 'defined constants' do
it { expect(described_class).to be_const_defined(:VALIDATION_LIST_TYPE_REGEX_PATTERN) }
end

describe '#create_servers_list' do
context 'without size' do
subject(:servers_list) { create_servers_list }
Expand Down Expand Up @@ -36,6 +40,7 @@
let(:validator_instance_result) { validator_instance.result }
let(:validator_instance_result_configuration) { validator_instance_result.configuration }
let(:success_status) { true }
let(:expected_vlidation_type) { validation_type }

shared_examples 'successful validator instance' do
it 'creates successful validator instance' do
Expand All @@ -44,19 +49,35 @@
expect(validator_instance_result.errors).to be_empty
expect(validator_instance_result.smtp_debug).to be_nil
expect(validator_instance_result_configuration).to be_an_instance_of(Truemail::Configuration)
expect(validator_instance.validation_type).to eq(validation_type)
expect(validator_instance.validation_type).to eq(expected_vlidation_type)
end
end

context 'with whitelist validation type' do
let(:validation_type) { :whitelist }
context 'with list match validation type' do
let(:expected_vlidation_type) { :whitelist }

include_examples 'successful validator instance'
context 'with emails list validation type' do
let(:validation_type) { :emails_list }

it 'has necessary validator instance result attributes' do
expect(validator_instance_result.domain).not_to be_nil
expect(validator_instance_result.mail_servers).to be_empty
expect(validator_instance_result_configuration.whitelisted_domains).not_to be_empty
include_examples 'successful validator instance'

it 'has necessary validator instance result attributes' do
expect(validator_instance_result.domain).to be_nil
expect(validator_instance_result.mail_servers).to be_empty
expect(validator_instance_result_configuration.whitelisted_emails).not_to be_empty
end
end

context 'with domains list validation type' do
let(:validation_type) { :domains_list }

include_examples 'successful validator instance'

it 'has necessary validator instance result attributes' do
expect(validator_instance_result.domain).not_to be_nil
expect(validator_instance_result.mail_servers).to be_empty
expect(validator_instance_result_configuration.whitelisted_domains).not_to be_empty
end
end
end

Expand Down Expand Up @@ -131,18 +152,34 @@
end
end

context 'with whitelist validation type' do
let(:validation_type) { :whitelist }
context 'with list match validation type' do
let(:expected_vlidation_type) { :whitelist }

include_examples 'fail validator instance'
shared_examples 'has necessary validator instance result attributes' do
it 'has necessary validator instance result attributes' do
expect(validator_instance_result.domain).not_to be_nil
expect(validator_instance_result.errors).to include(:list_match)
expect(validator_instance_result.mail_servers).to be_empty
expect(validator_instance_result.smtp_debug).to be_nil
expect(target_blacklist).not_to be_empty
expect(validator_instance.validation_type).to eq(:blacklist)
end
end

it 'has necessary validator instance result attributes' do
expect(validator_instance_result.domain).not_to be_nil
expect(validator_instance_result.errors).to include(:domain_list_match)
expect(validator_instance_result.mail_servers).to be_empty
expect(validator_instance_result.smtp_debug).to be_nil
expect(validator_instance_result_configuration.blacklisted_domains).not_to be_empty
expect(validator_instance.validation_type).to eq(:blacklist)
context 'with emails list validation type' do
let(:validation_type) { :emails_list }
let(:target_blacklist) { validator_instance_result_configuration.blacklisted_emails }

include_examples 'fail validator instance'
include_examples 'has necessary validator instance result attributes'
end

context 'with domains list validation type' do
let(:validation_type) { :domains_list }
let(:target_blacklist) { validator_instance_result_configuration.blacklisted_domains }

include_examples 'fail validator instance'
include_examples 'has necessary validator instance result attributes'
end
end

Expand Down
2 changes: 1 addition & 1 deletion truemail-rspec.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'ffaker', '~> 2.21'
spec.add_runtime_dependency 'net-smtp', '~> 0.3.2' if ::RUBY_VERSION >= '3.1.0'
spec.add_runtime_dependency 'rspec', '~> 3.11'
spec.add_runtime_dependency 'truemail', '~> 2.7', '>= 2.7.4'
spec.add_runtime_dependency 'truemail', '~> 3.0'

spec.add_development_dependency 'ffaker', '~> 2.21'
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
Expand Down

0 comments on commit 9683dda

Please sign in to comment.