1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
# 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
|