Sha256: 8a5f688b5a0d37eb9a756e485f3e383a2f7278d5a5d6eb3237756eaea216355a

Contents?: true

Size: 1.2 KB

Versions: 15

Compression:

Stored size: 1.2 KB

Contents

require File.expand_path("../../../spec_helper", __FILE__)

describe CouchRest::Streamer do
  before(:all) do
    @cr = CouchRest.new(COUCHHOST)
    @db = @cr.database(TESTDB)
    @db.delete! rescue nil
    @db = @cr.create_db(TESTDB) rescue nil
    @streamer = CouchRest::Streamer.new(@db)
    @docs = (1..1000).collect{|i| {:integer => i, :string => i.to_s}}
    @db.bulk_save(@docs)
    @db.save_doc({
      "_id" => "_design/first",
      :views => {
        :test => {
	  :map => "function(doc){for(var w in doc){ if(!w.match(/^_/))emit(w,doc[w])}}"
        }
      }
    })
  end
  
  it "should yield each row in a view" do
    count = 0
    sum = 0
    @streamer.view("_all_docs") do |row|
      count += 1
    end
    count.should == 1001
  end

  it "should accept several params" do
    count = 0
    @streamer.view("_design/first/_view/test", :include_docs => true, :limit => 5) do |row|
      count += 1
    end
    count.should == 5
  end

  it "should accept both view formats" do
    count = 0
    @streamer.view("_design/first/_view/test") do |row|
      count += 1
    end
    count.should == 2000
    count = 0
    @streamer.view("first/test") do |row|
      count += 1
    end
    count.should == 2000
  end

end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
couchrest-1.0.2 spec/couchrest/helpers/streamer_spec.rb
couchrest-1.0.1 spec/couchrest/helpers/streamer_spec.rb
couchrest-1.0.0 spec/couchrest/helpers/streamer_spec.rb
couchrest-0.38 spec/couchrest/helpers/streamer_spec.rb
couchrest-1.0.0.beta3 spec/couchrest/helpers/streamer_spec.rb
couchrest-1.0.0.beta2 spec/couchrest/helpers/streamer_spec.rb
couchrest-1.0.0.beta spec/couchrest/helpers/streamer_spec.rb
samlown-couchrest-1.0.0 spec/couchrest/helpers/streamer_spec.rb
samlown-couchrest-0.37.2 spec/couchrest/helpers/streamer_spec.rb
samlown-couchrest-0.37.1 spec/couchrest/helpers/streamer_spec.rb
samlown-couchrest-0.35 spec/couchrest/helpers/streamer_spec.rb
couchrest-0.37 spec/couchrest/helpers/streamer_spec.rb
couchrest-0.36 spec/couchrest/helpers/streamer_spec.rb
couchrest-0.35 spec/couchrest/helpers/streamer_spec.rb
couchrest-0.34 spec/couchrest/helpers/streamer_spec.rb