Module: Sonar

Included in:
SonarSession
Defined in:
lib/sonar.rb

Instance Method Summary collapse

Instance Method Details

#__sonar__session__(reset = false) ⇒ Object



90
91
92
93
# File 'lib/sonar.rb', line 90

def __sonar__session__ reset = false
  (@__sonar__session__ ||= {})[app.__id__] = ::SonarSession.new(app) if reset
  (@__sonar__session__ ||= {})[app.__id__] ||= ::SonarSession.new(app)
end

#app(app = nil) ⇒ Object

switch session

sonar using app based sessions, that’s it, creates sessions based on app __id__. you can test multiple apps and use ‘app RackApp` to switch between them.



25
26
27
28
# File 'lib/sonar.rb', line 25

def app app = nil
  @__sonar__app__ = app if app
  @__sonar__app__
end

#follow_redirect!Object



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

def follow_redirect!
  last_response.redirect? ||
      raise('Last response is not an redirect!')
  scheme = last_request.env['HTTPS'] == 'on' ? 'https' : 'http'
  request scheme, 'GET', last_response['Location'], {}, {'HTTP_REFERER' => last_request.url}
end

#map(*args) ⇒ Object



30
31
32
33
# File 'lib/sonar.rb', line 30

def map *args
  @__sonar__base_url__ = args.first if args.size > 0
  @__sonar__base_url__
end

#request(scheme, request_method, uri, params, env = {}) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/sonar.rb', line 71

def request scheme, request_method, uri, params, env = {}
  uri = [@__sonar__base_url__, uri].compact.join('/') unless uri =~ /\A\/|\A[\w|\d]+\:\/\//
  uri = ::URI.parse(uri.gsub(/\A\/+/, '/'))
  uri.scheme ||= scheme.to_s
  uri.host ||= ::SonarConstants::DEFAULT_HOST
  uri.path = '/' << uri.path unless uri.path =~ /\A\//
  params.is_a?(Hash) && params.each_pair do |k, v|
    (v.is_a?(Numeric) || v.is_a?(Symbol)) && params.update(k => v.to_s)
  end
  __sonar__session__.invoke_request request_method, uri, params, env
end

#reset_app!Object Also known as: reset_browser!

reset session for current app. everything will be reset - cookies, headers, authorizations etc.



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

def reset_app!
  __sonar__session__ :reset
end