You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To more fully mock an ActiveRecord object should the mock respond to the readonly? method (similar to the `new_record? query method)?
Use case. We sometimes have a object that enters a final state. To enforce that the record is not updated after that final state we override readonly? to examine the object state to determine if it should be read only or nor. For example:
def readonly?
super || state == 'complete'
end
Our UI then reads that attribute to know of it needs to present the option to edit that record (via a Pundit policy but that is an impl detail not relevant).
If I use a real ActiveRecord object this all works flawless because readonly? is a built-in method. But if I use a mock from this library that is supposed to be able to replace an ActiveRecord object it does not work.
Seems some way for it to respond to readonly? and return false (mirroring a ActiveRecord object by default) would be good. Bonus points if there was a good way to change the return value for a specific test although that's not a huge need of mine currently.
Wanted to inquire if this was in-scope for this project or just something I need to handle internally (by further mocking what this library returns to more closely mirror an ActiveRecord object myself).
The text was updated successfully, but these errors were encountered:
To more fully mock an ActiveRecord object should the mock respond to the
readonly?
method (similar to the `new_record? query method)?Use case. We sometimes have a object that enters a final state. To enforce that the record is not updated after that final state we override
readonly?
to examine the object state to determine if it should be read only or nor. For example:Our UI then reads that attribute to know of it needs to present the option to edit that record (via a Pundit policy but that is an impl detail not relevant).
If I use a real ActiveRecord object this all works flawless because
readonly?
is a built-in method. But if I use a mock from this library that is supposed to be able to replace an ActiveRecord object it does not work.Seems some way for it to respond to
readonly?
and return false (mirroring a ActiveRecord object by default) would be good. Bonus points if there was a good way to change the return value for a specific test although that's not a huge need of mine currently.Wanted to inquire if this was in-scope for this project or just something I need to handle internally (by further mocking what this library returns to more closely mirror an ActiveRecord object myself).
The text was updated successfully, but these errors were encountered: