Sha256: d3474881bb249c259e3ca1ab18740d55c8026440fc6354615eeb83b72d9d43b2

Contents?: true

Size: 914 Bytes

Versions: 3

Compression:

Stored size: 914 Bytes

Contents

require_relative '../../spec_helper'
require_relative 'spec_helper'

describe 'A model with a :set & :default options on a property' do
  before :all do
    class ::LimitedBoat
      include DataMapper::Resource
      property :id,      DataMapper::Property::Serial
      property :limited, String, :set => %w[ foo bar bang ], :default => 'foo'
    end

    LimitedBoat.finalize
  end

  describe "without value on that property" do
    before :all do
      @model = LimitedBoat.new
    end

    # default value is respected
    it_behaves_like 'valid model'
  end

  describe "without value on that property that is not in allowed range/set" do
    before :all do
      @model = LimitedBoat.new(:limited => "blah")
    end

    it_behaves_like 'invalid model'

    it "has a meaningful error message" do
      expect(@model.errors.on(:limited)).to eq [ 'Limited must be one of foo, bar, bang' ]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sbf-dm-validations-1.4.0 spec/integration/automatic_validation/inferred_within_validation_spec.rb
sbf-dm-validations-1.3.0 spec/integration/automatic_validation/inferred_within_validation_spec.rb
sbf-dm-validations-1.3.0.beta spec/integration/automatic_validation/inferred_within_validation_spec.rb