summaryrefslogtreecommitdiff
path: root/chef-solr
diff options
context:
space:
mode:
authorAdam Jacob <adam@opscode.com>2010-03-17 17:46:17 -0700
committerAdam Jacob <adam@opscode.com>2010-03-17 17:46:17 -0700
commit863f14459bf697cba57ad25c730d1bd071b953ff (patch)
tree41cdfc28e6a71d855e625f829f8d4821ff7ff67b /chef-solr
parent53964e735785fdf6ae43a62a913e682b30df284b (diff)
parentc4720a69f2720b472b42ce8a320119f176d69e45 (diff)
downloadchef-863f14459bf697cba57ad25c730d1bd071b953ff.tar.gz
Merge branch 'CHEF-1009' of git://github.com/danielsdeleo/chef into danielsdeleo/CHEF-1009
Diffstat (limited to 'chef-solr')
-rw-r--r--chef-solr/Rakefile2
-rw-r--r--chef-solr/lib/chef/solr.rb2
-rw-r--r--chef-solr/spec/chef/solr_spec.rb64
-rw-r--r--chef-solr/spec/spec.opts1
4 files changed, 67 insertions, 2 deletions
diff --git a/chef-solr/Rakefile b/chef-solr/Rakefile
index fbd51277ad..1c87fd267a 100644
--- a/chef-solr/Rakefile
+++ b/chef-solr/Rakefile
@@ -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|
diff --git a/chef-solr/lib/chef/solr.rb b/chef-solr/lib/chef/solr.rb
index 2a85c44322..d015195a16 100644
--- a/chef-solr/lib/chef/solr.rb
+++ b/chef-solr/lib/chef/solr.rb
@@ -122,7 +122,7 @@ class Chef
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)
diff --git a/chef-solr/spec/chef/solr_spec.rb b/chef-solr/spec/chef/solr_spec.rb
index 2c757323b0..1a0d1f301b 100644
--- a/chef-solr/spec/chef/solr_spec.rb
+++ b/chef-solr/spec/chef/solr_spec.rb
@@ -170,5 +170,69 @@ describe Chef::Solr do
@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
diff --git a/chef-solr/spec/spec.opts b/chef-solr/spec/spec.opts
new file mode 100644
index 0000000000..3062c724e8
--- /dev/null
+++ b/chef-solr/spec/spec.opts
@@ -0,0 +1 @@
+-cbfs \ No newline at end of file