Skip to content

Commit

Permalink
add params method to beers.
Browse files Browse the repository at this point in the history
It's an additional way to specify parameters to send to brewery db
  • Loading branch information
matthewshafer committed May 5, 2013
1 parent 7aea039 commit 320c379
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## v0.1.0 (unreleased)
* Add params method to beers. Allows passing additional parameters in an additional way.
* Add params method to beer. Allows passing additional parameters in an additional way.

## v0.0.1
Expand Down
7 changes: 7 additions & 0 deletions lib/tankard/api/beers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def page(number)
self
end

def params(options={})
options.each_pair do |key,value|
@options[key] = value
end
self
end

private

def options_have_page_set
Expand Down
21 changes: 21 additions & 0 deletions spec/tankard/api/beers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@
end
end

describe "#params" do

it "sets parameters" do
beers.params(withSocialAccounts: "y", withGuilds: "n")
beers_options = beers.instance_variable_get(:"@options")
expect(beers_options[:withSocialAccounts]).to eql("y")
expect(beers_options[:withGuilds]).to eql("n")
end

it "merges params when called multiple times" do
beers.params(test: "n")
beers.params(test: "y")
beers_options = beers.instance_variable_get(:"@options")
expect(beers_options[:test]).to eql("y")
end

it "returns itself" do
expect(beers.object_id).to eql(beers.params.object_id)
end
end

describe "when making a request" do

context "and a page is set" do
Expand Down

0 comments on commit 320c379

Please sign in to comment.