mongoid 5.0.1 → 5.0.2

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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/CHANGELOG.md +2 -0
  5. data/README.md +0 -1
  6. data/lib/mongoid.rb +0 -7
  7. data/lib/mongoid/attributes.rb +2 -1
  8. data/lib/mongoid/attributes/nested.rb +3 -0
  9. data/lib/mongoid/clients.rb +0 -6
  10. data/lib/mongoid/clients/options.rb +0 -6
  11. data/lib/mongoid/clients/storage_options.rb +0 -3
  12. data/lib/mongoid/clients/thread_options.rb +0 -3
  13. data/lib/mongoid/config.rb +0 -7
  14. data/lib/mongoid/contextual/command.rb +0 -3
  15. data/lib/mongoid/contextual/mongo.rb +2 -2
  16. data/lib/mongoid/criteria.rb +6 -1
  17. data/lib/mongoid/extensions/hash.rb +1 -1
  18. data/lib/mongoid/indexable.rb +7 -5
  19. data/lib/mongoid/indexable/specification.rb +14 -0
  20. data/lib/mongoid/indexable/validators/options.rb +2 -1
  21. data/lib/mongoid/persistable/settable.rb +8 -1
  22. data/lib/mongoid/query_cache.rb +14 -4
  23. data/lib/mongoid/railtie.rb +1 -0
  24. data/lib/mongoid/relations/accessors.rb +3 -1
  25. data/lib/mongoid/relations/embedded/batchable.rb +5 -1
  26. data/lib/mongoid/relations/metadata.rb +3 -0
  27. data/lib/mongoid/tasks/database.rb +1 -1
  28. data/lib/mongoid/threaded.rb +0 -5
  29. data/lib/mongoid/version.rb +1 -1
  30. data/spec/app/models/bomb.rb +4 -0
  31. data/spec/app/models/building.rb +2 -1
  32. data/spec/app/models/building_address.rb +3 -1
  33. data/spec/app/models/courier_job.rb +4 -0
  34. data/spec/app/models/explosion.rb +4 -0
  35. data/spec/app/models/message.rb +3 -0
  36. data/spec/app/models/name.rb +1 -0
  37. data/spec/app/models/post.rb +3 -0
  38. data/spec/app/models/sandwich.rb +5 -0
  39. data/spec/app/models/shipment_address.rb +2 -0
  40. data/spec/mongoid/attributes/nested_spec.rb +77 -18
  41. data/spec/mongoid/attributes_spec.rb +13 -0
  42. data/spec/mongoid/criteria_spec.rb +52 -0
  43. data/spec/mongoid/document_spec.rb +37 -13
  44. data/spec/mongoid/indexable/specification_spec.rb +25 -0
  45. data/spec/mongoid/persistable_spec.rb +17 -0
  46. data/spec/mongoid/query_cache_spec.rb +51 -2
  47. data/spec/mongoid/relations/accessors_spec.rb +69 -0
  48. data/spec/mongoid/relations/embedded/many_spec.rb +63 -0
  49. data/spec/mongoid/relations/embedded/one_spec.rb +45 -0
  50. data/spec/mongoid/relations/metadata_spec.rb +16 -0
  51. data/spec/mongoid/relations/referenced/one_spec.rb +24 -0
  52. data/spec/mongoid/tasks/database_spec.rb +19 -0
  53. data/spec/spec_helper.rb +1 -8
  54. metadata +10 -2
  55. metadata.gz.sig +0 -0
@@ -75,6 +75,55 @@ describe Mongoid::QueryCache do
75
75
  end
76
76
  end
77
77
 
78
+ context "when the first query has no limit" do
79
+
80
+ let(:game) do
81
+ Game.create!(name: "2048")
82
+ end
83
+
84
+ before do
85
+ game.ratings.where(:value.gt => 5).asc(:id).all.to_a
86
+ end
87
+
88
+ context "when the next query has a limit" do
89
+
90
+ it "uses the cache" do
91
+ expect_no_queries do
92
+ game.ratings.where(:value.gt => 5).limit(2).asc(:id).to_a
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ context "when the first query has a limit" do
99
+
100
+ let(:game) do
101
+ Game.create!(name: "2048")
102
+ end
103
+
104
+ before do
105
+ game.ratings.where(:value.gt => 5).limit(3).asc(:id).all.to_a
106
+ end
107
+
108
+ context "when the next query has a limit" do
109
+
110
+ it "queries again" do
111
+ expect_query(1) do
112
+ game.ratings.where(:value.gt => 5).limit(2).asc(:id).to_a
113
+ end
114
+ end
115
+ end
116
+
117
+ context "when the new query does not have a limit" do
118
+
119
+ it "queries again" do
120
+ expect_query(1) do
121
+ game.ratings.where(:value.gt => 5).asc(:id).to_a
122
+ end
123
+ end
124
+ end
125
+ end
126
+
78
127
  context "when querying only the first" do
