Sha256: 05190bc512883753555d13076d72ac8f9244d72c6af12695f4d6eee12cc3ed3e

Contents?: true

Size: 1.18 KB

Versions: 48

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Spree::Order::NumberGenerator do
  subject { described_class.new.generate }

  it { is_expected.to be_a(String) }

  describe 'length' do
    let(:default_length) do
      Spree::Order::ORDER_NUMBER_LENGTH + Spree::Order::ORDER_NUMBER_PREFIX.length
    end

    it { expect(subject.length).to eq default_length }

    context "when length option is 5" do
      let(:option_length) { 5 + Spree::Order::ORDER_NUMBER_PREFIX.length }

      subject { described_class.new(length: 5).generate }

      it "should be 5 plus default prefix length" do
        expect(subject.length).to eq option_length
      end
    end
  end

  context "when letters option is true" do
    subject { described_class.new(letters: true).generate }

    it "generates order number including letters" do
      is_expected.to match /[A-Z]/
    end
  end

  describe 'prefix' do
    it { is_expected.to match /^#{Spree::Order::ORDER_NUMBER_PREFIX}/ }

    context "when prefix option is 'P'" do
      subject { described_class.new(prefix: 'P').generate }

      it "generates order number prefixed with 'P'" do
        is_expected.to match /^P/
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

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