mongoid 5.1.5 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/config/locales/en.yml +15 -0
- data/lib/mongoid.rb +5 -0
- data/lib/mongoid/attributes/dynamic.rb +3 -3
- data/lib/mongoid/clients/factory.rb +2 -0
- data/lib/mongoid/config.rb +1 -0
- data/lib/mongoid/config/options.rb +1 -1
- data/lib/mongoid/contextual/aggregable/mongo.rb +0 -1
- data/lib/mongoid/contextual/map_reduce.rb +20 -97
- data/lib/mongoid/contextual/memory.rb +1 -0
- data/lib/mongoid/contextual/mongo.rb +20 -15
- data/lib/mongoid/criteria.rb +2 -0
- data/lib/mongoid/document.rb +1 -0
- data/lib/mongoid/errors.rb +1 -0
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +20 -0
- data/lib/mongoid/errors/mongoid_error.rb +1 -1
- data/lib/mongoid/extensions.rb +1 -0
- data/lib/mongoid/extensions/decimal128.rb +39 -0
- data/lib/mongoid/fields/localized.rb +8 -3
- data/lib/mongoid/indexable/validators/options.rb +2 -1
- data/lib/mongoid/persistable/deletable.rb +3 -7
- data/lib/mongoid/persistable/settable.rb +3 -1
- data/lib/mongoid/query_cache.rb +24 -2
- data/lib/mongoid/relations/accessors.rb +1 -1
- data/lib/mongoid/relations/builders.rb +2 -2
- data/lib/mongoid/relations/eager.rb +2 -2
- data/lib/mongoid/relations/reflections.rb +5 -3
- data/lib/mongoid/relations/touchable.rb +1 -1
- data/lib/mongoid/scopable.rb +1 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +6 -2
- data/spec/app/models/band.rb +1 -0
- data/spec/config/mongoid.yml +5 -0
- data/spec/mongoid/clients/factory_spec.rb +8 -0
- data/spec/mongoid/clients_spec.rb +78 -1
- data/spec/mongoid/config_spec.rb +31 -0
- data/spec/mongoid/contextual/atomic_spec.rb +342 -76
- data/spec/mongoid/contextual/map_reduce_spec.rb +111 -119
- data/spec/mongoid/contextual/memory_spec.rb +316 -56
- data/spec/mongoid/contextual/mongo_spec.rb +391 -11
- data/spec/mongoid/criteria_spec.rb +21 -2
- data/spec/mongoid/extensions/decimal128_spec.rb +44 -0
- data/spec/mongoid/extensions/time_spec.rb +2 -2
- data/spec/mongoid/fields/localized_spec.rb +91 -0
- data/spec/mongoid/indexable_spec.rb +44 -0
- data/spec/mongoid/persistable/settable_spec.rb +44 -0
- data/spec/mongoid/query_cache_spec.rb +86 -0
- data/spec/mongoid/relations/cyclic_spec.rb +22 -0
- data/spec/mongoid/relations/referenced/many_spec.rb +11 -0
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +11 -0
- data/spec/mongoid/relations/reflections_spec.rb +9 -9
- data/spec/mongoid/scopable_spec.rb +12 -0
- data/spec/spec_helper.rb +9 -0
- metadata +26 -16
- metadata.gz.sig +0 -0
| @@ -73,6 +73,29 @@ describe Mongoid::Contextual::Atomic do | |
| 73 73 | 
             
                    expect(smiths.reload.members).to eq([ "Dave" ])
         | 
| 74 74 | 
             
                  end
         | 
| 75 75 | 
             
                end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                context 'when the criteria has a collation', if: collation_supported? do
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                  let(:criteria) do
         | 
| 80 | 
            +
                    Band.where(members: [ "DAVE" ]).collation(locale: 'en_US', strength: 2)
         | 
| 81 | 
            +
                  end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                  let(:context) do
         | 
