Sha256: ebe5532fc7ccfd8365a2cd567407bb2d7901f237b10e6599eb02846298c77f26

Contents?: true

Size: 1023 Bytes

Versions: 9

Compression:

Stored size: 1023 Bytes

Contents

require_relative 'helper'
require 'swift/validations'

describe 'validations' do
  before do
    @user = Class.new(Swift::Record) do
      store     :users
      attribute :id,   Swift::Type::Integer, serial: true, key: true
      attribute :name, Swift::Type::String

      validations do |errors|
        errors << [:name, 'is blank'] if name.to_s.empty?
      end
    end
  end

  describe 'validate' do
    it 'returns errors' do
      assert_kind_of Swift::Errors, @user.new.validate
    end

    it 'has errors when invalid' do
      assert !@user.new.validate.empty?
    end

    it 'has no errors when valid' do
      assert @user.new(name: 'Apple Arthurton').validate.empty?
    end
  end

  describe 'valid?' do
    it 'fails when invalid' do
      assert !@user.new.valid?
    end

    it 'passes when valid' do
      assert @user.new(name: 'Apple Arthurton').valid?
    end
  end

  describe 'errors' do
    it 'has relation' do
      assert_kind_of Swift::Record, @user.new.validate.relation
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
swift-1.2.3 test/test_validations.rb
swift-1.2.2 test/test_validations.rb
swift-1.2.1 test/test_validations.rb
swift-1.2.0 test/test_validations.rb
swift-1.1.0 test/test_validations.rb
swift-1.0.3 test/test_validations.rb
swift-1.0.2 test/test_validations.rb
swift-1.0.1 test/test_validations.rb
swift-1.0.0 test/test_validations.rb