Sha256: 02d31fc3768f52b107c869aee051d98b56f66aebe5ae7f1733d9ad886bb377b8

Contents?: true

Size: 616 Bytes

Versions: 1

Compression:

Stored size: 616 Bytes

Contents

require "cutest"
require "ohm"
require_relative "../lib/ohm/validations"

Ohm.redis = Redic.new("redis://127.0.0.1:6379/15")

setup do
  Ohm.flush
end

class User < Ohm::Model
  include Ohm::Validations

  attribute :name

  attr :before, :after

  def validate
    assert_present(:name)
  end

  def before_validation
    @before = true
  end

  def after_validation
    @after = true
  end
end

test "validations" do
  user = User.new({})

  assert !user.valid?

  user.name = "jhon"

  assert user.valid?
end

test "callbacks" do
  user = User.new({})

  user.valid?

  assert user.before
  assert user.after
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ohm-validations-0.0.1 test/validations.rb