draper icon indicating copy to clipboard operation
draper copied to clipboard

Unexpected behavior when `frozen?` method is defined in model

Open kenzo-tanaka opened this issue 2 years ago • 1 comments

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🙏

kenzo-tanaka avatar Apr 19 '22 03:04 kenzo-tanaka

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.

itzbernoulli avatar Apr 19 '22 09:04 itzbernoulli