Sha256: 70379143c966cb7421a1421c15f5ba2f3a7826aac14dd28d4825f05b4f35b28d

Contents?: true

Size: 1.03 KB

Versions: 17

Compression:

Stored size: 1.03 KB

Contents

module RestAssured
  class Response

    def self.perform(app)
      request = app.request
      if d = Models::Double.where(:fullpath => request.fullpath, :active => true, :verb => request.request_method).first
        return_double app, d
      elsif redirect_url = Models::Redirect.find_redirect_url_for(request.fullpath)
        if d = Models::Double.where(:fullpath => redirect_url, :active => true, :verb => request.request_method).first
          return_double app, d
        else
          app.redirect redirect_url
        end
      else
        app.status 404
      end
    end

    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)

      app.headers d.response_headers
      app.body d.content
      app.status d.status
    end

  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
rest-assured-2.0.2 lib/rest-assured/routes/response.rb
rest-assured-2.0.1 lib/rest-assured/routes/response.rb
rest-assured-2.0.0 lib/rest-assured/routes/response.rb
rest-assured-1.2.2 lib/rest-assured/routes/response.rb
rest-assured-1.2.1 lib/rest-assured/routes/response.rb
rest-assured-1.2.0 lib/rest-assured/routes/response.rb
rest-assured-1.1.10 lib/rest-assured/routes/response.rb
rest-assured-1.1.9 lib/rest-assured/routes/response.rb
rest-assured-1.1.8 lib/rest-assured/routes/response.rb
rest-assured-1.1.7 lib/rest-assured/routes/response.rb
rest-assured-1.1.6 lib/rest-assured/routes/response.rb
rest-assured-1.1.5 lib/rest-assured/routes/response.rb
rest-assured-1.1.4 lib/rest-assured/routes/response.rb
rest-assured-1.1.3 lib/rest-assured/routes/response.rb
rest-assured-1.1.2 lib/rest-assured/routes/response.rb
rest-assured-1.1.1 lib/rest-assured/routes/response.rb
rest-assured-1.1.0 lib/rest-assured/routes/response.rb