spec/supernova/solr_indexer_spec.rb in supernova-0.4.14 vs spec/supernova/solr_indexer_spec.rb in supernova-0.4.15

- old
+ new

@@ -181,11 +181,11 @@ end end describe "#query_db" do it "executes the query" do - db.should_receive(:query).with("query").and_return [to_index] + db.should_receive(:query).with("query", :as => :hash).and_return [to_index] indexer.query_db("query") end it "calls select_all when not responding to query" do old_mysql_double = double("old mysql double", :select_all => []) @@ -193,20 +193,56 @@ old_mysql_double.should_receive(:select_all).with("query").and_return [to_index] indexer.query_db("query") end end + describe "#debug" do + it "prints a line when debug is enabled" do + index = CustomSolrIndex.new(:debug => true) + index.should_receive(:puts).with(/hello world/) + index.debug "hello world" + end + + it "does not print print a line when debug is not enabled" do + index = CustomSolrIndex.new(:debug => false) + index.should_not_receive(:puts) + index.debug "hello world" + end + + it "can be called with block and still returns the response" do + index = CustomSolrIndex.new(:debug => true) + index.should_receive(:puts).with(/some message/) + res = index.debug "some message" do + 112 + end + res.should == 112 + end + + it "includes the time in the debug output when placeholder found" do + index = CustomSolrIndex.new(:debug => true) + Benchmark.stub(:realtime).and_return 0.12345 + index.should_receive(:puts).with(/indexed in 0.123/) + index.debug "indexed in %TIME%" do + 112 + end + end + end + describe "#map_hash_keys_to_solr" do class CustomSolrIndex < Supernova::SolrIndexer has :offer_id, :type => :integer has :lat, :type => :float has :lng, :type => :float has :created_at, :type => :date has :checkin_date, :type => :date has :indexed, :type => :boolean, :virtual => true end + it "sets empty dates to nil" do + CustomSolrIndex.new.map_hash_keys_to_solr("checkin_date" => nil)["checkin_date_dt"].should == nil + end + it "maps virtual fields" do CustomSolrIndex.new.map_hash_keys_to_solr("indexed" => true)["indexed_b"].should == true end it "maps fields with false as value" do @@ -249,9 +285,28 @@ it "adds the sets the cla" do clazz = Class.new(Supernova::SolrIndexer) clazz.clazz Offer clazz.new.map_hash_keys_to_solr({})["type"].should == "Offer" + end + end + + describe "#rows" do + let(:res) { double("result") } + + before(:each) do + custom_indexer.stub(:query_db).and_return([]) + end + + it "calls query_db with correct query" do + custom_indexer.should_receive(:query_db).with("some query").and_return res + custom_indexer.rows("some query").should == res + end + + it "uses the query_to_index when query is blank" do + custom_indexer.should_receive(:query_to_index).and_return "some other query" + custom_indexer.should_receive(:query_db).with("some other query").and_return res + custom_indexer.rows.should == res end end describe "#solr_rows_to_index_for_query" do let(:result) {