From 633d5fb7c808cf6672cc5ab355edff5cb5e95acc Mon Sep 17 00:00:00 2001 From: Stormwind Date: Sat, 17 Nov 2012 14:35:15 +0100 Subject: Converts any input in status to an integer --- lib/zero/response.rb | 12 +++++++++++- spec/unit/response/response_spec.rb | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/zero/response.rb b/lib/zero/response.rb index 418c8a7..3c54c54 100644 --- a/lib/zero/response.rb +++ b/lib/zero/response.rb @@ -3,7 +3,17 @@ module Zero # This is the representation of a response # class Response - attr_accessor :status, :header, :body + attr_reader :status + attr_accessor :header, :body + + # Sets the status. + # Also converts every input directly to an integer + # + # @param [Integer] status + # + def status=(status) + @status = status.to_i + end # Returns the data of the response as an array: # [status, header, body] diff --git a/spec/unit/response/response_spec.rb b/spec/unit/response/response_spec.rb index a0d423f..28ee6db 100644 --- a/spec/unit/response/response_spec.rb +++ b/spec/unit/response/response_spec.rb @@ -15,5 +15,15 @@ describe Zero::Response, '#finish' do value[1].should eq({}) # Headers value[2].should eq([]) # Body end +end +describe Zero::Response, '#status' do + it "must return the status always as an integer" do + + subject.status = "foobar" + subject.status.should eq(0) + + subject.status = 240.5 + subject.status.should eq(240) + end end \ No newline at end of file -- cgit v1.2.3-70-g09d2