Sha256: ee5da569a511f39b5dc1dfb3d3f3529266b57c563ae3b68eadd3f11176fd6265

Contents?: true

Size: 1.67 KB

Versions: 13

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

require 'spec_helper'
require 'spree/core/environment/promotions'
require 'spree/promo/environment'

RSpec.describe 'Spree::Promo::Environment' do
  it 'is deprecated' do
    expect(Spree::Deprecation).to receive(:warn)

    Spree::Promo::Environment.new
  end

  context 'when customized' do
    after do
      # This is needed to cleanup classes after the following specs run.
      # They will add two new methods but we don't want them to be defined
      # on the described class for specs that will run later.
      Spree::Core::Environment::Promotions.remove_method :custom_rules, :custom_rules=
    end

    context 'with class_eval' do
      it 'raises a deprecation warning but keep changes' do
        expect(Spree::Deprecation).to receive(:warn)

        Spree::Promo::Environment.class_eval do
          add_class_set :custom_rules
        end

        promo_environment_instance = Spree::Core::Environment::Promotions.new
        expect(promo_environment_instance).to respond_to(:custom_rules)
        expect(promo_environment_instance).to respond_to(:custom_rules=)
      end
    end

    context 'with prepend' do
      it 'raises a deprecation warning but keep changes' do
        expect(Spree::Deprecation).to receive(:warn)

        module CustomRules
          def self.prepended(base)
            base.add_class_set :custom_rules
          end
        end
        Spree::Promo::Environment.prepend CustomRules

        promo_environment_instance = Spree::Core::Environment::Promotions.new
        expect(promo_environment_instance).to respond_to(:custom_rules)
        expect(promo_environment_instance).to respond_to(:custom_rules=)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
solidus_core-2.10.5 spec/lib/spree/promo/environment_spec.rb
solidus_core-2.10.3 spec/lib/spree/promo/environment_spec.rb
solidus_core-2.10.2 spec/lib/spree/promo/environment_spec.rb
solidus_core-2.9.6 spec/lib/spree/promo/environment_spec.rb
solidus_core-2.10.1 spec/lib/spree/promo/environment_spec.rb
solidus_core-2.9.5 spec/lib/spree/promo/environment_spec.rb
solidus_core-2.10.0 spec/lib/spree/promo/environment_spec.rb
solidus_core-2.9.4 spec/lib/spree/promo/environment_spec.rb
solidus_core-2.9.3 spec/lib/spree/promo/environment_spec.rb
solidus_core-2.9.2 spec/lib/spree/promo/environment_spec.rb
solidus_core-2.10.0.beta1 spec/lib/spree/promo/environment_spec.rb
solidus_core-2.9.1 spec/lib/spree/promo/environment_spec.rb
solidus_core-2.9.0 spec/lib/spree/promo/environment_spec.rb