Sha256: 88a2eb4f537e2c4a52b579cd62e0cc4c55b41ba349cf6ec581e75a37c46d650a

Contents?: true

Size: 840 Bytes

Versions: 48

Compression:

Stored size: 840 Bytes

Contents

# frozen_string_literal: true

require 'rails_helper'

RSpec.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

48 entries across 48 versions & 2 rubygems

Version Path
solidus_core-2.10.5 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.10.3 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.10.2 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.9.6 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.8.6 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.10.1 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.9.5 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.10.0 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.9.4 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.6.6 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.7.4 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.8.5 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.9.3 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.9.2 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.10.0.beta1 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.7.3 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.6.5 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.9.1 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.9.0 spec/models/spree/validations/db_maximum_length_validator_spec.rb
solidus_core-2.9.0.rc.1 spec/models/spree/validations/db_maximum_length_validator_spec.rb