| 84 | 
            +
                    Mongoid::Contextual::Mongo.new(criteria)
         | 
| 85 | 
            +
                  end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                  before do
         | 
| 88 | 
            +
                    context.add_to_set(members: "Dave", genres: "Electro")
         | 
| 89 | 
            +
                  end
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                  it "does not add duplicates" do
         | 
| 92 | 
            +
                    expect(depeche_mode.reload.members).to eq([ "Dave" ])
         | 
| 93 | 
            +
                  end
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                  it "adds multiple operations" do
         | 
| 96 | 
            +
                    expect(depeche_mode.reload.genres).to eq([ "Electro" ])
         | 
| 97 | 
            +
                  end
         | 
| 98 | 
            +
                end
         | 
| 76 99 | 
             
              end
         | 
| 77 100 |  | 
| 78 101 | 
             
              describe "#bit" do
         | 
| @@ -121,6 +144,29 @@ describe Mongoid::Contextual::Atomic do | |
| 121 144 | 
             
                    expect(depeche_mode.reload.likes).to eq(14)
         | 
| 122 145 | 
             
                  end
         | 
| 123 146 | 
             
                end
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                context 'when the criteria has a collation', if: collation_supported? do
         | 
| 149 | 
            +
             | 
| 150 | 
            +
                  let!(:depeche_mode) do
         | 
| 151 | 
            +
                    Band.create(members: [ "Dave" ], likes: 60)
         | 
| 152 | 
            +
                  end
         | 
| 153 | 
            +
             | 
| 154 | 
            +
                  let(:criteria) do
         | 
| 155 | 
            +
                    Band.where(members: [ "DAVE" ]).collation(locale: 'en_US', strength: 2)
         | 
| 156 | 
            +
                  end
         | 
| 157 | 
            +
             | 
| 158 | 
            +
                  let(:context) do
         | 
| 159 | 
            +
                    Mongoid::Contextual::Mongo.new(criteria)
         | 
| 160 | 
            +
                  end
         | 
| 161 | 
            +
             | 
| 162 | 
            +
                  before do
         | 
| 163 | 
            +
                    context.bit(likes: { and: 13, or: 10 })
         | 
| 164 | 
            +
                  end
         | 
| 165 | 
            +
             | 
| 166 | 
            +
                  it "performs the bitwise operation on initialized fields" do
         | 
| 167 | 
            +
                    expect(depeche_mode.reload.likes).to eq(14)
         | 
| 168 | 
            +
                  end
         | 
| 169 | 
            +
                end
         | 
| 124 170 | 
             
              end
         | 
| 125 171 |  | 
| 126 172 | 
             
              describe "#inc" do
         | 
| @@ -177,6 +223,29 @@ describe Mongoid::Contextual::Atomic do | |
| 177 223 | 
             
                    expect(beatles.reload.y).to eq(3)
         | 
| 178 224 | 
             
                  end
         | 
| 179 225 | 
             
                end
         | 
| 226 | 
            +
             | 
| 227 | 
            +
                context 'when the criteria has a collation', if: collation_supported? do
         | 
| 228 | 
            +
             | 
| 229 | 
            +
                  let!(:depeche_mode) do
         | 
| 230 | 
            +
                    Band.create(members: [ "Dave" ])
         | 
| 231 | 
            +
                  end
         | 
| 232 | 
            +
             | 
| 233 | 
            +
                  let(:criteria) do
         | 
| 234 | 
            +
                    Band.where(members: [ "DAVE" ]).collation(locale: 'en_US', strength: 2)
         | 
| 235 | 
            +
                  end
         | 
| 236 | 
            +
             | 
| 237 | 
            +
                  let(:context) do
         | 
| 238 | 
            +
                    Mongoid::Contextual::Mongo.new(criteria)
         | 
| 239 | 
            +
                  end
         | 
| 240 | 
            +
             | 
| 241 | 
            +
                  before do
         | 
