0
0
Fork 0

Kill all mutants i Zero::Request

Fix tests for PATCH, because spec_helper didn't support it and the tests where
wrong.
Remove if statement from "conent_type", because ruby already returns nil, if the
requested key in a hash is not found. (Sounds a bit ugly, but it's true.)
This commit is contained in:
Stormwind 2013-01-06 12:37:07 +01:00
parent cd97198e22
commit e81dff9c07
3 changed files with 10 additions and 5 deletions

View File

@ -56,7 +56,7 @@ module Zero
# TODO change into its own object?
# @return [String] returns the content type of the request
def content_type
@env[CONST_CONTENT_TYPE] if @env.has_key?(CONST_CONTENT_TYPE)
@env[CONST_CONTENT_TYPE]
end
# get the media types

View File

@ -40,6 +40,7 @@ class EnvGenerator
KEY_REQUEST_POST = 'POST'
KEY_REQUEST_PUT = 'PUT'
KEY_REQUEST_DELETE = 'DELETE'
KEY_REQUEST_PATCH = 'PATCH'
def self.generate_env(uri, options)
Rack::MockRequest.env_for(uri, options)
@ -64,4 +65,8 @@ class EnvGenerator
def self.delete(uri, options = {})
generate_env(uri, options.merge(KEY_REQUEST_METHOD => KEY_REQUEST_DELETE))
end
def self.patch(uri, options = {})
generate_env(uri, options.merge(KEY_REQUEST_METHOD => KEY_REQUEST_PATCH))
end
end

View File

@ -3,13 +3,13 @@ require 'spec_helper'
describe Zero::Request, '#patch?' do
subject { Zero::Request.new(env) }
context "with a post request" do
let(:env) { EnvGenerator.post('/foo') }
its(:post?) { should be(true) }
context "with a patch request" do
let(:env) { EnvGenerator.patch('/foo') }
its(:patch?) { should be(true) }
end
context "with a get request" do
let(:env) { EnvGenerator.get('/foo') }
its(:post?) { should be(false) }
its(:patch?) { should be(false) }
end
end