Sha256: 1e16f3a928b3efc6f12e2d5e72e259a7ab945690f7918226cfb43ec78c428e50

Contents?: true

Size: 826 Bytes

Versions: 26

Compression:

Stored size: 826 Bytes

Contents

require 'spec_helper'
require 'roqua/validators/subset_validator'

describe SubsetValidator do
  let(:validatable) do
    Class.new do
      include ActiveModel::Validations

      attr_accessor :list

      validates :list, subset: {of: [1, 2, 3]}

      def initialize(list)
        self.list = list
      end
    end
  end

  it 'allows nil values' do
    expect(validatable.new(nil)).to be_valid
  end

  it 'allows empty arrays' do
    expect(validatable.new([])).to be_valid
  end

  it 'allows a subset' do
    expect(validatable.new([1])).to be_valid
    expect(validatable.new([1, 2])).to be_valid
  end

  it 'allows exact match to set' do
    expect(validatable.new([1, 2, 3])).to be_valid
  end

  it 'does not allow an element not in the set' do
    expect(validatable.new([1, 2, 100])).not_to be_valid
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
roqua-support-0.1.25 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.1.24 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.1.23 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.1.22 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.1.21 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.1.20 spec/roqua/validators/subset_validator_spec.rb