| 242 | 
            +
                    context.inc(years: 1)
         | 
| 243 | 
            +
                  end
         | 
| 244 | 
            +
             | 
| 245 | 
            +
                  it "incs the value and read from alias" do
         | 
| 246 | 
            +
                    expect(depeche_mode.reload.years).to eq(1)
         | 
| 247 | 
            +
                  end
         | 
| 248 | 
            +
                end
         | 
| 180 249 | 
             
              end
         | 
| 181 250 |  | 
| 182 251 | 
             
              describe "#pop" do
         | 
| @@ -226,6 +295,29 @@ describe Mongoid::Contextual::Atomic do | |
| 226 295 | 
             
                    expect(smiths.reload.members).to be_nil
         | 
| 227 296 | 
             
                  end
         | 
| 228 297 | 
             
                end
         | 
| 298 | 
            +
             | 
| 299 | 
            +
                context 'when the criteria has a collation', if: collation_supported? do
         | 
| 300 | 
            +
             | 
| 301 | 
            +
                  let!(:depeche_mode) do
         | 
| 302 | 
            +
                    Band.create(members: [ "Dave" ])
         | 
| 303 | 
            +
                  end
         | 
| 304 | 
            +
             | 
| 305 | 
            +
                  let(:criteria) do
         | 
| 306 | 
            +
                    Band.where(members: [ "DAVE" ]).collation(locale: 'en_US', strength: 2)
         | 
| 307 | 
            +
                  end
         | 
| 308 | 
            +
             | 
| 309 | 
            +
                  let(:context) do
         | 
| 310 | 
            +
                    Mongoid::Contextual::Mongo.new(criteria)
         | 
| 311 | 
            +
                  end
         | 
| 312 | 
            +
             | 
| 313 | 
            +
                  before do
         | 
| 314 | 
            +
                    context.pop(members: 1)
         | 
| 315 | 
            +
                  end
         | 
| 316 | 
            +
             | 
| 317 | 
            +
                  it "pops the last element off the array" do
         | 
| 318 | 
            +
                    expect(depeche_mode.reload.members).to be_empty
         | 
| 319 | 
            +
                  end
         | 
| 320 | 
            +
                end
         | 
| 229 321 | 
             
              end
         | 
| 230 322 |  | 
| 231 323 | 
             
              describe "#pull" do
         | 
| @@ -257,129 +349,276 @@ describe Mongoid::Contextual::Atomic do | |
| 257 349 | 
             
                it "does not error on non existent fields" do
         | 
| 258 350 | 
             
                  expect(smiths.reload.members).to be_nil
         | 
| 259 351 | 
             
                end
         | 
| 352 | 
            +
             | 
| 353 | 
            +
                context 'when the criteria has a collation', if: collation_supported? do
         | 
| 354 | 
            +
             | 
| 355 | 
            +
                  let!(:depeche_mode) do
         | 
| 356 | 
            +
                    Band.create(members: [ "Dave" ])
         | 
| 357 | 
            +
                  end
         | 
| 358 | 
            +
             | 
| 359 | 
            +
                  let(:criteria) do
         | 
| 360 | 
            +
                    Band.where(members: [ "DAVE" ]).collation(locale: 'en_US', strength: 2)
         | 
| 361 | 
            +
                  end
         | 
| 362 | 
            +
             | 
| 363 | 
            +
                  let(:context) do
         | 
| 364 | 
            +
                    Mongoid::Contextual::Mongo.new(criteria)
         | 
| 365 | 
            +
                  end
         | 
| 366 | 
            +
             | 
| 367 | 
            +
                  before do
         | 
| 368 | 
            +
                    context.pull(members: "DAVE")
         | 
| 369 | 
            +
                  end
         | 
| 370 | 
            +
             | 
| 371 | 
            +
                  it "pulls when the value is found" do
         | 
