Skip to content

Commit

Permalink
Merge branch 'CHEF-1044' of git://github.com/sdelano/chef into sdelan…
Browse files Browse the repository at this point in the history
…o/CHEF-1044
  • Loading branch information
adamhjk committed Mar 30, 2010
2 parents ceb8174 + a9c1c6d commit 51f1a16
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
13 changes: 10 additions & 3 deletions chef-solr/lib/chef/solr/index.rb
Expand Up @@ -112,7 +112,11 @@ def set_field_value(fields, key, value)
if value.kind_of?(Array)
fields[key] = Array.new
value.each do |v|
fields[key] << v.to_s
if v.kind_of?(Hash)
flatten_and_expand(v, fields, key)
else
fields[key] << v.to_s
end
end
else
fields[key] = value.to_s
Expand All @@ -125,8 +129,11 @@ def add_value_to_field_array(fields, key, value)
check_value(value)
if value.kind_of?(Array)
value.each do |v|
check_value(v)
fields[key] << v.to_s unless fields[key].include?(v.to_s)
if v.kind_of?(Hash)
flatten_and_expand(v, fields, key)
else
fields[key] << v.to_s unless fields[key].include?(v.to_s)
end
end
else
fields[key] << value.to_s unless fields[key].include?(value.to_s)
Expand Down
20 changes: 20 additions & 0 deletions chef-solr/spec/chef/solr/index_spec.rb
Expand Up @@ -112,6 +112,26 @@
end
end

it "should call itself recursively for hashes nested in arrays" do
@index.flatten_and_expand({ :one => [ { :two => "three" }, { :four => { :five => "six" } } ] }, @fields)
{
"one_X_five" => "six",
"one_four" => "five",
"one_X" => [ "three", "five" ],
"two" => "three",
"one_four_X" => "six",
"X_four" => "five",
"X_four_five" => "six",
"one" => [ "two", "four" ],
"one_four_five" => "six",
"five" => "six",
"X_two" => "three",
"one_two" => "three"
}.each do |k, v|
@fields[k].should == v
end
end

end

describe "set_field_value" do
Expand Down

0 comments on commit 51f1a16

Please sign in to comment.