Sha256: e2bd36dbe274dbe243c80dc91bf972e85ffa355283722ef1d6e2778558c17052

Contents?: true

Size: 1.64 KB

Versions: 7

Compression:

Stored size: 1.64 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 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

7 entries across 7 versions & 1 rubygems

Version Path
blacklight-8.8.0 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-8.7.0 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-8.6.1 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-8.6.0 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-8.5.1 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-8.5.0 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb
blacklight-8.4.0 spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb