Module: Shark::RSpec::Helpers::CacheHelper

Included in:
FakeContactService::ObjectCache
Defined in:
lib/shark/rspec/helpers/cache_helper.rb

Instance Method Summary collapse

Instance Method Details

#find(type, id) ⇒ Object



7
8
9
# File 'lib/shark/rspec/helpers/cache_helper.rb', line 7

def find(type, id)
  objects.detect { |o| o['type'] == type && o['id'] == id }
end

#included_resources(object_or_objects, params) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/shark/rspec/helpers/cache_helper.rb', line 11

def included_resources(object_or_objects, params)
  return [] unless params['include'].present?

  relationships = params['include'].split(',')
  included_objects = []

  to_array(object_or_objects).each do |object|
    relationships.each do |name|
      rdata = object.dig('relationships', name, 'data')
      to_array(rdata).each do |r|
        included_objects << find(r['type'], r['id'])
      end
    end
  end

  included_objects.compact
end