Sha256: 13a9e1058a41833af5a530486220c768dc7767834e1f2874423385ec75a28875

Contents?: true

Size: 1.44 KB

Versions: 4

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'

describe OData4::NavigationProperty::Proxy, vcr: {cassette_name: 'navigation_property_proxy_specs'} do
  before :each do
    OData4::Service.open('http://services.odata.org/V4/OData/OData.svc', name: 'ODataDemo')
  end

  let(:entity) { OData4::ServiceRegistry['ODataDemo']['Products'][1] }

  let(:categories_proxy) { OData4::NavigationProperty::Proxy.new(entity, 'Categories') }
  let(:detail_proxy) { OData4::NavigationProperty::Proxy.new(entity, 'ProductDetail') }
  let(:supplier_proxy) { OData4::NavigationProperty::Proxy.new(entity, 'Supplier') }

  describe 'value' do
    it { expect(categories_proxy.value).to be_a(Enumerable) }
    it { expect(supplier_proxy.value).to be_a(OData4::Entity) }
    it { expect(detail_proxy.value).to be_a(OData4::Entity) }

    context 'when value was explicitly set' do
      let(:supplier) { double('supplier') }

      it 'returns the set value' do
        supplier_proxy.value = supplier
        expect(supplier_proxy.value).to eq(supplier)
      end
    end

    context 'when no links exist for an entity' do
      before(:each) do
        expect(entity).to receive(:links) do
          { 'Categories' => nil, 'Supplier' => nil }
        end
      end

      context 'for a many NavigationProperty' do
        it { expect(categories_proxy.value).to eq([]) }
      end

      context 'for a singular NavigationProperty' do
        it { expect(supplier_proxy.value).to eq(nil) }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
odata4-0.8.2 spec/odata4/navigation_property/proxy_spec.rb
odata4-0.8.1 spec/odata4/navigation_property/proxy_spec.rb
odata4-0.8.0 spec/odata4/navigation_property/proxy_spec.rb
odata4-0.7.0 spec/odata4/navigation_property/proxy_spec.rb