Skip to content

Commit

Permalink
Merge branch 'CHEF-1009' of git://github.com/danielsdeleo/chef into d…
Browse files Browse the repository at this point in the history
…anielsdeleo/CHEF-1009
  • Loading branch information
adamhjk committed Mar 18, 2010
2 parents 53964e7 + c4720a6 commit 863f144
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion chef-solr/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |spec|
spec.libs << 'lib' << 'spec'
spec.spec_files = FileList['spec/**/*_spec.rb']
spec.spec_opts = %w{-fs --color}
spec.spec_opts = ['--options', File.expand_path(File.dirname(__FILE__) + '/spec/spec.opts')]
end

Spec::Rake::SpecTask.new(:rcov) do |spec|
Expand Down
2 changes: 1 addition & 1 deletion chef-solr/lib/chef/solr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def rebuild_index(url=Chef::Config[:couchdb_url], db=Chef::Config[:couchdb_datab
solr_commit

results = {}
[Chef::ApiClient, Chef::Node, Chef::OpenIDRegistration, Chef::Role, Chef::WebUIUser].each do |klass|
[Chef::ApiClient, Chef::Node, Chef::Role].each do |klass|
results[klass.name] = reindex_all(klass) ? "success" : "failed"
end
databags = Chef::DataBag.cdb_list(true)
Expand Down
64 changes: 64 additions & 0 deletions chef-solr/spec/chef/solr_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,69 @@
@solr.solr_delete_by_query([ "foo:bar", "baz:bum" ])
end
end

describe "rebuilding the index" do
before do
Chef::Config[:couchdb_database] = "chunky_bacon"
end

it "deletes the index and commits" do
@solr.should_receive(:solr_delete_by_query).with("X_CHEF_database_CHEF_X:chunky_bacon")
@solr.should_receive(:solr_commit)
@solr.stub!(:reindex_all)
Chef::DataBag.stub!(:cdb_list).and_return([])
@solr.rebuild_index
end

it "reindexes Chef::ApiClient, Chef::Node, and Chef::Role objects, reporting the results as a hash" do
@solr.stub!(:solr_delete_by_query).with("X_CHEF_database_CHEF_X:chunky_bacon")
@solr.stub!(:solr_commit)
@solr.should_receive(:reindex_all).with(Chef::ApiClient).and_return(true)
@solr.should_receive(:reindex_all).with(Chef::Node).and_return(true)
@solr.should_receive(:reindex_all).with(Chef::Role).and_return(true)
Chef::DataBag.stub!(:cdb_list).and_return([])

result = @solr.rebuild_index
result["Chef::ApiClient"].should == "success"
result["Chef::Node"].should == "success"
result["Chef::Role"].should == "success"
end

it "does not reindex Chef::OpenIDRegistration or Chef::WebUIUser objects" do
# hi there. the reason we're specifying this behavior is because these objects
# are not properly indexed in the first place and trying to reindex them
# tickles a bug in our CamelCase to snake_case code. See CHEF-1009.
@solr.stub!(:solr_delete_by_query).with("X_CHEF_database_CHEF_X:chunky_bacon")
@solr.stub!(:solr_commit)
@solr.stub!(:reindex_all).with(Chef::ApiClient)
@solr.stub!(:reindex_all).with(Chef::Node)
@solr.stub!(:reindex_all).with(Chef::Role)
@solr.should_not_receive(:reindex_all).with(Chef::OpenIDRegistration)
@solr.should_not_receive(:reindex_all).with(Chef::WebUIUser)
Chef::DataBag.stub!(:cdb_list).and_return([])

@solr.rebuild_index
end

it "reindexes databags" do
one_data_item = Chef::DataBagItem.new
one_data_item.raw_data = {"maybe"=>"snakes actually are evil", "id" => "just_sayin"}
two_data_item = Chef::DataBagItem.new
two_data_item.raw_data = {"tone_depth"=>"rumble_fish", "id" => "eff_yes"}
data_bag = Chef::DataBag.new
data_bag.stub!(:list).and_return([one_data_item, two_data_item])

@solr.stub!(:solr_delete_by_query).with("X_CHEF_database_CHEF_X:chunky_bacon")
@solr.stub!(:solr_commit)
@solr.stub!(:reindex_all)
Chef::DataBag.stub!(:cdb_list).and_return([data_bag])

data_bag.should_receive(:add_to_index)
one_data_item.should_receive(:add_to_index)
two_data_item.should_receive(:add_to_index)

@solr.rebuild_index["Chef::DataBag"].should == "success"
end
end

end
1 change: 1 addition & 0 deletions chef-solr/spec/spec.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-cbfs

0 comments on commit 863f144

Please sign in to comment.