Sha256: a144c77d304a97c305e3cc5b4ee78c9cb2aac32e88e194f4ba59d294d73e5548

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require_relative '../../../../spec_helper'
require 'virtus'
require 'aequitas'
require 'aequitas/virtus_integration'

describe Aequitas::VirtusIntegration::ClassMethods do
  let(:class_under_test) do
    Class.new do
      include Virtus
      include Aequitas

      attribute :validated_attribute, Integer, :not_equal_to => 3

      self
    end
  end

  describe '.validation_rules' do
    it 'includes the expected Rule for :validated_attribute' do
      attribute_rules = class_under_test.validation_rules[:validated_attribute]
      refute_predicate attribute_rules, :empty?
      assert_instance_of Aequitas::Rule::Value::NotEqual, attribute_rules.first
    end
  end

  describe '#valid?' do
    subject { class_under_test.new(:validated_attribute => attribute_value) }

    describe 'when value is less than expected' do
      let(:attribute_value) { 1 }
      it('is valid') { assert_predicate subject, :valid? }
    end

    describe 'when value is equal to expected' do
      let(:attribute_value) { 3 }
      it('is not valid') { refute_predicate subject, :valid? }
    end

    describe 'when value is greater than expected' do
      let(:attribute_value) { 5 }
      it('is valid') { assert_predicate subject, :valid? }
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aequitas-0.0.2 spec/integration/virtus/integer/value/not_equal_to_spec.rb