Sha256: aaf10c8f4820c18a66d6d1a41c3a54b6a82272a2ae995fc155d42f03d84ed408

Contents?: true

Size: 1.52 KB

Versions: 32

Compression:

Stored size: 1.52 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()
    @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 raise error on #view as depricated" do
    lambda { @streamer.view }.should raise_error(/depricated/)
  end

  it "should GET each row in a view" do
    count = 0
    @streamer.get("#{@db.root}/_all_docs") do |row|
      count += 1
    end
    count.should == 1001
  end

  it "should GET each row in a view with params" do
    count = 0
    @streamer.get("#{@db.root}/_all_docs?include_docs=true&limit=5") do |row|
      count += 1
    end
    count.should == 5
  end

  it "should POST for each row in a view" do
    # First grab a pair of IDs
    ids = []
    @streamer.get("#{@db.root}/_design/first/_view/test?limit=2") do |row|
      ids << row['id']
    end
    count = 0
    @streamer.post("#{@db.root}/_all_docs?include_docs=true", :keys => ids) do |row|
      count += 1
    end
    count.should == 2
  end

  it "should escape quotes" do
    @streamer.send(:escape_quotes, "keys: [\"sams's test\"]").should eql("keys: [\\\"sams's test\\\"]")
  end

end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
vulcan-0.8.2 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.8.1 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.8.0 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.7.2 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.7.1 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.7.0 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.6.1 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.6.0 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.5.0 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.4.0 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.3.0 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.2.5 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.2.4 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.2.3 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.2.2 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.2.1 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.2.0 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.1.6 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.1.5 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb
vulcan-0.1.4 server/vendor/gems/gems/couchrest-1.1.2/spec/couchrest/helpers/streamer_spec.rb