From e1426a4daeecf450d76bca2a6e7e81e2a99dc20f Mon Sep 17 00:00:00 2001 From: Xavier Barbosa Date: Fri, 5 May 2017 18:14:19 +0200 Subject: [PATCH 1/3] PATH_INFO must be a path --- spec/rspec/hanami/request_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/rspec/hanami/request_spec.rb b/spec/rspec/hanami/request_spec.rb index 449296c..9b373f7 100644 --- a/spec/rspec/hanami/request_spec.rb +++ b/spec/rspec/hanami/request_spec.rb @@ -5,13 +5,15 @@ describe '#env' do [['GET', '/', {}], ['POST', '/users', {}], + ['OPTIONS', '/users', {}], ['PATCH', '/posts', {}], ['PUT', '/comments', {}], ['DELETE', '/tags', {}]].each do |method, path, options| it "returns hash for #{path} #{method}" do request = RSpec::Hanami::RequestHelpers::Request.new(method, path, options).env expect(request["REQUEST_METHOD"]).to eq method - expect(request["PATH_INFO"]).to eq [path, method, "?"] + expect(request["PATH_INFO"]).to eq path + expect(request["QUERY_STRING"]).to eq "?" end end end From eff4fe627250add6e08ce49e9eac7a317713fe37 Mon Sep 17 00:00:00 2001 From: Xavier Barbosa Date: Fri, 5 May 2017 18:15:41 +0200 Subject: [PATCH 2/3] Fixed PATH_INFO --- lib/rspec/hanami/request_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rspec/hanami/request_helpers.rb b/lib/rspec/hanami/request_helpers.rb index cf07a41..6ef56bd 100644 --- a/lib/rspec/hanami/request_helpers.rb +++ b/lib/rspec/hanami/request_helpers.rb @@ -11,8 +11,8 @@ def initialize(method, path, options) def env default_env.tap do |env| - env['PATH_INFO'] = @path, - env['REQUEST_METHOD'] = @method, + env['PATH_INFO'] = @path + env['REQUEST_METHOD'] = @method env['QUERY_STRING'] = "?#{@query_string}" env['rack.input'] = StringIO.new(@params.to_json) if @params From f221cbc39b90bf13461afde123736a6532d4cca2 Mon Sep 17 00:00:00 2001 From: Xavier Barbosa Date: Fri, 5 May 2017 18:19:14 +0200 Subject: [PATCH 3/3] Added options routing --- lib/rspec/hanami/request_helpers.rb | 32 +++++++++++++++++------------ 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/rspec/hanami/request_helpers.rb b/lib/rspec/hanami/request_helpers.rb index 6ef56bd..328cebc 100644 --- a/lib/rspec/hanami/request_helpers.rb +++ b/lib/rspec/hanami/request_helpers.rb @@ -2,11 +2,11 @@ module RSpec module Hanami module RequestHelpers class Request - def initialize(method, path, options) + def initialize(method, path, opts) @path, @query_string = path.split('?', 2) @method = method - @params = options[:params] - @headers = options[:headers] || {} + @params = opts[:params] + @headers = opts[:headers] || {} end def env @@ -47,27 +47,33 @@ def self.included(klass) end def request(request) + puts request.env @response = ::Hanami.app.call(request.env) end - def get(path, options = {}) - request(Request.new('GET', path, options)) + def get(path, opts = {}) + request(Request.new('GET', path, opts)) end - def post(path, options = {}) - request(Request.new('POST', path, options)) + def post(path, opts = {}) + request(Request.new('POST', path, opts)) end - def patch(path, options = {}) - request(Request.new('PATCH', path, options)) + def patch(path, opts = {}) + request(Request.new('PATCH', path, opts)) end - def put(path, options = {}) - request(Request.new('PUT', path, options)) + def put(path, opts = {}) + request(Request.new('PUT', path, opts)) end - def delete(path, options = {}) - request(Request.new('DELETE', path, options)) + + def delete(path, opts = {}) + request(Request.new('DELETE', path, opts)) + end + + def options(path, opts = {}) + request(Request.new('OPTIONS', path, opts)) end end end