Skip to content

Commit c2eeb4f

Browse files
committed
Fixed tests for chef-222
1 parent c325a46 commit c2eeb4f

2 files changed

Lines changed: 20 additions & 24 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: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -248,30 +248,26 @@ def do_delete(rev=nil)
248248
end
249249
end
250250

251-
describe Chef::CouchDB, "safe_name" do
252-
before do
253-
@couchdb = mock("Chef::CouchDB", :null_object => true)
254-
Chef::CouchDB.stub!(:new).and_return(@couchdb)
255-
end
256-
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")
260-
end
261-
end
262-
263251
describe Chef::CouchDB, "view_uri" do
264252
before do
265-
@couchdb = mock("Chef::CouchDB", :null_object => true)
266-
Chef::CouchDB.stub!(:new).and_return(@couchdb)
267-
Chef::Config.stub!(:[]).with(:couchdb_database).and_return("chef")
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")
268256
end
269257

270258
describe "when the couchdb version is unknown" do
271259
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)
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" })
274269
@couchdb.view_uri("nodes", "all")
270+
Chef::Config[:couchdb_version] = ov
275271
end
276272
end
277273

0 commit comments

Comments
 (0)