Class: SearchIndexReceiver
- Inherits:
- 
      Object
      
        - Object
- SearchIndexReceiver
 
- Defined in:
- lib/chewy/minitest/search_index_receiver.rb
Overview
Intended to be used in conjunction with a test helper which mocks over the #bulk method on a Chewy::Index class. (See Chewy::Minitest::Helpers)
Test helper class to provide minitest hooks for Chewy::Index testing.
The class will capture the data from the *param on the Chewy::Index.bulk method and aggregate the data for test analysis.
Defined Under Namespace
Classes: MUTATION_FOR_CLASS
Instance Method Summary collapse
- #catch(bulk_params, index) ⇒ Object
- 
  
    
      #deleted?(obj, index)  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    Check to see if a given object has been deleted. 
- 
  
    
      #deletes_for(index = nil)  ⇒ Hash 
    
    
      (also: #deletes)
    
  
  
  
  
  
  
  
  
  
    The index deletes captured by the mock. 
- 
  
    
      #indexed?(obj, index)  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    Check to see if a given object has been indexed. 
- 
  
    
      #indexes_for(index = nil)  ⇒ Hash 
    
    
      (also: #indexes)
    
  
  
  
  
  
  
  
  
  
    The index changes captured by the mock. 
- 
  
    
      #initialize  ⇒ SearchIndexReceiver 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of SearchIndexReceiver. 
- 
  
    
      #updated_indexes  ⇒ Array<Chewy::Index> 
    
    
  
  
  
  
  
  
  
  
  
    A list of indexes changed. 
Constructor Details
#initialize ⇒ SearchIndexReceiver
Returns a new instance of SearchIndexReceiver.
| 11 12 13 | # File 'lib/chewy/minitest/search_index_receiver.rb', line 11 def initialize @mutations = {} end | 
Instance Method Details
#catch(bulk_params, index) ⇒ Object
| 17 18 19 20 21 22 23 24 25 | # File 'lib/chewy/minitest/search_index_receiver.rb', line 17 def catch(bulk_params, index) Array.wrap(bulk_params).map { |y| y[:body] }.flatten.each do |update| if update[:delete] mutation_for(index).deletes << update[:delete][:_id] elsif update[:index] mutation_for(index).indexes << update[:index] end end end | 
#deleted?(obj, index) ⇒ true, false
Check to see if a given object has been deleted.
| 61 62 63 | # File 'lib/chewy/minitest/search_index_receiver.rb', line 61 def deleted?(obj, index) deletes_for(index).include? obj.id end | 
#deletes_for(index = nil) ⇒ Hash Also known as: deletes
Returns the index deletes captured by the mock.
| 40 41 42 43 44 45 46 | # File 'lib/chewy/minitest/search_index_receiver.rb', line 40 def deletes_for(index = nil) if index mutation_for(index).deletes else @mutations.transform_values(&:deletes) end end | 
#indexed?(obj, index) ⇒ true, false
Check to see if a given object has been indexed.
| 53 54 55 | # File 'lib/chewy/minitest/search_index_receiver.rb', line 53 def indexed?(obj, index) indexes_for(index).map { |i| i[:_id] }.include? obj.id end | 
#indexes_for(index = nil) ⇒ Hash Also known as: indexes
Returns the index changes captured by the mock.
| 29 30 31 32 33 34 35 | # File 'lib/chewy/minitest/search_index_receiver.rb', line 29 def indexes_for(index = nil) if index mutation_for(index).indexes else @mutations.transform_values(&:indexes) end end | 
#updated_indexes ⇒ Array<Chewy::Index>
Returns a list of indexes changed.
| 66 67 68 | # File 'lib/chewy/minitest/search_index_receiver.rb', line 66 def updated_indexes @mutations.keys end |