Skip to content

Commit ddb24f8

Browse files
authored
MONGOID-4547 adds regexps to all DocumentNotFound error tests (#5353)
* MONGOID-4547 add regexps to all DocumentNotFound error tests * MONGOID-4547 add shard key test with description
1 parent 21389fe commit ddb24f8

File tree

17 files changed

+72
-58
lines changed

17 files changed

+72
-58
lines changed

spec/mongoid/association/counter_cache_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
it "expect to raise an error" do
134134
expect {
135135
Person.reset_counters "1", :drugs
136-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
136+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Person with id\(s\)/)
137137
end
138138
end
139139

spec/mongoid/association/depending_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class DependentCollegeUser < DependentUser; end
7373
r = DependentReportCard.create!(dependent_student: s)
7474
s.destroy!
7575

76-
expect { DependentReportCard.find(r.id) }.to raise_error(Mongoid::Errors::DocumentNotFound)
76+
expect { DependentReportCard.find(r.id) }.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class DependentReportCard with id\(s\)/)
7777
end
7878

7979
it 'facilitates proper transitive destroying of the object' do
@@ -84,7 +84,7 @@ class DependentCollegeUser < DependentUser; end
8484
r = DependentReportCard.create!(dependent_student: s)
8585
s.destroy!
8686

87-
expect { DependentReportCard.find(r.id) }.to raise_error(Mongoid::Errors::DocumentNotFound)
87+
expect { DependentReportCard.find(r.id) }.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class DependentReportCard with id\(s\)/)
8888
end
8989

9090
it 'adds the dependent to subclasses' do
@@ -105,7 +105,7 @@ class DependentCollegeUser < DependentUser; end
105105
r = DependentReportCard.create!(dependent_student: s)
106106
s.destroy!
107107

108-
expect { DependentReportCard.find(r.id) }.to raise_error(Mongoid::Errors::DocumentNotFound)
108+
expect { DependentReportCard.find(r.id) }.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class DependentReportCard with id\(s\)/)
109109
end
110110

111111
it "doesn't add the dependent to sibling classes" do
@@ -177,7 +177,7 @@ class DependentSuperclass
177177

178178
expect {
179179
DependentOwnedOne.find(owned.id)
180-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
180+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class DependentOwnedOne with id\(s\)/)
181181
end
182182
end
183183

@@ -250,7 +250,7 @@ class DoubleAssocThree < DoubleAssoc; end
250250
dep = Dep.create!(double_assoc: two)
251251
two.destroy!
252252

253-
expect { Dep.find(dep.id) }.to raise_error(Mongoid::Errors::DocumentNotFound)
253+
expect { Dep.find(dep.id) }.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Dep with id\(s\)/)
254254
end
255255
end
256256
end
@@ -362,7 +362,7 @@ class DoubleAssocThree < DoubleAssoc; end
362362
it "deletes the associated documents" do
363363
expect {
364364
child.class.find(child.id)
365-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
365+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class #{child.class.to_s} with id\(s\)/)
366366
end
367367
end
368368

@@ -674,7 +674,7 @@ class DoubleAssocThree < DoubleAssoc; end
674674
it "persists the deletion" do
675675
expect {
676676
home.reload
677-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
677+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Home with id\(s\)/)
678678
end
679679
end
680680

@@ -733,13 +733,13 @@ class DoubleAssocThree < DoubleAssoc; end
733733
it "persists the first deletion" do
734734
expect {
735735
post_one.reload
736-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
736+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Post with id\(s\)/)
737737
end
738738

739739
it "persists the second deletion" do
740740
expect {
741741
post_two.reload
742-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
742+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Post with id\(s\)/)
743743
end
744744
end
745745
end

spec/mongoid/association/embedded/embeds_many/proxy_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,7 +2360,7 @@ class TrackingIdValidationHistory
23602360
it "raises an error" do
23612361
expect {
23622362
person.addresses.find(BSON::ObjectId.new)
2363-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
2363+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Address with id\(s\)/)
23642364
end
23652365
end
23662366

@@ -2409,7 +2409,7 @@ class TrackingIdValidationHistory
24092409
it "raises an error" do
24102410
expect {
24112411
person.addresses.find([ BSON::ObjectId.new ])
2412-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
2412+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Address with id\(s\)/)
24132413
end
24142414
end
24152415

spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,7 +2516,7 @@
25162516
it "raises an error" do
25172517
expect {
25182518
preference
2519-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
2519+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Preference with id\(s\)/)
25202520
end
25212521
end
25222522

@@ -2531,7 +2531,7 @@
25312531
it "raises an error" do
25322532
expect {
25332533
person.preferences.find(BSON::ObjectId.new)
2534-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
2534+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Preference with id\(s\)/)
25352535
end
25362536
end
25372537

@@ -2580,7 +2580,7 @@
25802580
it "raises an error" do
25812581
expect {
25822582
preferences
2583-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
2583+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Preference with id\(s\)/)
25842584
end
25852585
end
25862586

@@ -2595,7 +2595,7 @@
25952595
it "raises an error" do
25962596
expect {
25972597
person.preferences.find([ BSON::ObjectId.new ])
2598-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
2598+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Preference with id\(s\)/)
25992599
end
26002600
end
26012601

spec/mongoid/association/referenced/has_many/proxy_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,7 +2540,7 @@
25402540
it "raises an error" do
25412541
expect {
25422542
person.posts.find(post.id)
2543-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
2543+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Post with id\(s\)/)
25442544
end
25452545
end
25462546

@@ -2555,7 +2555,7 @@
25552555
it "raises an error" do
25562556
expect {
25572557
person.posts.find(BSON::ObjectId.new)
2558-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
2558+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Post with id\(s\)/)
25592559
end
25602560
end
25612561

@@ -2604,7 +2604,7 @@
26042604
it "raises an error" do
26052605
expect {
26062606
person.posts.find([ BSON::ObjectId.new ])
2607-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
2607+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Post with id\(s\)/)
26082608
end
26092609
end
26102610

@@ -2668,7 +2668,7 @@
26682668
it "raises an error" do
26692669
expect {
26702670
movie.ratings.find(BSON::ObjectId.new)
2671-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
2671+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Rating with id\(s\)/)
26722672
end
26732673
end
26742674

@@ -2725,7 +2725,7 @@
27252725
it "raises an error" do
27262726
expect {
27272727
movie.ratings.find([ BSON::ObjectId.new ])
2728-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
2728+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Rating with id\(s\)/)
27292729
end
27302730
end
27312731

spec/mongoid/association/referenced/has_one/proxy_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
it "detaches the previous relation" do
134134
expect {
135135
game.reload
136-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
136+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Game with id\(s\)/)
137137
end
138138
end
139139
end

spec/mongoid/attributes/nested_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@
13561356
expect {
13571357
person.addresses_attributes =
13581358
{ "foo" => { "id" => "test", "street" => "Test" } }
1359-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
1359+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Address with id\(s\)/)
13601360
end
13611361
end
13621362
end
@@ -3015,7 +3015,7 @@ class BandWithAllowDestroyedRecords < Band
30153015
{ "0" =>
30163016
{ "id" => BSON::ObjectId.new.to_s, "title" => "Rogue" }
30173017
}
3018-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
3018+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Post with id\(s\)/)
30193019
end
30203020
end
30213021
end
@@ -3049,7 +3049,7 @@ class BandWithAllowDestroyedRecords < Band
30493049
expect {
30503050
person.posts_attributes =
30513051
{ "foo" => { "id" => "test", "title" => "Test" } }
3052-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
3052+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Post with id\(s\)/)
30533053
end
30543054
end
30553055
end
@@ -3766,7 +3766,7 @@ class BandWithAllowDestroyedRecords < Band
37663766
expect {
37673767
person.preferences_attributes =
37683768
{ "foo" => { "id" => "test", "name" => "Test" } }
3769-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
3769+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Preference with id\(s\)/)
37703770
end
37713771
end
37723772
end

spec/mongoid/clients_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@
802802
it "does not persist to the default database" do
803803
expect {
804804
Band.find(band.id)
805-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
805+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Band with id\(s\)/)
806806
end
807807

808808
let(:from_db) do
@@ -840,7 +840,7 @@
840840
it "does not persist to the default database" do
841841
expect {
842842
Band.find(band.id)
843-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
843+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Band with id\(s\)/)
844844
end
845845

846846
let(:from_db) do

spec/mongoid/contextual/mongo_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,7 @@
18531853
it "deletes the document from the database" do
18541854
expect {
18551855
depeche.reload
1856-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
1856+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Band with id\(s\)/)
18571857
end
18581858

18591859
context 'when a collation is specified on the criteria' do
@@ -1878,7 +1878,7 @@
18781878
it "deletes the document from the database" do
18791879
expect {
18801880
depeche.reload
1881-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
1881+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Band with id\(s\)/)
18821882
end
18831883
end
18841884
end

0 commit comments

Comments
 (0)