-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* date of entry * start date * date of birth
- Loading branch information
1 parent
cc4fb62
commit 901e21a
Showing
11 changed files
with
107 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class FutureDateValidator | ||
def initialize(record, field) | ||
@record = record | ||
@field = field | ||
@test_date = record.public_send(field) | ||
end | ||
|
||
def validate | ||
return unless test_date.present? && test_date > Date.current | ||
|
||
record.errors.add(field, :not_in_future) | ||
end | ||
|
||
private | ||
|
||
attr_reader :record, :field, :test_date | ||
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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require "rails_helper" | ||
|
||
describe FutureDateValidator do | ||
subject(:validator) { described_class.new(form, :date_of_birth) } | ||
|
||
let(:form) { build(:form) } | ||
|
||
before do | ||
form.date_of_birth = dob | ||
validator.validate | ||
end | ||
|
||
context "returns no error when date not in the future" do | ||
let(:dob) { 1.day.ago } | ||
|
||
it { expect(form.errors[:date_of_birth]).to be_blank } | ||
end | ||
|
||
context "returns an error when date is in the future" do | ||
let(:dob) { 1.day.from_now } | ||
|
||
it { expect(form.errors[:date_of_birth]).to be_present } | ||
end | ||
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