Skip to content

Commit

Permalink
Merge pull request #14 from emailable/setup_gh_actions
Browse files Browse the repository at this point in the history
Setup GitHub actions
  • Loading branch information
jclusso authored Mar 19, 2024
2 parents bfec899 + bff8e45 commit d37de93
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 88 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: bundler
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
tests:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3']

steps:
- uses: actions/checkout@v4
- name: Set up Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true

- name: Run tests
run: bundle exec rake

linters:
name: Linters
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: RuboCop
run: bundle exec rubocop --parallel
if: always()
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
inherit_from: .rubocop_todo.yml

inherit_gem:
rubocop-cache-ventures: rubocop.yml
7 changes: 7 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This configuration was generated by
# `rubocop --auto-gen-config --exclude-limit 10000`
# on 2024-03-18 16:04:55 UTC using RuboCop version 1.62.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.4
3.3.0
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Emailable Ruby Library

[![Gem Version](https://badge.fury.io/rb/emailable.svg)](https://rubygems.org/gems/emailable)
[![Build Status](https://app.travis-ci.com/emailable/emailable-ruby.svg)](https://app.travis-ci.com/emailable/emailable-ruby)
![Build Status](https://github.com/emailable/emailable-ruby/actions/workflows/ci.yml/badge.svg)
[![Maintainability](https://api.codeclimate.com/v1/badges/e7eef54e491adec95e6d/maintainability)](https://codeclimate.com/github/emailable/emailable-ruby/maintainability)

This is the official ruby wrapper for the Emailable API.
Expand Down
1 change: 1 addition & 0 deletions emailable.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'minitest', '~> 5.0'
s.add_development_dependency 'minitest-reporters'
s.add_development_dependency 'activemodel'
s.add_development_dependency 'rubocop-cache-ventures'
end
2 changes: 1 addition & 1 deletion lib/emailable/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def verify(parameters = {})
end

def status(parameters = {})
return nil unless @id
return unless @id
return @status if @status

parameters[:id] = @id
Expand Down
4 changes: 2 additions & 2 deletions lib/emailable/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def request(method, endpoint, params = {})

response = Response.new(http_response)
rescue => e
retry if (tries -= 1) > 0 && self.class.should_retry?(e, tries)
retry if (tries -= 1) > 0 && should_retry?(e, tries)

raise e
end
Expand Down Expand Up @@ -70,7 +70,7 @@ def create_connection(uri)
connection
end

def self.should_retry?(error, num_retries)
def should_retry?(error, num_retries)
return false if num_retries >= Emailable.max_network_retries

case error
Expand Down
4 changes: 2 additions & 2 deletions lib/emailable/resources/api_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def to_h

alias_method :to_hash, :to_h

def to_json
JSON.generate(to_h)
def to_json(*args)
JSON.generate(to_h, *args)
end

def inspect
Expand Down
111 changes: 53 additions & 58 deletions test/email_validator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,96 +3,91 @@

class EmailValidatorTest < Minitest::Test

def user_class(
smtp: true, states: %i[deliverable risky unknown], free: true, role: true,
accept_all: true, disposable: true, timeout: 3, **options
)
Class.new do
include ActiveModel::Model
attr_accessor :email, :email_verification_result

validates :email, presence: true, email: {
smtp: smtp, states: states,
free: free, role: role, disposable: disposable, accept_all: accept_all,
timeout: timeout
}.merge(options)

def self.name
'TestClass'
end

# stub changes to always be true
def changes
{ email: true }
end
end
end

def setup
Emailable.api_key = 'test_7aff7fc0142c65f86a00'
sleep(0.25)
end

def test_valid
@user = user_class.new(email: '[email protected]')
valid_user = user_class.new(email: '[email protected]')

assert @user.valid?
assert @user.errors.empty?
assert valid_user.valid?
assert valid_user.errors.empty?
end

def test_invalid
@user = user_class.new(email: '[email protected]')
invalid_user = user_class.new(email: '[email protected]')

assert !@user.valid?
assert @user.errors[:email].present?
refute invalid_user.valid?
assert invalid_user.errors[:email].present?
end

def test_verification_result
@user = user_class.new(email: '[email protected]')
@user.valid?
invalid_user = user_class.new(email: '[email protected]')
invalid_user.valid?

refute_nil @user.email_verification_result
assert @user.email_verification_result.state, :undeliverable
refute_nil invalid_user.email_verification_result
assert_equal 'undeliverable', invalid_user.email_verification_result.state
end

def test_boolean_options
def test_boolean_options_with_invalid_value
%i[smtp free role disposable accept_all].each do |option|
invalid_user = user_class(option => 'string').new
valid_user = user_class.new
invalid_options = user_class(option => 'string').new

assert !valid_user.valid?
assert_raises(ArgumentError) { invalid_user.valid? }
assert_raises(ArgumentError) { invalid_options.valid? }
end
end

def test_states_option
invalid_user = user_class(states: %i[invalid_state]).new
valid_user = user_class.new
def test_states_option_with_invalid_value
invalid_options = user_class(states: %i[invalid_state]).new

assert !valid_user.valid?
assert_raises(ArgumentError) { invalid_user.valid? }
assert_raises(ArgumentError) { invalid_options.valid? }
end

def test_timeout_option
invalid_user1 = user_class(timeout: 'string').new
invalid_user2 = user_class(timeout: 1).new
valid_user = user_class.new
def test_timeout_option_with_invalid_value
invalid_options1 = user_class(timeout: 'string').new
invalid_options2 = user_class(timeout: 1).new

assert !valid_user.valid?
assert_raises(ArgumentError) { invalid_user1.valid? }
assert_raises(ArgumentError) { invalid_user2.valid? }
assert_raises(ArgumentError) { invalid_options1.valid? }
assert_raises(ArgumentError) { invalid_options2.valid? }
end

def test_custom_option
message = 'invalid message'
invalid_user = user_class(message: message, reportable: true).new(
valid_options = user_class(message: message, reportable: true).new(
email: '[email protected]'
)

refute invalid_user.valid?
assert invalid_user.errors[:email].present?
assert_equal message, invalid_user.errors[:email].first
assert invalid_user.errors.where(:email, reportable: true).present?
refute valid_options.valid?
assert valid_options.errors[:email].present?
assert_equal message, valid_options.errors[:email].first
assert valid_options.errors.where(:email, reportable: true).present?
end

private

def user_class(
smtp: true, states: %i[deliverable risky unknown], free: true, role: true,
accept_all: true, disposable: true, timeout: 3, **options
)
Class.new do
include ActiveModel::Model
attr_accessor :email, :email_verification_result

validates :email, presence: true, email: {
smtp: smtp, states: states,
free: free, role: role, disposable: disposable, accept_all: accept_all,
timeout: timeout
}.merge(options)

def self.name
'TestClass'
end

# stub changes to always be true
def changes
{ email: true }
end
end
end

end
2 changes: 0 additions & 2 deletions test/emailable/batch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ module Emailable
class BatchTest < Minitest::Test

def setup
sleep(1)
Emailable.api_key = 'test_7aff7fc0142c65f86a00'
@emails = ['[email protected]', '[email protected]']
@batch = Emailable::Batch.new(@emails)
@batch_id ||= @batch.verify
sleep(1)
end

def test_start_batch
Expand Down
2 changes: 1 addition & 1 deletion test/emailable/resources/api_resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setup
def test_init
assert_equal 'abc', @e.foo
assert_equal 123, @e.bar
assert_equal true, @e.baz
assert @e.baz
end

def test_to_h
Expand Down
20 changes: 7 additions & 13 deletions test/emailable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_verification_state

def test_verification_tag
result = Emailable.verify('[email protected]')
assert result.tag == 'marketing'
assert_equal 'marketing', result.tag
end

def test_account
Expand All @@ -49,33 +49,27 @@ def test_name_and_gender
end

def test_accept_all?
result = Emailable.verify('[email protected]')
assert result.accept_all?
assert Emailable.verify('[email protected]').accept_all?
end

def test_disposable?
result = Emailable.verify('[email protected]')
assert result.disposable?
assert Emailable.verify('[email protected]').disposable?
end

def test_free?
result = Emailable.verify('[email protected]')
assert result.free?
assert Emailable.verify('[email protected]').free?
end

def test_role?
result = Emailable.verify('[email protected]')
assert result.role?
assert Emailable.verify('[email protected]').role?
end

def test_mailbox_full?
result = Emailable.verify('[email protected]')
assert result.mailbox_full?
assert Emailable.verify('[email protected]').mailbox_full?
end

def test_no_reply?
result = Emailable.verify('[email protected]')
assert result.no_reply?
assert Emailable.verify('[email protected]').no_reply?
end

def test_slow_verification
Expand Down

0 comments on commit d37de93

Please sign in to comment.