Sha256: 4a22369a6256f1c4c71e088714a63a0731fca2ee2ecd287a357935d8f5623d20

Contents?: true

Size: 1.98 KB

Versions: 2

Compression:

Stored size: 1.98 KB

Contents

describe Unidom::Standard::Standard, type: :model do

  before :each do
  end

  after :each do
  end

  context do

    model_attributes = {
      name:         'Some Name',
      number:       'GB/T 3259-2008',
      ics_code:     '11-23-68',
      published_on: Date.current-1.year,
      applied_on:   Date.current,
      obsoleted_on: Date.current+20.years
    }

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

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

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

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

    it_behaves_like 'scope', :number_is, [
      { attributes_collection: [ model_attributes                                                ], count_diff: 1, args: [ model_attributes[:number]       ] },
      { attributes_collection: [ model_attributes                                                ], count_diff: 0, args: [ "#{model_attributes[:number]}0" ] },
      { attributes_collection: [ model_attributes.merge(number: "#{model_attributes[:number]}0") ], count_diff: 0, args: [ model_attributes[:number]       ] },
      { attributes_collection: [ model_attributes.merge(number: "#{model_attributes[:number]}0") ], count_diff: 1, args: [ "#{model_attributes[:number]}0" ] } ]

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
unidom-standard-1.4.3 lib/rspec/models/unidom/standard/standard_spec.rb
unidom-standard-1.4.2 lib/rspec/models/unidom/standard/standard_spec.rb