Sha256: 7eb14f6aee659d2aeef654bc27af33f6464d6e6a05c1e8c43c67f7d31e8f21df
Contents?: true
Size: 1.62 KB
Versions: 24
Compression:
Stored size: 1.62 KB
Contents
require 'spec_helper' describe 'Criteria and default scope' do context 'order in query' do let(:query) do Acolyte.order(status: :desc) end let(:sort_options) do query.options[:sort] end it 'is added after order of default scope' do sort_options.should == {'status' => -1, 'name' => 1} # Keys in Ruby are ordered sort_options.keys.should == %w(name status) end end context 'default scope + logical operator' do context 'logical operator applied to a criteria' do let(:base) { Appointment.where } it 'has default scope' do base.selector.should == {'active' => true} end context '.or' do let(:criteria) do base.or(timed: true) end it 'adds new condition in parallel to default scope conditions' do criteria.selector.should == {'$or' => [ {'active' => true}, {'timed' => true}, ]} end end context '.any_of' do let(:criteria) do base.any_of(timed: true) end it 'maintains default scope conditions' do criteria.selector.should == {'active' => true, 'timed' => true} end end end context 'logical operator called on the class' do let(:base) { Appointment } context '.or' do let(:criteria) do base.or(timed: true) end it 'adds new condition in parallel to default scope conditions' do criteria.selector.should == {'$or' => [ {'active' => true}, {'timed' => true}, ]} end end end end end
Version data entries
24 entries across 24 versions & 1 rubygems