| 372 | 
            +
                    expect(depeche_mode.reload.members).to be_empty
         | 
| 373 | 
            +
                  end
         | 
| 374 | 
            +
                end
         | 
| 260 375 | 
             
              end
         | 
| 261 376 |  | 
| 262 377 | 
             
              describe "#pull_all" do
         | 
| 263 378 |  | 
| 264 | 
            -
                 | 
| 265 | 
            -
                  Band.create(members: [ "Dave", "Alan", "Fletch" ])
         | 
| 266 | 
            -
                end
         | 
| 379 | 
            +
                context 'when the criteria does not have a collation' do
         | 
| 267 380 |  | 
| 268 | 
            -
             | 
| 269 | 
            -
             | 
| 270 | 
            -
             | 
| 381 | 
            +
                  let!(:depeche_mode) do
         | 
| 382 | 
            +
                    Band.create(members: [ "Dave", "Alan", "Fletch" ])
         | 
| 383 | 
            +
                  end
         | 
| 271 384 |  | 
| 272 | 
            -
             | 
| 273 | 
            -
             | 
| 274 | 
            -
             | 
| 385 | 
            +
                  let!(:smiths) do
         | 
| 386 | 
            +
                    Band.create
         | 
| 387 | 
            +
                  end
         | 
| 275 388 |  | 
| 276 | 
            -
             | 
| 277 | 
            -
             | 
| 278 | 
            -
             | 
| 389 | 
            +
                  let(:criteria) do
         | 
| 390 | 
            +
                    Band.all
         | 
| 391 | 
            +
                  end
         | 
| 279 392 |  | 
| 280 | 
            -
             | 
| 281 | 
            -
             | 
| 282 | 
            -
             | 
| 393 | 
            +
                  let(:context) do
         | 
| 394 | 
            +
                    Mongoid::Contextual::Mongo.new(criteria)
         | 
| 395 | 
            +
                  end
         | 
| 396 | 
            +
             | 
| 397 | 
            +
                  before do
         | 
| 398 | 
            +
                    context.pull_all(members: [ "Alan", "Dave" ])
         | 
| 399 | 
            +
                  end
         | 
| 283 400 |  | 
| 284 | 
            -
             | 
| 285 | 
            -
             | 
| 401 | 
            +
                  it "pulls when the values are found" do
         | 
| 402 | 
            +
                    expect(depeche_mode.reload.members).to eq([ "Fletch" ])
         | 
| 403 | 
            +
                  end
         | 
| 404 | 
            +
             | 
| 405 | 
            +
                  it "does not error on non existent fields" do
         | 
| 406 | 
            +
                    expect(smiths.reload.members).to be_nil
         | 
| 407 | 
            +
                  end
         | 
| 286 408 | 
             
                end
         | 
| 287 409 |  | 
| 288 | 
            -
                 | 
| 289 | 
            -
             | 
| 410 | 
            +
                context 'when the criteria has a collation', if: collation_supported? do
         | 
| 411 | 
            +
             | 
| 412 | 
            +
                  let!(:depeche_mode) do
         | 
| 413 | 
            +
                    Band.create(members: [ "Dave", "Alan", "Fletch" ])
         | 
| 414 | 
            +
                  end
         | 
| 415 | 
            +
             | 
| 416 | 
            +
                  let(:criteria) do
         | 
| 417 | 
            +
                    Band.all.collation(locale: 'en_US', strength: 2)
         | 
| 418 | 
            +
                  end
         | 
| 419 | 
            +
             | 
| 420 | 
            +
                  let(:context) do
         | 
| 421 | 
            +
                    Mongoid::Contextual::Mongo.new(criteria)
         | 
| 422 | 
            +
                  end
         | 
| 423 | 
            +
             | 
| 424 | 
            +
                  before do
         | 
| 425 | 
            +
                    context.pull_all(members: [ "ALAN", "DAVE" ])
         | 
