lib/rspec/models/unidom/geo/location_spec.rb in unidom-geo-1.5.4 vs lib/rspec/models/unidom/geo/location_spec.rb in unidom-geo-1.5.5

- old
+ new

@@ -19,191 +19,26 @@ minimum_latitude: 30.990000, maximum_longitude: 120.010000, maximum_latitude: 31.010000 } - postal_address_max_length = described_class.columns_hash['postal_address'].limit - postal_code_max_length = described_class.columns_hash['postal_code'].limit - it_behaves_like 'Unidom::Common::Concerns::ModelExtension', model_attributes - it_behaves_like 'validates', model_attributes, :latitude, - { } => 0, - { latitude: nil } => 2, - { latitude: '' } => 2, - { latitude: 'A' } => 1, - { latitude: '10' } => 0, - { latitude: 10 } => 0, - { latitude: '10.1' } => 0, - { latitude: 10.1 } => 0, - { latitude: '-10' } => 0, - { latitude: -10 } => 0, - { latitude: '-10.1' } => 0, - { latitude: -10.1 } => 0, - { latitude: -90.000001 } => 1, - { latitude: '-90.000001' } => 1, - { latitude: -90 } => 0, - { latitude: '-90' } => 0, - { latitude: -89.999999 } => 0, - { latitude: '-89.999999' } => 0, - { latitude: 90.000001 } => 1, - { latitude: '90.000001' } => 1, - { latitude: 90 } => 0, - { latitude: '90' } => 0, - { latitude: 89.999999 } => 0, - { latitude: '89.999999' } => 0 + it_behaves_like 'validates numericality', model_attributes, :latitude, + range: -90..90, minimum_inclusive: true, maximum_inclusive: true, allow_blank: false + it_behaves_like 'validates numericality', model_attributes, :minimum_latitude, + range: -90..90, minimum_inclusive: true, maximum_inclusive: true, allow_blank: false + it_behaves_like 'validates numericality', model_attributes, :maximum_latitude, + range: -90..90, minimum_inclusive: true, maximum_inclusive: true, allow_blank: false + it_behaves_like 'validates numericality', model_attributes, :longitude, + range: -180..180, minimum_inclusive: true, maximum_inclusive: true, allow_blank: false + it_behaves_like 'validates numericality', model_attributes, :minimum_longitude, + range: -180..180, minimum_inclusive: true, maximum_inclusive: true, allow_blank: false + it_behaves_like 'validates numericality', model_attributes, :maximum_longitude, + range: -180..180, minimum_inclusive: true, maximum_inclusive: true, allow_blank: false - it_behaves_like 'validates', model_attributes, :minimum_latitude, - { } => 0, - { minimum_latitude: nil } => 2, - { minimum_latitude: '' } => 2, - { minimum_latitude: 'A' } => 1, - { minimum_latitude: '10' } => 0, - { minimum_latitude: 10 } => 0, - { minimum_latitude: '10.1' } => 0, - { minimum_latitude: 10.1 } => 0, - { minimum_latitude: '-10' } => 0, - { minimum_latitude: -10 } => 0, - { minimum_latitude: '-10.1' } => 0, - { minimum_latitude: -10.1 } => 0, - { minimum_latitude: -90.000001 } => 1, - { minimum_latitude: '-90.000001' } => 1, - { minimum_latitude: -90 } => 0, - { minimum_latitude: '-90' } => 0, - { minimum_latitude: -89.999999 } => 0, - { minimum_latitude: '-89.999999' } => 0, - { minimum_latitude: 90.000001 } => 1, - { minimum_latitude: '90.000001' } => 1, - { minimum_latitude: 90 } => 0, - { minimum_latitude: '90' } => 0, - { minimum_latitude: 89.999999 } => 0, - { minimum_latitude: '89.999999' } => 0 - - it_behaves_like 'validates', model_attributes, :maximum_latitude, - { } => 0, - { maximum_latitude: nil } => 2, - { maximum_latitude: '' } => 2, - { maximum_latitude: 'A' } => 1, - { maximum_latitude: '10' } => 0, - { maximum_latitude: 10 } => 0, - { maximum_latitude: '10.1' } => 0, - { maximum_latitude: 10.1 } => 0, - { maximum_latitude: '-10' } => 0, - { maximum_latitude: -10 } => 0, - { maximum_latitude: '-10.1' } => 0, - { maximum_latitude: -10.1 } => 0, - { maximum_latitude: -90.000001 } => 1, - { maximum_latitude: '-90.000001' } => 1, - { maximum_latitude: -90 } => 0, - { maximum_latitude: '-90' } => 0, - { maximum_latitude: -89.999999 } => 0, - { maximum_latitude: '-89.999999' } => 0, - { maximum_latitude: 90.000001 } => 1, - { maximum_latitude: '90.000001' } => 1, - { maximum_latitude: 90 } => 0, - { maximum_latitude: '90' } => 0, - { maximum_latitude: 89.999999 } => 0, - { maximum_latitude: '89.999999' } => 0 - - it_behaves_like 'validates', model_attributes, :longitude, - { } => 0, - { longitude: nil } => 2, - { longitude: '' } => 2, - { longitude: 'A' } => 1, - { longitude: '10' } => 0, - { longitude: 10 } => 0, - { longitude: '10.1' } => 0, - { longitude: 10.1 } => 0, - { longitude: '-10' } => 0, - { longitude: -10 } => 0, - { longitude: '-10.1' } => 0, - { longitude: -10.1 } => 0, - { longitude: -180.000001 } => 1, - { longitude: '-180.000001' } => 1, - { longitude: -180 } => 0, - { longitude: '-180' } => 0, - { longitude: -179.999999 } => 0, - { longitude: '-179.999999' } => 0, - { longitude: 180.000001 } => 1, - { longitude: '180.000001' } => 1, - { longitude: 180 } => 0, - { longitude: '180' } => 0, - { longitude: 179.999999 } => 0, - { longitude: '179.999999' } => 0 - - it_behaves_like 'validates', model_attributes, :minimum_longitude, - { } => 0, - { minimum_longitude: nil } => 2, - { minimum_longitude: '' } => 2, - { minimum_longitude: 'A' } => 1, - { minimum_longitude: '10' } => 0, - { minimum_longitude: 10 } => 0, - { minimum_longitude: '10.1' } => 0, - { minimum_longitude: 10.1 } => 0, - { minimum_longitude: '-10' } => 0, - { minimum_longitude: -10 } => 0, - { minimum_longitude: '-10.1' } => 0, - { minimum_longitude: -10.1 } => 0, - { minimum_longitude: -180.000001 } => 1, - { minimum_longitude: '-180.000001' } => 1, - { minimum_longitude: -180 } => 0, - { minimum_longitude: '-180' } => 0, - { minimum_longitude: -179.999999 } => 0, - { minimum_longitude: '-179.999999' } => 0, - { minimum_longitude: 180.000001 } => 1, - { minimum_longitude: '180.000001' } => 1, - { minimum_longitude: 180 } => 0, - { minimum_longitude: '180' } => 0, - { minimum_longitude: 179.999999 } => 0, - { minimum_longitude: '179.999999' } => 0 - - it_behaves_like 'validates', model_attributes, :maximum_longitude, - { } => 0, - { maximum_longitude: nil } => 2, - { maximum_longitude: '' } => 2, - { maximum_longitude: 'A' } => 1, - { maximum_longitude: '10' } => 0, - { maximum_longitude: 10 } => 0, - { maximum_longitude: '10.1' } => 0, - { maximum_longitude: 10.1 } => 0, - { maximum_longitude: '-10' } => 0, - { maximum_longitude: -10 } => 0, - { maximum_longitude: '-10.1' } => 0, - { maximum_longitude: -10.1 } => 0, - { maximum_longitude: -180.000001 } => 1, - { maximum_longitude: '-180.000001' } => 1, - { maximum_longitude: -180 } => 0, - { maximum_longitude: '-180' } => 0, - { maximum_longitude: -179.999999 } => 0, - { maximum_longitude: '-179.999999' } => 0, - { maximum_longitude: 180.000001 } => 1, - { maximum_longitude: '180.000001' } => 1, - { maximum_longitude: 180 } => 0, - { maximum_longitude: '180' } => 0, - { maximum_longitude: 179.999999 } => 0, - { maximum_longitude: '179.999999' } => 0 - - it_behaves_like 'validates', model_attributes, :postal_address, - { } => 0, - { postal_address: nil } => 2, - { postal_address: '' } => 2, - { postal_address: 'A' } => 1, - { postal_address: 'AA' } => 0, - { postal_address: 'AAA' } => 0, - { postal_address: 'A'*(postal_address_max_length-1) } => 0, - { postal_address: 'A'*postal_address_max_length } => 0, - { postal_address: 'A'*(postal_address_max_length+1) } => 1 - - it_behaves_like 'validates', model_attributes, :postal_code, - { } => 0, - { postal_code: nil } => 2, - { postal_code: '' } => 2, - { postal_code: 'A' } => 1, - { postal_code: 'AA' } => 1, - { postal_code: 'AAA' } => 0, - { postal_code: 'A'*(postal_code_max_length-1) } => 0, - { postal_code: 'A'*postal_code_max_length } => 0, - { postal_code: 'A'*(postal_code_max_length+1) } => 1 + it_behaves_like 'validates text', model_attributes, :postal_address, length: 2..described_class.columns_hash['postal_address'].limit + it_behaves_like 'validates text', model_attributes, :postal_code, length: 3..described_class.columns_hash['postal_code'].limit locating_1_attributes = { located_id: SecureRandom.uuid, located_type: 'Unidom::Geo::Located::Mock', locator_id: SecureRandom.uuid,