Sha256: 6962d54d8210572d5106e4a2c241f54d5d5f4741acc724b4476714ce3f6f7294

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

describe Unidom::Geo::China::Town, type: :model do

  before :each do
  end

  after :each do
  end

  context do

    model_attributes = {
      region_id:    SecureRandom.uuid,
      numeric_code: '1'*9,
      name:         'Some Town'
    }

    name_max_length = described_class.columns_hash['name'].limit

    it_behaves_like 'Unidom::Common::Concerns::ModelExtension', model_attributes

    it_behaves_like 'validates', model_attributes, :numeric_code,
      {                             } => 0,
      { numeric_code: nil           } => 3,
      { numeric_code: ''            } => 3,
      { numeric_code: '1'           } => 1,
      { numeric_code: '1'*8         } => 1,
      { numeric_code: 11_111_111    } => 1,
      { numeric_code: "-#{'1'*8}"   } => 1,
      { numeric_code: -11_111_111   } => 1,
      { numeric_code: '1'*9         } => 0,
      { numeric_code: 111_111_111   } => 0,
      { numeric_code: "-#{'1'*9}"   } => 2,
      { numeric_code: -111_111_111  } => 2,
      { numeric_code: '1'*10        } => 1,
      { numeric_code: 1_111_111_111 } => 1,
      { numeric_code: "#{'1'*8}A"   } => 1,
      { numeric_code: '111111.11'   } => 1,
      { numeric_code: 111111.11     } => 1

    it_behaves_like 'validates', model_attributes, :name,
      {              } => 0,
      { name: nil    } => 2,
      { name: ''     } => 2,
      { name: '1'    } => 1,
      { name: '11'   } => 0,
      { name: 'AA'   } => 0,
      { name: '111'  } => 0,
      { name: 'AAA'  } => 0,
      { name: '1'*(name_max_length-1) } => 0,
      { name: 'A'*(name_max_length-1) } => 0,
      { name: '1'*name_max_length     } => 0,
      { name: 'A'*name_max_length     } => 0,
      { name: '1'*(name_max_length+1) } => 1,
      { name: 'A'*(name_max_length+1) } => 1

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
unidom-geo-china-0.5.2 lib/rspec/models/unidom/geo/china/town_spec.rb
unidom-geo-china-0.5.1 lib/rspec/models/unidom/geo/china/town_spec.rb