|
210 | 210 | } |
211 | 211 | end |
212 | 212 | end |
| 213 | + |
| 214 | + context 'when value is a hash combine values with different operator keys' do |
| 215 | + let(:base) do |
| 216 | + query.add_field_expression('foo', {'$in' => ['bar']}) |
| 217 | + end |
| 218 | + |
| 219 | + let(:modified) do |
| 220 | + base.add_field_expression('foo', {'$nin' => ['zoom']}) |
| 221 | + end |
| 222 | + |
| 223 | + it 'combines the conditions using $and' do |
| 224 | + modified.selector.should == { |
| 225 | + 'foo' => { |
| 226 | + '$in' => ['bar'], |
| 227 | + '$nin' => ['zoom'] |
| 228 | + } |
| 229 | + } |
| 230 | + end |
| 231 | + end |
| 232 | + |
| 233 | + context 'when value is a hash with symbol operator key combine values with different operator keys' do |
| 234 | + let(:base) do |
| 235 | + query.add_field_expression('foo', {:$in => ['bar']}) |
| 236 | + end |
| 237 | + |
| 238 | + let(:modified) do |
| 239 | + base.add_field_expression('foo', {:$nin => ['zoom']}) |
| 240 | + end |
| 241 | + |
| 242 | + it 'combines the conditions using $and' do |
| 243 | + modified.selector.should == { |
| 244 | + 'foo' => { |
| 245 | + :$in => ['bar'], |
| 246 | + :$nin => ['zoom'] |
| 247 | + } |
| 248 | + } |
| 249 | + end |
| 250 | + end |
| 251 | + |
| 252 | + context 'when value is a hash add values with same operator keys using $and' do |
| 253 | + let(:base) do |
| 254 | + query.add_field_expression('foo', {'$in' => ['bar']}) |
| 255 | + end |
| 256 | + |
| 257 | + let(:modified) do |
| 258 | + base.add_field_expression('foo', {'$in' => ['zoom']}) |
| 259 | + end |
| 260 | + |
| 261 | + it 'adds the new condition using $and' do |
| 262 | + modified.selector.should == { |
| 263 | + 'foo' => {'$in' => ['bar']}, |
| 264 | + '$and' => ['foo' => {'$in' => ['zoom']}] |
| 265 | + } |
| 266 | + end |
| 267 | + end |
| 268 | + |
| 269 | + context 'when value is a hash with symbol operator key add values with same operator keys using $and' do |
| 270 | + let(:base) do |
| 271 | + query.add_field_expression('foo', {:$in => ['bar']}) |
| 272 | + end |
| 273 | + |
| 274 | + let(:modified) do |
| 275 | + base.add_field_expression('foo', {:$in => ['zoom']}) |
| 276 | + end |
| 277 | + |
| 278 | + it 'adds the new condition using $and' do |
| 279 | + modified.selector.should == { |
| 280 | + 'foo' => {:$in => ['bar']}, |
| 281 | + '$and' => ['foo' => {:$in => ['zoom']}] |
| 282 | + } |
| 283 | + end |
213 | 284 | end |
| 285 | +end |
214 | 286 |
|
215 | 287 | describe '#add_operator_expression' do |
216 | 288 | let(:query_method) { :add_operator_expression } |
|
0 commit comments