diff options
| author | Stormwind <stormwind@stormwinds-page.de> | 2012-11-23 20:05:58 +0100 | 
|---|---|---|
| committer | Stormwind <stormwind@stormwinds-page.de> | 2012-11-23 20:05:58 +0100 | 
| commit | fea8ac2bbd04fd4abea929fef1b7e8ac305b4ca1 (patch) | |
| tree | 76a0b11d30d8a60621ab057a999f188586276cfc | |
| parent | 16eef08688a50b31239cd67080439e8e6dead4a2 (diff) | |
Sets the Content-Type in to_a unless it is already set before
The default value is 'text/html'.
| -rw-r--r-- | lib/zero/response.rb | 3 | ||||
| -rw-r--r-- | spec/unit/response/response_spec.rb | 19 | 
2 files changed, 18 insertions, 4 deletions
| diff --git a/lib/zero/response.rb b/lib/zero/response.rb index 0d23194..fefa320 100644 --- a/lib/zero/response.rb +++ b/lib/zero/response.rb @@ -34,7 +34,8 @@ module Zero        # TODO Remove content length and body, on certain status codes        # Set content length, if not already set        content_length unless header.has_key? 'Content-Length' -      # TODO Set content type, if not already set +      # Set content type, if not already set +      content_type 'text/html' unless header.has_key? 'Content-Type'        [status, header, body]      end diff --git a/spec/unit/response/response_spec.rb b/spec/unit/response/response_spec.rb index 58b8d07..18612ce 100644 --- a/spec/unit/response/response_spec.rb +++ b/spec/unit/response/response_spec.rb @@ -14,7 +14,7 @@ describe Zero::Response do        value.should be_an_instance_of(Array)        value[0].should eq(200) # Status code -      value[1].should eq({"Content-Length" => 0})  # Headers +      value[1].should be_an_instance_of(Hash)  # Headers        value[2].should eq([])  # Body      end @@ -22,7 +22,7 @@ describe Zero::Response do        subject.body = ['foobar']        value = subject.to_a -      value[1].should eq({'Content-Length' => 6})  # Headers +      value[1]['Content-Length'].should eq(6)  # Headers      end      it "does not fix the Content-Length, if it's already set" do @@ -30,7 +30,20 @@ describe Zero::Response do        subject.header = {'Content-Length' => 3}        value = subject.to_a -      value[1].should eq({'Content-Length' => 3})  # Headers +      value[1]['Content-Length'].should eq(3)  # Headers +    end + +    it "returns the Content-Type in the header" do +      subject.header = {'Content-Type' => 'application/json'} +      value = subject.to_a + +      value[1]['Content-Type'].should eq('application/json')  # Headers +    end + +    it "returns as default 'text/html' as Content-Type" do +      value = subject.to_a + +      value[1]['Content-Type'].should eq('text/html')  # Headers      end    end | 
