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.4.4 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.4.3 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.4.2 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.4.1 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.4.0 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.3.5 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.3.4 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.3.3 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.3.2 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.3.1 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.3.0 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.1.34 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.1.33 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.1.32 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.1.31 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.1.30 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.1.29 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.1.28 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.1.27 spec/roqua/validators/subset_validator_spec.rb
roqua-support-0.1.26 spec/roqua/validators/subset_validator_spec.rb