Sha256: c3933d7168a69dbffa9c0bfca57eaec0b530ccf8de8b034b59df4e91d89acbf9

Contents?: true

Size: 966 Bytes

Versions: 3

Compression:

Stored size: 966 Bytes

Contents

require_relative "helper"

MINIMUM = "*" * 10
MAXIMUM = "*" * 20
EXACT   = "*" * 8

class Signup < Scrivener
  attr_accessor :fname
  attr_accessor :lname
  attr_accessor :passport

  def validate
    assert_minimum_length :fname, MINIMUM.length
    assert_maximum_length :lname, MAXIMUM.length
    assert_exact_length   :passport, EXACT.length
  end
end

setup do
  Signup.new(fname: MINIMUM, lname: MAXIMUM, passport: EXACT)
end

test "valid" do |signup|
  assert signup.valid?
  assert signup.errors.empty?
end

test "invalid minimum length" do |signup|
  signup.fname = ""

  assert !(signup.valid?)
  assert_equal [:too_short], signup.errors[:fname]
end

test "invalid maximum length" do |signup|
  signup.lname = MAXIMUM + "*"

  assert !(signup.valid?)
  assert_equal [:too_long], signup.errors[:lname]
end

test "invalid exact length" do |signup|
  signup.passport = ""

  assert !(signup.valid?)
  assert_equal [:wrong_length], signup.errors[:passport]
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
scrivener-contrib-1.1.0 test/length.rb
scrivener-contrib-1.0.0 test/length.rb
scrivener-contrib-0.0.1 test/length.rb