-
-
Notifications
You must be signed in to change notification settings - Fork 910
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
Testing with validates_comparison_of or comparison #1514
Comments
Hello, I'm fine, thanks for asking! I'd say that currently, class Order
validates :start_date, comparison: { greater_than_or_equal_to: Date.today }
validates :end_date, comparison: { greater_than: :start_date }
end
RSpec.describe Order, type: :model do
describe "validations" do
context "when start date is less than the current day" do
it "record is not valid and adds greater_than_or_equal_to error to start_date attribute" do
reward = Order.new(start_date: Time.zone.tomorrow)
expect(reward.valid?).to be false
expect(reward.errors[:start_date]).not_to be_empty
end
end
context "when start date is not less than the current day" do
it "record is valid and doesn't add greater_than_or_equal_to error to start_date attribute" do
reward = Order.new(start_date: Time.zone.tomorrow)
expect(reward.valid?).to be true
expect(reward.errors[:estimated_delivers_on]).to be_empty
end
end
context "when end date is not greater than the start_date" do
it "record is not valid and adds greater_than error to end_date attribute" do
reward = Order.new(start_date: Time.zone.today, end_date: Time.zone.today)
expect(reward.valid?).to be false
expect(reward.errors[:start_date]).not_to be_empty
end
end
context "when end date is greater than the start_date" do
it "record is valid and doesn't add greater_than error to end_date attribute" do
reward = Order.new(start_date: Time.zone.today, end_date: Time.zone.tomorrow)
expect(reward.valid?).to be true
expect(reward.errors[:start_date]).to be_empty
end
end
end
end I can probably work on implementing this in the next weeks, but we are happy to receive new contributions if you want to work on this 😄 |
Any updates on this issue? |
I started to work on a PR for implementing that feature but went on vacation and only had a little time to spend on that since. My plan is to work on that PR in the next weeks, starting this Friday. But feel free to implement that if you want to! |
Guys, how are you? Has anyone implemented testing using these new Rails 7 validates? If yes, could you give me a hint?
First validate
validates :start_date, comparison: { greater_than_or_equal_to: Date.today }
Second validate
validates :end_date, comparison: { greater_than: :start_date }
Tutorial link:
https://www.bigbinary.com/blog/rails-7-adds-comparison-validator-to-active-record
The text was updated successfully, but these errors were encountered: