Skip to content

MONGOID-5173 Specs should use bang (!) methods as much as possible #5061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions spec/integration/callbacks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
end
end

context 'when updating top-level document via #update_attributes' do
context 'when updating top-level document via #update_attributes!' do
let!(:instance) do
Galaxy.create!
end
Expand All @@ -166,15 +166,15 @@

context 'set as a document instance' do
before do
instance.update_attributes(stars: [Star.new])
instance.update_attributes!(stars: [Star.new])
end

include_examples 'persists the attribute value'
end

context 'set as attributes on parent' do
before do
instance.update_attributes(stars: [{}])
instance.update_attributes!(stars: [{}])
end

include_examples 'persists the attribute value'
Expand All @@ -196,15 +196,15 @@

context 'set as a document instance' do
before do
instance.update_attributes(stars: [Star.new(planets: [Planet.new])])
instance.update_attributes!(stars: [Star.new(planets: [Planet.new])])
end

include_examples 'persists the attribute value'
end

context 'set as attributes on parent' do
before do
instance.update_attributes(stars: [planets: [{}]])
instance.update_attributes!(stars: [planets: [{}]])
end

include_examples 'persists the attribute value'
Expand Down
30 changes: 15 additions & 15 deletions spec/mongoid/attributes/nested_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4304,7 +4304,7 @@ class BandWithAllowDestroyedRecords < Band
end
end

describe "#update_attributes" do
describe "#update_attributes!" do

before do
Person.send(:undef_method, :addresses_attributes=)
Expand Down Expand Up @@ -4337,7 +4337,7 @@ class BandWithAllowDestroyedRecords < Band
end

before do
node.update_attributes(attributes)
node.update_attributes!(attributes)
end

it "adds the new embedded document" do
Expand Down Expand Up @@ -4369,7 +4369,7 @@ class BandWithAllowDestroyedRecords < Band
end

before do
person.update_attributes(attributes)
person.update_attributes!(attributes)
end

it "removes the document from the parent" do
Expand Down Expand Up @@ -4420,7 +4420,7 @@ class BandWithAllowDestroyedRecords < Band
end

before do
address.update_attributes(attributes)
address.update_attributes!(attributes)
address.reload
end

Expand Down Expand Up @@ -4463,7 +4463,7 @@ class BandWithAllowDestroyedRecords < Band
end

before do
person_one.update_attributes(attributes)
person_one.update_attributes!(attributes)
end

it "deletes the document from the relation" do
Expand Down Expand Up @@ -4513,7 +4513,7 @@ class BandWithAllowDestroyedRecords < Band
end

before do
band.update_attributes(attributes)
band.update_attributes!(attributes)
end

it "removes the child from the relation" do
Expand Down Expand Up @@ -4546,7 +4546,7 @@ class BandWithAllowDestroyedRecords < Band
end

before do
person.update_attributes(attributes)
person.update_attributes!(attributes)
end

let(:address) do
Expand Down Expand Up @@ -4586,7 +4586,7 @@ class BandWithAllowDestroyedRecords < Band
end

before do
person.update_attributes(attributes)
person.update_attributes!(attributes)
person.reload
end

Expand Down Expand Up @@ -4617,7 +4617,7 @@ class BandWithAllowDestroyedRecords < Band
end

before do
person.update_attributes(attributes)
person.update_attributes!(attributes)
end

let(:address) do
Expand Down Expand Up @@ -4666,7 +4666,7 @@ class BandWithAllowDestroyedRecords < Band
end

before do
person.update_attributes(attributes)
person.update_attributes!(attributes)
end

it "updates the first level embedded document" do
Expand Down Expand Up @@ -4706,7 +4706,7 @@ class BandWithAllowDestroyedRecords < Band
end

before do
person.update_attributes(attributes)
person.update_attributes!(attributes)
end

it "updates the first level embedded document" do
Expand Down Expand Up @@ -4742,7 +4742,7 @@ class BandWithAllowDestroyedRecords < Band
end

before do
person.update_attributes(attributes)
person.update_attributes!(attributes)
end

it "updates the nested embedded document" do
Expand All @@ -4769,7 +4769,7 @@ class BandWithAllowDestroyedRecords < Band
end

before do
user.update_attributes(params)
user.update_attributes!(params)
end

around do |example|
Expand Down Expand Up @@ -4891,7 +4891,7 @@ class BandWithAllowDestroyedRecords < Band
end

before do
league.update_attributes(params)
league.update_attributes!(params)
end

it "sets the nested attributes" do
Expand All @@ -4911,7 +4911,7 @@ class BandWithAllowDestroyedRecords < Band
end

before do
league.update_attributes(new_params)
league.update_attributes!(new_params)
end

it "sets the nested attributes" do
Expand Down
12 changes: 6 additions & 6 deletions spec/mongoid/clients_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -791,11 +791,11 @@
end
end

describe ".create" do
describe ".create!" do

let!(:band) do
Band.with(database: database_id_alt) do |klass|
klass.create
klass.create!
end
end

Expand Down Expand Up @@ -829,11 +829,11 @@

context "when sending operations to a different collection" do

describe ".create" do
describe ".create!" do

let!(:band) do
Band.with(collection: "artists") do |klass|
klass.create
klass.create!
end
end

Expand Down Expand Up @@ -944,7 +944,7 @@
describe ".save" do

before do
Person.create(ssn: "432-97-1113")
Person.create!(ssn: "432-97-1113")
end

context "when a mongodb error occurs" do
Expand Down Expand Up @@ -1037,7 +1037,7 @@
end

let!(:band) do
Band.create(name: "Tool")
Band.create!(name: "Tool")
end

it "persists to the overridden database" do
Expand Down
18 changes: 18 additions & 0 deletions spec/mongoid/persistable/updatable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -739,4 +739,22 @@
end
end
end

describe "#update_attributes!" do

let(:person) do
Person.create!
end

let(:attributes) do
{ security_code: 'secret' }
end

it 'calls update_attributes' do
person.should receive(:update_attributes).with(attributes).and_call_original
lambda do
person.update_attributes!(attributes)
end.should_not raise_error
end
end
end