Skip to content

Commit c325a46

Browse files
author
AJ Christensen
committed
CHEF-222: shift the couchdb detection into view_uri
1 parent 5081a15 commit c325a46

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

chef/lib/chef/couchdb.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class CouchDB
2929
def initialize(url=nil)
3030
url ||= Chef::Config[:couchdb_url]
3131
@rest = Chef::REST.new(url)
32-
Chef::Config[:couchdb_version] ||= @rest.run_request(:GET, URI.parse(@rest.url + "/"), false, 10, false)["version"].gsub(/-.+/,"").to_f
3332
end
3433

3534
def create_db
@@ -152,6 +151,7 @@ def safe_name(name)
152151
end
153152

154153
def view_uri(design, view)
154+
Chef::Config[:couchdb_version] ||= @rest.run_request(:GET, URI.parse(@rest.url + "/"), false, 10, false)["version"].gsub(/-.+/,"").to_f
155155
case Chef::Config[:couchdb_version]
156156
when 0.9
157157
"#{Chef::Config[:couchdb_database]}/_design/#{design}/_view/#{view}"

chef/spec/unit/couchdb_spec.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@
3636
Chef::REST.should_receive(:new).with("http://monkeypants")
3737
Chef::CouchDB.new("http://monkeypants")
3838
end
39-
40-
it "should parse the CouchDB version number" do
41-
42-
end
4339
end
4440

4541
describe Chef::CouchDB, "create_db" do
@@ -271,6 +267,14 @@ def do_delete(rev=nil)
271267
Chef::Config.stub!(:[]).with(:couchdb_database).and_return("chef")
272268
end
273269

270+
describe "when the couchdb version is unknown" do
271+
it "should set the couchdb version appropriately" do
272+
Chef::Config.stub!(:[]).with(:couchdb_version).and_return(nil)
273+
Chef::Config.should_receive(:couchdb_version).and_return(true)
274+
@couchdb.view_uri("nodes", "all")
275+
end
276+
end
277+
274278
describe "on couchdb 0.8" do
275279
before do
276280
Chef::Config.stub!(:[]).with(:couchdb_version).and_return(0.8)

0 commit comments

Comments
 (0)