Class: SunspotMatchers::SunspotSessionSpy

Inherits:
Sunspot::Session
  • Object
show all
Defined in:
lib/sunspot_matchers/sunspot_session_spy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_session) ⇒ SunspotSessionSpy

Returns a new instance of SunspotSessionSpy.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 20

def initialize(original_session)
  # Support Sunspot random field in test -- Sunspot originally generate a random number for the field
  # Only patch method if SunspotSessionSpy is initialized to prevent poisoning class simply by being included in Gemfile.
  Sunspot::Query::Sort::RandomSort.class_eval do
    define_method :to_param do
      "random #{direction_for_solr}"
    end
  end

  @searches = []
  @original_session = original_session
  @config = Sunspot::Configuration.build
end

Instance Attribute Details

#current_search_classObject (readonly)

Returns the value of attribute current_search_class.



16
17
18
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 16

def current_search_class
  @current_search_class
end

#original_sessionObject (readonly)

Returns the value of attribute original_session.



15
16
17
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 15

def original_session
  @original_session
end

#searchesObject

Returns the value of attribute searches.



18
19
20
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 18

def searches
  @searches
end

Instance Method Details

#build_search(*types, &block) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 90

def build_search(*types, &block)
  types.flatten!
  search = SunspotSearchSpy.new(
    nil,
    setup_for_types(types),
    Sunspot::Query::StandardQuery.new(types),
    @config
  )
  search.build(&block) if block
  search
end

#commitObject



76
77
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 76

def commit
end

#commit_if_delete_dirtyObject



73
74
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 73

def commit_if_delete_dirty
end

#commit_if_dirtyObject



70
71
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 70

def commit_if_dirty
end

#delete_dirty?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 66

def delete_dirty?
  false
end

#dirty?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 62

def dirty?
  false
end

#index(*objects) ⇒ Object



38
39
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 38

def index(*objects)
end

#index!(*objects) ⇒ Object



41
42
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 41

def index!(*objects)
end

#inspectObject



34
35
36
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 34

def inspect
  'Solr Search'
end

#new_search(*types, &block) ⇒ Object



83
84
85
86
87
88
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 83

def new_search(*types, &block)
  types.flatten!
  search = build_search(*types, &block)
  @searches << [types, search]
  search
end

#remove(*objects) ⇒ Object



44
45
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 44

def remove(*objects)
end

#remove!(*objects) ⇒ Object



47
48
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 47

def remove!(*objects)
end

#remove_all(clazz = nil) ⇒ Object



56
57
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 56

def remove_all(clazz = nil)
end

#remove_all!(clazz = nil) ⇒ Object



59
60
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 59

def remove_all!(clazz = nil)
end

#remove_by_id(clazz, id) ⇒ Object



50
51
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 50

def remove_by_id(clazz, id)
end

#remove_by_id!(clazz, id) ⇒ Object



53
54
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 53

def remove_by_id!(clazz, id)
end

#search(*types, &block) ⇒ Object



79
80
81
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 79

def search(*types, &block)
  new_search(*types, &block)
end

#setup_for_types(types) ⇒ Object



102
103
104
105
106
107
108
109
110
111
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 102

def setup_for_types(types)
  if types.empty?
    raise(ArgumentError, "You must specify at least one type to search")
  end
  if types.length == 1
    Sunspot::Setup.for(types.first)
  else
    Sunspot::CompositeSetup.for(types)
  end
end