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
36
# 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
    remove_method :to_param
    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



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

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



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

def commit(soft_delete = false)
end

#commit_if_delete_dirty(soft_delete = false) ⇒ Object



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

def commit_if_delete_dirty(soft_delete = false)
end

#commit_if_dirty(soft_delete = false) ⇒ Object



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

def commit_if_dirty(soft_delete = false)
end

#delete_dirty?Boolean

Returns:

  • (Boolean)


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

def delete_dirty?
  false
end

#dirty?Boolean

Returns:

  • (Boolean)


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

def dirty?
  false
end

#index(*objects) ⇒ Object



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

def index(*objects)
end

#index!(*objects) ⇒ Object



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

def index!(*objects)
end

#inspectObject



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

def inspect
  'Solr Search'
end

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



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

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

#new_search(*types, &block) ⇒ Object



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

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

#remove(*objects) ⇒ Object



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

def remove(*objects)
end

#remove!(*objects) ⇒ Object



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

def remove!(*objects)
end

#remove_all(clazz = nil) ⇒ Object



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

def remove_all(clazz = nil)
end

#remove_all!(clazz = nil) ⇒ Object



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

def remove_all!(clazz = nil)
end

#remove_by_id(clazz, id) ⇒ Object



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

def remove_by_id(clazz, id)
end

#remove_by_id!(clazz, id) ⇒ Object



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

def remove_by_id!(clazz, id)
end

#search(*types, &block) ⇒ Object



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

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

#setup_for_types(types) ⇒ Object



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

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