-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add options to PromotionCode::BatchBuilder and spec for unique promotion code contention #2579
Add options to PromotionCode::BatchBuilder and spec for unique promotion code contention #2579
Conversation
delegate attr, to: self | ||
end | ||
|
||
def initialize(promotion_code_batch, options={}) |
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.
Surrounding space missing in default value assignment.
fe2584f
to
0d44f96
Compare
Failure should be fixed by #2580 |
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.
Besides a small nit. Nice 👍
define_singleton_method(:"#{attr}=") do |val| | ||
Spree::Deprecation.warn "#{name}.#{attr}= is deprecated. Use #{name}::DEFAULT_OPTIONS[:#{attr}]= instead" | ||
DEFAULT_OPTIONS[attr] = val | ||
end |
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.
👍nice
@promotion_code_batch = promotion_code_batch | ||
@options = DEFAULT_OPTIONS.merge(options) |
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.
Not necessary, but could we use a attr_reader for @options? Consistency
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.
Agree with @tvdeyen , attr_reader
for @options
will make this class more consistent.
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.
Same, not necessary, note as @tvdeyen. The rest is great, thanks!
@promotion_code_batch = promotion_code_batch | ||
@options = DEFAULT_OPTIONS.merge(options) |
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.
Agree with @tvdeyen , attr_reader
for @options
will make this class more consistent.
This deprecates the existing class-attributes in favour of having a defaults option hash. This allows creating instances of BatchBuilder with different rules than the defaults. This makes testing different rules a lot easier and may allow for per-batch settings in the future.
Previously we had an issue where BatchBuilder would create the wrong number of promotion codes if it encountered a conflict. Out specs didn't catch this. This commit adds an additional spec which runs the BatchBuilder with settings that make it extremely likely that there will a conflict: from a space of 100 possible codes (00 to 99) we generate 50. An online birthday problem calculator tells me this is 99.99997% likely that the generator will encounter at least one conflict. That seems plenty. I haven't verified this, but intuitively it seems very likely.
77a5319
to
17f0ef0
Compare
The issue fixed by #2578 wasn't caught by our specs. It was hard to write a spec to test that issue because the
PromotionCode::BatchBuilder
was configured byclass_attribute
s.This PR deprecates the existing class-attributes in favour of having a defaults option hash.
It uses this to add an additional spec which runs the BatchBuilder with settings that make it extremely likely that there will a conflict: from a space of 100 possible codes (
00
to99
) we generate 50.An online birthday problem calculator tells me this is 99.99997% likely that the generator will encounter at least one conflict. That seems plenty. I haven't verified this, but intuitively it seems very likely.
This would have caught the issue prior to #2578