Skip to content
New issue

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

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

Already on GitHub? # to your account

BugFix: Ensure callbacks only run once per instance. #1712

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

CodeMeister
Copy link
Contributor

@CodeMeister CodeMeister commented Nov 4, 2024

Fixes: #1703

CallbacksObserver refactored to ignore an individual callback that has already been run on the given instance.

EXAMPLE

factory :user do
  name { "Jane" }

  trait :trait_a do
    trait_b
  end

  trait :trait_b do
    after(:build) { |user| user.name += " Doe" }
  end
end

user = build(:user, :trait_a, :trait_b)

BEFORE:
user.name #=> "Jane Doe Doe"

AFTER:
user.name #=> "Jane Doe"

See issue: #1703 for the full issue.

CallbacksObserver refactored to ignore an individual
callback that has already been run on the given instance.

EXAMPLE

factory :user do
  name { "Jane" }

  trait :trait_a do
    trait_b
  end

  trait :trait_b do
    after(:build) { |user| user.name += " Doe" }
  end
end

user = build(:user, :trait_a, :trait_b)

BEFORE:
user.name #=> "Jane Doe Doe"

AFTER:
user.name #=> "Jane Doe"
@CodeMeister CodeMeister changed the title Ensure callbacks only run once per instance. BugFix: Ensure callbacks only run once per instance. Nov 5, 2024
@neilvcarvalho neilvcarvalho requested review from neilvcarvalho and removed request for smaboshe January 31, 2025 13:06
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Traits that imply other ones can cause double running of callbacks
1 participant