| 426 | 
            +
                  end
         | 
| 427 | 
            +
             | 
| 428 | 
            +
                  it "pulls when the value is found" do
         | 
| 429 | 
            +
                    expect(depeche_mode.reload.members).to eq([ "Fletch" ])
         | 
| 430 | 
            +
                  end
         | 
| 290 431 | 
             
                end
         | 
| 291 432 | 
             
              end
         | 
| 292 433 |  | 
| 293 434 | 
             
              describe "#push" do
         | 
| 294 435 |  | 
| 295 | 
            -
                 | 
| 296 | 
            -
                  Band.create(members: [ "Dave" ])
         | 
| 297 | 
            -
                end
         | 
| 436 | 
            +
                context 'when the criteria does not have a collation' do
         | 
| 298 437 |  | 
| 299 | 
            -
             | 
| 300 | 
            -
             | 
| 301 | 
            -
             | 
| 438 | 
            +
                  let!(:depeche_mode) do
         | 
| 439 | 
            +
                    Band.create(members: [ "Dave" ])
         | 
| 440 | 
            +
                  end
         | 
| 302 441 |  | 
| 303 | 
            -
             | 
| 304 | 
            -
             | 
| 305 | 
            -
             | 
| 442 | 
            +
                  let!(:smiths) do
         | 
| 443 | 
            +
                    Band.create
         | 
| 444 | 
            +
                  end
         | 
| 306 445 |  | 
| 307 | 
            -
             | 
| 308 | 
            -
             | 
| 309 | 
            -
             | 
| 446 | 
            +
                  let(:criteria) do
         | 
| 447 | 
            +
                    Band.all
         | 
| 448 | 
            +
                  end
         | 
| 310 449 |  | 
| 311 | 
            -
             | 
| 312 | 
            -
             | 
| 313 | 
            -
             | 
| 450 | 
            +
                  let(:context) do
         | 
| 451 | 
            +
                    Mongoid::Contextual::Mongo.new(criteria)
         | 
| 452 | 
            +
                  end
         | 
| 453 | 
            +
             | 
| 454 | 
            +
                  before do
         | 
| 455 | 
            +
                    context.push(members: "Alan")
         | 
| 456 | 
            +
                  end
         | 
| 457 | 
            +
             | 
| 458 | 
            +
                  it "pushes the value to existing arrays" do
         | 
| 459 | 
            +
                    expect(depeche_mode.reload.members).to eq([ "Dave", "Alan" ])
         | 
| 460 | 
            +
                  end
         | 
| 314 461 |  | 
| 315 | 
            -
             | 
| 316 | 
            -
             | 
| 462 | 
            +
                  it "pushes to non existent fields" do
         | 
| 463 | 
            +
                    expect(smiths.reload.members).to eq([ "Alan" ])
         | 
| 464 | 
            +
                  end
         | 
| 317 465 | 
             
                end
         | 
| 318 466 |  | 
| 319 | 
            -
                 | 
| 320 | 
            -
             | 
| 467 | 
            +
                context 'when the criteria has a collation', if: collation_supported? do
         | 
| 468 | 
            +
             | 
| 469 | 
            +
                  let!(:depeche_mode) do
         | 
| 470 | 
            +
                    Band.create(members: [ "Dave" ])
         | 
| 471 | 
            +
                  end
         | 
| 472 | 
            +
             | 
| 473 | 
            +
                  let!(:smiths) do
         | 
| 474 | 
            +
                    Band.create
         | 
| 475 | 
            +
                  end
         | 
| 476 | 
            +
             | 
| 477 | 
            +
                  let(:criteria) do
         | 
| 478 | 
            +
                    Band.where(members: ['DAVE']).collation(locale: 'en_US', strength: 2)
         | 
| 479 | 
            +
                  end
         | 
| 480 | 
            +
             | 
| 481 | 
            +
                  let(:context) do
         | 
