class Object

Public Instance Methods

array_difference(first, second) click to toggle source
# File lib/chewy/rspec/update_index.rb, line 248
def array_difference(first, second)
  difference = first.to_ary.dup
  second.to_ary.each do |element|
    index = difference.index(element)
    difference.delete_at(index) if index
  end
  difference.none?
end
compare_attributes(expected, real) click to toggle source
# File lib/chewy/rspec/update_index.rb, line 235
def compare_attributes(expected, real)
  expected.inject(true) do |result, (key, value)|
    equal = if value.is_a?(Array) && real[key].is_a?(Array)
      array_difference(value, real[key]) && array_difference(real[key], value)
    elsif value.is_a?(Hash) && real[key].is_a?(Hash)
      compare_attributes(value, real[key])
    else
      real[key] == value
    end
    result && equal
  end
end
extract_documents(*args) click to toggle source
# File lib/chewy/rspec/update_index.rb, line 217
def extract_documents(*args)
  options = args.extract_options!

  expected_count = options[:times] || options[:count]
  expected_attributes = (options[:with] || options[:attributes] || {}).deep_symbolize_keys

  args.flatten.to_h do |document|
    id = document.respond_to?(:id) ? document.id.to_s : document.to_s
    [id, {
      document: document,
      expected_count: expected_count,
      expected_attributes: expected_attributes,
      real_count: 0,
      real_attributes: {}
    }]
  end
end
mock_bulk_request() click to toggle source
# File lib/chewy/rspec/update_index.rb, line 213
def mock_bulk_request
  @mock_bulk_request ||= MockBulkRequest.new
end
supports_block_expectations?() click to toggle source
# File lib/chewy/rspec/update_index.rb, line 96
def supports_block_expectations?
  true
end
try_require(path) click to toggle source
# File lib/chewy.rb, line 25
def try_require(path)
  require path
rescue LoadError
  nil
end