79
128
 
80
129
  let(:game) do
@@ -94,8 +143,8 @@ describe Mongoid::QueryCache do
94
143
 
95
144
  context "when limiting the result" do
96
145
 
97
- it "queries again" do
98
- expect_query(1) do
146
+ it "does not query again" do
147
+ expect_query(0) do
99
148
  Band.limit(2).all.to_a
100
149
  end
101
150
  end
@@ -749,4 +749,73 @@ describe Mongoid::Relations::Accessors do
749
749
  end
750
750
  end
751
751
  end
752
+
753
+ context 'when setting the relation more than once' do
754
+
755
+ let(:person) do
756
+ Person.create
757
+ end
758
+
759
+ context 'when the relation is a references one' do
760
+
761
+ let(:game) do
762
+ Game.create
763
+ end
764
+
765
+ before do
766
+ person.game = game
767
+ game.person = person
768
+ end
769
+
770
+ it 'allows the object to be set twice' do
771
+ expect(person.game = game).to be(game)
772
+ end
773
+ end
774
+
775
+ context 'when the relation is a references many' do
776
+
777
+ let!(:preference) do
778
+ Preference.create(name: "Setting")
779
+ end
780
+
781
+ before do
782
+ person.preferences << Preference.last
783
+ end
784
+
785
+ it 'allows the object to be set twice' do
786
+ expect(person.preferences << Preference.last).to be_a(Array)
787
+ end
788
+ end
789
+
790
+ context 'when the relation is an embeds one' do
791
+
792
+ let!(:name) do
793
+ Name.new
794
+ end
795
+
796
+ before do
797
+ person.name = name
798
+ name.person = person
799
+ end
800
+
801
+ it 'allows the object to be set twice' do
802
+ expect(person.name = name).to be(name)
803
+ end
804
+ end
805
+
806
+ context 'when the relation is an embeds many' do
807
+
808
+ let!(:address) do
809
+ Address.new
810
+ end
811
+
812
+ before do
813
+ person.addresses << address
814
+ end
815
+
816
+ it 'allows the object to be set twice' do
817
+ expect(person.addresses << address).to be_a(Array)
818
+ end
819
+ end
820
+ end
752
821
  end
@@ -1545,6 +1545,38 @@ describe Mongoid::Relations::Embedded::Many do
1545
1545
  person.addresses.create!(street: "1")
1546
1546
  }.to raise_error(Mongoid::Errors::Validations)
1547
1547
  end
1548
+
1549
+ context 'when the presence of the embedded relation is validated' do
1550
+
1551
+ before do
1552
+ class Book
1553
+ validates :pages, presence: true
1554
+ end
1555
+ end
1556
+
1557
+ let(:book) do
1558
+ Book.new.tap do |b|
1559
+ b.pages = [Page.new]
1560
+ b.save!
1561
+ end
1562
+ end
1563
+
1564
+ let(:num_pages) do
1565
+ book.pages.size
1566
+ end
1567
+
1568
+ let(:reloaded) do
1569
+ book.reload
1570
+ end
1571
+
1572
+ before do
1573
+ begin; book.update_attributes!({"pages"=>nil}); rescue; end
1574
+ end
1575
+
1576
+ it 'does not delete the embedded relation' do
1577
+ expect(reloaded.pages.size).to eq(num_pages)
1578
+ end
1579
+ end
1548
1580
  end
1549
1581
  end
1550
1582
 
@@ -3531,6 +3563,37 @@ describe Mongoid::Relations::Embedded::Many do
3531
3563
  end
3532
3564
  end
3533
3565
 
3566
+ context "when the association has an order defined" do
3567
+
3568
+ let(:person) do
3569
+ Person.create
3570
+ end
3571
+
3572
+ let(:message_one) do
3573
+ Message.new(priority: 5, body: 'This is a test')
3574
+ end
3575
+
3576
+ let(:message_two) do
3577
+ Message.new(priority: 10, body: 'This is a test')
3578
+ end
3579
+
3580
+ let(:message_three) do
3581
+ Message.new(priority: 20, body: 'Zee test')
3582
+ end
3583
+
3584
+ before do
3585
+ person.messages.push(message_one, message_two, message_three)
3586
+ end
3587
+
3588
+ let(:criteria) do
3589
+ person.messages.order_by(:body.asc, :priority.desc)
3590
+ end
3591
+
3592
+ it "properly orders the related objects" do
3593
+ expect(criteria.to_a).to eq([message_two, message_one, message_three])
3594
+ end
3595
+ end
3596
+
3534
3597
  context "when using dot notation in a criteria" do
