Skip to content

Commit ea58e2e

Browse files
committed
Merge branch 'fujin/chef-222'
Conflicts: chef/spec/unit/couchdb_spec.rb
2 parents d19d716 + c2eeb4f commit ea58e2e

2 files changed

Lines changed: 47 additions & 13 deletions

File tree

chef/lib/chef/couchdb.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,6 @@ def has_key?(obj_type, name)
144144
end
145145
end
146146

147-
private
148-
149-
def safe_name(name)
150-
name.gsub(/\./, "_")
151-
end
152-
153147
def view_uri(design, view)
154148
Chef::Config[:couchdb_version] ||= @rest.run_request(:GET, URI.parse(@rest.url + "/"), false, 10, false)["version"].gsub(/-.+/,"").to_f
155149
case Chef::Config[:couchdb_version]
@@ -159,6 +153,12 @@ def view_uri(design, view)
159153
"#{Chef::Config[:couchdb_database]}/_view/#{design}/#{view}"
160154
end
161155
end
162-
156+
157+
private
158+
159+
def safe_name(name)
160+
name.gsub(/\./, "_")
161+
end
162+
163163
end
164164
end

chef/spec/unit/couchdb_spec.rb

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,48 @@ def do_delete(rev=nil)
248248
end
249249
end
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
261295
end

0 commit comments

Comments
 (0)