-
Notifications
You must be signed in to change notification settings - Fork 121
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
Fixed longstanding bug with with_read_marks_for
#56
Conversation
private | ||
|
||
def read_mark_id_belongs_to?(readable) | ||
self.read_mark_readable_type == readable.class.name and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small bug: Must be compared to readable.class.base_class.name
. Also, I would prefer to use &&
over and
and ||
over or
.
Great description and fix! Thanks @mikeki, will merge soon! |
Addressed your comments. Thank you :) |
Squashed and merged into 11a2547. |
Thank you, and don't worry! |
There was a bug explained with the next code snippets:
Suppose:
expect behavior:
current behavior:
This happens because
with_read_marks_for
just joins with the read_mark_id, but there is never any indication as to who owns theread_mark_id
, so currently we just assume it belongs to allreadables
The same bug was implemented in my previous branch for readers(User), but gets fixed here too.
Fix:
I added
read_mark_user_id
forreadables
scope andread_mark_readable_type
andread_mark_readable_id
forreader
scopes.Now inside
unread?
andhave_read?
, besides testing if the recordrespond_to?(:read_mark_id)
we also test if theread_mark_id
belongs to the user/readable being tested, otherwise it would load the whole set ofunread_by(user)
/have_not_read(readable)
and verify if the object that we are looking for is present.