Skip to content

Commit

Permalink
changing find to not use instance variables from the class it is incl…
Browse files Browse the repository at this point in the history
…uded in.
  • Loading branch information
matthewshafer committed May 8, 2013
1 parent 93ed55d commit 6f9d491
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
8 changes: 8 additions & 0 deletions lib/tankard/api/beer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ def raise_if_no_id_in_options
def route
"beer"
end

def http_client
@request
end

def http_request_parameters
@options
end
end
end
end
8 changes: 8 additions & 0 deletions lib/tankard/api/style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def raise_if_no_id_in_options
def route
"style"
end

def http_client
@request
end

def http_request_parameters
@options
end
end
end
end
14 changes: 11 additions & 3 deletions lib/tankard/api/utils/find.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ module Find
include Tankard::Api::Request::Get

def find(id_or_array, options={})
@options.merge!(options)
options = http_request_parameters.merge!(options)

if id_or_array.is_a?(Array)
id_or_array.map { |id| request_data_with_nil_on_http_error(@request, "#{route}/#{id}", @options) }.compact
id_or_array.map { |id| request_data_with_nil_on_http_error(http_client, "#{route}/#{id}", options) }.compact
else
request_data_with_nil_on_http_error(@request, "#{route}/#{id_or_array}", @options)
request_data_with_nil_on_http_error(http_client, "#{route}/#{id_or_array}", options)
end
end

Expand All @@ -21,6 +21,14 @@ def find(id_or_array, options={})
def route
raise NoMethodError.new("Must implement and return the base route")
end

def http_client
raise NoMethodError.new("Must return the http object to make requests with")
end

def http_request_parameters
raise NoMethodError.new("Must return a hash like structure with request parameters")
end
end
end
end
Expand Down
27 changes: 27 additions & 0 deletions spec/tankard/api/utils/find_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'spec_helper'

describe Tankard::Api::Utils::Find do

let(:find) { Class.new { include Tankard::Api::Utils::Find }.new }

describe "#route" do

it "raises NoMethodError" do
expect { find.send(:route) }.to raise_error(NoMethodError, "Must implement and return the base route")
end
end

describe "#http_client" do

it "raises NoMethodError" do
expect { find.send(:http_client) }.to raise_error(NoMethodError, "Must return the http object to make requests with")
end
end

describe "#http_request_parameters" do

it "raises NoMethodError" do
expect { find.send(:http_request_parameters) }.to raise_error(NoMethodError, "Must return a hash like structure with request parameters")
end
end
end

0 comments on commit 6f9d491

Please sign in to comment.