summaryrefslogtreecommitdiff
path: root/test/unit/couch_changes_test.rb
blob: 043caf19c82f824dd72b06814977a99bac5370d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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