| 482 | 
            +
                    Mongoid::Contextual::Mongo.new(criteria)
         | 
| 483 | 
            +
                  end
         | 
| 484 | 
            +
             | 
| 485 | 
            +
                  before do
         | 
| 486 | 
            +
                    context.push(members: "Alan")
         | 
| 487 | 
            +
                  end
         | 
| 488 | 
            +
             | 
| 489 | 
            +
                  it "pushes the value to existing arrays" do
         | 
| 490 | 
            +
                    expect(depeche_mode.reload.members).to eq([ "Dave", "Alan" ])
         | 
| 491 | 
            +
                  end
         | 
| 492 | 
            +
             | 
| 493 | 
            +
                  it "pushes to non existent fields" do
         | 
| 494 | 
            +
                    expect(smiths.reload.members).to be_nil
         | 
| 495 | 
            +
                  end
         | 
| 321 496 | 
             
                end
         | 
| 322 497 | 
             
              end
         | 
| 323 498 |  | 
| 324 499 | 
             
              describe "#push_all" do
         | 
| 325 500 |  | 
| 326 | 
            -
                 | 
| 327 | 
            -
                  Band.create(members: [ "Dave" ])
         | 
| 328 | 
            -
                end
         | 
| 501 | 
            +
                context 'when the criteria does not have a collation' do
         | 
| 329 502 |  | 
| 330 | 
            -
             | 
| 331 | 
            -
             | 
| 332 | 
            -
             | 
| 503 | 
            +
                  let!(:depeche_mode) do
         | 
| 504 | 
            +
                    Band.create(members: [ "Dave" ])
         | 
| 505 | 
            +
                  end
         | 
| 333 506 |  | 
| 334 | 
            -
             | 
| 335 | 
            -
             | 
| 336 | 
            -
             | 
| 507 | 
            +
                  let!(:smiths) do
         | 
| 508 | 
            +
                    Band.create
         | 
| 509 | 
            +
                  end
         | 
| 337 510 |  | 
| 338 | 
            -
             | 
| 339 | 
            -
             | 
| 340 | 
            -
             | 
| 511 | 
            +
                  let(:criteria) do
         | 
| 512 | 
            +
                    Band.all
         | 
| 513 | 
            +
                  end
         | 
| 341 514 |  | 
| 342 | 
            -
             | 
| 343 | 
            -
             | 
| 344 | 
            -
             | 
| 515 | 
            +
                  let(:context) do
         | 
| 516 | 
            +
                    Mongoid::Contextual::Mongo.new(criteria)
         | 
| 517 | 
            +
                  end
         | 
| 518 | 
            +
             | 
| 519 | 
            +
                  before do
         | 
| 520 | 
            +
                    context.push_all(members: [ "Alan", "Fletch" ])
         | 
| 521 | 
            +
                  end
         | 
| 345 522 |  | 
| 346 | 
            -
             | 
| 347 | 
            -
             | 
| 523 | 
            +
                  it "pushes the values to existing arrays" do
         | 
| 524 | 
            +
                    expect(depeche_mode.reload.members).to eq([ "Dave", "Alan", "Fletch" ])
         | 
| 525 | 
            +
                  end
         | 
| 526 | 
            +
             | 
| 527 | 
            +
                  it "pushes to non existent fields" do
         | 
| 528 | 
            +
                    expect(smiths.reload.members).to eq([ "Alan", "Fletch" ])
         | 
| 529 | 
            +
                  end
         | 
| 348 530 | 
             
                end
         | 
| 349 531 |  | 
| 350 | 
            -
                 | 
| 351 | 
            -
             | 
| 532 | 
            +
                context 'when the criteria has a collation', if: collation_supported? do
         | 
| 533 | 
            +
             | 
| 534 | 
            +
                  let!(:depeche_mode) do
         | 
| 535 | 
            +
                    Band.create(members: [ "Dave" ])
         | 
