You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These are two specs that describe the behavior we had with discard 1.0.0:
describe'discarded? value on callbacks/validations'dowith_model:Post,scope: :alldotabledo |t|
t.datetime:discarded_att.timestampsnull: falseendmodeldoincludeDiscard::Modelvalidate:validate_something,if: :discarded?before_discard:do_before_discard,if: :discarded?defvalidate_something;enddefdo_before_discard;endendendlet!(:post){Post.create!}it"runs validations with if: :discarded?"doexpect(post).toreceive(:validate_something)expect(post.discard).tobetrueexpect(post).tobe_discardedendit"does not run callbacks with if: :discarded?"doexpect(post).to_notreceive(:do_before_discard)expect(post.discard).tobetrueexpect(post).tobe_discardedendend
and in 1.1.0 the validation spec fails with:
1) Discard::Model discarded? value on callbacks runs validations with if: :discarded?
Failure/Error: expect(post).to receive(:validate_something)
(#<Post id: 1, discarded_at: "2019-05-08 10:52:56", created_at: "2019-05-08 10:52:56", updated_at: "2019-05-08 10:52:56">).validate_something(*(any args))
expected: 1 time with any arguments
received: 0 times with any arguments
# ./spec/discard/model_spec.rb:24:in `block (3 levels) in <top (required)>'
so the validations are no more called if you use if: :discarded?, differently from the previous version.
I think version 1.1.0 is more consistent with what happens for callbacks, like before_save, since in that case they are not called either.
Not sure if there is a specific reason behind that and I'm not sure if this could be considered a regression since this specific scenario is not documented anywhere.
The text was updated successfully, but these errors were encountered:
I think this is an enhancement, but one that should have been considered a breaking change and warranted a major version bump. I'm leaning towards keeping this behaviour, possibly testing it, and regretting that I didn't realize that this change broke things.
I'll also leave this issue open so that I can either document and potential test this behaviour to avoid regressions or changes to it.
I'm trying to understand an issue we have on Solidus: solidusio/solidus#3202.
These are two specs that describe the behavior we had with discard 1.0.0:
and in 1.1.0 the validation spec fails with:
so the validations are no more called if you use
if: :discarded?
, differently from the previous version.I think version
1.1.0
is more consistent with what happens for callbacks, likebefore_save
, since in that case they are not called either.Not sure if there is a specific reason behind that and I'm not sure if this could be considered a regression since this specific scenario is not documented anywhere.
The text was updated successfully, but these errors were encountered: