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.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 23

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.



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

def current_search_class
  @current_search_class
end

#original_sessionObject (readonly)

Returns the value of attribute original_session.



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

def original_session
  @original_session
end

#searchesObject

Returns the value of attribute searches.



21
22
23
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 21

def searches
  @searches
end

Instance Method Details

#build_search(*types, &block) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 93

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

#commit(soft_delete = false) ⇒ Object



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

def commit(soft_delete = false)
end

#commit_if_delete_dirty(soft_delete = false) ⇒ Object



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

def commit_if_delete_dirty(soft_delete = false)
end

#commit_if_dirty(soft_delete = false) ⇒ Object



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

def commit_if_dirty(soft_delete = false)
end

#delete_dirty?Boolean

Returns:

  • (Boolean)


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

def delete_dirty?
  false
end

#dirty?Boolean

Returns:

  • (Boolean)


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

def dirty?
  false
end

#index(*objects) ⇒ Object



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

def index(*objects)
end

#index!(*objects) ⇒ Object



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

def index!(*objects)
end

#inspectObject



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

def inspect
  'Solr Search'
end

#more_like_this(object, *types, &block) ⇒ Object



116
117
118
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 116

def more_like_this(object, *types, &block)
  new_more_like_this(object, *types, &block)
end

#new_search(*types, &block) ⇒ Object



86
87
88
89
90
91
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 86

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

#remove(*objects) ⇒ Object



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

def remove(*objects)
end

#remove!(*objects) ⇒ Object



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

def remove!(*objects)
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_all!(clazz = nil) ⇒ Object



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

def remove_all!(clazz = nil)
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

#remove_by_id!(clazz, id) ⇒ Object



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

def remove_by_id!(clazz, id)
end

#search(*types, &block) ⇒ Object



82
83
84
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 82

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

#setup_for_types(types) ⇒ Object



105
106
107
108
109
110
111
112
113
114
# File 'lib/sunspot_matchers/sunspot_session_spy.rb', line 105

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