|
188 | 188 | }
|
189 | 189 | end
|
190 | 190 | end
|
| 191 | + |
| 192 | + context 'when value is a hash combine values with different operator keys' do |
| 193 | + let(:base) do |
| 194 | + query.add_field_expression('foo', {'$in' => ['bar']}) |
| 195 | + end |
| 196 | + |
| 197 | + let(:modified) do |
| 198 | + base.add_field_expression('foo', {'$nin' => ['zoom']}) |
| 199 | + end |
| 200 | + |
| 201 | + it 'combines the conditions using $and' do |
| 202 | + modified.selector.should == { |
| 203 | + 'foo' => { |
| 204 | + '$in' => ['bar'], |
| 205 | + '$nin' => ['zoom'] |
| 206 | + } |
| 207 | + } |
| 208 | + end |
| 209 | + end |
| 210 | + |
| 211 | + context 'when value is a hash with symbol operator key combine values with different operator keys' do |
| 212 | + let(:base) do |
| 213 | + query.add_field_expression('foo', {:$in => ['bar']}) |
| 214 | + end |
| 215 | + |
| 216 | + let(:modified) do |
| 217 | + base.add_field_expression('foo', {:$nin => ['zoom']}) |
| 218 | + end |
| 219 | + |
| 220 | + it 'combines the conditions using $and' do |
| 221 | + modified.selector.should == { |
| 222 | + 'foo' => { |
| 223 | + :$in => ['bar'], |
| 224 | + :$nin => ['zoom'] |
| 225 | + } |
| 226 | + } |
| 227 | + end |
| 228 | + end |
| 229 | + |
| 230 | + context 'when value is a hash add values with same operator keys using $and' do |
| 231 | + let(:base) do |
| 232 | + query.add_field_expression('foo', {'$in' => ['bar']}) |
| 233 | + end |
| 234 | + |
| 235 | + let(:modified) do |
| 236 | + base.add_field_expression('foo', {'$in' => ['zoom']}) |
| 237 | + end |
| 238 | + |
| 239 | + it 'adds the new condition using $and' do |
| 240 | + modified.selector.should == { |
| 241 | + 'foo' => {'$in' => ['bar']}, |
| 242 | + '$and' => ['foo' => {'$in' => ['zoom']}] |
| 243 | + } |
| 244 | + end |
| 245 | + end |
| 246 | + |
| 247 | + context 'when value is a hash with symbol operator key add values with same operator keys using $and' do |
| 248 | + let(:base) do |
| 249 | + query.add_field_expression('foo', {:$in => ['bar']}) |
| 250 | + end |
| 251 | + |
| 252 | + let(:modified) do |
| 253 | + base.add_field_expression('foo', {:$in => ['zoom']}) |
| 254 | + end |
| 255 | + |
| 256 | + it 'adds the new condition using $and' do |
| 257 | + modified.selector.should == { |
| 258 | + 'foo' => {:$in => ['bar']}, |
| 259 | + '$and' => ['foo' => {:$in => ['zoom']}] |
| 260 | + } |
| 261 | + end |
191 | 262 | end
|
| 263 | +end |
192 | 264 |
|
193 | 265 | describe '#add_operator_expression' do
|
194 | 266 | let(:query_method) { :add_operator_expression }
|
|
0 commit comments