Module: Heliosphere::Stubs

Extended by:
Stubs
Included in:
Stubs
Defined in:
lib/heliosphere/stubs.rb

Instance Method Summary collapse

Instance Method Details

#sessionObject



7
8
9
# File 'lib/heliosphere/stubs.rb', line 7

def session
  @session ||= Sunspot.session
end

#with_searchObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/heliosphere/stubs.rb', line 15

def with_search
  unless Heliosphere.up?
    sunspot = Sunspot::Rails::Server.new
    pid = fork do
      STDERR.reopen('/dev/null')
      STDOUT.reopen('/dev/null')
      sunspot.run
    end
    # shut down the Solr server
    at_exit { Process.kill('TERM', pid); Heliosphere.wait(&:down?) }
    # wait for solr to start
    Heliosphere.wait(&:up?)
  end

  Sunspot.session = session
  Sunspot.session.remove_all
end

#without_searchObject



11
12
13
# File 'lib/heliosphere/stubs.rb', line 11

def without_search
  Sunspot.session = Sunspot::Rails::StubSessionProxy.new(session)
end