Sha256: 916fb59fc2557bdbd958420ca7f23bcf982564b38cec6c660e85b42722aee7e9

Contents?: true

Size: 1.8 KB

Versions: 3

Compression:

Stored size: 1.8 KB

Contents

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

describe "A model with a Boolean property" do
  before :all do
    @model = HasNullableBoolean.new(:id => 1)
  end

  describe "assigned a true" do
    before :all do
      @model.bool = true
    end

    it_behaves_like 'valid model'
  end

  describe "assigned a false" do
    before :all do
      @model.bool = false
    end

    it_behaves_like 'valid model'
  end

  describe "assigned a nil" do
    before :all do
      @model.bool = nil
    end

    it_behaves_like 'valid model'
  end
end

describe "A model with a required Boolean property" do
  before :all do
    @model = HasRequiredBoolean.new(:id => 1)
  end

  describe "assigned a true" do
    before :all do
      @model.bool = true
    end

    it_behaves_like 'valid model'
  end

  describe "assigned a false" do
    before :all do
      @model.bool = false
    end

    it_behaves_like 'valid model'
  end

  describe "assigned a nil" do
    before :all do
      @model.bool = nil
    end

    it_behaves_like 'invalid model'

    it "has a meaningful error message" do
      expect(@model.errors.on(:bool)).to eq [ 'Bool must not be nil' ]
    end
  end
end

describe "A model with a required paranoid Boolean property" do
  before :all do
    @model = HasRequiredParanoidBoolean.new(:id => 1)
  end

  describe "assigned a true" do
    before :all do
      @model.bool = true
    end

    it_behaves_like 'valid model'
  end

  describe "assigned a false" do
    before :all do
      @model.bool = false
    end

    it_behaves_like 'valid model'
  end

  describe "assigned a nil" do
    before :all do
      @model.bool = nil
    end

    it_behaves_like 'invalid model'

    it "has a meaningful error message" do
      expect(@model.errors.on(:bool)).to eq [ 'Bool must not be nil' ]
    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_boolean_properties_validation_spec.rb
sbf-dm-validations-1.3.0 spec/integration/automatic_validation/inferred_boolean_properties_validation_spec.rb
sbf-dm-validations-1.3.0.beta spec/integration/automatic_validation/inferred_boolean_properties_validation_spec.rb