3535
3598
 
3536
3599
  let(:person) do
@@ -768,6 +768,37 @@ describe Mongoid::Relations::Embedded::One do
768
768
  end
769
769
  end
770
770
 
771
+ describe "when the relationship is polymorphic" do
772
+
773
+ context "when updating an aliased embedded document" do
774
+
775
+ context "when the embedded document inherits its relationship" do
776
+
777
+ let(:courier_job) do
778
+ CourierJob.create
779
+ end
780
+
781
+ let(:old_child) do
782
+ ShipmentAddress.new
783
+ end
784
+
785
+ let(:new_child) do
786
+ ShipmentAddress.new
787
+ end
788
+
789
+ before do
790
+ courier_job.drop_address = old_child
791
+ courier_job.update_attribute(:drop_address, new_child)
792
+ courier_job.reload
793
+ end
794
+
795
+ it "the child is embedded correctly" do
796
+ expect(courier_job.drop_address).to eq(new_child)
797
+ end
798
+ end
799
+ end
800
+ end
801
+
771
802
  describe ".embedded?" do
772
803
 
773
804
  it "returns true" do
@@ -1019,4 +1050,18 @@ describe Mongoid::Relations::Embedded::One do
1019
1050
  end
1020
1051
  end
1021
1052
  end
1053
+
1054
+ context "when parent validation of child is set to false" do
1055
+
1056
+ let(:building) do
1057
+ building = Building.create
1058
+ building.building_address = BuildingAddress.new
1059
+ building.save
1060
+ building.reload
1061
+ end
1062
+
1063
+ it "parent successfully embeds an invalid child" do
1064
+ expect(building.building_address).to be_a(BuildingAddress)
1065
+ end
1066
+ end
1022
1067
  end
@@ -586,6 +586,22 @@ describe Mongoid::Relations::Metadata do
586
586
  end
587
587
  end
588
588
 
589
+ context "when the association is polymorphic" do
590
+
591
+ let(:metadata) do
592
+ described_class.new(
593
+ name: :ratable,
594
+ relation: Mongoid::Relations::Referenced::In,
595
+ polymorphic: true,
596
+ inverse_class_name: "Rating"
597
+ )
598
+ end
599
+
600
+ it "returns the polymorphic class name" do
601
+ expect(metadata.class_name).to eq("Ratable")
602
+ end
603
+ end
604
+
589
605
  describe "#destructive?" do
590
606
 
591
607
  context "when the relation has a destructive dependent option" do
@@ -1213,4 +1213,28 @@ describe Mongoid::Relations::Referenced::One do
1213
1213
  end
1214
1214
  end
1215
1215
  end
1216
+
1217
+ context "when dependent is set to delete for child" do
1218
+
1219
+ context "when autobuild is true for child" do
1220
+
1221
+ let(:explosion) do
1222
+ Explosion.create
1223
+ end
1224
+
1225
+ let(:bomb) do
1226
+ bomb = Bomb.create
1227
+ bomb.explosion = explosion
1228
+ bomb
1229
+ end
1230
+
1231
+ let(:clear_child) do
1232
+ bomb.explosion.clear
1233
+ end
1234
+
1235
+ it "clearing the child raises no error" do
1236
+ expect{ clear_child }.not_to raise_error
1237
+ end
1238
+ end
1239
+ end
1216
1240
  end
@@ -132,6 +132,25 @@ describe "Mongoid::Tasks::Database" do
132
132
  it "returns the removed indexes" do
133
133
  expect(removed_indexes).to be_empty
134
134
  end
135
+
136
+ context 'when the index is a text index', if: non_legacy_server? do
137
+
138
+ before do
139
+ class Band
140
+ index origin: Mongo::Index::TEXT
141
+ end
142
+ Mongoid::Tasks::Database.create_indexes([Band])
143
+ Mongoid::Tasks::Database.remove_undefined_indexes([Band])
144
+ end
145
+
146
+ let(:indexes) do
147
+ Band.collection.indexes
148
+ end
149
+
150
+ it 'does not delete the text index' do
151
+ expect(indexes.find { |i| i['name'] == 'origin_text' }).not_to be_nil
152
+ end
153
+ end
135
154
  end
136
155
 
137
156
  describe ".remove_indexes" do
@@ -4,13 +4,6 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
4
4
  MODELS = File.join(File.dirname(__FILE__), "app/models")
