require 'spec_helper' class ConditionalViewWidget include SimplyBased::Model property :name property :completed, type: :boolean # A CouchDB-era declaration: the :conditions JavaScript fragment cannot be # translated to N1QL. Declaring it must stay legal (simply_couch models load # unchanged), but *querying* it must fail loudly — the previous behaviour # silently dropped the condition and returned every document of the class. view :completed_by_name, key: :name, conditions: 'doc.completed === true' view :names_only, key: :name, emit_value: :name end RSpec.describe 'Untranslatable view declarations' do it 'still allows the model to load and plain views to work' do ConditionalViewWidget.create(name: 'a', completed: false) expect(ConditionalViewWidget.all.size).to eq 1 end it 'raises UnsupportedView when querying a :conditions view instead of silently ignoring the condition' do ConditionalViewWidget.create(name: 'done', completed: true) ConditionalViewWidget.create(name: 'done', completed: false) expect { ConditionalViewWidget.database.view(ConditionalViewWidget.completed_by_name(key: 'done')) }.to raise_error(SimplyBased::UnsupportedView, /conditions/) end it 'raises UnsupportedView for :emit_value views' do expect { ConditionalViewWidget.database.view(ConditionalViewWidget.names_only(key: 'x')) }.to raise_error(SimplyBased::UnsupportedView, /emit_value/) end end