Skip to content

Commit e840b10

Browse files
johnnyshieldscomandeo-mongop
authored
MONGOID-5173 Specs should use bang (!) methods as much as possible (#5061)
* MONGOID-5173 Specs should use bang (!) methods as much as possible * Update app_spec.rb * Update shardable_spec.rb * revert savable changes * update_attributes! delegation test Co-authored-by: shields <shields@tablecheck.com> Co-authored-by: Dmitry Rybakov <dmitry.rybakov@mongodb.com> Co-authored-by: Oleg Pudeyev <code@olegp.name>
1 parent a0e09f0 commit e840b10

File tree

4 files changed

+44
-26
lines changed

4 files changed

+44
-26
lines changed

spec/integration/callbacks_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
end
149149
end
150150

151-
context 'when updating top-level document via #update_attributes' do
151+
context 'when updating top-level document via #update_attributes!' do
152152
let!(:instance) do
153153
Galaxy.create!
154154
end
@@ -166,15 +166,15 @@
166166

167167
context 'set as a document instance' do
168168
before do
169-
instance.update_attributes(stars: [Star.new])
169+
instance.update_attributes!(stars: [Star.new])
170170
end
171171

172172
include_examples 'persists the attribute value'
173173
end
174174

175175
context 'set as attributes on parent' do
176176
before do
177-
instance.update_attributes(stars: [{}])
177+
instance.update_attributes!(stars: [{}])
178178
end
179179

180180
include_examples 'persists the attribute value'
@@ -196,15 +196,15 @@
196196

197197
context 'set as a document instance' do
198198
before do
199-
instance.update_attributes(stars: [Star.new(planets: [Planet.new])])
199+
instance.update_attributes!(stars: [Star.new(planets: [Planet.new])])
200200
end
201201

202202
include_examples 'persists the attribute value'
203203
end
204204

205205
context 'set as attributes on parent' do
206206
before do
207-
instance.update_attributes(stars: [planets: [{}]])
207+
instance.update_attributes!(stars: [planets: [{}]])
208208
end
209209

210210
include_examples 'persists the attribute value'

spec/mongoid/attributes/nested_spec.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4304,7 +4304,7 @@ class BandWithAllowDestroyedRecords < Band
43044304
end
43054305
end
43064306

4307-
describe "#update_attributes" do
4307+
describe "#update_attributes!" do
43084308

43094309
before do
43104310
Person.send(:undef_method, :addresses_attributes=)
@@ -4337,7 +4337,7 @@ class BandWithAllowDestroyedRecords < Band
43374337
end
43384338

43394339
before do
4340-
node.update_attributes(attributes)
4340+
node.update_attributes!(attributes)
43414341
end
43424342

43434343
it "adds the new embedded document" do
@@ -4369,7 +4369,7 @@ class BandWithAllowDestroyedRecords < Band
43694369
end
43704370

43714371
before do
4372-
person.update_attributes(attributes)
4372+
person.update_attributes!(attributes)
43734373
end
43744374

43754375
it "removes the document from the parent" do
@@ -4420,7 +4420,7 @@ class BandWithAllowDestroyedRecords < Band
44204420
end
44214421

44224422
before do
4423-
address.update_attributes(attributes)
4423+
address.update_attributes!(attributes)
44244424
address.reload
44254425
end
44264426

@@ -4463,7 +4463,7 @@ class BandWithAllowDestroyedRecords < Band
44634463
end
44644464

44654465
before do
4466-
person_one.update_attributes(attributes)
4466+
person_one.update_attributes!(attributes)
44674467
end
44684468

44694469
it "deletes the document from the relation" do
@@ -4513,7 +4513,7 @@ class BandWithAllowDestroyedRecords < Band
45134513
end
45144514

45154515
before do
4516-
band.update_attributes(attributes)
4516+
band.update_attributes!(attributes)
45174517
end
45184518

45194519
it "removes the child from the relation" do
@@ -4546,7 +4546,7 @@ class BandWithAllowDestroyedRecords < Band
45464546
end
45474547

45484548
before do
4549-
person.update_attributes(attributes)
4549+
person.update_attributes!(attributes)
45504550
end
45514551

45524552
let(:address) do
@@ -4586,7 +4586,7 @@ class BandWithAllowDestroyedRecords < Band
45864586
end
45874587

45884588
before do
4589-
person.update_attributes(attributes)
4589+
person.update_attributes!(attributes)
45904590
person.reload
45914591
end
45924592

@@ -4617,7 +4617,7 @@ class BandWithAllowDestroyedRecords < Band
46174617
end
46184618

46194619
before do
4620-
person.update_attributes(attributes)
4620+
person.update_attributes!(attributes)
46214621
end
46224622

46234623
let(:address) do
@@ -4666,7 +4666,7 @@ class BandWithAllowDestroyedRecords < Band
46664666
end
46674667

46684668
before do
4669-
person.update_attributes(attributes)
4669+
person.update_attributes!(attributes)
46704670
end
46714671

46724672
it "updates the first level embedded document" do
@@ -4706,7 +4706,7 @@ class BandWithAllowDestroyedRecords < Band
47064706
end
47074707

47084708
before do
4709-
person.update_attributes(attributes)
4709+
person.update_attributes!(attributes)
47104710
end
47114711

47124712
it "updates the first level embedded document" do
@@ -4742,7 +4742,7 @@ class BandWithAllowDestroyedRecords < Band
47424742
end
47434743

47444744
before do
4745-
person.update_attributes(attributes)
4745+
person.update_attributes!(attributes)
47464746
end
47474747

47484748
it "updates the nested embedded document" do
@@ -4769,7 +4769,7 @@ class BandWithAllowDestroyedRecords < Band
47694769
end
47704770

47714771
before do
4772-
user.update_attributes(params)
4772+
user.update_attributes!(params)
47734773
end
47744774

47754775
around do |example|
@@ -4891,7 +4891,7 @@ class BandWithAllowDestroyedRecords < Band
48914891
end
48924892

48934893
before do
4894-
league.update_attributes(params)
4894+
league.update_attributes!(params)
48954895
end
48964896

48974897
it "sets the nested attributes" do
@@ -4911,7 +4911,7 @@ class BandWithAllowDestroyedRecords < Band
49114911
end
49124912

49134913
before do
4914-
league.update_attributes(new_params)
4914+
league.update_attributes!(new_params)
49154915
end
49164916

49174917
it "sets the nested attributes" do

spec/mongoid/clients_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -791,11 +791,11 @@
791791
end
792792
end
793793

794-
describe ".create" do
794+
describe ".create!" do
795795

796796
let!(:band) do
797797
Band.with(database: database_id_alt) do |klass|
798-
klass.create
798+
klass.create!
799799
end
800800
end
801801

@@ -829,11 +829,11 @@
829829

830830
context "when sending operations to a different collection" do
831831

832-
describe ".create" do
832+
describe ".create!" do
833833

834834
let!(:band) do
835835
Band.with(collection: "artists") do |klass|
836-
klass.create
836+
klass.create!
837837
end
838838
end
839839

@@ -944,7 +944,7 @@
944944
describe ".save" do
945945

946946
before do
947-
Person.create(ssn: "432-97-1113")
947+
Person.create!(ssn: "432-97-1113")
948948
end
949949

950950
context "when a mongodb error occurs" do
@@ -1037,7 +1037,7 @@
10371037
end
10381038

10391039
let!(:band) do
1040-
Band.create(name: "Tool")
1040+
Band.create!(name: "Tool")
10411041
end
10421042

10431043
it "persists to the overridden database" do

spec/mongoid/persistable/updatable_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,4 +739,22 @@
739739
end
740740
end
741741
end
742+
743+
describe "#update_attributes!" do
744+
745+
let(:person) do
746+
Person.create!
747+
end
748+
749+
let(:attributes) do
750+
{ security_code: 'secret' }
751+
end
752+
753+
it 'calls update_attributes' do
754+
person.should receive(:update_attributes).with(attributes).and_call_original
755+
lambda do
756+
person.update_attributes!(attributes)
757+
end.should_not raise_error
758+
end
759+
end
742760
end

0 commit comments

Comments
 (0)