-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #271 from truemail-rb/develop
Truemail v3.1.0
- Loading branch information
Showing
25 changed files
with
219 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Truemail | ||
VERSION = '3.0.9' | ||
VERSION = '3.1.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
module Truemail | ||
module RspecHelper | ||
module Context | ||
NON_ASCII_WORDS = %w[mañana ĉapelo dấu παράδειγμα 屋企].freeze | ||
|
||
def random_email | ||
ffaker.email | ||
end | ||
|
||
def random_uniq_email | ||
ffaker.unique.email | ||
end | ||
|
||
def random_internationalized_email | ||
"#{ffaker.user_name}@#{Truemail::RspecHelper::Context::NON_ASCII_WORDS.sample}.#{ffaker.domain_suffix}" | ||
end | ||
|
||
def random_ip_address | ||
ffaker.ip_v4_address | ||
end | ||
|
||
def random_domain_name | ||
ffaker.domain_name | ||
end | ||
|
||
def random_uniq_domain_name | ||
ffaker.unique.domain_name | ||
end | ||
|
||
def rdns_lookup_host_address(host_address) | ||
DnsMock::Representer::RdnsLookup.call(host_address) | ||
end | ||
|
||
def domain_from_email(email) | ||
email[Truemail::RegexConstant::REGEX_DOMAIN_FROM_EMAIL, 1] | ||
end | ||
|
||
def email_punycode_domain(email) | ||
DnsMock::Representer::Punycode.call(domain_from_email(email)) | ||
end | ||
|
||
def attempts_getter | ||
->(smtp_request_instance) { smtp_request_instance.send(:attempts) } | ||
end | ||
|
||
private | ||
|
||
def ffaker | ||
FFaker::Internet | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Truemail | ||
module RspecHelper | ||
module Dns | ||
LOCALHOST_IP_ADDRESS = '127.0.0.1' | ||
|
||
def dns_mock_gateway | ||
["#{Truemail::RspecHelper::Dns::LOCALHOST_IP_ADDRESS}:#{dns_mock_server.port}"] | ||
end | ||
|
||
def dns_mock_records_by_email(email, dimension: 1) | ||
mx_records = ::Array.new(dimension) { random_domain_name } | ||
a_records = ::Array.new(dimension) { [Truemail::RspecHelper::Dns::LOCALHOST_IP_ADDRESS] } | ||
mx_records_dns_mock = mx_records.zip(a_records).to_h.transform_values { |value| { a: value } } | ||
{ domain_from_email(email) => { mx: mx_records } }.merge(mx_records_dns_mock) | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# frozen_string_literal: true | ||
|
||
module Truemail | ||
module RspecHelper | ||
class GenerateEmail | ||
def self.call(**options) | ||
new(**options).call | ||
end | ||
|
||
def initialize(size: :auto, symbols: %w[- _ . +], invalid_email_with: []) | ||
@size = calculate_email_size(size) | ||
@symbols = symbols | ||
@invalid_symbols = invalid_email_with | ||
user_name | ||
end | ||
|
||
def call | ||
"#{user_name}@#{('a'..'z').zip(0..Float::INFINITY).flatten.shuffle.sample[0]}.#{('aa'..'zz').to_a.sample}" | ||
end | ||
|
||
private | ||
|
||
attr_reader :size, :symbols, :invalid_symbols | ||
|
||
def calculate_email_size(size) | ||
case size | ||
when :auto then rand(15..250) | ||
when :min then 1 | ||
when :max then 250 | ||
when :out_of_range then rand(251..300) | ||
end | ||
end | ||
|
||
def sample_size | ||
symbols_size = symbols.size | ||
invalid_symbols_size = invalid_symbols.size | ||
size < (symbols_size + invalid_symbols_size + 1) ? 1 : size - symbols_size - invalid_symbols_size - 1 | ||
end | ||
|
||
def invalid_symbols_empty? | ||
invalid_symbols.empty? | ||
end | ||
|
||
def size_one? | ||
size == 1 | ||
end | ||
|
||
def user_name | ||
@user_name ||= | ||
if size_one? && !invalid_symbols_empty? | ||
invalid_symbols.sample | ||
elsif size_one? && invalid_symbols_empty? | ||
('a'..'z').to_a.sample | ||
else | ||
prepare_user_name(randomizer) | ||
end | ||
end | ||
|
||
def randomizer # rubocop:disable Metrics/AbcSize | ||
( | ||
('Aa'..'Zz').to_a.shuffle.join.chars.sample(sample_size).push(*symbols.shuffle) << rand(0..9) | ||
).shuffle.push(*invalid_symbols.sample(size)).shuffle[0...size] | ||
end | ||
|
||
def prepare_user_name(sample) | ||
sample.rotate!(1) while symbols.include?(sample.first) | ||
sample.join | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.