Skip to content

Commit

Permalink
feature: added helper method success? so it's easy to enquire if a re…
Browse files Browse the repository at this point in the history
…sponse was successful
  • Loading branch information
kernow committed Apr 3, 2010
1 parent 8d6e025 commit 0d6de88
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/panelbeater/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ def initialize(response)
@response = response
end

def success?
json['result'].first['status'] == 1
end

def json
JSON.parse @response.body
end
Expand Down
27 changes: 27 additions & 0 deletions test/whm_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,33 @@ def setup
end


context "returning a successful response" do
setup do
stub_request(:get, "#{@expected_url}applist?").
with(:headers => { 'Authorization' => @expected_auth_header }).
to_return(:body => fixture('createacct_success'))
@response = @connection.applist
end

should "return true" do
assert @response.success?
end
end


context "returning a unsuccessful response" do
setup do
stub_request(:get, "#{@expected_url}applist?").
with(:headers => { 'Authorization' => @expected_auth_header }).
to_return(:body => fixture('createacct_fail'))
@response = @connection.applist
end

should "return false" do
assert !@response.success?
end
end


context "getting a list of commands the server supports" do
setup do
Expand Down

0 comments on commit 0d6de88

Please sign in to comment.