Sha256: 21779760242d7e31f4650dce6f91e9aaa1aaede754a687d42f9bac088081d85b

Contents?: true

Size: 1.56 KB

Versions: 3

Compression:

Stored size: 1.56 KB

Contents

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

describe 'City' do
  before do
    City.auto_migrate!

    @city = City.new(:name => "Tokyo", :founded_in => 1603)
  end

  describe "with foundation year as integer" do
    before do
      # no op in this case
    end

    it "is valid" do
      expect(@city).to be_valid
    end
  end


  describe "with foundation year as integer" do
    before do
      @city.founded_in = 1603
    end

    it "is valid" do
      expect(@city).to be_valid
    end
  end


  describe "with foundation year as string containing only integers" do
    before do
      @city.founded_in = "1603"
    end

    it "is valid" do
      expect(@city).to be_valid
    end
  end


  describe "with foundation year as string containing a float" do
    before do
      @city.founded_in = "1603.6"
    end

    it "is valid" do
      expect(@city).to be_valid
    end
  end


  describe "with foundation year as string that is not an integer or float" do
    before do
      @string = "founded-in=1603"

      @city.founded_in = @string
    end

    it "is not altered" do
      expect(@city.founded_in).to be(@string)
    end

    it "IS NOT valid" do
      expect(@city).not_to be_valid
    end
  end


  describe "with unknown foundation date" do
    before do
      @city.founded_in = nil
    end

    it "is NOT valid" do
      expect(@city).not_to be_valid
    end

    it "has a meaningful error message on for the property" do
      @city.valid?
      expect(@city.errors.on(:founded_in)).to eq [ 'Foundation year must be an integer' ]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sbf-dm-validations-1.4.0 spec/integration/numeric_validator/integer_type_spec.rb
sbf-dm-validations-1.3.0 spec/integration/numeric_validator/integer_type_spec.rb
sbf-dm-validations-1.3.0.beta spec/integration/numeric_validator/integer_type_spec.rb