diff options
Diffstat (limited to 'spec/validators/iso8601_date_validator_spec.rb')
-rw-r--r-- | spec/validators/iso8601_date_validator_spec.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/validators/iso8601_date_validator_spec.rb b/spec/validators/iso8601_date_validator_spec.rb new file mode 100644 index 00000000000..8b9b8a5bb8f --- /dev/null +++ b/spec/validators/iso8601_date_validator_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Iso8601DateValidator do + subject do + Class.new(ActiveRecord::Base) do + self.table_name = 'deploy_tokens' + + attribute :expires_at + + validates :expires_at, iso8601_date: true + + def self.name + "DeployToken" + end + end.new + end + + it 'passes a valid date' do + subject.expires_at = DateTime.now + + expect(subject.valid?).to be_truthy + end + + it 'errors on an invalid date' do + subject.expires_at = '2-12-2022' + + expect(subject.valid?).to be_falsy + expect(subject.errors.full_messages).to include('Expires at must be in ISO 8601 format') + end +end |