-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 hoc sequences in create_list #1650
base: main
Are you sure you want to change the base?
Add hoc sequences in create_list #1650
Conversation
That was fast!
There's a backward compatibility issue to figure out. Imagine this: class UserWithCallback
def initialize(name, dob, on_save)
@name = name
@dob = dob
@on_save = on_save
end
def save
user = User.create!(name: @name, dob: @dob)
@on_save.call(user)
end
end
FactoryBot.define do
factory :user_with_callback do
name { "Zero Cool" }
dob { "1988-08-10" }
on_save do
proc { |user| Logger.info("created user #{user}") }
end
end
end This is, currently, a valid factory_bot definition(*) for a valid Ruby class. Good code? Probably not. Possible? For sure. So we need to make sure this still works even if we add new functionality. For that reason, I think we might need a new class. (* I haven't tried it.) |
f5fbc18
to
213bd29
Compare
Yes right didn't consider that, thanks for raising it! |
Hello @mike-burns! I can see you are no longer maintaining this repository, Can you please tell me who should I follow up regarding this (and the other PR) |
You were quick to notice!
We're still collecting maintainers, but these people will be in charge: https://github.com/thoughtbot/factory_bot/pull/1651/files
May 23, 2024 08:18:44 Mohammed Nasser ***@***.***>:
…
Hello @mike-burns[https://github.com/mike-burns]! I can see you are no longer maintaining this repository, Can you please tell me who should I follow up regarding this (and the other PR[#1639])
(I am really sorry for being obtrusive, I am just keen to contribute here 😅 )
—
Reply to this email directly, view it on GitHub[#1650 (comment)], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AAABDRVLAZWMLS5EUSFS72LZDYCFFAVCNFSM6AAAAABHS4SI6CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRXGQYDINRQGE].
You are receiving this because you were mentioned.
[Tracking image][https://github.com/notifications/beacon/AAABDRTT6EKSRSGVAD6S3ETZDYCFFA5CNFSM6AAAAABHS4SI6CWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTT6ZWPDS.gif]
|
We're steadily getting up to speed 😅. Thanks in advance for your patience, @mohammednasser-32. |
context "with sequencial attributes" do | ||
subject { FactoryBot.create_list(:post, 20, title: FactoryBot.build_sequence{ |n| "title_#{n}" }) } | ||
|
||
it "create sequencial attribute values" do |
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.
it "create sequencial attribute values" do | |
it "creates sequential attribute values" do |
@@ -38,6 +38,16 @@ | |||
end | |||
end | |||
|
|||
context "with sequencial attributes" do |
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.
context "with sequencial attributes" do | |
context "with sequential attributes" do |
end | ||
|
||
def evaluate(index) | ||
expression.call(index) |
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.
I am curious to know what is the result if expression
is nil
? What is the default behaviour if a block is not given?
What do you think about adding an additional test for the default behaviour. Something like:
Credit: @gkosmo Open to a discussion about what the default behaviour should ideally be 🙂. |
Hey @smaboshe , thanks for the review 🙏
|
Fixes #1647
Allow creation of sequence attributes in
create_list
This PR is more of a proof of concept, if I get the green light I can add documentation and more tests if needed.
It is working and all tests pass, however I am not confident about the code structure..in this approach
FactoryBot.build_sequence
is just a syntactical sugar for aProc
, however it will work fine if we pass aProc
too. Is it better to have a dedicated class for this instead?