| 536 | 
            +
                  end
         | 
| 537 | 
            +
             | 
| 538 | 
            +
                  let!(:smiths) do
         | 
| 539 | 
            +
                    Band.create
         | 
| 540 | 
            +
                  end
         | 
| 541 | 
            +
             | 
| 542 | 
            +
                  let(:criteria) do
         | 
| 543 | 
            +
                    Band.where(members: ['DAVE']).collation(locale: 'en_US', strength: 2)
         | 
| 544 | 
            +
                  end
         | 
| 545 | 
            +
             | 
| 546 | 
            +
                  let(:context) do
         | 
| 547 | 
            +
                    Mongoid::Contextual::Mongo.new(criteria)
         | 
| 548 | 
            +
                  end
         | 
| 549 | 
            +
             | 
| 550 | 
            +
                  before do
         | 
| 551 | 
            +
                    context.push_all(members: [ "Alan", "Fletch" ])
         | 
| 552 | 
            +
                  end
         | 
| 553 | 
            +
             | 
| 554 | 
            +
                  it "pushes the values to existing arrays" do
         | 
| 555 | 
            +
                    expect(depeche_mode.reload.members).to eq([ "Dave", "Alan", "Fletch" ])
         | 
| 556 | 
            +
                  end
         | 
| 352 557 | 
             
                end
         | 
| 353 558 | 
             
              end
         | 
| 354 559 |  | 
| 355 560 | 
             
              describe "#rename" do
         | 
| 356 561 |  | 
| 357 | 
            -
                 | 
| 358 | 
            -
                  Band.create(members: [ "Dave" ])
         | 
| 359 | 
            -
                end
         | 
| 562 | 
            +
                context 'when the criteria does not have a collation' do
         | 
| 360 563 |  | 
| 361 | 
            -
             | 
| 362 | 
            -
             | 
| 363 | 
            -
             | 
| 564 | 
            +
                  let!(:depeche_mode) do
         | 
| 565 | 
            +
                    Band.create(members: [ "Dave" ])
         | 
| 566 | 
            +
                  end
         | 
| 364 567 |  | 
| 365 | 
            -
             | 
| 366 | 
            -
             | 
| 367 | 
            -
             | 
| 568 | 
            +
                  let!(:smiths) do
         | 
| 569 | 
            +
                    Band.create
         | 
| 570 | 
            +
                  end
         | 
| 368 571 |  | 
| 369 | 
            -
             | 
| 370 | 
            -
             | 
| 371 | 
            -
             | 
| 572 | 
            +
                  let(:criteria) do
         | 
| 573 | 
            +
                    Band.all
         | 
| 574 | 
            +
                  end
         | 
| 372 575 |  | 
| 373 | 
            -
             | 
| 374 | 
            -
             | 
| 375 | 
            -
             | 
| 576 | 
            +
                  let(:context) do
         | 
| 577 | 
            +
                    Mongoid::Contextual::Mongo.new(criteria)
         | 
| 578 | 
            +
                  end
         | 
| 376 579 |  | 
| 377 | 
            -
             | 
| 378 | 
            -
             | 
| 580 | 
            +
                  before do
         | 
| 581 | 
            +
                    context.rename(members: :artists)
         | 
| 582 | 
            +
                  end
         | 
| 583 | 
            +
             | 
| 584 | 
            +
                  it "renames existing fields" do
         | 
| 585 | 
            +
                    expect(depeche_mode.reload.artists).to eq([ "Dave" ])
         | 
| 586 | 
            +
                  end
         | 
| 587 | 
            +
             | 
| 588 | 
            +
                  it "does not rename non existent fields" do
         | 
| 589 | 
            +
                    expect(smiths.reload).to_not respond_to(:artists)
         | 
| 590 | 
            +
                  end
         | 
| 379 591 | 
             
                end
         | 
| 380 592 |  | 
| 381 | 
            -
                 | 
