Sha256: f509c7305447a6c2a03481ff24487f413c7869b68e0629cc7e60b8af65b6eb4b

Contents?: true

Size: 802 Bytes

Versions: 26

Compression:

Stored size: 802 Bytes

Contents

require 'spec_helper'

describe Spree::Validations::DbMaximumLengthValidator, type: :model do
  with_model 'LimitedProduct', scope: :all do
    table do |t|
      t.string :slug, limit: 255
    end

    model do
      validates_with Spree::Validations::DbMaximumLengthValidator, field: :slug
    end
  end

  let(:record) { LimitedProduct.new(slug: slug) }

  context "when slug is below limit" do
    let(:slug) { 'a' * 255 }
    it 'should be valid' do
      expect(record).to be_valid
      expect(record.errors).to be_empty
    end
  end

  context "when slug is too long" do
    let(:slug) { 'a' * 256 }
    it 'should be invalid and set error' do
      expect(record).not_to be_valid
      expect(record.errors[:slug]).to include(I18n.t("errors.messages.too_long", count: 255))
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
solidus_core-2.3.1 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.2.2 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.1.1 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.0.3 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-1.4.2 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.3.0 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.3.0.rc3 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.3.0.rc2 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.3.0.rc1 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.3.0.beta1 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.0.2 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-1.4.1 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.2.1 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.2.0 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.2.0.rc1 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.2.0.beta1 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.1.0 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.1.0.rc1 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.0.1 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.1.0.beta1 spec/models/spree/validations/db_maximum_length_validator_spec.rb