Sha256: 5e67695134bd8d6d4bec8f06326ff23e1bf7ed2237ee121604b8cea44ad0b13e

Contents?: true

Size: 1.77 KB

Versions: 31

Compression:

Stored size: 1.77 KB

Contents

require 'spec_helper'

module ClassConstantizerTest
  ClassA = Class.new
  ClassB = Class.new

  def self.reload
    [:ClassA, :ClassB].each do |klass|
      remove_const(klass)
      const_set(klass, Class.new)
    end
  end
end

describe Spree::Core::ClassConstantizer::Set do
  let(:set) { described_class.new }

  describe "#concat" do
    it "can add one item" do
      set.concat(['ClassConstantizerTest::ClassA'])
      expect(set).to include(ClassConstantizerTest::ClassA)
    end

    it "can add two items" do
      set.concat(['ClassConstantizerTest::ClassA', ClassConstantizerTest::ClassB])
      expect(set).to include(ClassConstantizerTest::ClassA)
      expect(set).to include(ClassConstantizerTest::ClassB)
    end
  end

  describe "<<" do
    it "can add by string" do
      set << "ClassConstantizerTest::ClassA"
      expect(set).to include(ClassConstantizerTest::ClassA)
    end

    it "can add by class" do
      set << ClassConstantizerTest::ClassA
      expect(set).to include(ClassConstantizerTest::ClassA)
    end

    describe "class redefinition" do
      shared_examples "working code reloading" do
        it "works with a class" do
          original = ClassConstantizerTest::ClassA

          ClassConstantizerTest.reload

          # Sanity check
          expect(original).not_to eq(ClassConstantizerTest::ClassA)

          expect(set).to include(ClassConstantizerTest::ClassA)
          expect(set).to_not include(original)
        end
      end

      context "with a class" do
        before { set << ClassConstantizerTest::ClassA }
        it_should_behave_like "working code reloading"
      end

      context "with a string" do
        before { set << "ClassConstantizerTest::ClassA" }
        it_should_behave_like "working code reloading"
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
solidus_core-2.3.1 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-2.2.2 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-2.1.1 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-2.0.3 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-1.4.2 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-1.3.2 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-2.3.0 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-2.3.0.rc3 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-2.3.0.rc2 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-2.3.0.rc1 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-2.3.0.beta1 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-2.0.2 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-1.4.1 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-2.2.1 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-2.2.0 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-2.2.0.rc1 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-2.2.0.beta1 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-2.1.0 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-2.1.0.rc1 spec/lib/spree/core/class_constantizer_spec.rb
solidus_core-2.0.1 spec/lib/spree/core/class_constantizer_spec.rb