-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix build and migrate to GitHub Actions #125
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c52c583
Fix broken validation messages
f5d0a8f
Fix broken MX-with-fallback test
3467154
Clarify build output
afea079
Introduce basic GitHub Actions build
c4364a7
Unpin rake version
6ab7800
Add all passing ruby versions to matrix
d99c903
Show ruby warnings in CI
fce1f0f
Fix error assertions for ActiveModel < 6.0
db311d9
Add all remaining ruby 2.x versions to build matrix
b47313a
Fix gemspec for ruby 1.9.3 and add to matrix
97a2573
Remove travis-ci config
1fab0f2
Switch build status badge to GitHub Actions
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: CI | ||
on: | ||
workflow_dispatch: | ||
push: | ||
|
||
permissions: | ||
checks: write | ||
contents: read | ||
pull-requests: write | ||
|
||
jobs: | ||
rspec: | ||
name: RSpec (ruby ${{ matrix.ruby-version }}) | ||
runs-on: ubuntu-20.04 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
ruby-version: | ||
- '1.9.3' | ||
- '2.0' | ||
- '2.1' | ||
- '2.2' | ||
- '2.3' | ||
- '2.4' | ||
- '2.5' | ||
- '2.6' | ||
- '2.7' | ||
- '3.0' | ||
- '3.1' | ||
- '3.2' | ||
- 'jruby-head' | ||
- 'truffleruby-head' | ||
env: | ||
CI: true | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ matrix.ruby-version }} | ||
bundler-cache: true | ||
- name: Run tests | ||
run: bundle exec rake |
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 +0,0 @@ | ||
--warning | ||
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
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,21 @@ | ||
require 'spec_helper' | ||
|
||
RSpec::Matchers.define :have_error_messages do |field, expected| | ||
match do |model| | ||
errors = model.errors[field] | ||
|
||
messages = errors.map do |error| | ||
case error | ||
when String then error | ||
when Hash then error[:message] | ||
else fail ArgumentError, "Unknown model error type #{error.class}" | ||
end | ||
end | ||
|
||
expect(messages).to eq expected | ||
end | ||
end | ||
|
||
describe EmailValidator do | ||
email_class = Class.new do | ||
include ActiveModel::Validations | ||
|
@@ -69,43 +85,43 @@ def self.model_name | |
|
||
it "fails when email empty" do | ||
expect(subject.valid?).to be_falsey | ||
expect(subject.errors[:email]).to eq errors | ||
expect(subject).to have_error_messages(:email, errors) | ||
end | ||
|
||
it "fails when email is not valid" do | ||
subject.email = 'joh@doe' | ||
expect(subject.valid?).to be_falsey | ||
expect(subject.errors[:email]).to eq errors | ||
expect(subject).to have_error_messages(:email, errors) | ||
end | ||
|
||
it "fails when email domain is prefixed with dot" do | ||
subject.email = '[email protected]' | ||
expect(subject.valid?).to be_falsey | ||
expect(subject.errors[:email]).to eq errors | ||
expect(subject).to have_error_messages(:email, errors) | ||
end | ||
|
||
it "fails when email domain contains two consecutive dots" do | ||
subject.email = '[email protected]' | ||
expect(subject.valid?).to be_falsey | ||
expect(subject.errors[:email]).to eq errors | ||
expect(subject).to have_error_messages(:email, errors) | ||
end | ||
|
||
it "fails when email ends with a period" do | ||
subject.email = '[email protected].' | ||
expect(subject.valid?).to be_falsey | ||
expect(subject.errors[:email]).to eq errors | ||
expect(subject).to have_error_messages(:email, errors) | ||
end | ||
|
||
it "fails when email ends with special characters" do | ||
subject.email = '[email protected]&' | ||
expect(subject.valid?).to be_falsey | ||
expect(subject.errors[:email]).to eq errors | ||
expect(subject).to have_error_messages(:email, errors) | ||
end | ||
|
||
it "fails when email is valid with information" do | ||
subject.email = '"John Doe" <[email protected]>' | ||
expect(subject.valid?).to be_falsey | ||
expect(subject.errors[:email]).to eq errors | ||
expect(subject).to have_error_messages(:email, errors) | ||
end | ||
|
||
it "passes when email is simple email address" do | ||
|
@@ -117,42 +133,52 @@ def self.model_name | |
it "fails when email is simple email address not stripped" do | ||
subject.email = '[email protected] ' | ||
expect(subject.valid?).to be_falsey | ||
expect(subject.errors[:email]).to eq errors | ||
expect(subject).to have_error_messages(:email, errors) | ||
end | ||
|
||
it "fails when domain contains a space" do | ||
subject.email = 'john@doe .com' | ||
expect(subject.valid?).to be_falsey | ||
expect(subject.errors[:email]).to eq errors | ||
expect(subject).to have_error_messages(:email, errors) | ||
end | ||
|
||
it "fails when passing multiple simple email addresses" do | ||
subject.email = '[email protected], [email protected]' | ||
expect(subject.valid?).to be_falsey | ||
expect(subject.errors[:email]).to eq errors | ||
expect(subject).to have_error_messages(:email, errors) | ||
end | ||
|
||
end | ||
|
||
describe "validating email with MX and fallback to A" do | ||
let(:dns) { instance_double('Resolv::DNS', :dns) } | ||
|
||
subject { person_class_mx_with_fallback.new } | ||
|
||
before do | ||
allow(Resolv::DNS).to receive(:open).and_yield(dns) | ||
end | ||
|
||
it "passes when email domain has MX record" do | ||
subject.email = '[email protected]' | ||
allow(dns).to receive(:getresources).with('has-mx-record.org', Resolv::DNS::Resource::IN::MX).and_return(['1.2.3.4']) | ||
subject.email = '[email protected]' | ||
expect(subject.valid?).to be_truthy | ||
expect(subject.errors[:email]).to be_empty | ||
end | ||
|
||
it "passes when email domain has no MX record but has an A record" do | ||
subject.email = '[email protected]' | ||
allow(dns).to receive(:getresources).with('has-a-record.org', Resolv::DNS::Resource::IN::MX).and_return([]) | ||
allow(dns).to receive(:getresources).with('has-a-record.org', Resolv::DNS::Resource::IN::A).and_return(['1.2.3.4']) | ||
subject.email = '[email protected]' | ||
expect(subject.valid?).to be_truthy | ||
expect(subject.errors[:email]).to be_empty | ||
end | ||
|
||
it "fails when domain does not exists" do | ||
subject.email = '[email protected]' | ||
allow(dns).to receive(:getresources).with('does-not-exist.org', anything).and_return([]) | ||
subject.email = '[email protected]' | ||
expect(subject.valid?).to be_falsey | ||
expect(subject.errors[:email]).to eq errors | ||
expect(subject).to have_error_messages(:email, errors) | ||
end | ||
end | ||
|
||
|
@@ -168,13 +194,13 @@ def self.model_name | |
it "fails when email domain has no MX record" do | ||
subject.email = '[email protected]' | ||
expect(subject.valid?).to be_falsey | ||
expect(subject.errors[:email]).to eq errors | ||
expect(subject).to have_error_messages(:email, errors) | ||
end | ||
|
||
it "fails when domain does not exists" do | ||
subject.email = '[email protected]' | ||
expect(subject.valid?).to be_falsey | ||
expect(subject.errors[:email]).to eq errors | ||
expect(subject).to have_error_messages(:email, errors) | ||
end | ||
end | ||
|
||
|
@@ -218,7 +244,7 @@ def self.model_name | |
it "fails when email from disposable email services" do | ||
subject.email = '[email protected]' | ||
expect(subject.valid?).to be_falsey | ||
expect(subject.errors[:email]).to eq errors | ||
expect(subject).to have_error_messages(:email, errors) | ||
end | ||
end | ||
|
||
|
@@ -228,7 +254,7 @@ def self.model_name | |
it "does not pass with an invalid domain" do | ||
subject.email = "[email protected]$\'" | ||
expect(subject.valid?).to be_falsey | ||
expect(subject.errors[:email]).to eq errors | ||
expect(subject).to have_error_messages(:email, errors) | ||
end | ||
|
||
it "passes with valid domain" do | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of adding a matcher 👍