mongoid_rails4 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3213 -0
- data/LICENSE +20 -0
- data/README.md +62 -0
- data/Rakefile +35 -0
- data/lib/config/locales/en.yml +448 -0
- data/lib/mongoid.rb +104 -0
- data/lib/mongoid/atomic.rb +384 -0
- data/lib/mongoid/atomic/modifiers.rb +317 -0
- data/lib/mongoid/atomic/paths.rb +3 -0
- data/lib/mongoid/atomic/paths/embedded.rb +28 -0
- data/lib/mongoid/atomic/paths/embedded/many.rb +44 -0
- data/lib/mongoid/atomic/paths/embedded/one.rb +43 -0
- data/lib/mongoid/atomic/paths/root.rb +39 -0
- data/lib/mongoid/attributes.rb +284 -0
- data/lib/mongoid/attributes/dynamic.rb +154 -0
- data/lib/mongoid/attributes/nested.rb +82 -0
- data/lib/mongoid/attributes/processing.rb +147 -0
- data/lib/mongoid/attributes/readonly.rb +56 -0
- data/lib/mongoid/changeable.rb +379 -0
- data/lib/mongoid/composable.rb +104 -0
- data/lib/mongoid/config.rb +263 -0
- data/lib/mongoid/config/environment.rb +44 -0
- data/lib/mongoid/config/options.rb +74 -0
- data/lib/mongoid/config/validators.rb +3 -0
- data/lib/mongoid/config/validators/option.rb +25 -0
- data/lib/mongoid/config/validators/session.rb +140 -0
- data/lib/mongoid/contextual.rb +54 -0
- data/lib/mongoid/contextual/aggregable/memory.rb +109 -0
- data/lib/mongoid/contextual/aggregable/mongo.rb +147 -0
- data/lib/mongoid/contextual/atomic.rb +180 -0
- data/lib/mongoid/contextual/command.rb +61 -0
- data/lib/mongoid/contextual/eager.rb +158 -0
- data/lib/mongoid/contextual/find_and_modify.rb +69 -0
- data/lib/mongoid/contextual/geo_near.rb +238 -0
- data/lib/mongoid/contextual/map_reduce.rb +324 -0
- data/lib/mongoid/contextual/memory.rb +440 -0
- data/lib/mongoid/contextual/mongo.rb +676 -0
- data/lib/mongoid/contextual/queryable.rb +25 -0
- data/lib/mongoid/contextual/text_search.rb +180 -0
- data/lib/mongoid/copyable.rb +67 -0
- data/lib/mongoid/criteria.rb +562 -0
- data/lib/mongoid/criteria/findable.rb +179 -0
- data/lib/mongoid/criteria/inspectable.rb +25 -0
- data/lib/mongoid/criteria/marshalable.rb +50 -0
- data/lib/mongoid/criteria/modifiable.rb +189 -0
- data/lib/mongoid/criteria/scopable.rb +158 -0
- data/lib/mongoid/document.rb +361 -0
- data/lib/mongoid/equality.rb +66 -0
- data/lib/mongoid/errors.rb +40 -0
- data/lib/mongoid/errors/ambiguous_relationship.rb +51 -0
- data/lib/mongoid/errors/callback.rb +25 -0
- data/lib/mongoid/errors/delete_restriction.rb +29 -0
- data/lib/mongoid/errors/document_not_found.rb +111 -0
- data/lib/mongoid/errors/eager_load.rb +22 -0
- data/lib/mongoid/errors/invalid_collection.rb +18 -0
- data/lib/mongoid/errors/invalid_config_option.rb +27 -0
- data/lib/mongoid/errors/invalid_field.rb +64 -0
- data/lib/mongoid/errors/invalid_field_option.rb +35 -0
- data/lib/mongoid/errors/invalid_find.rb +19 -0
- data/lib/mongoid/errors/invalid_includes.rb +32 -0
- data/lib/mongoid/errors/invalid_index.rb +28 -0
- data/lib/mongoid/errors/invalid_options.rb +28 -0
- data/lib/mongoid/errors/invalid_path.rb +21 -0
- data/lib/mongoid/errors/invalid_scope.rb +24 -0
- data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +38 -0
- data/lib/mongoid/errors/invalid_storage_options.rb +27 -0
- data/lib/mongoid/errors/invalid_time.rb +22 -0
- data/lib/mongoid/errors/inverse_not_found.rb +29 -0
- data/lib/mongoid/errors/mixed_relations.rb +32 -0
- data/lib/mongoid/errors/mixed_session_configuration.rb +28 -0
- data/lib/mongoid/errors/mongoid_error.rb +92 -0
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +28 -0
- data/lib/mongoid/errors/no_default_session.rb +23 -0
- data/lib/mongoid/errors/no_environment.rb +19 -0
- data/lib/mongoid/errors/no_map_reduce_output.rb +24 -0
- data/lib/mongoid/errors/no_metadata.rb +21 -0
- data/lib/mongoid/errors/no_parent.rb +24 -0
- data/lib/mongoid/errors/no_session_config.rb +22 -0
- data/lib/mongoid/errors/no_session_database.rb +27 -0
- data/lib/mongoid/errors/no_session_hosts.rb +27 -0
- data/lib/mongoid/errors/no_sessions_config.rb +20 -0
- data/lib/mongoid/errors/readonly_attribute.rb +25 -0
- data/lib/mongoid/errors/scope_overwrite.rb +21 -0
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +20 -0
- data/lib/mongoid/errors/unknown_attribute.rb +25 -0
- data/lib/mongoid/errors/unsaved_document.rb +19 -0
- data/lib/mongoid/errors/unsupported_javascript.rb +27 -0
- data/lib/mongoid/errors/validations.rb +29 -0
- data/lib/mongoid/evolvable.rb +19 -0
- data/lib/mongoid/extensions.rb +35 -0
- data/lib/mongoid/extensions/array.rb +180 -0
- data/lib/mongoid/extensions/big_decimal.rb +69 -0
- data/lib/mongoid/extensions/boolean.rb +21 -0
- data/lib/mongoid/extensions/date.rb +77 -0
- data/lib/mongoid/extensions/date_time.rb +73 -0
- data/lib/mongoid/extensions/false_class.rb +38 -0
- data/lib/mongoid/extensions/float.rb +56 -0
- data/lib/mongoid/extensions/hash.rb +209 -0
- data/lib/mongoid/extensions/integer.rb +67 -0
- data/lib/mongoid/extensions/module.rb +28 -0
- data/lib/mongoid/extensions/nil_class.rb +33 -0
- data/lib/mongoid/extensions/object.rb +274 -0
- data/lib/mongoid/extensions/object_id.rb +54 -0
- data/lib/mongoid/extensions/range.rb +79 -0
- data/lib/mongoid/extensions/regexp.rb +27 -0
- data/lib/mongoid/extensions/set.rb +55 -0
- data/lib/mongoid/extensions/string.rb +199 -0
- data/lib/mongoid/extensions/symbol.rb +54 -0
- data/lib/mongoid/extensions/time.rb +88 -0
- data/lib/mongoid/extensions/time_with_zone.rb +56 -0
- data/lib/mongoid/extensions/true_class.rb +38 -0
- data/lib/mongoid/factory.rb +46 -0
- data/lib/mongoid/fields.rb +542 -0
- data/lib/mongoid/fields/foreign_key.rb +174 -0
- data/lib/mongoid/fields/localized.rb +73 -0
- data/lib/mongoid/fields/standard.rb +273 -0
- data/lib/mongoid/fields/validators.rb +2 -0
- data/lib/mongoid/fields/validators/macro.rb +92 -0
- data/lib/mongoid/findable.rb +133 -0
- data/lib/mongoid/identity_map.rb +163 -0
- data/lib/mongoid/indexable.rb +147 -0
- data/lib/mongoid/indexable/specification.rb +115 -0
- data/lib/mongoid/indexable/validators/options.rb +103 -0
- data/lib/mongoid/inspectable.rb +59 -0
- data/lib/mongoid/interceptable.rb +265 -0
- data/lib/mongoid/loggable.rb +69 -0
- data/lib/mongoid/matchable.rb +152 -0
- data/lib/mongoid/matchable/all.rb +27 -0
- data/lib/mongoid/matchable/and.rb +30 -0
- data/lib/mongoid/matchable/default.rb +72 -0
- data/lib/mongoid/matchable/exists.rb +23 -0
- data/lib/mongoid/matchable/gt.rb +21 -0
- data/lib/mongoid/matchable/gte.rb +21 -0
- data/lib/mongoid/matchable/in.rb +24 -0
- data/lib/mongoid/matchable/lt.rb +21 -0
- data/lib/mongoid/matchable/lte.rb +21 -0
- data/lib/mongoid/matchable/ne.rb +21 -0
- data/lib/mongoid/matchable/nin.rb +21 -0
- data/lib/mongoid/matchable/or.rb +33 -0
- data/lib/mongoid/matchable/size.rb +21 -0
- data/lib/mongoid/persistable.rb +207 -0
- data/lib/mongoid/persistable/creatable.rb +189 -0
- data/lib/mongoid/persistable/deletable.rb +149 -0
- data/lib/mongoid/persistable/destroyable.rb +55 -0
- data/lib/mongoid/persistable/incrementable.rb +36 -0
- data/lib/mongoid/persistable/logical.rb +38 -0
- data/lib/mongoid/persistable/poppable.rb +39 -0
- data/lib/mongoid/persistable/pullable.rb +55 -0
- data/lib/mongoid/persistable/pushable.rb +62 -0
- data/lib/mongoid/persistable/renamable.rb +35 -0
- data/lib/mongoid/persistable/savable.rb +52 -0
- data/lib/mongoid/persistable/settable.rb +33 -0
- data/lib/mongoid/persistable/unsettable.rb +36 -0
- data/lib/mongoid/persistable/updatable.rb +151 -0
- data/lib/mongoid/persistable/upsertable.rb +55 -0
- data/lib/mongoid/positional.rb +71 -0
- data/lib/mongoid/railtie.rb +156 -0
- data/lib/mongoid/railties/database.rake +97 -0
- data/lib/mongoid/railties/document.rb +12 -0
- data/lib/mongoid/relations.rb +162 -0
- data/lib/mongoid/relations/accessors.rb +299 -0
- data/lib/mongoid/relations/auto_save.rb +106 -0
- data/lib/mongoid/relations/binding.rb +218 -0
- data/lib/mongoid/relations/bindings.rb +9 -0
- data/lib/mongoid/relations/bindings/embedded/in.rb +63 -0
- data/lib/mongoid/relations/bindings/embedded/many.rb +50 -0
- data/lib/mongoid/relations/bindings/embedded/one.rb +55 -0
- data/lib/mongoid/relations/bindings/referenced/in.rb +65 -0
- data/lib/mongoid/relations/bindings/referenced/many.rb +42 -0
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +67 -0
- data/lib/mongoid/relations/bindings/referenced/one.rb +44 -0
- data/lib/mongoid/relations/builder.rb +57 -0
- data/lib/mongoid/relations/builders.rb +104 -0
- data/lib/mongoid/relations/builders/embedded/in.rb +29 -0
- data/lib/mongoid/relations/builders/embedded/many.rb +36 -0
- data/lib/mongoid/relations/builders/embedded/one.rb +30 -0
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +174 -0
- data/lib/mongoid/relations/builders/nested_attributes/one.rb +126 -0
- data/lib/mongoid/relations/builders/referenced/in.rb +26 -0
- data/lib/mongoid/relations/builders/referenced/many.rb +27 -0
- data/lib/mongoid/relations/builders/referenced/many_to_many.rb +40 -0
- data/lib/mongoid/relations/builders/referenced/one.rb +26 -0
- data/lib/mongoid/relations/cascading.rb +56 -0
- data/lib/mongoid/relations/cascading/delete.rb +44 -0
- data/lib/mongoid/relations/cascading/destroy.rb +43 -0
- data/lib/mongoid/relations/cascading/nullify.rb +35 -0
- data/lib/mongoid/relations/cascading/restrict.rb +39 -0
- data/lib/mongoid/relations/constraint.rb +49 -0
- data/lib/mongoid/relations/conversions.rb +34 -0
- data/lib/mongoid/relations/counter_cache.rb +105 -0
- data/lib/mongoid/relations/cyclic.rb +107 -0
- data/lib/mongoid/relations/embedded/batchable.rb +355 -0
- data/lib/mongoid/relations/embedded/in.rb +231 -0
- data/lib/mongoid/relations/embedded/many.rb +639 -0
- data/lib/mongoid/relations/embedded/one.rb +223 -0
- data/lib/mongoid/relations/macros.rb +356 -0
- data/lib/mongoid/relations/many.rb +208 -0
- data/lib/mongoid/relations/marshalable.rb +32 -0
- data/lib/mongoid/relations/metadata.rb +1174 -0
- data/lib/mongoid/relations/nested_builder.rb +74 -0
- data/lib/mongoid/relations/one.rb +48 -0
- data/lib/mongoid/relations/options.rb +48 -0
- data/lib/mongoid/relations/polymorphic.rb +39 -0
- data/lib/mongoid/relations/proxy.rb +270 -0
- data/lib/mongoid/relations/referenced/in.rb +297 -0
- data/lib/mongoid/relations/referenced/many.rb +787 -0
- data/lib/mongoid/relations/referenced/many_to_many.rb +486 -0
- data/lib/mongoid/relations/referenced/one.rb +290 -0
- data/lib/mongoid/relations/reflections.rb +62 -0
- data/lib/mongoid/relations/synchronization.rb +169 -0
- data/lib/mongoid/relations/targets.rb +2 -0
- data/lib/mongoid/relations/targets/enumerable.rb +473 -0
- data/lib/mongoid/relations/touchable.rb +94 -0
- data/lib/mongoid/reloadable.rb +95 -0
- data/lib/mongoid/scopable.rb +379 -0
- data/lib/mongoid/selectable.rb +59 -0
- data/lib/mongoid/serializable.rb +170 -0
- data/lib/mongoid/sessions.rb +330 -0
- data/lib/mongoid/sessions/factory.rb +129 -0
- data/lib/mongoid/sessions/mongo_uri.rb +93 -0
- data/lib/mongoid/sessions/options.rb +141 -0
- data/lib/mongoid/sessions/validators.rb +2 -0
- data/lib/mongoid/sessions/validators/storage.rb +49 -0
- data/lib/mongoid/shardable.rb +65 -0
- data/lib/mongoid/state.rb +97 -0
- data/lib/mongoid/threaded.rb +383 -0
- data/lib/mongoid/threaded/lifecycle.rb +164 -0
- data/lib/mongoid/timestamps.rb +15 -0
- data/lib/mongoid/timestamps/created.rb +30 -0
- data/lib/mongoid/timestamps/created/short.rb +19 -0
- data/lib/mongoid/timestamps/short.rb +10 -0
- data/lib/mongoid/timestamps/updated.rb +39 -0
- data/lib/mongoid/timestamps/updated/short.rb +19 -0
- data/lib/mongoid/traversable.rb +192 -0
- data/lib/mongoid/unit_of_work.rb +61 -0
- data/lib/mongoid/validatable.rb +180 -0
- data/lib/mongoid/validatable/associated.rb +48 -0
- data/lib/mongoid/validatable/format.rb +20 -0
- data/lib/mongoid/validatable/length.rb +20 -0
- data/lib/mongoid/validatable/localizable.rb +30 -0
- data/lib/mongoid/validatable/macros.rb +94 -0
- data/lib/mongoid/validatable/presence.rb +86 -0
- data/lib/mongoid/validatable/queryable.rb +30 -0
- data/lib/mongoid/validatable/uniqueness.rb +330 -0
- data/lib/mongoid/version.rb +4 -0
- data/lib/rack/mongoid.rb +2 -0
- data/lib/rack/mongoid/middleware/identity_map.rb +39 -0
- data/lib/rails/generators/mongoid/config/config_generator.rb +25 -0
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +76 -0
- data/lib/rails/generators/mongoid/model/model_generator.rb +25 -0
- data/lib/rails/generators/mongoid/model/templates/model.rb.tt +19 -0
- data/lib/rails/generators/mongoid/observer/observer_generator.rb +17 -0
- data/lib/rails/generators/mongoid/observer/templates/observer.rb.tt +4 -0
- data/lib/rails/generators/mongoid_generator.rb +65 -0
- data/lib/rails/mongoid.rb +180 -0
- data/lib/support/ruby_version.rb +26 -0
- data/spec/app/models/account.rb +28 -0
- data/spec/app/models/acolyte.rb +17 -0
- data/spec/app/models/actor.rb +18 -0
- data/spec/app/models/actress.rb +2 -0
- data/spec/app/models/address.rb +77 -0
- data/spec/app/models/address_component.rb +5 -0
- data/spec/app/models/address_number.rb +6 -0
- data/spec/app/models/agency.rb +5 -0
- data/spec/app/models/agent.rb +12 -0
- data/spec/app/models/album.rb +14 -0
- data/spec/app/models/alert.rb +5 -0
- data/spec/app/models/animal.rb +25 -0
- data/spec/app/models/answer.rb +4 -0
- data/spec/app/models/appointment.rb +7 -0
- data/spec/app/models/article.rb +10 -0
- data/spec/app/models/artist.rb +66 -0
- data/spec/app/models/artwork.rb +4 -0
- data/spec/app/models/audio.rb +5 -0
- data/spec/app/models/augmentation.rb +11 -0
- data/spec/app/models/author.rb +4 -0
- data/spec/app/models/band.rb +26 -0
- data/spec/app/models/bar.rb +10 -0
- data/spec/app/models/basic.rb +6 -0
- data/spec/app/models/bed.rb +1 -0
- data/spec/app/models/big_palette.rb +2 -0
- data/spec/app/models/birthday.rb +13 -0
- data/spec/app/models/book.rb +13 -0
- data/spec/app/models/breed.rb +4 -0
- data/spec/app/models/browser.rb +6 -0
- data/spec/app/models/building.rb +5 -0
- data/spec/app/models/building_address.rb +5 -0
- data/spec/app/models/bus.rb +7 -0
- data/spec/app/models/business.rb +5 -0
- data/spec/app/models/callback_recorder.rb +25 -0
- data/spec/app/models/callback_test.rb +9 -0
- data/spec/app/models/canvas.rb +25 -0
- data/spec/app/models/car.rb +1 -0
- data/spec/app/models/cat.rb +8 -0
- data/spec/app/models/category.rb +8 -0
- data/spec/app/models/child.rb +4 -0
- data/spec/app/models/child_doc.rb +22 -0
- data/spec/app/models/church.rb +4 -0
- data/spec/app/models/circle.rb +3 -0
- data/spec/app/models/circuit.rb +4 -0
- data/spec/app/models/circus.rb +7 -0
- data/spec/app/models/code.rb +5 -0
- data/spec/app/models/comment.rb +16 -0
- data/spec/app/models/contractor.rb +5 -0
- data/spec/app/models/cookie.rb +6 -0
- data/spec/app/models/country_code.rb +8 -0
- data/spec/app/models/definition.rb +7 -0
- data/spec/app/models/description.rb +11 -0
- data/spec/app/models/dictionary.rb +10 -0
- data/spec/app/models/division.rb +10 -0
- data/spec/app/models/doctor.rb +12 -0
- data/spec/app/models/dog.rb +7 -0
- data/spec/app/models/dokument.rb +5 -0
- data/spec/app/models/dragon.rb +4 -0
- data/spec/app/models/driver.rb +7 -0
- data/spec/app/models/drug.rb +6 -0
- data/spec/app/models/dungeon.rb +4 -0
- data/spec/app/models/email.rb +6 -0
- data/spec/app/models/employer.rb +5 -0
- data/spec/app/models/entry.rb +6 -0
- data/spec/app/models/eraser.rb +1 -0
- data/spec/app/models/event.rb +22 -0
- data/spec/app/models/exhibition.rb +4 -0
- data/spec/app/models/exhibitor.rb +5 -0
- data/spec/app/models/eye.rb +9 -0
- data/spec/app/models/eye_bowl.rb +9 -0
- data/spec/app/models/face.rb +8 -0
- data/spec/app/models/favorite.rb +6 -0
- data/spec/app/models/filesystem.rb +5 -0
- data/spec/app/models/fire_hydrant.rb +6 -0
- data/spec/app/models/firefox.rb +4 -0
- data/spec/app/models/fish.rb +7 -0
- data/spec/app/models/folder.rb +7 -0
- data/spec/app/models/folder_item.rb +9 -0
- data/spec/app/models/fruits.rb +28 -0
- data/spec/app/models/game.rb +19 -0
- data/spec/app/models/ghost.rb +7 -0
- data/spec/app/models/home.rb +4 -0
- data/spec/app/models/house.rb +6 -0
- data/spec/app/models/html_writer.rb +3 -0
- data/spec/app/models/image.rb +22 -0
- data/spec/app/models/implant.rb +16 -0
- data/spec/app/models/item.rb +8 -0
- data/spec/app/models/jar.rb +7 -0
- data/spec/app/models/label.rb +40 -0
- data/spec/app/models/language.rb +5 -0
- data/spec/app/models/lat_lng.rb +15 -0
- data/spec/app/models/league.rb +11 -0
- data/spec/app/models/learner.rb +2 -0
- data/spec/app/models/line_item.rb +6 -0
- data/spec/app/models/location.rb +8 -0
- data/spec/app/models/login.rb +8 -0
- data/spec/app/models/manufacturer.rb +7 -0
- data/spec/app/models/meat.rb +4 -0
- data/spec/app/models/membership.rb +4 -0
- data/spec/app/models/mixed_drink.rb +4 -0
- data/spec/app/models/movie.rb +13 -0
- data/spec/app/models/my_hash.rb +2 -0
- data/spec/app/models/name.rb +23 -0
- data/spec/app/models/node.rb +5 -0
- data/spec/app/models/note.rb +12 -0
- data/spec/app/models/ordered_post.rb +6 -0
- data/spec/app/models/ordered_preference.rb +6 -0
- data/spec/app/models/oscar.rb +15 -0
- data/spec/app/models/override.rb +16 -0
- data/spec/app/models/ownable.rb +6 -0
- data/spec/app/models/owner.rb +6 -0
- data/spec/app/models/pack.rb +3 -0
- data/spec/app/models/page.rb +5 -0
- data/spec/app/models/page_question.rb +4 -0
- data/spec/app/models/palette.rb +7 -0
- data/spec/app/models/parent.rb +5 -0
- data/spec/app/models/parent_doc.rb +6 -0
- data/spec/app/models/passport.rb +5 -0
- data/spec/app/models/patient.rb +9 -0
- data/spec/app/models/pdf_writer.rb +3 -0
- data/spec/app/models/pencil.rb +1 -0
- data/spec/app/models/person.rb +205 -0
- data/spec/app/models/pet.rb +23 -0
- data/spec/app/models/pet_owner.rb +6 -0
- data/spec/app/models/phone.rb +11 -0
- data/spec/app/models/pizza.rb +7 -0
- data/spec/app/models/player.rb +35 -0
- data/spec/app/models/post.rb +44 -0
- data/spec/app/models/powerup.rb +11 -0
- data/spec/app/models/preference.rb +9 -0
- data/spec/app/models/princess.rb +8 -0
- data/spec/app/models/product.rb +15 -0
- data/spec/app/models/profile.rb +5 -0
- data/spec/app/models/pronunciation.rb +5 -0
- data/spec/app/models/purchase.rb +4 -0
- data/spec/app/models/question.rb +8 -0
- data/spec/app/models/quiz.rb +7 -0
- data/spec/app/models/rating.rb +8 -0
- data/spec/app/models/record.rb +46 -0
- data/spec/app/models/registry.rb +4 -0
- data/spec/app/models/role.rb +7 -0
- data/spec/app/models/root_category.rb +4 -0
- data/spec/app/models/sandwich.rb +4 -0
- data/spec/app/models/scheduler.rb +7 -0
- data/spec/app/models/seo.rb +7 -0
- data/spec/app/models/series.rb +4 -0
- data/spec/app/models/server.rb +13 -0
- data/spec/app/models/service.rb +22 -0
- data/spec/app/models/shape.rb +12 -0
- data/spec/app/models/shelf.rb +5 -0
- data/spec/app/models/shipping_container.rb +5 -0
- data/spec/app/models/shipping_pack.rb +3 -0
- data/spec/app/models/shop.rb +6 -0
- data/spec/app/models/short_agent.rb +4 -0
- data/spec/app/models/short_quiz.rb +5 -0
- data/spec/app/models/slave.rb +6 -0
- data/spec/app/models/song.rb +8 -0
- data/spec/app/models/sound.rb +5 -0
- data/spec/app/models/square.rb +4 -0
- data/spec/app/models/strategy.rb +3 -0
- data/spec/app/models/sub_item.rb +3 -0
- data/spec/app/models/subscription.rb +4 -0
- data/spec/app/models/survey.rb +5 -0
- data/spec/app/models/symptom.rb +6 -0
- data/spec/app/models/tag.rb +8 -0
- data/spec/app/models/target.rb +5 -0
- data/spec/app/models/template.rb +5 -0
- data/spec/app/models/thing.rb +9 -0
- data/spec/app/models/title.rb +3 -0
- data/spec/app/models/tool.rb +8 -0
- data/spec/app/models/topping.rb +5 -0
- data/spec/app/models/track.rb +38 -0
- data/spec/app/models/translation.rb +5 -0
- data/spec/app/models/tree.rb +9 -0
- data/spec/app/models/truck.rb +3 -0
- data/spec/app/models/user.rb +21 -0
- data/spec/app/models/user_account.rb +10 -0
- data/spec/app/models/validation_callback.rb +10 -0
- data/spec/app/models/vehicle.rb +11 -0
- data/spec/app/models/version.rb +5 -0
- data/spec/app/models/vet_visit.rb +5 -0
- data/spec/app/models/video.rb +13 -0
- data/spec/app/models/weapon.rb +11 -0
- data/spec/app/models/wiki_page.rb +14 -0
- data/spec/app/models/word.rb +15 -0
- data/spec/app/models/word_origin.rb +11 -0
- data/spec/app/models/writer.rb +11 -0
- data/spec/config/mongoid.yml +38 -0
- data/spec/mongoid/atomic/modifiers_spec.rb +456 -0
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +118 -0
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +110 -0
- data/spec/mongoid/atomic/paths/root_spec.rb +48 -0
- data/spec/mongoid/atomic/paths_spec.rb +270 -0
- data/spec/mongoid/atomic_spec.rb +365 -0
- data/spec/mongoid/attributes/nested_spec.rb +4832 -0
- data/spec/mongoid/attributes/readonly_spec.rb +169 -0
- data/spec/mongoid/attributes_spec.rb +1412 -0
- data/spec/mongoid/changeable_spec.rb +1507 -0
- data/spec/mongoid/composable_spec.rb +24 -0
- data/spec/mongoid/config/environment_spec.rb +83 -0
- data/spec/mongoid/config/options_spec.rb +56 -0
- data/spec/mongoid/config_spec.rb +318 -0
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +293 -0
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +455 -0
- data/spec/mongoid/contextual/atomic_spec.rb +529 -0
- data/spec/mongoid/contextual/find_and_modify_spec.rb +220 -0
- data/spec/mongoid/contextual/geo_near_spec.rb +405 -0
- data/spec/mongoid/contextual/map_reduce_spec.rb +464 -0
- data/spec/mongoid/contextual/memory_spec.rb +1236 -0
- data/spec/mongoid/contextual/mongo_spec.rb +1843 -0
- data/spec/mongoid/contextual/text_search_spec.rb +207 -0
- data/spec/mongoid/copyable_spec.rb +393 -0
- data/spec/mongoid/criteria/findable_spec.rb +1189 -0
- data/spec/mongoid/criteria/inspectable_spec.rb +27 -0
- data/spec/mongoid/criteria/marshalable_spec.rb +28 -0
- data/spec/mongoid/criteria/modifiable_spec.rb +1063 -0
- data/spec/mongoid/criteria/scopable_spec.rb +391 -0
- data/spec/mongoid/criteria_spec.rb +3821 -0
- data/spec/mongoid/document_spec.rb +1205 -0
- data/spec/mongoid/equality_spec.rb +241 -0
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +29 -0
- data/spec/mongoid/errors/callback_spec.rb +29 -0
- data/spec/mongoid/errors/delete_restriction_spec.rb +29 -0
- data/spec/mongoid/errors/document_not_found_spec.rb +104 -0
- data/spec/mongoid/errors/eager_load_spec.rb +29 -0
- data/spec/mongoid/errors/invalid_collection_spec.rb +36 -0
- data/spec/mongoid/errors/invalid_config_option_spec.rb +29 -0
- data/spec/mongoid/errors/invalid_field_option_spec.rb +29 -0
- data/spec/mongoid/errors/invalid_field_spec.rb +37 -0
- data/spec/mongoid/errors/invalid_find_spec.rb +29 -0
- data/spec/mongoid/errors/invalid_includes_spec.rb +40 -0
- data/spec/mongoid/errors/invalid_index_spec.rb +29 -0
- data/spec/mongoid/errors/invalid_options_spec.rb +29 -0
- data/spec/mongoid/errors/invalid_path_spec.rb +23 -0
- data/spec/mongoid/errors/invalid_scope_spec.rb +29 -0
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +17 -0
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +29 -0
- data/spec/mongoid/errors/invalid_time_spec.rb +29 -0
- data/spec/mongoid/errors/inverse_not_found_spec.rb +29 -0
- data/spec/mongoid/errors/mixed_relations_spec.rb +29 -0
- data/spec/mongoid/errors/mixed_session_configuration_spec.rb +29 -0
- data/spec/mongoid/errors/mongoid_error_spec.rb +48 -0
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +29 -0
- data/spec/mongoid/errors/no_environment_spec.rb +29 -0
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +29 -0
- data/spec/mongoid/errors/no_metadata_spec.rb +23 -0
- data/spec/mongoid/errors/no_parent_spec.rb +29 -0
- data/spec/mongoid/errors/no_session_config_spec.rb +29 -0
- data/spec/mongoid/errors/no_session_database_spec.rb +29 -0
- data/spec/mongoid/errors/no_session_hosts_spec.rb +29 -0
- data/spec/mongoid/errors/no_sessions_config_spec.rb +29 -0
- data/spec/mongoid/errors/readonly_attribute_spec.rb +29 -0
- data/spec/mongoid/errors/scope_overwrite_spec.rb +29 -0
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +29 -0
- data/spec/mongoid/errors/unknown_attribute_spec.rb +29 -0
- data/spec/mongoid/errors/unsaved_document_spec.rb +37 -0
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +29 -0
- data/spec/mongoid/errors/validations_spec.rb +45 -0
- data/spec/mongoid/extensions/array_spec.rb +638 -0
- data/spec/mongoid/extensions/big_decimal_spec.rb +104 -0
- data/spec/mongoid/extensions/binary_spec.rb +60 -0
- data/spec/mongoid/extensions/boolean_spec.rb +135 -0
- data/spec/mongoid/extensions/date_spec.rb +235 -0
- data/spec/mongoid/extensions/date_time_spec.rb +155 -0
- data/spec/mongoid/extensions/false_class_spec.rb +42 -0
- data/spec/mongoid/extensions/float_spec.rb +133 -0
- data/spec/mongoid/extensions/hash_spec.rb +333 -0
- data/spec/mongoid/extensions/integer_spec.rb +136 -0
- data/spec/mongoid/extensions/module_spec.rb +42 -0
- data/spec/mongoid/extensions/nil_class_spec.rb +11 -0
- data/spec/mongoid/extensions/object_id_spec.rb +946 -0
- data/spec/mongoid/extensions/object_spec.rb +292 -0
- data/spec/mongoid/extensions/range_spec.rb +105 -0
- data/spec/mongoid/extensions/regexp_spec.rb +47 -0
- data/spec/mongoid/extensions/set_spec.rb +33 -0
- data/spec/mongoid/extensions/string_spec.rb +357 -0
- data/spec/mongoid/extensions/symbol_spec.rb +76 -0
- data/spec/mongoid/extensions/time_spec.rb +467 -0
- data/spec/mongoid/extensions/time_with_zone_spec.rb +405 -0
- data/spec/mongoid/extensions/true_class_spec.rb +42 -0
- data/spec/mongoid/extensions_spec.rb +15 -0
- data/spec/mongoid/factory_spec.rb +185 -0
- data/spec/mongoid/fields/foreign_key_spec.rb +694 -0
- data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +184 -0
- data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +201 -0
- data/spec/mongoid/fields/localized_spec.rb +386 -0
- data/spec/mongoid/fields/standard_spec.rb +166 -0
- data/spec/mongoid/fields_spec.rb +1229 -0
- data/spec/mongoid/findable_spec.rb +342 -0
- data/spec/mongoid/identity_map_spec.rb +564 -0
- data/spec/mongoid/indexable/specification_spec.rb +87 -0
- data/spec/mongoid/indexable_spec.rb +504 -0
- data/spec/mongoid/inspectable_spec.rb +49 -0
- data/spec/mongoid/interceptable_spec.rb +1564 -0
- data/spec/mongoid/loggable_spec.rb +21 -0
- data/spec/mongoid/matchable/all_spec.rb +31 -0
- data/spec/mongoid/matchable/and_spec.rb +162 -0
- data/spec/mongoid/matchable/default_spec.rb +130 -0
- data/spec/mongoid/matchable/exists_spec.rb +57 -0
- data/spec/mongoid/matchable/gt_spec.rb +75 -0
- data/spec/mongoid/matchable/gte_spec.rb +74 -0
- data/spec/mongoid/matchable/in_spec.rb +25 -0
- data/spec/mongoid/matchable/lt_spec.rb +74 -0
- data/spec/mongoid/matchable/lte_spec.rb +74 -0
- data/spec/mongoid/matchable/ne_spec.rb +25 -0
- data/spec/mongoid/matchable/nin_spec.rb +25 -0
- data/spec/mongoid/matchable/or_spec.rb +106 -0
- data/spec/mongoid/matchable/size_spec.rb +25 -0
- data/spec/mongoid/matchable_spec.rb +532 -0
- data/spec/mongoid/persistable/creatable_spec.rb +512 -0
- data/spec/mongoid/persistable/deletable_spec.rb +205 -0
- data/spec/mongoid/persistable/destroyable_spec.rb +148 -0
- data/spec/mongoid/persistable/incrementable_spec.rb +173 -0
- data/spec/mongoid/persistable/logical_spec.rb +143 -0
- data/spec/mongoid/persistable/poppable_spec.rb +115 -0
- data/spec/mongoid/persistable/pullable_spec.rb +228 -0
- data/spec/mongoid/persistable/pushable_spec.rb +258 -0
- data/spec/mongoid/persistable/renamable_spec.rb +135 -0
- data/spec/mongoid/persistable/savable_spec.rb +432 -0
- data/spec/mongoid/persistable/settable_spec.rb +139 -0
- data/spec/mongoid/persistable/unsettable_spec.rb +155 -0
- data/spec/mongoid/persistable/updatable_spec.rb +522 -0
- data/spec/mongoid/persistable/upsertable_spec.rb +106 -0
- data/spec/mongoid/persistable_spec.rb +206 -0
- data/spec/mongoid/positional_spec.rb +227 -0
- data/spec/mongoid/railties/document_spec.rb +24 -0
- data/spec/mongoid/relations/accessors_spec.rb +736 -0
- data/spec/mongoid/relations/auto_save_spec.rb +261 -0
- data/spec/mongoid/relations/bindings/embedded/in_spec.rb +171 -0
- data/spec/mongoid/relations/bindings/embedded/many_spec.rb +54 -0
- data/spec/mongoid/relations/bindings/embedded/one_spec.rb +77 -0
- data/spec/mongoid/relations/bindings/referenced/in_spec.rb +241 -0
- data/spec/mongoid/relations/bindings/referenced/many_spec.rb +153 -0
- data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +178 -0
- data/spec/mongoid/relations/bindings/referenced/one_spec.rb +131 -0
- data/spec/mongoid/relations/builders/embedded/in_spec.rb +34 -0
- data/spec/mongoid/relations/builders/embedded/many_spec.rb +132 -0
- data/spec/mongoid/relations/builders/embedded/one_spec.rb +99 -0
- data/spec/mongoid/relations/builders/nested_attributes/many_spec.rb +234 -0
- data/spec/mongoid/relations/builders/nested_attributes/one_spec.rb +250 -0
- data/spec/mongoid/relations/builders/referenced/in_spec.rb +241 -0
- data/spec/mongoid/relations/builders/referenced/many_spec.rb +137 -0
- data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +178 -0
- data/spec/mongoid/relations/builders/referenced/one_spec.rb +124 -0
- data/spec/mongoid/relations/builders_spec.rb +226 -0
- data/spec/mongoid/relations/cascading/delete_spec.rb +101 -0
- data/spec/mongoid/relations/cascading/destroy_spec.rb +47 -0
- data/spec/mongoid/relations/cascading/nullify_spec.rb +32 -0
- data/spec/mongoid/relations/cascading/restrict_spec.rb +68 -0
- data/spec/mongoid/relations/cascading_spec.rb +355 -0
- data/spec/mongoid/relations/constraint_spec.rb +74 -0
- data/spec/mongoid/relations/conversions_spec.rb +126 -0
- data/spec/mongoid/relations/counter_cache_spec.rb +205 -0
- data/spec/mongoid/relations/cyclic_spec.rb +156 -0
- data/spec/mongoid/relations/embedded/dirty_spec.rb +65 -0
- data/spec/mongoid/relations/embedded/in_spec.rb +579 -0
- data/spec/mongoid/relations/embedded/many_spec.rb +3781 -0
- data/spec/mongoid/relations/embedded/one_spec.rb +1014 -0
- data/spec/mongoid/relations/macros_spec.rb +613 -0
- data/spec/mongoid/relations/metadata_spec.rb +1917 -0
- data/spec/mongoid/relations/options_spec.rb +35 -0
- data/spec/mongoid/relations/polymorphic_spec.rb +128 -0
- data/spec/mongoid/relations/proxy_spec.rb +48 -0
- data/spec/mongoid/relations/referenced/in_spec.rb +1435 -0
- data/spec/mongoid/relations/referenced/many_spec.rb +3546 -0
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +3556 -0
- data/spec/mongoid/relations/referenced/one_spec.rb +1289 -0
- data/spec/mongoid/relations/reflections_spec.rb +101 -0
- data/spec/mongoid/relations/synchronization_spec.rb +449 -0
- data/spec/mongoid/relations/targets/enumerable_spec.rb +1710 -0
- data/spec/mongoid/relations/touchable_spec.rb +296 -0
- data/spec/mongoid/relations_spec.rb +188 -0
- data/spec/mongoid/reloadable_spec.rb +305 -0
- data/spec/mongoid/scopable_spec.rb +926 -0
- data/spec/mongoid/selectable_spec.rb +134 -0
- data/spec/mongoid/serializable_spec.rb +862 -0
- data/spec/mongoid/sessions/factory_spec.rb +312 -0
- data/spec/mongoid/sessions/mongo_uri_spec.rb +103 -0
- data/spec/mongoid/sessions/options_spec.rb +71 -0
- data/spec/mongoid/sessions_spec.rb +1078 -0
- data/spec/mongoid/shardable_spec.rb +61 -0
- data/spec/mongoid/state_spec.rb +102 -0
- data/spec/mongoid/threaded_spec.rb +258 -0
- data/spec/mongoid/timestamps/created/short_spec.rb +51 -0
- data/spec/mongoid/timestamps/created_spec.rb +44 -0
- data/spec/mongoid/timestamps/updated/short_spec.rb +90 -0
- data/spec/mongoid/timestamps/updated_spec.rb +86 -0
- data/spec/mongoid/timestamps_spec.rb +112 -0
- data/spec/mongoid/traversable_spec.rb +244 -0
- data/spec/mongoid/unit_of_work_spec.rb +196 -0
- data/spec/mongoid/validatable/associated_spec.rb +183 -0
- data/spec/mongoid/validatable/format_spec.rb +83 -0
- data/spec/mongoid/validatable/length_spec.rb +119 -0
- data/spec/mongoid/validatable/numericality_spec.rb +30 -0
- data/spec/mongoid/validatable/presence_spec.rb +511 -0
- data/spec/mongoid/validatable/uniqueness_spec.rb +2305 -0
- data/spec/mongoid/validatable_spec.rb +309 -0
- data/spec/mongoid_spec.rb +74 -0
- data/spec/rack/mongoid/middleware/identity_map_spec.rb +72 -0
- data/spec/rails/mongoid_spec.rb +462 -0
- data/spec/spec_helper.rb +103 -0
- metadata +1159 -0
@@ -0,0 +1,1710 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Mongoid::Relations::Targets::Enumerable do
|
4
|
+
|
5
|
+
describe "#==" do
|
6
|
+
|
7
|
+
context "when comparing with an enumerable" do
|
8
|
+
|
9
|
+
let(:person) do
|
10
|
+
Person.create
|
11
|
+
end
|
12
|
+
|
13
|
+
let!(:post) do
|
14
|
+
Post.create(person_id: person.id)
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when only a criteria target exists" do
|
18
|
+
|
19
|
+
let(:criteria) do
|
20
|
+
Post.where(person_id: person.id)
|
21
|
+
end
|
22
|
+
|
23
|
+
let!(:enumerable) do
|
24
|
+
described_class.new(criteria)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns the equality check" do
|
28
|
+
expect(enumerable).to eq([ post ])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when only an array target exists" do
|
33
|
+
|
34
|
+
let!(:enumerable) do
|
35
|
+
described_class.new([ post ])
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns the equality check" do
|
39
|
+
expect(enumerable._loaded.values).to eq([ post ])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when a criteria and added exist" do
|
44
|
+
|
45
|
+
let(:criteria) do
|
46
|
+
Post.where(person_id: person.id)
|
47
|
+
end
|
48
|
+
|
49
|
+
let(:enumerable) do
|
50
|
+
described_class.new(criteria)
|
51
|
+
end
|
52
|
+
|
53
|
+
let(:post_two) do
|
54
|
+
Post.new
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when the added does not contain unloaded docs" do
|
58
|
+
|
59
|
+
before do
|
60
|
+
enumerable << post_two
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns the equality check" do
|
64
|
+
expect(enumerable).to eq([ post, post_two ])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when the added contains unloaded docs" do
|
69
|
+
|
70
|
+
before do
|
71
|
+
enumerable << post
|
72
|
+
end
|
73
|
+
|
74
|
+
it "returns the equality check" do
|
75
|
+
expect(enumerable).to eq([ post ])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when the enumerable is loaded" do
|
80
|
+
|
81
|
+
before do
|
82
|
+
enumerable.instance_variable_set(:@executed, true)
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when the loaded has no docs and added is persisted" do
|
86
|
+
|
87
|
+
before do
|
88
|
+
post.save
|
89
|
+
enumerable._added[post.id] = post
|
90
|
+
end
|
91
|
+
|
92
|
+
it "returns the equality check" do
|
93
|
+
expect(enumerable).to eq([ post ])
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "when comparing with a non enumerable" do
|
101
|
+
|
102
|
+
let(:enumerable) do
|
103
|
+
described_class.new([])
|
104
|
+
end
|
105
|
+
|
106
|
+
it "returns false" do
|
107
|
+
expect(enumerable).to_not eq("person")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#===" do
|
113
|
+
|
114
|
+
let(:enumerable) do
|
115
|
+
described_class.new([])
|
116
|
+
end
|
117
|
+
|
118
|
+
context "when compared to an array class" do
|
119
|
+
|
120
|
+
it "returns true" do
|
121
|
+
expect(enumerable === Array).to be_true
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context "when compared to a different class" do
|
126
|
+
|
127
|
+
it "returns false" do
|
128
|
+
expect(enumerable === Mongoid::Document).to be_false
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "when compared to an array instance" do
|
133
|
+
|
134
|
+
context "when the entries are equal" do
|
135
|
+
|
136
|
+
let(:other) do
|
137
|
+
described_class.new([])
|
138
|
+
end
|
139
|
+
|
140
|
+
it "returns true" do
|
141
|
+
expect(enumerable === other).to be_true
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context "when the entries are not equal" do
|
146
|
+
|
147
|
+
let(:other) do
|
148
|
+
described_class.new([ Band.new ])
|
149
|
+
end
|
150
|
+
|
151
|
+
it "returns false" do
|
152
|
+
expect(enumerable === other).to be_false
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "#<<" do
|
159
|
+
|
160
|
+
let(:person) do
|
161
|
+
Person.create
|
162
|
+
end
|
163
|
+
|
164
|
+
let!(:post) do
|
165
|
+
Post.create(person_id: person.id)
|
166
|
+
end
|
167
|
+
|
168
|
+
let!(:enumerable) do
|
169
|
+
described_class.new([])
|
170
|
+
end
|
171
|
+
|
172
|
+
context "when the relation is empty" do
|
173
|
+
|
174
|
+
let!(:added) do
|
175
|
+
enumerable << post
|
176
|
+
end
|
177
|
+
|
178
|
+
it "adds the document to the added target" do
|
179
|
+
expect(enumerable._added).to eq({ post.id => post })
|
180
|
+
end
|
181
|
+
|
182
|
+
it "returns the added documents" do
|
183
|
+
expect(added).to eq([ post ])
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "#any?" do
|
189
|
+
|
190
|
+
let(:person) do
|
191
|
+
Person.create
|
192
|
+
end
|
193
|
+
|
194
|
+
let!(:post_one) do
|
195
|
+
Post.create(person_id: person.id)
|
196
|
+
end
|
197
|
+
|
198
|
+
let!(:post_two) do
|
199
|
+
Post.create(person_id: person.id)
|
200
|
+
end
|
201
|
+
|
202
|
+
context "when only a criteria target exists" do
|
203
|
+
|
204
|
+
let(:criteria) do
|
205
|
+
Post.where(person_id: person.id)
|
206
|
+
end
|
207
|
+
|
208
|
+
let!(:enumerable) do
|
209
|
+
described_class.new(criteria)
|
210
|
+
end
|
211
|
+
|
212
|
+
let!(:any) do
|
213
|
+
enumerable.any?
|
214
|
+
end
|
215
|
+
|
216
|
+
it "returns true" do
|
217
|
+
expect(any).to be_true
|
218
|
+
end
|
219
|
+
|
220
|
+
it "retains the correct length" do
|
221
|
+
expect(enumerable.length).to eq(2)
|
222
|
+
end
|
223
|
+
|
224
|
+
it "retains the correct length when calling to_a" do
|
225
|
+
expect(enumerable.to_a.length).to eq(2)
|
226
|
+
end
|
227
|
+
|
228
|
+
context "when iterating over the relation a second time" do
|
229
|
+
|
230
|
+
before do
|
231
|
+
enumerable.each { |post| post }
|
232
|
+
end
|
233
|
+
|
234
|
+
it "retains the correct length" do
|
235
|
+
expect(enumerable.length).to eq(2)
|
236
|
+
end
|
237
|
+
|
238
|
+
it "retains the correct length when calling to_a" do
|
239
|
+
expect(enumerable.to_a.length).to eq(2)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
describe "#clear" do
|
246
|
+
|
247
|
+
let(:person) do
|
248
|
+
Person.create
|
249
|
+
end
|
250
|
+
|
251
|
+
let!(:post) do
|
252
|
+
Post.create(person_id: person.id)
|
253
|
+
end
|
254
|
+
|
255
|
+
let!(:post_two) do
|
256
|
+
Post.create(person_id: person.id)
|
257
|
+
end
|
258
|
+
|
259
|
+
let(:criteria) do
|
260
|
+
Post.where(person_id: person.id)
|
261
|
+
end
|
262
|
+
|
263
|
+
let(:enumerable) do
|
264
|
+
described_class.new(criteria)
|
265
|
+
end
|
266
|
+
|
267
|
+
before do
|
268
|
+
enumerable._loaded[post.id] = post
|
269
|
+
enumerable << post
|
270
|
+
end
|
271
|
+
|
272
|
+
let!(:clear) do
|
273
|
+
enumerable.clear do |doc|
|
274
|
+
expect(doc).to be_a(Post)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
it "clears out the loaded docs" do
|
279
|
+
expect(enumerable._loaded).to be_empty
|
280
|
+
end
|
281
|
+
|
282
|
+
it "clears out the added docs" do
|
283
|
+
expect(enumerable._added).to be_empty
|
284
|
+
end
|
285
|
+
|
286
|
+
it "retains its loaded state" do
|
287
|
+
expect(enumerable).to_not be__loaded
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
describe "#clone" do
|
292
|
+
|
293
|
+
let(:person) do
|
294
|
+
Person.create
|
295
|
+
end
|
296
|
+
|
297
|
+
let!(:post) do
|
298
|
+
Post.create(title: "one", person_id: person.id)
|
299
|
+
end
|
300
|
+
|
301
|
+
let!(:post_two) do
|
302
|
+
Post.create(title: "two", person_id: person.id)
|
303
|
+
end
|
304
|
+
|
305
|
+
let(:criteria) do
|
306
|
+
Post.where(person_id: person.id)
|
307
|
+
end
|
308
|
+
|
309
|
+
let(:enumerable) do
|
310
|
+
described_class.new(criteria)
|
311
|
+
end
|
312
|
+
|
313
|
+
before do
|
314
|
+
enumerable << post
|
315
|
+
enumerable << post_two
|
316
|
+
end
|
317
|
+
|
318
|
+
let(:cloned) do
|
319
|
+
enumerable.clone
|
320
|
+
end
|
321
|
+
|
322
|
+
it "does not retain the first id" do
|
323
|
+
expect(cloned.first).to_not eq(post)
|
324
|
+
end
|
325
|
+
|
326
|
+
it "does not retain the last id" do
|
327
|
+
expect(cloned.last).to_not eq(post_two)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
describe "#delete" do
|
332
|
+
|
333
|
+
let(:person) do
|
334
|
+
Person.create
|
335
|
+
end
|
336
|
+
|
337
|
+
context "when the document is loaded" do
|
338
|
+
|
339
|
+
let!(:post) do
|
340
|
+
Post.create(person_id: person.id)
|
341
|
+
end
|
342
|
+
|
343
|
+
let!(:enumerable) do
|
344
|
+
described_class.new([ post ])
|
345
|
+
end
|
346
|
+
|
347
|
+
let!(:deleted) do
|
348
|
+
enumerable.delete(post)
|
349
|
+
end
|
350
|
+
|
351
|
+
it "deletes the document from the enumerable" do
|
352
|
+
expect(enumerable._loaded).to be_empty
|
353
|
+
end
|
354
|
+
|
355
|
+
it "returns the document" do
|
356
|
+
expect(deleted).to eq(post)
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
context "when the document is added" do
|
361
|
+
|
362
|
+
let!(:post) do
|
363
|
+
Post.new
|
364
|
+
end
|
365
|
+
|
366
|
+
let(:criteria) do
|
367
|
+
Person.where(person_id: person.id)
|
368
|
+
end
|
369
|
+
|
370
|
+
let!(:enumerable) do
|
371
|
+
described_class.new(criteria)
|
372
|
+
end
|
373
|
+
|
374
|
+
before do
|
375
|
+
enumerable << post
|
376
|
+
end
|
377
|
+
|
378
|
+
let!(:deleted) do
|
379
|
+
enumerable.delete(post)
|
380
|
+
end
|
381
|
+
|
382
|
+
it "removes the document from the added docs" do
|
383
|
+
expect(enumerable._added).to be_empty
|
384
|
+
end
|
385
|
+
|
386
|
+
it "returns the document" do
|
387
|
+
expect(deleted).to eq(post)
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
context "when the document is unloaded" do
|
392
|
+
|
393
|
+
let!(:post) do
|
394
|
+
Post.create(person_id: person.id)
|
395
|
+
end
|
396
|
+
|
397
|
+
let(:criteria) do
|
398
|
+
Post.where(person_id: person.id)
|
399
|
+
end
|
400
|
+
|
401
|
+
let!(:enumerable) do
|
402
|
+
described_class.new(criteria)
|
403
|
+
end
|
404
|
+
|
405
|
+
let!(:deleted) do
|
406
|
+
enumerable.delete(post)
|
407
|
+
end
|
408
|
+
|
409
|
+
it "does not load the document" do
|
410
|
+
expect(enumerable._loaded).to be_empty
|
411
|
+
end
|
412
|
+
|
413
|
+
it "returns the document" do
|
414
|
+
expect(deleted).to eq(post)
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
context "when the document is not found" do
|
419
|
+
|
420
|
+
let!(:post) do
|
421
|
+
Post.create(person_id: person.id)
|
422
|
+
end
|
423
|
+
|
424
|
+
let(:criteria) do
|
425
|
+
Person.where(person_id: person.id)
|
426
|
+
end
|
427
|
+
|
428
|
+
let!(:enumerable) do
|
429
|
+
described_class.new([ post ])
|
430
|
+
end
|
431
|
+
|
432
|
+
let!(:deleted) do
|
433
|
+
enumerable.delete(Post.new) do |doc|
|
434
|
+
expect(doc).to be_nil
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
it "returns nil" do
|
439
|
+
expect(deleted).to be_nil
|
440
|
+
end
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
describe "#delete_if" do
|
445
|
+
|
446
|
+
let(:person) do
|
447
|
+
Person.create
|
448
|
+
end
|
449
|
+
|
450
|
+
context "when the document is loaded" do
|
451
|
+
|
452
|
+
let!(:post) do
|
453
|
+
Post.create(person_id: person.id)
|
454
|
+
end
|
455
|
+
|
456
|
+
let!(:enumerable) do
|
457
|
+
described_class.new([ post ])
|
458
|
+
end
|
459
|
+
|
460
|
+
let!(:deleted) do
|
461
|
+
enumerable.delete_if { |doc| doc == post }
|
462
|
+
end
|
463
|
+
|
464
|
+
it "deletes the document from the enumerable" do
|
465
|
+
expect(enumerable._loaded).to be_empty
|
466
|
+
end
|
467
|
+
|
468
|
+
it "returns the remaining docs" do
|
469
|
+
expect(deleted).to be_empty
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
context "when the document is added" do
|
474
|
+
|
475
|
+
let!(:post) do
|
476
|
+
Post.new
|
477
|
+
end
|
478
|
+
|
479
|
+
let(:criteria) do
|
480
|
+
Person.where(person_id: person.id)
|
481
|
+
end
|
482
|
+
|
483
|
+
let!(:enumerable) do
|
484
|
+
described_class.new(criteria)
|
485
|
+
end
|
486
|
+
|
487
|
+
before do
|
488
|
+
enumerable << post
|
489
|
+
end
|
490
|
+
|
491
|
+
let!(:deleted) do
|
492
|
+
enumerable.delete_if { |doc| doc == post }
|
493
|
+
end
|
494
|
+
|
495
|
+
it "removes the document from the added docs" do
|
496
|
+
expect(enumerable._added).to be_empty
|
497
|
+
end
|
498
|
+
|
499
|
+
it "returns the remaining docs" do
|
500
|
+
expect(deleted).to be_empty
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
504
|
+
context "when the document is unloaded" do
|
505
|
+
|
506
|
+
let!(:post) do
|
507
|
+
Post.create(person_id: person.id)
|
508
|
+
end
|
509
|
+
|
510
|
+
let(:criteria) do
|
511
|
+
Post.where(person_id: person.id)
|
512
|
+
end
|
513
|
+
|
514
|
+
let!(:enumerable) do
|
515
|
+
described_class.new(criteria)
|
516
|
+
end
|
517
|
+
|
518
|
+
let!(:deleted) do
|
519
|
+
enumerable.delete_if { |doc| doc == post }
|
520
|
+
end
|
521
|
+
|
522
|
+
it "does not load the document" do
|
523
|
+
expect(enumerable._loaded).to be_empty
|
524
|
+
end
|
525
|
+
|
526
|
+
it "returns the remaining docs" do
|
527
|
+
expect(deleted).to be_empty
|
528
|
+
end
|
529
|
+
end
|
530
|
+
|
531
|
+
context "when the block doesn't match" do
|
532
|
+
|
533
|
+
let!(:post) do
|
534
|
+
Post.create(person_id: person.id)
|
535
|
+
end
|
536
|
+
|
537
|
+
let(:criteria) do
|
538
|
+
Person.where(person_id: person.id)
|
539
|
+
end
|
540
|
+
|
541
|
+
let!(:enumerable) do
|
542
|
+
described_class.new([ post ])
|
543
|
+
end
|
544
|
+
|
545
|
+
let!(:deleted) do
|
546
|
+
enumerable.delete_if { |doc| doc == Post.new }
|
547
|
+
end
|
548
|
+
|
549
|
+
it "returns the remaining docs" do
|
550
|
+
expect(deleted).to eq([ post ])
|
551
|
+
end
|
552
|
+
end
|
553
|
+
end
|
554
|
+
|
555
|
+
describe "#detect" do
|
556
|
+
|
557
|
+
let(:person) do
|
558
|
+
Person.create
|
559
|
+
end
|
560
|
+
|
561
|
+
let!(:post) do
|
562
|
+
Post.create(person: person, title: "test")
|
563
|
+
end
|
564
|
+
|
565
|
+
let(:criteria) do
|
566
|
+
Post.where(person_id: person.id)
|
567
|
+
end
|
568
|
+
|
569
|
+
let!(:enumerable) do
|
570
|
+
described_class.new(criteria)
|
571
|
+
end
|
572
|
+
|
573
|
+
context "when setting a value on the matching document" do
|
574
|
+
|
575
|
+
before do
|
576
|
+
enumerable.detect{ |post| post.title = "test" }.rating = 10
|
577
|
+
end
|
578
|
+
|
579
|
+
it "sets the value on the instance" do
|
580
|
+
expect(enumerable.detect{ |post| post.title = "test" }.rating).to eq(10)
|
581
|
+
end
|
582
|
+
end
|
583
|
+
end
|
584
|
+
|
585
|
+
describe "#each" do
|
586
|
+
|
587
|
+
let(:person) do
|
588
|
+
Person.create
|
589
|
+
end
|
590
|
+
|
591
|
+
let!(:post) do
|
592
|
+
Post.create(person_id: person.id)
|
593
|
+
end
|
594
|
+
|
595
|
+
context "when only a criteria target exists" do
|
596
|
+
|
597
|
+
let(:criteria) do
|
598
|
+
Post.where(person_id: person.id)
|
599
|
+
end
|
600
|
+
|
601
|
+
let!(:enumerable) do
|
602
|
+
described_class.new(criteria)
|
603
|
+
end
|
604
|
+
|
605
|
+
let!(:iterated) do
|
606
|
+
enumerable.each do |doc|
|
607
|
+
expect(doc).to be_a(Post)
|
608
|
+
end
|
609
|
+
end
|
610
|
+
|
611
|
+
it "loads each document" do
|
612
|
+
expect(enumerable._loaded).to eq({ post.id => post })
|
613
|
+
end
|
614
|
+
|
615
|
+
it "becomes loaded" do
|
616
|
+
expect(enumerable).to be__loaded
|
617
|
+
end
|
618
|
+
end
|
619
|
+
|
620
|
+
context "when only an array target exists" do
|
621
|
+
|
622
|
+
let!(:enumerable) do
|
623
|
+
described_class.new([ post ])
|
624
|
+
end
|
625
|
+
|
626
|
+
let!(:iterated) do
|
627
|
+
enumerable.each do |doc|
|
628
|
+
expect(doc).to be_a(Post)
|
629
|
+
end
|
630
|
+
end
|
631
|
+
|
632
|
+
it "does not alter the loaded docs" do
|
633
|
+
expect(enumerable._loaded).to eq({ post.id => post })
|
634
|
+
end
|
635
|
+
|
636
|
+
it "stays loaded" do
|
637
|
+
expect(enumerable).to be__loaded
|
638
|
+
end
|
639
|
+
end
|
640
|
+
|
641
|
+
context "when a criteria and added exist" do
|
642
|
+
|
643
|
+
let(:criteria) do
|
644
|
+
Post.where(person_id: person.id)
|
645
|
+
end
|
646
|
+
|
647
|
+
let!(:enumerable) do
|
648
|
+
described_class.new(criteria)
|
649
|
+
end
|
650
|
+
|
651
|
+
let(:post_two) do
|
652
|
+
Post.new
|
653
|
+
end
|
654
|
+
|
655
|
+
context "when the added does not contain unloaded docs" do
|
656
|
+
|
657
|
+
before do
|
658
|
+
enumerable << post_two
|
659
|
+
end
|
660
|
+
|
661
|
+
let!(:iterated) do
|
662
|
+
enumerable.each do |doc|
|
663
|
+
expect(doc).to be_a(Post)
|
664
|
+
end
|
665
|
+
end
|
666
|
+
|
667
|
+
it "adds the unloaded to the loaded docs" do
|
668
|
+
expect(enumerable._loaded).to eq({ post.id => post })
|
669
|
+
end
|
670
|
+
|
671
|
+
it "keeps the appended in the added docs" do
|
672
|
+
expect(enumerable._added).to eq({ post_two.id => post_two })
|
673
|
+
end
|
674
|
+
|
675
|
+
it "stays loaded" do
|
676
|
+
expect(enumerable).to be__loaded
|
677
|
+
end
|
678
|
+
end
|
679
|
+
|
680
|
+
context "when the added contains unloaded docs" do
|
681
|
+
|
682
|
+
before do
|
683
|
+
enumerable << post
|
684
|
+
end
|
685
|
+
|
686
|
+
let!(:iterated) do
|
687
|
+
enumerable.each do |doc|
|
688
|
+
expect(doc).to be_a(Post)
|
689
|
+
end
|
690
|
+
end
|
691
|
+
|
692
|
+
it "adds the persisted added doc to the loaded" do
|
693
|
+
expect(enumerable._loaded).to eq({ post.id => post })
|
694
|
+
end
|
695
|
+
|
696
|
+
it "stays loaded" do
|
697
|
+
expect(enumerable).to be__loaded
|
698
|
+
end
|
699
|
+
end
|
700
|
+
end
|
701
|
+
|
702
|
+
context "when no block is passed" do
|
703
|
+
|
704
|
+
let(:criteria) do
|
705
|
+
Post.where(person_id: person.id)
|
706
|
+
end
|
707
|
+
|
708
|
+
let!(:enumerable) do
|
709
|
+
described_class.new(criteria)
|
710
|
+
end
|
711
|
+
|
712
|
+
it "returns an enumerator" do
|
713
|
+
expect(enumerable.each.class.include?(Enumerable)).to be_true
|
714
|
+
end
|
715
|
+
|
716
|
+
end
|
717
|
+
end
|
718
|
+
|
719
|
+
describe "#entries" do
|
720
|
+
|
721
|
+
let(:person) do
|
722
|
+
Person.create
|
723
|
+
end
|
724
|
+
|
725
|
+
let(:criteria) do
|
726
|
+
Post.where(person_id: person.id)
|
727
|
+
end
|
728
|
+
|
729
|
+
let!(:enumerable) do
|
730
|
+
described_class.new(criteria)
|
731
|
+
end
|
732
|
+
|
733
|
+
context "when the added contains a persisted document" do
|
734
|
+
|
735
|
+
let!(:post) do
|
736
|
+
Post.create(person_id: person.id)
|
737
|
+
end
|
738
|
+
|
739
|
+
before do
|
740
|
+
enumerable << post
|
741
|
+
end
|
742
|
+
|
743
|
+
let(:entries) do
|
744
|
+
enumerable.entries
|
745
|
+
end
|
746
|
+
|
747
|
+
it "yields to the in memory documents first" do
|
748
|
+
expect(entries.first).to equal(post)
|
749
|
+
end
|
750
|
+
end
|
751
|
+
end
|
752
|
+
|
753
|
+
describe "#first" do
|
754
|
+
|
755
|
+
let(:person) do
|
756
|
+
Person.create
|
757
|
+
end
|
758
|
+
|
759
|
+
context "when the enumerable is not loaded" do
|
760
|
+
|
761
|
+
let(:criteria) do
|
762
|
+
Post.where(person_id: person.id)
|
763
|
+
end
|
764
|
+
|
765
|
+
let(:enumerable) do
|
766
|
+
described_class.new(criteria)
|
767
|
+
end
|
768
|
+
|
769
|
+
context "when unloaded is not empty" do
|
770
|
+
|
771
|
+
context "when added is empty" do
|
772
|
+
|
773
|
+
let!(:post) do
|
774
|
+
Post.create(person_id: person.id)
|
775
|
+
end
|
776
|
+
|
777
|
+
let(:first) do
|
778
|
+
enumerable.first
|
779
|
+
end
|
780
|
+
|
781
|
+
it "returns the first unloaded doc" do
|
782
|
+
expect(first).to eq(post)
|
783
|
+
end
|
784
|
+
|
785
|
+
it "does not load the enumerable" do
|
786
|
+
expect(enumerable).to_not be__loaded
|
787
|
+
end
|
788
|
+
|
789
|
+
it "receives query only once" do
|
790
|
+
criteria.should_receive(:first).once
|
791
|
+
first
|
792
|
+
end
|
793
|
+
end
|
794
|
+
|
795
|
+
context "when added is not empty" do
|
796
|
+
|
797
|
+
let!(:post) do
|
798
|
+
Post.create(person_id: person.id)
|
799
|
+
end
|
800
|
+
|
801
|
+
let(:post_two) do
|
802
|
+
Post.new(person_id: person.id)
|
803
|
+
end
|
804
|
+
|
805
|
+
before do
|
806
|
+
enumerable << post_two
|
807
|
+
end
|
808
|
+
|
809
|
+
let(:first) do
|
810
|
+
enumerable.first
|
811
|
+
end
|
812
|
+
|
813
|
+
context "when a perviously persisted unloaded doc exists" do
|
814
|
+
|
815
|
+
it "returns the first added doc" do
|
816
|
+
expect(first).to eq(post)
|
817
|
+
end
|
818
|
+
|
819
|
+
it "does not load the enumerable" do
|
820
|
+
expect(enumerable).to_not be__loaded
|
821
|
+
end
|
822
|
+
end
|
823
|
+
end
|
824
|
+
end
|
825
|
+
|
826
|
+
context "when unloaded is empty" do
|
827
|
+
|
828
|
+
let!(:post) do
|
829
|
+
Post.new(person_id: person.id)
|
830
|
+
end
|
831
|
+
|
832
|
+
before do
|
833
|
+
enumerable << post
|
834
|
+
end
|
835
|
+
|
836
|
+
let(:first) do
|
837
|
+
enumerable.first
|
838
|
+
end
|
839
|
+
|
840
|
+
it "returns the first loaded doc" do
|
841
|
+
expect(first).to eq(post)
|
842
|
+
end
|
843
|
+
|
844
|
+
it "does not load the enumerable" do
|
845
|
+
expect(enumerable).to_not be__loaded
|
846
|
+
end
|
847
|
+
end
|
848
|
+
|
849
|
+
context "when unloaded and added are empty" do
|
850
|
+
|
851
|
+
let(:first) do
|
852
|
+
enumerable.first
|
853
|
+
end
|
854
|
+
|
855
|
+
it "returns nil" do
|
856
|
+
expect(first).to be_nil
|
857
|
+
end
|
858
|
+
|
859
|
+
it "does not load the enumerable" do
|
860
|
+
expect(enumerable).to_not be__loaded
|
861
|
+
end
|
862
|
+
end
|
863
|
+
end
|
864
|
+
|
865
|
+
context "when the enumerable is loaded" do
|
866
|
+
|
867
|
+
context "when loaded is not empty" do
|
868
|
+
|
869
|
+
let!(:post) do
|
870
|
+
Post.create(person_id: person.id)
|
871
|
+
end
|
872
|
+
|
873
|
+
let(:enumerable) do
|
874
|
+
described_class.new([ post ])
|
875
|
+
end
|
876
|
+
|
877
|
+
let(:first) do
|
878
|
+
enumerable.first
|
879
|
+
end
|
880
|
+
|
881
|
+
it "returns the first loaded doc" do
|
882
|
+
expect(first).to eq(post)
|
883
|
+
end
|
884
|
+
end
|
885
|
+
|
886
|
+
context "when loaded is empty" do
|
887
|
+
|
888
|
+
let!(:post) do
|
889
|
+
Post.create(person_id: person.id)
|
890
|
+
end
|
891
|
+
|
892
|
+
let(:enumerable) do
|
893
|
+
described_class.new([])
|
894
|
+
end
|
895
|
+
|
896
|
+
before do
|
897
|
+
enumerable << post
|
898
|
+
end
|
899
|
+
|
900
|
+
let(:first) do
|
901
|
+
enumerable.first
|
902
|
+
end
|
903
|
+
|
904
|
+
it "returns the first added doc" do
|
905
|
+
expect(first).to eq(post)
|
906
|
+
end
|
907
|
+
end
|
908
|
+
|
909
|
+
context "when loaded and added are empty" do
|
910
|
+
|
911
|
+
let(:enumerable) do
|
912
|
+
described_class.new([])
|
913
|
+
end
|
914
|
+
|
915
|
+
let(:first) do
|
916
|
+
enumerable.first
|
917
|
+
end
|
918
|
+
|
919
|
+
it "returns nil" do
|
920
|
+
expect(first).to be_nil
|
921
|
+
end
|
922
|
+
end
|
923
|
+
end
|
924
|
+
end
|
925
|
+
|
926
|
+
describe "#include?" do
|
927
|
+
|
928
|
+
let(:person) do
|
929
|
+
Person.create
|
930
|
+
end
|
931
|
+
|
932
|
+
let!(:post_one) do
|
933
|
+
Post.create(person_id: person.id)
|
934
|
+
end
|
935
|
+
|
936
|
+
let!(:post_two) do
|
937
|
+
Post.create(person_id: person.id)
|
938
|
+
end
|
939
|
+
|
940
|
+
context "when no criteria exists" do
|
941
|
+
|
942
|
+
context "when the enumerable is loaded" do
|
943
|
+
|
944
|
+
let!(:enumerable) do
|
945
|
+
described_class.new([ post_one, post_two ])
|
946
|
+
end
|
947
|
+
|
948
|
+
let!(:included) do
|
949
|
+
enumerable.include?(post_two)
|
950
|
+
end
|
951
|
+
|
952
|
+
it "returns true" do
|
953
|
+
expect(included).to be_true
|
954
|
+
end
|
955
|
+
|
956
|
+
it "retains the correct length" do
|
957
|
+
expect(enumerable.length).to eq(2)
|
958
|
+
end
|
959
|
+
|
960
|
+
it "retains the correct length when calling to_a" do
|
961
|
+
expect(enumerable.to_a.length).to eq(2)
|
962
|
+
end
|
963
|
+
end
|
964
|
+
|
965
|
+
context "when the enumerable contains an added document" do
|
966
|
+
|
967
|
+
let!(:enumerable) do
|
968
|
+
described_class.new([])
|
969
|
+
end
|
970
|
+
|
971
|
+
let(:post_three) do
|
972
|
+
Post.new(person_id: person)
|
973
|
+
end
|
974
|
+
|
975
|
+
before do
|
976
|
+
enumerable.push(post_three)
|
977
|
+
end
|
978
|
+
|
979
|
+
let!(:included) do
|
980
|
+
enumerable.include?(post_three)
|
981
|
+
end
|
982
|
+
|
983
|
+
it "returns true" do
|
984
|
+
expect(included).to be_true
|
985
|
+
end
|
986
|
+
end
|
987
|
+
end
|
988
|
+
|
989
|
+
context "when the document is present and not the first" do
|
990
|
+
|
991
|
+
let(:criteria) do
|
992
|
+
Post.where(person_id: person.id)
|
993
|
+
end
|
994
|
+
|
995
|
+
let!(:enumerable) do
|
996
|
+
described_class.new(criteria)
|
997
|
+
end
|
998
|
+
|
999
|
+
let!(:included) do
|
1000
|
+
enumerable.include?(post_two)
|
1001
|
+
end
|
1002
|
+
|
1003
|
+
it "returns true" do
|
1004
|
+
expect(included).to be_true
|
1005
|
+
end
|
1006
|
+
|
1007
|
+
it "retains the correct length" do
|
1008
|
+
expect(enumerable.length).to eq(2)
|
1009
|
+
end
|
1010
|
+
|
1011
|
+
it "retains the correct length when calling to_a" do
|
1012
|
+
expect(enumerable.to_a.length).to eq(2)
|
1013
|
+
end
|
1014
|
+
|
1015
|
+
context "when iterating over the relation a second time" do
|
1016
|
+
|
1017
|
+
before do
|
1018
|
+
enumerable.each { |post| post }
|
1019
|
+
end
|
1020
|
+
|
1021
|
+
it "retains the correct length" do
|
1022
|
+
expect(enumerable.length).to eq(2)
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
it "retains the correct length when calling to_a" do
|
1026
|
+
expect(enumerable.to_a.length).to eq(2)
|
1027
|
+
end
|
1028
|
+
end
|
1029
|
+
end
|
1030
|
+
end
|
1031
|
+
|
1032
|
+
describe "#initialize" do
|
1033
|
+
|
1034
|
+
let(:person) do
|
1035
|
+
Person.new
|
1036
|
+
end
|
1037
|
+
|
1038
|
+
context "when provided with a criteria" do
|
1039
|
+
|
1040
|
+
let(:criteria) do
|
1041
|
+
Post.where(person_id: person.id)
|
1042
|
+
end
|
1043
|
+
|
1044
|
+
let(:enumerable) do
|
1045
|
+
described_class.new(criteria)
|
1046
|
+
end
|
1047
|
+
|
1048
|
+
it "sets the criteria" do
|
1049
|
+
expect(enumerable._unloaded).to eq(criteria)
|
1050
|
+
end
|
1051
|
+
|
1052
|
+
it "is not loaded" do
|
1053
|
+
expect(enumerable).to_not be__loaded
|
1054
|
+
end
|
1055
|
+
end
|
1056
|
+
|
1057
|
+
context "when provided an array" do
|
1058
|
+
|
1059
|
+
let(:post) do
|
1060
|
+
Post.new
|
1061
|
+
end
|
1062
|
+
|
1063
|
+
let(:enumerable) do
|
1064
|
+
described_class.new([ post ])
|
1065
|
+
end
|
1066
|
+
|
1067
|
+
it "does not set a criteria" do
|
1068
|
+
expect(enumerable._unloaded).to be_nil
|
1069
|
+
end
|
1070
|
+
|
1071
|
+
it "is loaded" do
|
1072
|
+
expect(enumerable).to be__loaded
|
1073
|
+
end
|
1074
|
+
end
|
1075
|
+
end
|
1076
|
+
|
1077
|
+
describe "#in_memory" do
|
1078
|
+
|
1079
|
+
let(:person) do
|
1080
|
+
Person.new
|
1081
|
+
end
|
1082
|
+
|
1083
|
+
context "when the enumerable is loaded" do
|
1084
|
+
|
1085
|
+
let(:post) do
|
1086
|
+
Post.new
|
1087
|
+
end
|
1088
|
+
|
1089
|
+
let(:enumerable) do
|
1090
|
+
described_class.new([ post ])
|
1091
|
+
end
|
1092
|
+
|
1093
|
+
let(:post_two) do
|
1094
|
+
Post.new
|
1095
|
+
end
|
1096
|
+
|
1097
|
+
before do
|
1098
|
+
enumerable << post_two
|
1099
|
+
end
|
1100
|
+
|
1101
|
+
let(:in_memory) do
|
1102
|
+
enumerable.in_memory
|
1103
|
+
end
|
1104
|
+
|
1105
|
+
it "returns the loaded and added docs" do
|
1106
|
+
expect(in_memory).to eq([ post, post_two ])
|
1107
|
+
end
|
1108
|
+
end
|
1109
|
+
|
1110
|
+
context "when the enumerable is not loaded" do
|
1111
|
+
|
1112
|
+
let(:post) do
|
1113
|
+
Post.new(person_id: person.id)
|
1114
|
+
end
|
1115
|
+
|
1116
|
+
let(:enumerable) do
|
1117
|
+
described_class.new(Post.where(person_id: person.id))
|
1118
|
+
end
|
1119
|
+
|
1120
|
+
let(:post_two) do
|
1121
|
+
Post.new(person_id: person.id)
|
1122
|
+
end
|
1123
|
+
|
1124
|
+
before do
|
1125
|
+
enumerable << post_two
|
1126
|
+
end
|
1127
|
+
|
1128
|
+
let(:in_memory) do
|
1129
|
+
enumerable.in_memory
|
1130
|
+
end
|
1131
|
+
|
1132
|
+
it "returns the added docs" do
|
1133
|
+
expect(in_memory).to eq([ post_two ])
|
1134
|
+
end
|
1135
|
+
end
|
1136
|
+
|
1137
|
+
context "when passed a block" do
|
1138
|
+
|
1139
|
+
let(:enumerable) do
|
1140
|
+
described_class.new(Post.where(person_id: person.id))
|
1141
|
+
end
|
1142
|
+
|
1143
|
+
let(:post_two) do
|
1144
|
+
Post.new(person_id: person.id)
|
1145
|
+
end
|
1146
|
+
|
1147
|
+
before do
|
1148
|
+
enumerable << post_two
|
1149
|
+
end
|
1150
|
+
|
1151
|
+
it "yields to each in memory document" do
|
1152
|
+
enumerable.in_memory do |doc|
|
1153
|
+
expect(doc).to eq(post_two)
|
1154
|
+
end
|
1155
|
+
end
|
1156
|
+
end
|
1157
|
+
end
|
1158
|
+
|
1159
|
+
describe "#is_a?" do
|
1160
|
+
|
1161
|
+
let(:enumerable) do
|
1162
|
+
described_class.new(Post.all)
|
1163
|
+
end
|
1164
|
+
|
1165
|
+
context "when checking against enumerable" do
|
1166
|
+
|
1167
|
+
it "returns true" do
|
1168
|
+
expect(enumerable.is_a?(::Enumerable)).to be_true
|
1169
|
+
end
|
1170
|
+
end
|
1171
|
+
|
1172
|
+
context "when checking against array" do
|
1173
|
+
|
1174
|
+
it "returns true" do
|
1175
|
+
expect(enumerable.is_a?(Array)).to be_true
|
1176
|
+
end
|
1177
|
+
end
|
1178
|
+
end
|
1179
|
+
|
1180
|
+
describe "#last" do
|
1181
|
+
|
1182
|
+
let(:person) do
|
1183
|
+
Person.create
|
1184
|
+
end
|
1185
|
+
|
1186
|
+
context "when the enumerable is not loaded" do
|
1187
|
+
|
1188
|
+
let(:criteria) do
|
1189
|
+
Post.where(person_id: person.id)
|
1190
|
+
end
|
1191
|
+
|
1192
|
+
let(:enumerable) do
|
1193
|
+
described_class.new(criteria)
|
1194
|
+
end
|
1195
|
+
|
1196
|
+
context "when unloaded is not empty" do
|
1197
|
+
|
1198
|
+
let!(:post) do
|
1199
|
+
Post.create(person_id: person.id)
|
1200
|
+
end
|
1201
|
+
|
1202
|
+
let(:last) do
|
1203
|
+
enumerable.last
|
1204
|
+
end
|
1205
|
+
|
1206
|
+
it "returns the last unloaded doc" do
|
1207
|
+
expect(last).to eq(post)
|
1208
|
+
end
|
1209
|
+
|
1210
|
+
it "does not load the enumerable" do
|
1211
|
+
expect(enumerable).to_not be__loaded
|
1212
|
+
end
|
1213
|
+
|
1214
|
+
it "receives query only once" do
|
1215
|
+
criteria.should_receive(:last).once
|
1216
|
+
last
|
1217
|
+
end
|
1218
|
+
end
|
1219
|
+
|
1220
|
+
context "when unloaded is empty" do
|
1221
|
+
|
1222
|
+
let!(:post) do
|
1223
|
+
Post.new(person_id: person.id)
|
1224
|
+
end
|
1225
|
+
|
1226
|
+
before do
|
1227
|
+
enumerable << post
|
1228
|
+
end
|
1229
|
+
|
1230
|
+
let(:last) do
|
1231
|
+
enumerable.last
|
1232
|
+
end
|
1233
|
+
|
1234
|
+
it "returns the last unloaded doc" do
|
1235
|
+
expect(last).to eq(post)
|
1236
|
+
end
|
1237
|
+
|
1238
|
+
it "does not load the enumerable" do
|
1239
|
+
expect(enumerable).to_not be__loaded
|
1240
|
+
end
|
1241
|
+
end
|
1242
|
+
|
1243
|
+
context "when unloaded and added are empty" do
|
1244
|
+
|
1245
|
+
let(:last) do
|
1246
|
+
enumerable.last
|
1247
|
+
end
|
1248
|
+
|
1249
|
+
it "returns nil" do
|
1250
|
+
expect(last).to be_nil
|
1251
|
+
end
|
1252
|
+
|
1253
|
+
it "does not load the enumerable" do
|
1254
|
+
expect(enumerable).to_not be__loaded
|
1255
|
+
end
|
1256
|
+
end
|
1257
|
+
|
1258
|
+
context "when added is not empty" do
|
1259
|
+
|
1260
|
+
let!(:post_one) do
|
1261
|
+
person.posts.create
|
1262
|
+
end
|
1263
|
+
|
1264
|
+
let!(:post_two) do
|
1265
|
+
person.posts.create
|
1266
|
+
end
|
1267
|
+
|
1268
|
+
let(:last) do
|
1269
|
+
enumerable.last
|
1270
|
+
end
|
1271
|
+
|
1272
|
+
context "when accessing from a reloaded child" do
|
1273
|
+
|
1274
|
+
it "returns the last document" do
|
1275
|
+
expect(post_one.reload.person.posts.last).to eq(post_two)
|
1276
|
+
end
|
1277
|
+
end
|
1278
|
+
end
|
1279
|
+
end
|
1280
|
+
|
1281
|
+
context "when the enumerable is loaded" do
|
1282
|
+
|
1283
|
+
context "when loaded is not empty" do
|
1284
|
+
|
1285
|
+
let!(:post) do
|
1286
|
+
Post.create(person_id: person.id)
|
1287
|
+
end
|
1288
|
+
|
1289
|
+
let(:enumerable) do
|
1290
|
+
described_class.new([ post ])
|
1291
|
+
end
|
1292
|
+
|
1293
|
+
let(:last) do
|
1294
|
+
enumerable.last
|
1295
|
+
end
|
1296
|
+
|
1297
|
+
it "returns the last loaded doc" do
|
1298
|
+
expect(last).to eq(post)
|
1299
|
+
end
|
1300
|
+
end
|
1301
|
+
|
1302
|
+
context "when loaded is empty" do
|
1303
|
+
|
1304
|
+
let!(:post) do
|
1305
|
+
Post.create(person_id: person.id)
|
1306
|
+
end
|
1307
|
+
|
1308
|
+
let(:enumerable) do
|
1309
|
+
described_class.new([])
|
1310
|
+
end
|
1311
|
+
|
1312
|
+
before do
|
1313
|
+
enumerable << post
|
1314
|
+
end
|
1315
|
+
|
1316
|
+
let(:last) do
|
1317
|
+
enumerable.last
|
1318
|
+
end
|
1319
|
+
|
1320
|
+
it "returns the last added doc" do
|
1321
|
+
expect(last).to eq(post)
|
1322
|
+
end
|
1323
|
+
end
|
1324
|
+
|
1325
|
+
context "when loaded and added are empty" do
|
1326
|
+
|
1327
|
+
let(:enumerable) do
|
1328
|
+
described_class.new([])
|
1329
|
+
end
|
1330
|
+
|
1331
|
+
let(:last) do
|
1332
|
+
enumerable.last
|
1333
|
+
end
|
1334
|
+
|
1335
|
+
it "returns nil" do
|
1336
|
+
expect(last).to be_nil
|
1337
|
+
end
|
1338
|
+
end
|
1339
|
+
end
|
1340
|
+
end
|
1341
|
+
|
1342
|
+
describe "#kind_of?" do
|
1343
|
+
|
1344
|
+
let(:enumerable) do
|
1345
|
+
described_class.new(Post.all)
|
1346
|
+
end
|
1347
|
+
|
1348
|
+
context "when checking against enumerable" do
|
1349
|
+
|
1350
|
+
it "returns true" do
|
1351
|
+
expect(enumerable.kind_of?(::Enumerable)).to be_true
|
1352
|
+
end
|
1353
|
+
end
|
1354
|
+
|
1355
|
+
context "when checking against array" do
|
1356
|
+
|
1357
|
+
it "returns true" do
|
1358
|
+
expect(enumerable.kind_of?(Array)).to be_true
|
1359
|
+
end
|
1360
|
+
end
|
1361
|
+
end
|
1362
|
+
|
1363
|
+
describe "#load_all!" do
|
1364
|
+
|
1365
|
+
let(:person) do
|
1366
|
+
Person.create
|
1367
|
+
end
|
1368
|
+
|
1369
|
+
let!(:post) do
|
1370
|
+
Post.create(person_id: person.id)
|
1371
|
+
end
|
1372
|
+
|
1373
|
+
let(:criteria) do
|
1374
|
+
Post.where(person_id: person.id)
|
1375
|
+
end
|
1376
|
+
|
1377
|
+
let!(:enumerable) do
|
1378
|
+
described_class.new(criteria)
|
1379
|
+
end
|
1380
|
+
|
1381
|
+
let!(:loaded) do
|
1382
|
+
enumerable.load_all!
|
1383
|
+
end
|
1384
|
+
|
1385
|
+
it "loads all the unloaded documents" do
|
1386
|
+
expect(enumerable._loaded).to eq({ post.id => post })
|
1387
|
+
end
|
1388
|
+
|
1389
|
+
it "returns true" do
|
1390
|
+
expect(loaded).to be_true
|
1391
|
+
end
|
1392
|
+
|
1393
|
+
it "sets loaded to true" do
|
1394
|
+
expect(enumerable).to be__loaded
|
1395
|
+
end
|
1396
|
+
end
|
1397
|
+
|
1398
|
+
describe "#reset" do
|
1399
|
+
|
1400
|
+
let(:person) do
|
1401
|
+
Person.create
|
1402
|
+
end
|
1403
|
+
|
1404
|
+
let(:post) do
|
1405
|
+
Post.create(person_id: person.id)
|
1406
|
+
end
|
1407
|
+
|
1408
|
+
let(:post_two) do
|
1409
|
+
Post.create(person_id: person.id)
|
1410
|
+
end
|
1411
|
+
|
1412
|
+
let(:enumerable) do
|
1413
|
+
described_class.new([ post ])
|
1414
|
+
end
|
1415
|
+
|
1416
|
+
before do
|
1417
|
+
enumerable << post_two
|
1418
|
+
end
|
1419
|
+
|
1420
|
+
let!(:reset) do
|
1421
|
+
enumerable.reset
|
1422
|
+
end
|
1423
|
+
|
1424
|
+
it "is not loaded" do
|
1425
|
+
expect(enumerable).to_not be__loaded
|
1426
|
+
end
|
1427
|
+
|
1428
|
+
it "clears out the loaded docs" do
|
1429
|
+
expect(enumerable._loaded).to be_empty
|
1430
|
+
end
|
1431
|
+
|
1432
|
+
it "clears out the added docs" do
|
1433
|
+
expect(enumerable._added).to be_empty
|
1434
|
+
end
|
1435
|
+
end
|
1436
|
+
|
1437
|
+
describe "#respond_to?" do
|
1438
|
+
|
1439
|
+
let(:enumerable) do
|
1440
|
+
described_class.new([])
|
1441
|
+
end
|
1442
|
+
|
1443
|
+
context "when checking against array methods" do
|
1444
|
+
|
1445
|
+
[].methods.each do |method|
|
1446
|
+
|
1447
|
+
it "returns true for #{method}" do
|
1448
|
+
expect(enumerable).to respond_to(method)
|
1449
|
+
end
|
1450
|
+
end
|
1451
|
+
end
|
1452
|
+
end
|
1453
|
+
|
1454
|
+
describe "#size" do
|
1455
|
+
|
1456
|
+
let(:person) do
|
1457
|
+
Person.create
|
1458
|
+
end
|
1459
|
+
|
1460
|
+
let!(:post) do
|
1461
|
+
Post.create(person_id: person.id)
|
1462
|
+
end
|
1463
|
+
|
1464
|
+
context "when the base is new" do
|
1465
|
+
|
1466
|
+
let!(:person) do
|
1467
|
+
Person.new
|
1468
|
+
end
|
1469
|
+
|
1470
|
+
context "when the added contains a persisted document" do
|
1471
|
+
|
1472
|
+
let!(:post) do
|
1473
|
+
Post.create(person_id: person.id)
|
1474
|
+
end
|
1475
|
+
|
1476
|
+
context "when the enumerable is not loaded" do
|
1477
|
+
|
1478
|
+
let(:enumerable) do
|
1479
|
+
described_class.new(Post.where(person_id: person.id))
|
1480
|
+
end
|
1481
|
+
|
1482
|
+
it "includes the number of all added documents" do
|
1483
|
+
expect(enumerable.size).to eq(1)
|
1484
|
+
end
|
1485
|
+
end
|
1486
|
+
end
|
1487
|
+
end
|
1488
|
+
|
1489
|
+
context "when the enumerable is loaded" do
|
1490
|
+
|
1491
|
+
let(:enumerable) do
|
1492
|
+
described_class.new([ post ])
|
1493
|
+
end
|
1494
|
+
|
1495
|
+
let(:post_two) do
|
1496
|
+
Post.new(person_id: person.id)
|
1497
|
+
end
|
1498
|
+
|
1499
|
+
before do
|
1500
|
+
enumerable << post_two
|
1501
|
+
end
|
1502
|
+
|
1503
|
+
let(:size) do
|
1504
|
+
enumerable.size
|
1505
|
+
end
|
1506
|
+
|
1507
|
+
it "returns the loaded size plus added size" do
|
1508
|
+
expect(size).to eq(2)
|
1509
|
+
end
|
1510
|
+
|
1511
|
+
it "matches the size of the loaded enumerable" do
|
1512
|
+
expect(size).to eq(enumerable.to_a.size)
|
1513
|
+
end
|
1514
|
+
end
|
1515
|
+
|
1516
|
+
context "when the enumerable is not loaded" do
|
1517
|
+
|
1518
|
+
let(:enumerable) do
|
1519
|
+
described_class.new(Post.where(person_id: person.id))
|
1520
|
+
end
|
1521
|
+
|
1522
|
+
context "when the added contains new documents" do
|
1523
|
+
|
1524
|
+
let(:post_two) do
|
1525
|
+
Post.new(person_id: person.id)
|
1526
|
+
end
|
1527
|
+
|
1528
|
+
before do
|
1529
|
+
enumerable << post_two
|
1530
|
+
end
|
1531
|
+
|
1532
|
+
let(:size) do
|
1533
|
+
enumerable.size
|
1534
|
+
end
|
1535
|
+
|
1536
|
+
it "returns the unloaded count plus added new size" do
|
1537
|
+
expect(size).to eq(2)
|
1538
|
+
end
|
1539
|
+
end
|
1540
|
+
|
1541
|
+
context "when the added contains persisted documents" do
|
1542
|
+
|
1543
|
+
let(:post_two) do
|
1544
|
+
Post.create(person_id: person.id)
|
1545
|
+
end
|
1546
|
+
|
1547
|
+
before do
|
1548
|
+
enumerable << post_two
|
1549
|
+
end
|
1550
|
+
|
1551
|
+
let(:size) do
|
1552
|
+
enumerable.size
|
1553
|
+
end
|
1554
|
+
|
1555
|
+
it "returns the unloaded count plus added new size" do
|
1556
|
+
expect(size).to eq(2)
|
1557
|
+
end
|
1558
|
+
end
|
1559
|
+
end
|
1560
|
+
end
|
1561
|
+
|
1562
|
+
describe "#to_json" do
|
1563
|
+
|
1564
|
+
let(:person) do
|
1565
|
+
Person.create
|
1566
|
+
end
|
1567
|
+
|
1568
|
+
let!(:post) do
|
1569
|
+
Post.create(title: "test", person_id: person.id)
|
1570
|
+
end
|
1571
|
+
|
1572
|
+
let(:criteria) do
|
1573
|
+
Post.where(person_id: person.id)
|
1574
|
+
end
|
1575
|
+
|
1576
|
+
let!(:enumerable) do
|
1577
|
+
described_class.new(criteria)
|
1578
|
+
end
|
1579
|
+
|
1580
|
+
before do
|
1581
|
+
enumerable << post
|
1582
|
+
end
|
1583
|
+
|
1584
|
+
let!(:json) do
|
1585
|
+
enumerable.to_json
|
1586
|
+
end
|
1587
|
+
|
1588
|
+
it "serializes the enumerable" do
|
1589
|
+
expect(json).to include(post.title)
|
1590
|
+
end
|
1591
|
+
end
|
1592
|
+
|
1593
|
+
describe "#to_json(parameters)" do
|
1594
|
+
|
1595
|
+
let(:person) do
|
1596
|
+
Person.create
|
1597
|
+
end
|
1598
|
+
|
1599
|
+
let!(:post) do
|
1600
|
+
Post.create(title: "test", person_id: person.id)
|
1601
|
+
end
|
1602
|
+
|
1603
|
+
let(:criteria) do
|
1604
|
+
Post.where(person_id: person.id)
|
1605
|
+
end
|
1606
|
+
|
1607
|
+
let!(:json) do
|
1608
|
+
person.posts.to_json({except: 'title'})
|
1609
|
+
end
|
1610
|
+
|
1611
|
+
it "serializes the enumerable" do
|
1612
|
+
expect(json).to_not include(post.title)
|
1613
|
+
end
|
1614
|
+
end
|
1615
|
+
|
1616
|
+
describe "#as_json" do
|
1617
|
+
|
1618
|
+
let(:person) do
|
1619
|
+
Person.create
|
1620
|
+
end
|
1621
|
+
|
1622
|
+
let!(:post) do
|
1623
|
+
Post.create(title: "test", person_id: person.id)
|
1624
|
+
end
|
1625
|
+
|
1626
|
+
let(:criteria) do
|
1627
|
+
Post.where(person_id: person.id)
|
1628
|
+
end
|
1629
|
+
|
1630
|
+
let!(:enumerable) do
|
1631
|
+
described_class.new(criteria)
|
1632
|
+
end
|
1633
|
+
|
1634
|
+
before do
|
1635
|
+
enumerable << post
|
1636
|
+
end
|
1637
|
+
|
1638
|
+
let!(:json) do
|
1639
|
+
enumerable.as_json
|
1640
|
+
end
|
1641
|
+
|
1642
|
+
it "serializes the enumerable" do
|
1643
|
+
expect(json.size).to eq(1)
|
1644
|
+
expect(json[0]['title']).to eq(post.title)
|
1645
|
+
end
|
1646
|
+
end
|
1647
|
+
|
1648
|
+
describe "#as_json(parameters)" do
|
1649
|
+
|
1650
|
+
let(:person) do
|
1651
|
+
Person.create
|
1652
|
+
end
|
1653
|
+
|
1654
|
+
let!(:post) do
|
1655
|
+
Post.create(title: "test", person_id: person.id)
|
1656
|
+
end
|
1657
|
+
|
1658
|
+
let(:criteria) do
|
1659
|
+
Post.where(person_id: person.id)
|
1660
|
+
end
|
1661
|
+
|
1662
|
+
let!(:json) do
|
1663
|
+
person.posts.as_json({except: "title"})
|
1664
|
+
end
|
1665
|
+
|
1666
|
+
it "serializes the enumerable" do
|
1667
|
+
expect(json.size).to eq(1)
|
1668
|
+
end
|
1669
|
+
|
1670
|
+
it "includes the proper fields" do
|
1671
|
+
expect(json[0].keys).to_not include("title")
|
1672
|
+
end
|
1673
|
+
end
|
1674
|
+
|
1675
|
+
describe "#uniq" do
|
1676
|
+
|
1677
|
+
let(:person) do
|
1678
|
+
Person.create
|
1679
|
+
end
|
1680
|
+
|
1681
|
+
let!(:post) do
|
1682
|
+
Post.create(person_id: person.id)
|
1683
|
+
end
|
1684
|
+
|
1685
|
+
let(:criteria) do
|
1686
|
+
Post.where(person_id: person.id)
|
1687
|
+
end
|
1688
|
+
|
1689
|
+
let!(:enumerable) do
|
1690
|
+
described_class.new(criteria)
|
1691
|
+
end
|
1692
|
+
|
1693
|
+
before do
|
1694
|
+
enumerable << post
|
1695
|
+
enumerable._loaded[post.id] = post
|
1696
|
+
end
|
1697
|
+
|
1698
|
+
let!(:uniq) do
|
1699
|
+
enumerable.uniq
|
1700
|
+
end
|
1701
|
+
|
1702
|
+
it "returns the unique documents" do
|
1703
|
+
expect(uniq).to eq([ post ])
|
1704
|
+
end
|
1705
|
+
|
1706
|
+
it "sets loaded to true" do
|
1707
|
+
expect(enumerable).to be__loaded
|
1708
|
+
end
|
1709
|
+
end
|
1710
|
+
end
|