inossidabile / protector

Comfortable (seriously) white-list security restrictions for models on a field level
MIT License
270 stars 31 forks source link

Rails 4.1. read an enum returns nil #42

Closed toxix closed 10 years ago

toxix commented 10 years ago
class Conversation < ActiveRecord::Base
  protect do |user|
    can :create
    can :read
    can :update
    can :destroy
  end

  enum status: [ :active, :archived ]
end

#
c = Conversation.restrict!(current_user).find 1

# Works fine and save value to the db
c.active!

# return nil instead of status enum value
c.status

# return false in every case instead of true/false dependent on status
c.active?

# returns the integer number of the enum value, just fine
c["status"]

Reading within insecure blocks or unrestricted Objects works fine.

http://edgeguides.rubyonrails.org/4_1_release_notes.html#active-record-enums src for enums https://github.com/rails/rails/blob/4-1-stable/activerecord/lib/active_record/enum.rb

inossidabile commented 10 years ago

Released as 0.7.6