Skip to content
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

Format Validation only works for yyyy-mm-dd #234

Open
micahtessler opened this issue Aug 14, 2023 · 0 comments
Open

Format Validation only works for yyyy-mm-dd #234

micahtessler opened this issue Aug 14, 2023 · 0 comments

Comments

@micahtessler
Copy link

I have instances where I need to validate other formats, mm/dd/yyyy or dd/mm/yyyy for example.
Those formats never seem to validate with this gem.

I added the following context to spec/validates_timeliness/validator/format_spec.rb under the date type, and it fails the specs on the gem.

    context "when the format is dd/mm/yyyy" do
      before do
        Person.validates_date :birth_date, format: "dd/mm/yyyy"
      end

      it "should be valid for string given in the right format" do
        valid!(:birth_date, '23/12/2023')
      end

      it "should not be valid for string given in the wrong format" do
        invalid!(:birth_date, '2023-12-23', /is not a valid date/)
      end

      it "should be valid for date instance" do
        valid!(:birth_date, Date.new(2022,12,23))
      end
    end
     Failure/Error: expect(record).to be_valid
      expected `#<Person:0x0000000109337f20 @attributes=#<ActiveModel::AttributeSet:0x0000000109337ea8 @attributes={"...Model::Error attribute=birth_date, type=invalid_date, options={:message=>nil, :restriction=>nil}>]>>.valid?` to be truthy, got false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant