Sha256: bd3f6c0b042c537017e496d22a0b462a5b5fb4404941483b4412ac49941e80dd

Contents?: true

Size: 660 Bytes

Versions: 1

Compression:

Stored size: 660 Bytes

Contents

require "ohm"
require_relative "helper"

Ohm.redis = Redic.new("redis://localhost:6379/30")

class User < Ohm::Model
  attribute :email
  unique :email
end

class Signup < Scrivener
  attr_accessor :email

  def validate
    assert_unique :email, :User
  end
end

prepare do
  Ohm.flush
end

test "invalid if attribute is already taken" do
  user   = User.create(email: "aquiles@me.com")
  signup = Signup.new(email: user.email)

  assert !(signup.valid?)
  assert_equal [:not_unique], signup.errors[:email]
end

test "valid if attribute is not taken" do
  signup = Signup.new(email: "aquiles@me.com")

  assert signup.valid?
  assert signup.errors.empty?
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scrivener-contrib-0.0.1 test/ohm.rb