Permalink
Browse files

Support deleting beers and breweries.

  • Loading branch information...
1 parent 0d7a520 commit fba174712086a197bc6424e8b5a081e785d34d2e @tristandunn tristandunn committed May 28, 2011
View
@@ -24,6 +24,16 @@ def self.create(attributes = {}, options = {})
Bartender::Request.post("/beers", attributes, options)
end
+ # Deletes a beer.
+ #
+ # @param [Integer] id The ID of the beer to delete.
+ # @param [Hash] options The options for the API request.
+ # @option options [String] :token A private token to override the current configuration with (optional).
+ # @return [Boolean] +true+ if successful, +false+ otherwise.
+ def self.delete(id, options = {})
+ Bartender::Request.delete("/beers/#{id}", options)
+ end
+
# Retrieve a specific beer.
#
# @param [Fixnum] id The ID of the beer to retrieve.
View
@@ -22,6 +22,16 @@ def self.create(attributes = {}, options = {})
Bartender::Request.post("/breweries", { :brewery => attributes }, options)
end
+ # Deletes a brewery.
+ #
+ # @param [Integer] id The ID of the brewery to delete.
+ # @param [Hash] options The options for the API request.
+ # @option options [String] :token A private token to override the current configuration with (optional).
+ # @return [Boolean] +true+ if successful, +false+ otherwise.
+ def self.delete(id, options = {})
+ Bartender::Request.delete("/breweries/#{id}", options)
+ end
+
# Retrieve a specific brewery.
#
# @param [Fixnum] id The ID of the brewery to retrieve.
View
@@ -4,6 +4,13 @@
module Bartender
# @private
class Request
+ def self.delete(path, options = {})
+ options[:token] ||= Bartender.configuration.private_token
+
+ response = request.delete(uri(path, options))
+ response.code.to_i == 200
+ end
+
def self.get(path, options = {})
token = Bartender.configuration.public_token
@@ -30,6 +30,19 @@
end
end
+describe Bartender::Beer, ".delete" do
+ let(:options) { { :token => "Fake" } }
+
+ before do
+ Bartender::Request.stubs(:delete)
+ end
+
+ it "creates a beer" do
+ Bartender::Beer.delete(1, options)
+ Bartender::Request.should have_received(:delete).with("/beers/1", options)
+ end
+end
+
describe Bartender::Beer, ".find" do
before do
Bartender::Request.stubs(:get)
@@ -30,6 +30,19 @@
end
end
+describe Bartender::Brewery, ".delete" do
+ let(:options) { { :token => "Fake" } }
+
+ before do
+ Bartender::Request.stubs(:delete)
+ end
+
+ it "creates a brewery" do
+ Bartender::Brewery.delete(1, options)
+ Bartender::Request.should have_received(:delete).with("/breweries/1", options)
+ end
+end
+
describe Bartender::Brewery, ".find" do
before do
Bartender::Request.stubs(:get)
@@ -1,5 +1,41 @@
require "spec_helper"
+describe Bartender::Request, ".delete" do
+ let(:request) { stub("Request", :delete => response) }
+ let(:response) { stub("Response", :code => 200) }
+ let(:private_token) { "a1b2c3" }
+
+ before do
+ Bartender::Request.stubs(:uri).returns("/")
+ Bartender::Request.stubs(:request).returns(request)
+ Bartender.configuration.private_token = private_token
+ end
+
+ it "constructs the request URI" do
+ Bartender::Request.delete("/", :option => 1)
+ Bartender::Request.should have_received(:uri).with("/", :option => 1, :token => private_token)
+ end
+
+ it "allows overriding of configured private token" do
+ Bartender::Request.delete("/", :token => "x1y2z3")
+ Bartender::Request.should have_received(:uri).with("/", :token => "x1y2z3")
+ end
+
+ it "makes an API request" do
+ Bartender::Request.delete("/")
+ request.should have_received(:delete).with("/")
+ end
+
+ it "returns true for a successful response" do
+ Bartender::Request.delete("/").should == true
+ end
+
+ it "returns false for all other responses" do
+ response.stubs(:code => "401")
+ Bartender::Request.delete("/").should == false
+ end
+end
+
describe Bartender::Request, ".get" do
let(:request) { stub("Request", :get => response) }
let(:response) { stub("Response", :body => "{}") }

0 comments on commit fba1747

Please sign in to comment.