| 382 | 
            -
             | 
| 593 | 
            +
                context 'when the criteria has a collation', if: collation_supported? do
         | 
| 594 | 
            +
             | 
| 595 | 
            +
                  let!(:depeche_mode) do
         | 
| 596 | 
            +
                    Band.create(members: [ "Dave" ])
         | 
| 597 | 
            +
                  end
         | 
| 598 | 
            +
             | 
| 599 | 
            +
                  let!(:smiths) do
         | 
| 600 | 
            +
                    Band.create
         | 
| 601 | 
            +
                  end
         | 
| 602 | 
            +
             | 
| 603 | 
            +
                  let(:criteria) do
         | 
| 604 | 
            +
                    Band.where(members: ['DAVE']).collation(locale: 'en_US', strength: 2)
         | 
| 605 | 
            +
                  end
         | 
| 606 | 
            +
             | 
| 607 | 
            +
                  let(:context) do
         | 
| 608 | 
            +
                    Mongoid::Contextual::Mongo.new(criteria)
         | 
| 609 | 
            +
                  end
         | 
| 610 | 
            +
             | 
| 611 | 
            +
                  before do
         | 
| 612 | 
            +
                    context.rename(members: :artists)
         | 
| 613 | 
            +
                  end
         | 
| 614 | 
            +
             | 
| 615 | 
            +
                  it "renames existing fields" do
         | 
| 616 | 
            +
                    expect(depeche_mode.reload.artists).to eq([ "Dave" ])
         | 
| 617 | 
            +
                  end
         | 
| 618 | 
            +
             | 
| 619 | 
            +
                  it "does not rename non existent fields" do
         | 
| 620 | 
            +
                    expect(smiths.reload).to_not respond_to(:artists)
         | 
| 621 | 
            +
                  end
         | 
| 383 622 | 
             
                end
         | 
| 384 623 | 
             
              end
         | 
| 385 624 |  | 
| @@ -509,5 +748,32 @@ describe Mongoid::Contextual::Atomic do | |
| 509 748 | 
             
                    end
         | 
| 510 749 | 
             
                  end
         | 
| 511 750 | 
             
                end
         | 
| 751 | 
            +
             | 
| 752 | 
            +
                context 'when the criteria has a collation', if: collation_supported? do
         | 
| 753 | 
            +
             | 
| 754 | 
            +
                  let!(:depeche_mode) do
         | 
| 755 | 
            +
                    Band.create(name: "Depeche Mode", years: 10)
         | 
| 756 | 
            +
                  end
         | 
| 757 | 
            +
             | 
| 758 | 
            +
                  let!(:new_order) do
         | 
| 759 | 
            +
                    Band.create(name: "New Order", years: 10)
         | 
| 760 | 
            +
                  end
         | 
| 761 | 
            +
             | 
| 762 | 
            +
                  let(:criteria) do
         | 
| 763 | 
            +
                    Band.where(name: 'DEPECHE MODE').collation(locale: 'en_US', strength: 2)
         | 
| 764 | 
            +
                  end
         | 
| 765 | 
            +
             | 
| 766 | 
            +
                  let(:context) do
         | 
| 767 | 
            +
                    Mongoid::Contextual::Mongo.new(criteria)
         | 
| 768 | 
            +
                  end
         | 
| 769 | 
            +
             | 
| 770 | 
            +
                  before do
         | 
| 771 | 
            +
                    context.unset(:name)
         | 
| 772 | 
            +
                  end
         | 
| 773 | 
            +
             | 
| 774 | 
            +
                  it "unsets the unaliased field" do
         | 
| 775 | 
            +
                    expect(depeche_mode.reload.name).to be_nil
         | 
| 776 | 
            +
                  end
         | 
| 777 | 
            +
                end
         | 
| 512 778 | 
             
              end
         | 
| 513 779 | 
             
            end
         |