Sha256: 40434ef286c6e7c9f4f602b45ceb088663ec7a29ecb86cfe5218e8a2842cbc61

Contents?: true

Size: 642 Bytes

Versions: 10

Compression:

Stored size: 642 Bytes

Contents

require 'spec_helper'

Spree::Product.class_eval do
  attribute :slug, ActiveRecord::Type::String.new(limit: 255)
  # Slug currently has no validation for maximum length
  validates :slug, db_maximum_length: true
end

describe DbMaximumLengthValidator, type: :model do
  let(:limit_for_slug) { Spree::Product.columns_hash['slug'].limit.to_i }
  let(:product) { Spree::Product.new }
  let(:slug) { 'x' * (limit_for_slug + 1) }

  before do
    product.slug = slug
  end

  it 'should maximum validate slug' do
    product.valid?
    expect(product.errors[:slug]).to include(I18n.t("errors.messages.too_long", count: limit_for_slug))
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
spree_core-3.1.5 spec/validators/db_maximum_length_validator_spec.rb
spree_core-3.1.4 spec/validators/db_maximum_length_validator_spec.rb
spree_core-3.1.3 spec/validators/db_maximum_length_validator_spec.rb
spree_core-3.1.2 spec/validators/db_maximum_length_validator_spec.rb
spree_core-3.1.1 spec/validators/db_maximum_length_validator_spec.rb
spree_core-3.1.0 spec/validators/db_maximum_length_validator_spec.rb
spree_core-3.1.0.rc4 spec/validators/db_maximum_length_validator_spec.rb
spree_core-3.1.0.rc3 spec/validators/db_maximum_length_validator_spec.rb
spree_core-3.1.0.rc2 spec/validators/db_maximum_length_validator_spec.rb
spree_core-3.1.0.rc1 spec/validators/db_maximum_length_validator_spec.rb