Skip to content

Commit 5f102bf

Browse files
MONGOID-5442 - Rename #set_mul to #mul (#5527)
1 parent cab0350 commit 5f102bf

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

lib/mongoid/contextual/atomic.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ def inc(incs)
5555
# Perform an atomic $mul operation on the matching documents.
5656
#
5757
# @example Perform the atomic multiplication.
58-
# context.set_mul(likes: 10)
58+
# context.mul(likes: 10)
5959
#
6060
# @param [ Hash ] factors The operations.
6161
#
6262
# @return [ nil ] Nil.
63-
def set_mul(factors)
63+
def mul(factors)
6464
view.update_many("$mul" => collect_operations(factors))
6565
end
6666

lib/mongoid/persistable/multipliable.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ module Multipliable
1212
# be set to zero.
1313
#
1414
# @example Multiply the fields.
15-
# document.set_mul(score: 10, place: 1, lives: -10)
15+
# document.mul(score: 10, place: 1, lives: -10)
1616
#
1717
# @param [ Hash ] factors The field/factor multiplier pairs.
1818
#
1919
# @return [ Document ] The document.
20-
def set_mul(factors)
20+
def mul(factors)
2121
prepare_atomic_operation do |ops|
2222
process_atomic_operations(factors) do |field, value|
2323
factor = value.__to_inc__

spec/mongoid/contextual/atomic_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@
350350
end
351351
end
352352

353-
describe "#set_mul" do
353+
describe "#mul" do
354354

355355
let!(:depeche_mode) { Band.create!(likes: 60) }
356356
let!(:smiths) { Band.create! }
@@ -359,7 +359,7 @@
359359
let(:criteria) { Band.all }
360360
let(:context) { Mongoid::Contextual::Mongo.new(criteria) }
361361

362-
before { context.set_mul(likes: 10) }
362+
before { context.mul(likes: 10) }
363363

364364
context "when the field exists" do
365365

@@ -378,7 +378,7 @@
378378
context "when using the alias" do
379379

380380
before do
381-
context.set_mul(years: 2)
381+
context.mul(years: 2)
382382
end
383383

384384
it "muls the value and read from alias" do
@@ -400,7 +400,7 @@
400400

401401
let(:context) { Mongoid::Contextual::Mongo.new(criteria) }
402402

403-
before { context.set_mul(years: 2) }
403+
before { context.mul(years: 2) }
404404

405405
it "muls the value" do
406406
expect(depeche_mode.reload.years).to eq(6)

spec/mongoid/persistable/multipliable_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
describe Mongoid::Persistable::Multipliable do
66

7-
describe "#set_mul" do
7+
describe "#mul" do
88

99
context "when the document is a root document" do
1010

@@ -50,7 +50,7 @@
5050
context "when providing string fields" do
5151

5252
let!(:op) do
53-
person.set_mul("age" => 5, "score" => -5, "inte" => 30)
53+
person.mul("age" => 5, "score" => -5, "inte" => 30)
5454
end
5555

5656
it_behaves_like "a multipliable root document"
@@ -59,7 +59,7 @@
5959
context "when providing symbol fields" do
6060

6161
let!(:op) do
62-
person.set_mul(age: 5, score: -5, inte: 30)
62+
person.mul(age: 5, score: -5, inte: 30)
6363
end
6464

6565
it_behaves_like "a multipliable root document"
@@ -80,7 +80,7 @@
8080
end
8181

8282
let!(:op) do
83-
person.set_mul(age: positive, score: negative, inte: dynamic)
83+
person.mul(age: positive, score: negative, inte: dynamic)
8484
end
8585

8686
it_behaves_like "a multipliable root document"
@@ -135,7 +135,7 @@
135135
context "when providing string fields" do
136136

137137
let!(:op) do
138-
address.set_mul("number" => 5, "no" => -5, "house" => 30)
138+
address.mul("number" => 5, "no" => -5, "house" => 30)
139139
end
140140

141141
it_behaves_like "a multipliable embedded document"
@@ -144,7 +144,7 @@
144144
context "when providing symbol fields" do
145145

146146
let!(:op) do
147-
address.set_mul(number: 5, no: -5, house: 30)
147+
address.mul(number: 5, no: -5, house: 30)
148148
end
149149

150150
it_behaves_like "a multipliable embedded document"
@@ -165,7 +165,7 @@
165165
end
166166

167167
let!(:op) do
168-
address.set_mul(number: positive, no: negative, house: dynamic)
168+
address.mul(number: positive, no: negative, house: dynamic)
169169
end
170170

171171
it_behaves_like "a multipliable embedded document"
@@ -180,7 +180,7 @@
180180

181181
it "marks a dirty change for the multiplied fields" do
182182
person.atomically do
183-
person.set_mul age: 15, score: 2
183+
person.mul age: 15, score: 2
184184
expect(person.changes).to eq({"age" => [10, 150], "score" => [100, 200]})
185185
end
186186
end
@@ -201,7 +201,7 @@
201201

202202
it "persists the changes" do
203203
expect(person).to be_readonly
204-
person.set_mul(age: 15, score: 2)
204+
person.mul(age: 15, score: 2)
205205
expect(person.age).to eq(150)
206206
expect(person.score).to eq(200)
207207
end
@@ -217,7 +217,7 @@
217217
it "raises a ReadonlyDocument error" do
218218
expect(person).to be_readonly
219219
expect do
220-
person.set_mul(age: 15, score: 2)
220+
person.mul(age: 15, score: 2)
221221
end.to raise_error(Mongoid::Errors::ReadonlyDocument)
222222
end
223223
end

0 commit comments

Comments
 (0)