Sha256: 62b7c3c9205138cd55211a9593c822c5ac567bfb75e3718cab572b98b212c0fc

Contents?: true

Size: 1.59 KB

Versions: 16

Compression:

Stored size: 1.59 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' => {:map => 'function(doc) {}', :reduce => 'function() {}'}}, nil).query_view! # create view
    CouchPotato::View::ViewQuery.new(@db, 'test_design1', {'test_view' => {:map => 'function(doc) {emit(doc.id, null)}', :reduce => 'function(key, values) {return sum(values)}'}}, nil).query_view!
    expect(CouchPotato.database.load('_design/test_design1')['views']['test_view']).to eq({
      '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' => {:map => 'function(doc) {}', :reduce => 'function() {}'}}, nil).query_view! # create view
    CouchPotato::View::ViewQuery.new(@db, 'test_design2', {'test_view' => {:map => 'function(doc) {emit(doc.id, null)}', :reduce => 'function(key, values) {return sum(values)}'}}, nil).query_view!
    CouchPotato::View::ViewQuery.new(@db, 'test_design2', {'test_view' => {:map => 'function(doc) {}', :reduce => 'function() {}'}}, nil).query_view!
    expect(CouchPotato.database.load('_design/test_design2')['views']['test_view']).to eq({
      'map' => 'function(doc) {emit(doc.id, null)}',
      'reduce' => 'function(key, values) {return sum(values)}'
    })
  end
  
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
couch_potato-1.17.0 spec/view_updates_spec.rb
couch_potato-1.16.0 spec/view_updates_spec.rb
couch_potato-1.15.0 spec/view_updates_spec.rb
couch_potato-1.14.0 spec/view_updates_spec.rb
couch_potato-1.13.0 spec/view_updates_spec.rb
couch_potato-1.12.1 spec/view_updates_spec.rb
couch_potato-1.12.0 spec/view_updates_spec.rb
couch_potato-1.11.0 spec/view_updates_spec.rb
couch_potato-1.10.1 spec/view_updates_spec.rb
couch_potato-1.10.0 spec/view_updates_spec.rb
couch_potato-1.9.0 spec/view_updates_spec.rb
couch_potato-1.7.1 spec/view_updates_spec.rb
couch_potato-1.7.0 spec/view_updates_spec.rb
couch_potato-1.6.5 spec/view_updates_spec.rb
couch_potato-1.6.4 spec/view_updates_spec.rb
couch_potato-1.6.3 spec/view_updates_spec.rb