Sha256: ecc1606a11089db0fc7faa7691971c5332edfabbfe296eec766a7d1c886238e7

Contents?: true

Size: 1.65 KB

Versions: 55

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

RSpec.describe Blacklight::NestedOpenStructWithHashAccess do
  subject { described_class.new(Blacklight::OpenStructWithHashAccess) }

  describe '#key' do
    context 'for an object provided by the initializer' do
      subject { described_class.new(Blacklight::OpenStructWithHashAccess, a: { b: 1 }) }

      it 'copies the key to the initialized value' do
        expect(subject.a).to have_attributes key: :a, b: 1
      end
    end

    context 'for an object provided through assignment' do
      it 'copies the key to the initialized value' do
        subject.a!

        expect(subject.a).to have_attributes key: :a
      end
    end
  end

  describe "#deep_dup" do
    it "preserves the current class" do
      expect(described_class.new(described_class).deep_dup).to be_a_kind_of described_class
    end

    it "preserves the default proc" do
      nested = described_class.new Hash

      copy = nested.deep_dup
      copy.a[:b] = 1
      expect(copy.a[:b]).to eq 1
    end
  end

  describe '#<<' do
    subject { described_class.new(Blacklight::Configuration::Field) }

    it 'includes the key in the hash' do
      subject << :blah
      expect(subject.blah).to have_attributes(key: :blah)
    end
  end

  describe 'adding new parameters' do
    subject { described_class.new(Blacklight::Configuration::Field) }

    it 'strips the trailing !' do
      subject.blah!
      expect(subject.blah).to have_attributes(key: :blah)
      expect(subject.keys).to eq [:blah]
    end

    it 'supports direct assignment' do
      subject.blah = '123'
      expect(subject.blah).to eq '123'
      expect(subject.keys).to eq [:blah]
    end
  end
end

Version data entries

55 entries across 54 versions & 2 rubygems

Version Path
blacklight-7.40.0 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-7.39.0 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-7.38.0 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-7.37.0/spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-8.3.0/spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-8.3.0 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-8.2.2 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-8.2.1 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-8.2.0 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-7.37.0 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-7.36.2 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-7.36.1 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-7.36.0 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-7.35.0 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-8.1.0 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-7.34.0 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-8.0.1 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-8.0.0 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-8.0.0.beta8 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-8.0.0.beta7 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb