Sha256: 0806d8881e45e5ce7c88cb3d257db4c6ae24679efcbdb64925d4e7709e87141d

Contents?: true

Size: 1.95 KB

Versions: 11

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Grape::Entity::Exposure::NestingExposure::NestedExposures do
  subject(:nested_exposures) { described_class.new([]) }

  describe '#deep_complex_nesting?(entity)' do
    it 'is reset when additional exposure is added' do
      subject << Grape::Entity::Exposure.new(:x, {})
      expect(subject.instance_variable_get(:@deep_complex_nesting)).to be_nil
      subject.deep_complex_nesting?(subject)
      expect(subject.instance_variable_get(:@deep_complex_nesting)).to_not be_nil
      subject << Grape::Entity::Exposure.new(:y, {})
      expect(subject.instance_variable_get(:@deep_complex_nesting)).to be_nil
    end

    it 'is reset when exposure is deleted' do
      subject << Grape::Entity::Exposure.new(:x, {})
      expect(subject.instance_variable_get(:@deep_complex_nesting)).to be_nil
      subject.deep_complex_nesting?(subject)
      expect(subject.instance_variable_get(:@deep_complex_nesting)).to_not be_nil
      subject.delete_by(:x)
      expect(subject.instance_variable_get(:@deep_complex_nesting)).to be_nil
    end

    it 'is reset when exposures are cleared' do
      subject << Grape::Entity::Exposure.new(:x, {})
      expect(subject.instance_variable_get(:@deep_complex_nesting)).to be_nil
      subject.deep_complex_nesting?(subject)
      expect(subject.instance_variable_get(:@deep_complex_nesting)).to_not be_nil
      subject.clear
      expect(subject.instance_variable_get(:@deep_complex_nesting)).to be_nil
    end
  end

  describe '.delete_by' do
    subject { nested_exposures.delete_by(*attributes) }

    let(:attributes) { [:id] }

    before do
      nested_exposures << Grape::Entity::Exposure.new(:id, {})
    end

    it 'deletes matching exposure' do
      is_expected.to eq []
    end

    context "when given attribute doesn't exists" do
      let(:attributes) { [:foo] }

      it 'deletes matching exposure' do
        is_expected.to eq(nested_exposures)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
grape-entity-1.0.1 spec/grape_entity/exposure/nesting_exposure/nested_exposures_spec.rb
grape-entity-1.0.0 spec/grape_entity/exposure/nesting_exposure/nested_exposures_spec.rb
grape-entity-0.10.2 spec/grape_entity/exposure/nesting_exposure/nested_exposures_spec.rb
grape-entity-0.10.1 spec/grape_entity/exposure/nesting_exposure/nested_exposures_spec.rb
grape-entity-0.10.0 spec/grape_entity/exposure/nesting_exposure/nested_exposures_spec.rb
grape-entity-0.9.0 spec/grape_entity/exposure/nesting_exposure/nested_exposures_spec.rb
grape-entity-0.8.2 spec/grape_entity/exposure/nesting_exposure/nested_exposures_spec.rb
grape-entity-0.8.1 spec/grape_entity/exposure/nesting_exposure/nested_exposures_spec.rb
grape-entity-0.8.0 spec/grape_entity/exposure/nesting_exposure/nested_exposures_spec.rb
grape-entity-0.7.1 spec/grape_entity/exposure/nesting_exposure/nested_exposures_spec.rb
grape-entity-0.7.0 spec/grape_entity/exposure/nesting_exposure/nested_exposures_spec.rb