draper
draper copied to clipboard
Unexpected behavior when `frozen?` method is defined in model
Hi👋
First of all thank you for the very helpful gem!
I found an unexpected behavior while using draper and would like to report it.
When the frozen?
method is defined in the model, the decorated instance returns false.
The following is a sample code.
# app/models/user.rb
class User < ApplicationRecord
def frozen?
true
end
end
class UserDecorator < Draper::Decorator
delegate_all
end
rails console
irb(main):001:0> User.first.decorate.frozen?
(1.2ms) SELECT sqlite_version(*)
User Load (0.2ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ? [["LIMIT", 1]]
=> false # expected true
https://github.com/kenzo-tanaka/tmp_draper
I'm sorry if I misunderstood something about this behaviour🙏
Hi @kenzo-tanaka seems this is a ruby thing rather than a draper issue. If you call frozen? on the object without decorating it still returns false as long as you didn't freeze the object.