Sha256: 671918978064a67fbd3eb5a30d5df35cfc90d4f0ecccfad2a1add30889108f73

Contents?: true

Size: 709 Bytes

Versions: 6

Compression:

Stored size: 709 Bytes

Contents

require 'spec_helper'

describe Spree::Validations::DbMaximumLengthValidator, :type => :model do
  context 'when Spree::Product' do
    Spree::Product.class_eval do
      attribute :slug, ActiveRecord::Type::String.new(limit: 255)
      # Slug currently has no validation for maximum length
      validates_with Spree::Validations::DbMaximumLengthValidator, field: :slug
    end

    let(:limit) { 255 }
    let(:product) { Spree::Product.new }
    let(:slug) { "x" * (limit + 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))
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spree_core-3.0.10 spec/models/spree/validations/db_maximum_length_validator_spec.rb
spree_core-3.0.9 spec/models/spree/validations/db_maximum_length_validator_spec.rb
spree_core-3.0.8 spec/models/spree/validations/db_maximum_length_validator_spec.rb
spree_core-3.0.7 spec/models/spree/validations/db_maximum_length_validator_spec.rb
spree_core-3.0.6.1 spec/models/spree/validations/db_maximum_length_validator_spec.rb
spree_core-3.0.6 spec/models/spree/validations/db_maximum_length_validator_spec.rb