Sha256: 18bd6f72a5dc952b24c1c0e57e8273ac0fc4b7bf2b7033ac1da835b85b65a25f

Contents?: true

Size: 1.46 KB

Versions: 8

Compression:

Stored size: 1.46 KB

Contents

# -*- coding: utf-8 -*-
require 'spec_helper'
require 'unit/contextual_validators/spec_helper'

describe 'DataMapper::Validations::ContextualValidators' do
  before :all do
    @model = DataMapper::Validations::ContextualValidators.new
  end

  describe "#execute(name, target)" do
    before do
      @validator_one = DataMapper::Validations::PresenceValidator.new(:name)
      @validator_two = DataMapper::Validations::WithinValidator.new(:operating_system, :set => ["Mac OS X", "Linux", "FreeBSD", "Solaris"])

      @model.context(:default) << @validator_one << @validator_two
    end


    describe "when target satisfies all validators" do
      before do
        @target = DataMapper::Validations::Fixtures::PieceOfSoftware.new(:name => 'gcc', :operating_system => "Mac OS X")
        @validator_one.call(@target).should be(true)
        @validator_two.call(@target).should be(true)

        @result = @model.execute(:default, @target)
      end

      it "returns true" do
        @result.should be(true)
      end
    end


    describe "when target does not satisfy all validators" do
      before do
        @target = DataMapper::Validations::Fixtures::PieceOfSoftware.new(:name => 'Skitch', :operating_system => "Haiku")
        @validator_one.call(@target).should be(true)
        @validator_two.call(@target).should be(false)

        @result = @model.execute(:default, @target)
      end

      it "returns true" do
        @result.should be(false)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dm-validations-1.1.0 spec/unit/contextual_validators/execution_spec.rb
dm-validations-1.1.0.rc3 spec/unit/contextual_validators/execution_spec.rb
dm-validations-1.1.0.rc2 spec/unit/contextual_validators/execution_spec.rb
dm-validations-1.1.0.rc1 spec/unit/contextual_validators/execution_spec.rb
dm-validations-1.0.2 spec/unit/contextual_validators/execution_spec.rb
dm-validations-1.0.1 spec/unit/contextual_validators/execution_spec.rb
dm-validations-1.0.0 spec/unit/contextual_validators/execution_spec.rb
dm-validations-1.0.0.rc3 spec/unit/contextual_validators/execution_spec.rb