Sha256: 5e31b93f1e01828848b10960d2db069d0bf4b1e70b1649ef3c4ad18265b8d55f

Contents?: true

Size: 990 Bytes

Versions: 13

Compression:

Stored size: 990 Bytes

Contents

require 'rails_helper'

describe LHS::Record do
  before(:each) do
    class Location < LHS::Record
      endpoint 'http://uberall/locations'
      endpoint 'http://uberall/locations/{id}'
      has_many :listings
    end

    class Listing < LHS::Record

      def supported?
        true
      end
    end
  end

  context 'has_many' do
    let(:location) { Location.find(1) }
    let(:listing) { location.listings.first }

    before(:each) do
      stub_request(:get, 'http://uberall/locations/1')
        .to_return(body: {
          listings: [{
            directory: { name: 'Instagram' }
          }]
        }.to_json)
    end

    it 'casts the relation into the correct type' do
      expect(listing).to be_kind_of(Listing)
      expect(listing.supported?).to eq true
    end

    it 'keeps hirachy when casting it to another class on access' do
      expect(listing._root._raw).to eq location._raw
      expect(listing.parent.parent._raw).to eq location._raw
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
lhs-15.2.5 spec/record/has_many_spec.rb
lhs-15.2.4 spec/record/has_many_spec.rb
lhs-15.2.3 spec/record/has_many_spec.rb
lhs-15.2.3.pre.favorites.1 spec/record/has_many_spec.rb
lhs-15.2.2.pre.favorites.1 spec/record/has_many_spec.rb
lhs-15.2.2 spec/record/has_many_spec.rb
lhs-15.2.1 spec/record/has_many_spec.rb
lhs-15.2.0 spec/record/has_many_spec.rb
lhs-15.1.1 spec/record/has_many_spec.rb
lhs-15.1.0 spec/record/has_many_spec.rb
lhs-15.0.2 spec/record/has_many_spec.rb
lhs-15.0.1 spec/record/has_many_spec.rb
lhs-15.0.0 spec/record/has_many_spec.rb