From 9683dda9a664b0f465192fbc1fe70bb6a88e52a4 Mon Sep 17 00:00:00 2001 From: Vladislav Trotsenko Date: Tue, 25 Oct 2022 09:39:10 +0200 Subject: [PATCH] Feature/Ability to create ListMatch validation instances (#47) * Added support for ListMatch validation layer * Updated runtime/development dependencies * Updated circleci/codeclimate configs * Updated gem readme, version, changelog --- .circleci/config.yml | 2 +- .circleci/gemspec_compatible | 2 +- .circleci/gemspec_latest | 4 +- .codeclimate.yml | 2 +- CHANGELOG.md | 13 ++++ README.md | 2 +- lib/truemail/rspec/validator_helper.rb | 14 ++-- lib/truemail/rspec/version.rb | 2 +- spec/truemail/rspec/validator_helper_spec.rb | 73 +++++++++++++++----- truemail-rspec.gemspec | 2 +- 10 files changed, 85 insertions(+), 31 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 03bc7bf..dac48f5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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: diff --git a/.circleci/gemspec_compatible b/.circleci/gemspec_compatible index ce5855e..c203f88 100644 --- a/.circleci/gemspec_compatible +++ b/.circleci/gemspec_compatible @@ -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' diff --git a/.circleci/gemspec_latest b/.circleci/gemspec_latest index 63a63fc..a908833 100644 --- a/.circleci/gemspec_latest +++ b/.circleci/gemspec_latest @@ -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' @@ -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' diff --git a/.codeclimate.yml b/.codeclimate.yml index c03e971..854ffb1 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -7,7 +7,7 @@ checks: plugins: rubocop: enabled: true - channel: rubocop-1-36 + channel: rubocop-1-37 reek: enabled: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 9196c9c..04e30ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 79c0c36..4925e94 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/truemail/rspec/validator_helper.rb b/lib/truemail/rspec/validator_helper.rb index 53966dd..c4ba9b3 100644 --- a/lib/truemail/rspec/validator_helper.rb +++ b/lib/truemail/rspec/validator_helper.rb @@ -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 @@ -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 diff --git a/lib/truemail/rspec/version.rb b/lib/truemail/rspec/version.rb index 010e974..d1418a5 100644 --- a/lib/truemail/rspec/version.rb +++ b/lib/truemail/rspec/version.rb @@ -2,6 +2,6 @@ module Truemail module RSpec - VERSION = '0.9.2' + VERSION = '1.0.0' end end diff --git a/spec/truemail/rspec/validator_helper_spec.rb b/spec/truemail/rspec/validator_helper_spec.rb index a4b1cff..a8c771b 100644 --- a/spec/truemail/rspec/validator_helper_spec.rb +++ b/spec/truemail/rspec/validator_helper_spec.rb @@ -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 } @@ -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 @@ -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 @@ -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 diff --git a/truemail-rspec.gemspec b/truemail-rspec.gemspec index 136b25e..9deaf6f 100644 --- a/truemail-rspec.gemspec +++ b/truemail-rspec.gemspec @@ -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'