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
validate_uniqueness_of with scoped_to fails when the scope is of data type time #1114
Comments
Ah... yes that makes sense! We would definitely appreciate a PR. 👍 |
See issue thoughtbot#1114: validate_uniqueness_of with scoped_to fails when the scope is of data type time
Hey folks. In an effort to lighten our load as maintainers and be able to serve you better in the future, the shoulda-matchers team is working on cleaning out the cobwebs in this repo by pruning the backlog. As there are few of us, there are a lot of items that will simply never earn our attention in a reasonable time frame, and rather than giving you an empty promise, we think it makes more sense to focus on more recent issues. That means, unfortunately, that we must close this issue. Don't take this the wrong way: our aim is not to diminish the effort people have made or dismiss problems that have been raised. If you feel that we should reopen this issue, then please let us know so that we can reprioritize it. Thanks! |
Reopening since this is dependent on a PR. |
See issue thoughtbot#1114: validate_uniqueness_of with scoped_to fails when the scope is of data type time
See issue thoughtbot#1114: validate_uniqueness_of with scoped_to fails when the scope is of data type time Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
@mcmire seems like this issue is also fixed in the PR mentioned, and will be good to close. |
@KapilSachdev Oops, good eye! Will close. |
The validation fails but it should pass when the scope has data type
time
.Example: model
Schedule
with the following attributes and their data types:day_of_week
:integer
start_time
:time
Spec:
This bug is caused by the method that calculates the next value to test for the uniqueness of the scope:
lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb
When
previous_value
is of typetime
:previous_value
->2018-07-02 11:20:14
previous_value.to_datetime.next
->2018-07-03 11:20:14
The date is incremented by 1, however the time remains the same. As a result when the next value is set on the new record the uniqueness validation fails since the 2 records have the same time value.
A possible fix would be to also increment the
previous_value
by 60 seconds before callingnext
to guarantee both the time and the date are different:previous_value.to_datetime.in(60).next
I'm more than happy to open a PR for this fix! Let me know what you guys think about this.
The text was updated successfully, but these errors were encountered: