The `validates_includes` validation works with strings and numeric values

require 'sequel'

DB = Sequel.sqlite

DB.create_table(:users) do
  primary_key :id
  String :name, null: false
  String :type
end

class User < Sequel::Model
  plugin :validation_helpers

  def validate
    super
    validates_presence [:name]
    validates_includes %w(a b c), :type
  end

end

irb> u = User.new(name: 'craig', type: 'a')
=> #<User @values={:name=>"craig",:type=>a}>
irb> u.valid?
=> true

However, if the validation is changed:

  def validate
    super
    validates_presence [:name]
    validates_includes %i(a b c), :type
  end

the validations fail:

irb> u = User.new(name: 'craig', type: :c)
=> #<User @values={:name=>"craig",:type=>:c}>
irb> u.valid?
=> false
irb> u.errors
=> {:type=>["is not in range or set: [:a, :b, :c]"]}

Can symbols be used in this type of validation?

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to