Skip to content

Commit

Permalink
Default hash params/merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dbalatero committed May 3, 2010
1 parent c9a9d90 commit 2786ceb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/monster_mash/request.rb
Expand Up @@ -68,7 +68,11 @@ def #{method}(value = nil, &block)
def assign_or_return_option!(name, value = nil)
symbolized_name = name.to_sym
if value
self.options[symbolized_name] = value
if self.options[symbolized_name].respond_to?(:merge) and value.respond_to?(:merge)
self.options[symbolized_name].merge!(value)
else
self.options[symbolized_name] = value
end
else
self.options[symbolized_name]
end
Expand Down
24 changes: 24 additions & 0 deletions spec/monster_mash/request_spec.rb
Expand Up @@ -20,6 +20,30 @@
end
end

describe "adding to default params" do
before(:each) do
@request = MonsterMash::Request.new(:get) do
params :api_key => 'fdsa',
:format => 'json'
end
end

it "should merge in the params hash" do
@request.execute_dsl do
params :format => 'xml',
:a => 'ok',
:b => 'ok2'
end

@request.options[:params].should == {
:api_key => 'fdsa',
:format => 'xml',
:a => 'ok',
:b => 'ok2'
}
end
end

describe "#handler" do
before(:each) do
@request = MonsterMash::Request.new(:get)
Expand Down

0 comments on commit 2786ceb

Please sign in to comment.