langalex/couch_potato — Issue #55: wrong view-data problem in test context
Author: phoet
Created: 2012-02-17 14:10:48+00:00
State: open

when executing spec in a specific order, there was an error when using views.

it looks as if the problem was within the view invalidation logic within `ViewQuery`

this spec reproduces the error:

```ruby
require 'spec_helper'

class Build
include CouchPotato::Persistence

property :site_code

view :by_site_code, :key => :site_code, :reduce => true
end

describe "automatic view updates" do
before(:each) do
recreate_db
end

it "should return a valid result after view-update" do
10.times { CouchPotato.database.save_document Build.new(:site_code => 'DE') }
CouchPotato.database.view(Build.by_site_code(:keys => ['EN'], :include_docs => false)).size.should eql(0)
CouchPotato::View::ViewQuery.class_variable_get(:@@updated_views).should eql({})
CouchPotato.database.view(Build.by_site_code(:keys => ['EN'], :include_docs => false)).size.should eql(0)
CouchPotato::View::ViewQuery.class_variable_get(:@@updated_views).should eql({["build", "by_site_code"]=>true})
CouchPotato.database.view(Build.by_site_code(:keys => ['EN'], :include_docs => false)).size.should eql(0)
recreate_db
10.times { CouchPotato.database.save_document Build.new(:site_code => 'DE') }
# broken, returns 10 instead of 0 expected
CouchPotato.database.view(Build.by_site_code(:keys => ['EN'], :include_docs => false)).size.should eql(0)
end
end
```