From 57140b80f00aab43918a3ec3276062823971dec7 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 10 Sep 2013 09:44:38 +0200 Subject: bringing over couch_changes from leap_ca including tests --- test/config/config.yaml | 5 +++++ test/test_helper.rb | 10 ++++++++++ test/unit/couch_changes_test.rb | 32 ++++++++++++++++++++++++++++++++ test/unit/couch_stream_test.rb | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 test/config/config.yaml create mode 100644 test/test_helper.rb create mode 100644 test/unit/couch_changes_test.rb create mode 100644 test/unit/couch_stream_test.rb (limited to 'test') diff --git a/test/config/config.yaml b/test/config/config.yaml new file mode 100644 index 0000000..ee10fe6 --- /dev/null +++ b/test/config/config.yaml @@ -0,0 +1,5 @@ +# +# testing configuration options +# + +db_prefix: "tapicero_test-" diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..3857e2c --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,10 @@ +require 'rubygems' +require 'minitest/autorun' + +BASE_DIR = File.expand_path('../..', __FILE__) +$:.unshift File.expand_path('lib', BASE_DIR) + +require 'mocha/setup' + +TAPICERO_CONFIG = "test/config/config.yaml" +require 'tapicero' diff --git a/test/unit/couch_changes_test.rb b/test/unit/couch_changes_test.rb new file mode 100644 index 0000000..043caf1 --- /dev/null +++ b/test/unit/couch_changes_test.rb @@ -0,0 +1,32 @@ +require File.expand_path('../../test_helper.rb', __FILE__) +require 'tapicero/couch_changes' + +class CouchChangesTest < MiniTest::Unit::TestCase + + LAST_SEQ = 12 + + def setup + @stream = mock() + @changes = Tapicero::CouchChanges.new(@stream) + end + + def test_last_seq + @stream.expects(:get). + with('_changes', {:limit => 1, :descending => true}). + yields(:last_seq => LAST_SEQ) + assert_equal LAST_SEQ, @changes.last_seq + end + + def test_follow + stub_entry = {:new => :result} + @stream.expects(:get). + with('_changes', {:limit => 1, :descending => true}). + yields(:last_seq => LAST_SEQ) + @stream.expects(:get). + with('_changes', {:feed => :continuous, :since => LAST_SEQ}). + yields(stub_entry) + @changes.follow do |hash| + assert_equal stub_entry, hash + end + end +end diff --git a/test/unit/couch_stream_test.rb b/test/unit/couch_stream_test.rb new file mode 100644 index 0000000..48b663a --- /dev/null +++ b/test/unit/couch_stream_test.rb @@ -0,0 +1,35 @@ +require File.expand_path('../../test_helper.rb', __FILE__) +require 'tapicero/couch_stream' + +# we'll mock this +module Yajl + class HttpStream + end +end + +class CouchStreamTest < MiniTest::Unit::TestCase + + def setup + @root = "http://server/database" + @stream = Tapicero::CouchStream.new(@root) + @url = @root + "/_changes?a=b&c=d" + @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 -- cgit v1.2.3