Class: RestAssured::Response
- Inherits:
-
Object
- Object
- RestAssured::Response
- Defined in:
- lib/rest-assured/routes/response.rb
Class Method Summary collapse
- .find_matching_double(method, fullpath) ⇒ Object
- .perform(app) ⇒ Object
- .return_double(app, d) ⇒ Object
Class Method Details
.find_matching_double(method, fullpath) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/rest-assured/routes/response.rb', line 19 def self.find_matching_double(method, fullpath) active_doubles_for_verb = Models::Double.where(:active => true, :verb => method) active_doubles_for_verb.select {|d| !d.fullpath.blank? && d.fullpath == fullpath}.sort_by { |d| d[:id] }.last || active_doubles_for_verb.select {|d| !d.pathpattern.blank? && Regexp.new(d.pathpattern).match(fullpath)}.sort_by { |d| d[:id] }.last end |
.perform(app) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rest-assured/routes/response.rb', line 4 def self.perform(app) request = app.request if d = find_matching_double(request.request_method, request.fullpath) return_double app, d elsif redirect_url = Models::Redirect.find_redirect_url_for(request.fullpath) if d = find_matching_double(request.request_method, redirect_url) return_double app, d else app.redirect redirect_url end else app.status 404 end end |
.return_double(app, d) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rest-assured/routes/response.rb', line 26 def self.return_double(app, d) request = app.request request.body.rewind body = request.body.read #without temp variable ':body = > body' is always nil. mistery env = request.env.except('rack.input', 'rack.errors', 'rack.logger') d.requests.create!(:rack_env => env.to_json, :body => body, :params => request.params.to_json) sleep d.delay app.headers d.response_headers app.body d.content app.status d.status end |