-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
MONGOID-5173 Specs should use bang (!) methods as much as possible #5061
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Johnny,
Did you read (i.e. review) this diff? Green CI doesn't guarantee the tests are correct in that they are testing, for example, the desired functionality.
6c181f3
to
99f0e19
Compare
@p-mongo ready for your review. In some tests, only one of
By the way, in the process of making this PR I did find several places where models were not being saved as intended. The most common was Regarding this comment:
Except in a limited number of specific specs like |
@p-mongo this PR is going to continually generate conflicts as new PRs are merged so it would be ideal if we could merge it first. |
* master: Remove remaining encoding declarations (mongodb#5088) Add a more descriptive error when spec load fails (mongodb#5066) MONGOID-5191 Proper order for after_create callback (mongodb#5087) MONGOID-5189 Proper order of *_save callbacks (mongodb#5083) MONGOID-5098 Standardize/improve Range queries -- .where(field: 1..3) (mongodb#5025)
@comandeo let's merge this? |
…s-no-context-change' into MONGOID-5173-specs-bang-methods
* master: MONGOID-5173 Specs should use bang (!) methods (without describe/context change) (mongodb#5109) Fix doc syntax RUBY-2783 Require bson 4-stable for Mongoid as bson master is 5.0 and not compatible with driver (mongodb#5113) MONGOID-5208 fix error on reloading nil embedded document (mongodb#5116) MONGOID-5206 fix bug where embedded document is not re-embedded (mongodb#5115) MONGOID-5207 Add Ruby 3.1 to GH Actions (mongodb#5114) MONGOID-5207 Use YAML.safe_load in specs (mongodb#5112) MONGOID-5199 Reloadable#reload_embedded_document doesn't respect session (mongodb#5105) Fix MONGOID-5198 Calling children_changed? on a deep cyclical data structure will cause semi-infinite looping (mongodb#5104)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of this PR seems to only affect update_attributes
. It looks like we currently only have tests for update_attributes
and not update_attributes!
, so perhaps both should be minimally covered?
@@ -296,7 +296,7 @@ | |||
# no conflicts. | |||
#expect(truck.atomic_updates[:conflicts]).to eq nil | |||
|
|||
expect { truck.save! }.not_to raise_error | |||
expect(truck.save).to eq true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johnnyshields I am having difficulty understanding the changes in this file, could you explain them please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect { truck.save! }.not_to raise_error
is equivalent to:
expect(truck.save).to eq true
Both statements verify the document saved successfully. The latter syntax more clearly expresses the intention of the spec in this case: we are specifically testing that the document was saved.
@p-mongo is my comment here sufficient to merge? Tests are green... |
* master: MONGOID-5098 Bug fix: Range.mongoize should mongoize its members (mongodb#5108) MONGOID-5212 Support for Decimal128 type (mongodb#5125) MONGOID-5213 Document changes to BigDecimal type and addition of global flag (mongodb#5126) MONGOID-5209 Document "Custom Field Options" functionality + various docs improvements (mongodb#5120) MONGOID-5193 rails 7 support (mongodb#5122) Fix default topology name - should be standalone (mongodb#5130) Update MRSS (mongodb#5129) MONGOID-5207 Test Ruby 3.1 on Evergreen (mongodb#5123) MONGOID-5186 .with_scope should restore previous scope (mongodb#5127) MONGOID-5161 - [Documentation Only] Clarify the policy for working with . and $ named fields which were introduced in MongoDB 5.0 (mongodb#5051)
…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>
Bang methods .create!, .save!, and .update_attributes! ensure that the methods actually persisted to the DB and do not have silent failures. They will raise an error (which will make test red) if they fail.
Follow-up from conversation in #5029