summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-09-04 18:26:19 +0200
committerAzul <azul@leap.se>2012-09-04 18:26:19 +0200
commitb0ee08ded6aca81a58b82ebd99dbfaaa441ac9f2 (patch)
tree61c2d5e64f4caa4ea2c75151fabc7c713d09f575
parent6ea671ff9fca7a22126f2348c63eb4ac471eecea (diff)
added test for CouchStream, made url_for protected
-rw-r--r--lib/couch_stream.rb4
-rw-r--r--test/unit/couch_stream_test.rb34
2 files changed, 37 insertions, 1 deletions
diff --git a/lib/couch_stream.rb b/lib/couch_stream.rb
index e3f66cc..bed296a 100644
--- a/lib/couch_stream.rb
+++ b/lib/couch_stream.rb
@@ -11,8 +11,10 @@ class CouchStream
yield(hash)
end
end
+
+ protected
- def url_for(path, options)
+ def url_for(path, options = {})
url = @server + @db + '/' + path
url += '?' if options.any?
url += options.map {|k,v| "#{k}=#{v}"}.join('&')
diff --git a/test/unit/couch_stream_test.rb b/test/unit/couch_stream_test.rb
new file mode 100644
index 0000000..5826ad3
--- /dev/null
+++ b/test/unit/couch_stream_test.rb
@@ -0,0 +1,34 @@
+require 'test_helper'
+require 'lib/couch_stream'
+
+# we'll mock this
+module Yajl
+ class HttpStream
+ end
+end
+
+class CouchStreamTest < MiniTest::Unit::TestCase
+
+ def setup
+ @stream = CouchStream.new("http://server/", "database")
+ @url = "http://server/database/_changes?c=d&a=b"
+ @path = "_changes"
+ @options = {:a => :b, :c => :d}
+ end
+
+ def test_get
+ Yajl::HttpStream.expects(:get).
+ with(@url, :symbolize_keys => true).
+ yields(stub_hash = stub)
+ @stream.get(@path, @options) do |hash|
+ assert_equal stub_hash, hash
+ end
+ end
+
+ # internal
+ def test_url_creation
+ assert_equal "http://server/database/", @stream.send(:url_for, "")
+ assert_equal @url, @stream.send(:url_for, @path, @options)
+ end
+
+end