5
5
  $LOAD_PATH.unshift(MODELS)
6
6
 
7
- if ENV["CI"]
8
- require "coveralls"
9
- Coveralls.wear! do
10
- add_filter "spec"
11
- end
12
- end
13
-
14
7
  require "action_controller"
15
8
  require "mongoid"
16
9
  require "rspec"
@@ -48,7 +41,7 @@ if (ENV['CI'] == 'travis')
48
41
  client = Mongo::Client.new(['127.0.0.1:27017'])
49
42
  while starting
50
43
  begin
51
- client.command(Mongo::Server::Monitor::STATUS)
44
+ client.command(Mongo::Server::Monitor::Connection::ISMASTER)
52
45
  break
53
46
  rescue Mongo::Error::OperationFailure => e
54
47
  sleep(2)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.1
4
+ version: 5.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan
@@ -30,7 +30,7 @@ cert_chain:
30
30
  ZIvvwAhgCjVW5QCi2I1noxXLmtZ3XDawWu8kaGtu8giHXcwL3941m8hvFZ/Wr9Yi
31
31
  JvcXJt2a4/JvwnIs2hmKuyfhZmB9HEE5wQQaCMnnC14=
32
32
  -----END CERTIFICATE-----
33
- date: 2015-11-03 00:00:00.000000000 Z
33
+ date: 2015-12-22 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: activemodel
@@ -387,6 +387,7 @@ files:
387
387
  - spec/app/models/bed.rb
388
388
  - spec/app/models/big_palette.rb
389
389
  - spec/app/models/birthday.rb
390
+ - spec/app/models/bomb.rb
390
391
  - spec/app/models/book.rb
391
392
  - spec/app/models/breed.rb
392
393
  - spec/app/models/browser.rb
@@ -413,6 +414,7 @@ files:
413
414
  - spec/app/models/contractor.rb
414
415
  - spec/app/models/cookie.rb
415
416
  - spec/app/models/country_code.rb
417
+ - spec/app/models/courier_job.rb
416
418
  - spec/app/models/definition.rb
417
419
  - spec/app/models/description.rb
418
420
  - spec/app/models/dictionary.rb
@@ -434,6 +436,7 @@ files:
434
436
  - spec/app/models/event.rb
435
437
  - spec/app/models/exhibition.rb
436
438
  - spec/app/models/exhibitor.rb
439
+ - spec/app/models/explosion.rb
437
440
  - spec/app/models/eye.rb
438
441
  - spec/app/models/eye_bowl.rb
439
442
  - spec/app/models/face.rb
@@ -522,6 +525,7 @@ files:
522
525
  - spec/app/models/service.rb
523
526
  - spec/app/models/shape.rb
524
527
  - spec/app/models/shelf.rb
528
+ - spec/app/models/shipment_address.rb
525
529
  - spec/app/models/shipping_container.rb
526
530
  - spec/app/models/shipping_pack.rb
527
531
  - spec/app/models/shop.rb
@@ -838,6 +842,7 @@ test_files:
838
842
  - spec/app/models/bed.rb
839
843
  - spec/app/models/big_palette.rb
840
844
  - spec/app/models/birthday.rb
845
+ - spec/app/models/bomb.rb
841
846
  - spec/app/models/book.rb
842
847
  - spec/app/models/breed.rb
843
848
  - spec/app/models/browser.rb
@@ -864,6 +869,7 @@ test_files:
864
869
  - spec/app/models/contractor.rb
865
870
  - spec/app/models/cookie.rb
866
871
  - spec/app/models/country_code.rb
872
+ - spec/app/models/courier_job.rb
867
873
  - spec/app/models/definition.rb
868
874
  - spec/app/models/description.rb
869
875
  - spec/app/models/dictionary.rb
@@ -885,6 +891,7 @@ test_files:
885
891
  - spec/app/models/event.rb
886
892
  - spec/app/models/exhibition.rb
887
893
  - spec/app/models/exhibitor.rb
894
+ - spec/app/models/explosion.rb
888
895
  - spec/app/models/eye.rb
889
896
  - spec/app/models/eye_bowl.rb
890
897
  - spec/app/models/face.rb
@@ -973,6 +980,7 @@ test_files:
973
980
  - spec/app/models/service.rb
974
981
  - spec/app/models/shape.rb
975
982
  - spec/app/models/shelf.rb
983
+ - spec/app/models/shipment_address.rb
976
984
  - spec/app/models/shipping_container.rb
977
985
  - spec/app/models/shipping_pack.rb
978
986
  - spec/app/models/shop.rb