diff options
| author | Stormwind <stormwind@stormwinds-page.de> | 2012-11-23 19:54:17 +0100 | 
|---|---|---|
| committer | Stormwind <stormwind@stormwinds-page.de> | 2012-11-23 19:54:17 +0100 | 
| commit | 16eef08688a50b31239cd67080439e8e6dead4a2 (patch) | |
| tree | af7cee737de4344708441ea3456d8af986acf15c | |
| parent | 78121c6eea9cc6d2a669c93f0b89557b5c59babc (diff) | |
content_type sets the Content-Type header to the given value
| -rw-r--r-- | lib/zero/response.rb | 7 | ||||
| -rw-r--r-- | spec/unit/response/response_spec.rb | 14 | 
2 files changed, 18 insertions, 3 deletions
| diff --git a/lib/zero/response.rb b/lib/zero/response.rb index eec4559..0d23194 100644 --- a/lib/zero/response.rb +++ b/lib/zero/response.rb @@ -46,5 +46,12 @@ module Zero        header['Content-Length'] = body.join.bytesize      end +    # Sets the content type to the given value +    # Also creates it, if it does not exists +    # +    def content_type(value) +      header['Content-Type'] = value +    end +    end  end diff --git a/spec/unit/response/response_spec.rb b/spec/unit/response/response_spec.rb index b6428fc..58b8d07 100644 --- a/spec/unit/response/response_spec.rb +++ b/spec/unit/response/response_spec.rb @@ -61,20 +61,20 @@ describe Zero::Response do    end    describe '#content_length' do -    it "sets the content_length to 0, if there is no content" do +    it "sets the Content-Length to 0, if there is no content" do        subject.content_length        subject.header['Content-Length'].should eq(0)      end -    it "sets the content_length to the size of the message body" do +    it "sets the Content-Length to the size of the message body" do        subject.body = ['foo', 'bar']        subject.content_length        subject.header['Content-Length'].should eq(6)      end -     it "sets the content_length to the bytesize of the message body" do +     it "sets the Content-Length to the bytesize of the message body" do        subject.body = ['föö', 'bär']        subject.content_length @@ -82,4 +82,12 @@ describe Zero::Response do      end    end +  describe '#content_type' do +    it "sets the Content-Type to the given value" do +      subject.content_type 'application/json' + +      subject.header['Content-Type'].should eq('application/json') +    end +  end +  end
\ No newline at end of file | 
