Sha256: 3dc5e75c94351bfb1168a0a1c3bb46b9a938e2e785bd022e47823762499666c1

Contents?: true

Size: 1.43 KB

Versions: 5

Compression:

Stored size: 1.43 KB

Contents

require 'spec_helper'

describe "automatic view updates" do
  before(:each) do
    recreate_db
    @db = CouchPotato.couchrest_database
  end
  
  it "should update a view that doesn't match the given functions" do
    CouchPotato::View::ViewQuery.new(@db, 'test_design1', 'test_view', 'function(doc) {}', 'function() {}').query_view! # create view
    CouchPotato::View::ViewQuery.new(@db, 'test_design1', 'test_view', 'function(doc) {emit(doc.id, null)}', 'function(key, values) {return sum(values)}').query_view!
    CouchPotato.database.load('_design/test_design1')['views']['test_view'].should == {
      'map' => 'function(doc) {emit(doc.id, null)}',
      'reduce' => 'function(key, values) {return sum(values)}'
    }
  end
  
  it "should only update a view once to avoid writing the view for every request" do
    CouchPotato::View::ViewQuery.new(@db, 'test_design2', 'test_view', 'function(doc) {}', 'function() {}').query_view! # create view
    CouchPotato::View::ViewQuery.new(@db, 'test_design2', 'test_view', 'function(doc) {emit(doc.id, null)}', 'function(key, values) {return sum(values)}').query_view!
    CouchPotato::View::ViewQuery.new(@db, 'test_design2', 'test_view', 'function(doc) {}', 'function() {}').query_view!
    CouchPotato.database.load('_design/test_design2')['views']['test_view'].should == {
      'map' => 'function(doc) {emit(doc.id, null)}',
      'reduce' => 'function(key, values) {return sum(values)}'
    }
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
couch_potato-0.2.32 spec/view_updates_spec.rb
couch_potato-0.2.31 spec/view_updates_spec.rb
couch_potato-0.2.30 spec/view_updates_spec.rb
couch_potato-0.2.29 spec/view_updates_spec.rb
couch_potato-0.2.28 spec/view_updates_spec.rb