@@ -248,14 +248,48 @@ def do_delete(rev=nil)
248248 end
249249end
250250
251- describe Chef ::CouchDB , "safe_name " do
251+ describe Chef ::CouchDB , "view_uri " do
252252 before do
253- @couchdb = mock ( "Chef::CouchDB" , :null_object => true )
254- Chef ::CouchDB . stub! ( :new ) . and_return ( @couchdb )
253+ @mock_rest = mock ( "Chef::REST" , :null_object => true , :url => "http://monkeypants" )
254+ Chef ::REST . stub! ( :new ) . and_return ( @mock_rest )
255+ @couchdb = Chef ::CouchDB . new ( "http://localhost" )
256+ end
257+
258+ describe "when the couchdb version is unknown" do
259+ it "should set the couchdb version appropriately" do
260+ ov = Chef ::Config [ :couchdb_version ]
261+ Chef ::Config [ :couchdb_version ] = nil
262+ @mock_rest . should_receive ( :run_request ) . with (
263+ :GET ,
264+ URI . parse ( "http://monkeypants/" ) ,
265+ false ,
266+ 10 ,
267+ false
268+ ) . and_return ( { "version" => "0.9" } )
269+ @couchdb . view_uri ( "nodes" , "all" )
270+ Chef ::Config [ :couchdb_version ] = ov
271+ end
255272 end
256273
257- it "should convert the name to a safe name" do
258- @couchdb . should_receive ( :safe_name ) . with ( "asdf.lol.com" ) . and_return ( "asdf_lol_com" )
259- @couchdb . safe_name ( "asdf.lol.com" )
274+ describe "on couchdb 0.8" do
275+ before do
276+ Chef ::Config . stub! ( :[] ) . with ( :couchdb_version ) . and_return ( 0.8 )
277+ end
278+
279+ it "should output an appropriately formed view URI" do
280+ @couchdb . should_receive ( :view_uri ) . with ( "nodes" , "all" ) . and_return ( "chef/_view/nodes/all" )
281+ @couchdb . view_uri ( "nodes" , "all" )
282+ end
283+ end
284+
285+ describe "on couchdb 0.9" do
286+ before do
287+ Chef ::Config . stub! ( :[] ) . with ( :couchdb_version ) . and_return ( 0.9 )
288+ end
289+
290+ it "should output an appropriately formed view URI" do
291+ @couchdb . should_receive ( :view_uri ) . with ( "nodes" , "all" ) . and_return ( "chef/_design/nodes/_view/all" )
292+ @couchdb . view_uri ( "nodes" , "all" )
293+ end
260294 end
261295end
0 commit comments