Skip to content

Commit

Permalink
Bug fix for hash merging Mashes
Browse files Browse the repository at this point in the history
  • Loading branch information
brynary committed Nov 17, 2008
1 parent 83f3ab4 commit 1bdead1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/webrat/core/form.rb
Expand Up @@ -110,7 +110,7 @@ def form_action
def merge(all_params, new_param)
new_param.each do |key, value|
case all_params[key]
when *HASH
when *hash_classes
merge_hash_values(all_params[key], value)
when Array
all_params[key] += value
Expand All @@ -124,7 +124,7 @@ def merge_hash_values(a, b) # :nodoc:
a.keys.each do |k|
if b.has_key?(k)
case [a[k], b[k]].map{|value| value.class}
when *HASH.zip(HASH)
when *hash_classes.zip(hash_classes)
a[k] = merge_hash_values(a[k], b[k])
b.delete(k)
when [Array, Array]
Expand All @@ -136,5 +136,12 @@ def merge_hash_values(a, b) # :nodoc:
a.merge!(b)
end

def hash_classes
klasses = [Hash]
klasses << HashWithIndifferentAccess if defined?(HashWithIndifferentAccess) # Rails
klasses << Mash if defined?(Mash) # Merb
klasses
end

end
end

0 comments on commit 1bdead1

Please sign in to comment.