Skip to content

Commit 09afa78

Browse files
johnnyshieldscomandeo-mongop
committed
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 c8ad882 commit 09afa78

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
@@ -4427,7 +4427,7 @@ class BandWithAllowDestroyedRecords < Band
44274427
end
44284428

44294429
before do
4430-
address.update_attributes(attributes)
4430+
address.update_attributes!(attributes)
44314431
address.reload
44324432
end
44334433

@@ -4470,7 +4470,7 @@ class BandWithAllowDestroyedRecords < Band
44704470
end
44714471

44724472
before do
4473-
person_one.update_attributes(attributes)
4473+
person_one.update_attributes!(attributes)
44744474
end
44754475

44764476
it "deletes the document from the relation" do
@@ -4520,7 +4520,7 @@ class BandWithAllowDestroyedRecords < Band
45204520
end
45214521

45224522
before do
4523-
band.update_attributes(attributes)
4523+
band.update_attributes!(attributes)
45244524
end
45254525

45264526
it "removes the child from the relation" do
@@ -4553,7 +4553,7 @@ class BandWithAllowDestroyedRecords < Band
45534553
end
45544554

45554555
before do
4556-
person.update_attributes(attributes)
4556+
person.update_attributes!(attributes)
45574557
end
45584558

45594559
let(:address) do
@@ -4593,7 +4593,7 @@ class BandWithAllowDestroyedRecords < Band
45934593
end
45944594

45954595
before do
4596-
person.update_attributes(attributes)
4596+
person.update_attributes!(attributes)
45974597
person.reload
45984598
end
45994599

@@ -4624,7 +4624,7 @@ class BandWithAllowDestroyedRecords < Band
46244624
end
46254625

46264626
before do
4627-
person.update_attributes(attributes)
4627+
person.update_attributes!(attributes)
46284628
end
46294629

46304630
let(:address) do
@@ -4673,7 +4673,7 @@ class BandWithAllowDestroyedRecords < Band
46734673
end
46744674

46754675
before do
4676-
person.update_attributes(attributes)
4676+
person.update_attributes!(attributes)
46774677
end
46784678

46794679
it "updates the first level embedded document" do
@@ -4713,7 +4713,7 @@ class BandWithAllowDestroyedRecords < Band
47134713
end
47144714

47154715
before do
4716-
person.update_attributes(attributes)
4716+
person.update_attributes!(attributes)
47174717
end
47184718

47194719
it "updates the first level embedded document" do
@@ -4749,7 +4749,7 @@ class BandWithAllowDestroyedRecords < Band
47494749
end
47504750

47514751
before do
4752-
person.update_attributes(attributes)
4752+
person.update_attributes!(attributes)
47534753
end
47544754

47554755
it "updates the nested embedded document" do
@@ -4776,7 +4776,7 @@ class BandWithAllowDestroyedRecords < Band
47764776
end
47774777

47784778
before do
4779-
user.update_attributes(params)
4779+
user.update_attributes!(params)
47804780
end
47814781

47824782
around do |example|
@@ -4898,7 +4898,7 @@ class BandWithAllowDestroyedRecords < Band
48984898
end
48994899

49004900
before do
4901-
league.update_attributes(params)
4901+
league.update_attributes!(params)
49024902
end
49034903

49044904
it "sets the nested attributes" do
@@ -4918,7 +4918,7 @@ class BandWithAllowDestroyedRecords < Band
49184918
end
49194919

49204920
before do
4921-
league.update_attributes(new_params)
4921+
league.update_attributes!(new_params)
49224922
end
49234923

49244924
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)