Callback collision #269

Closed
wants to merge 3 commits into
from

Conversation

Projects
None yet
5 participants

Add unit test to demonstrate issue with similar callback methods overriding each other in distinct contexts

phene commented Apr 14, 2011

I think this also affects after_commit callbacks. Should we add a test for that, too?

@ghost ghost assigned josevalim May 7, 2011

Contributor

bgentry commented May 11, 2011

Can we please get this merged in prior to the 3.1 release?

Contributor

josevalim commented May 11, 2011

Thanks for the patch with the fix but it does not make sense to hardcode options[:on]. The :on option just makes sense for a few callbacks and does not belong conceptually in AS::Callbacks. I am still unsure on how to properly solve the issue. Maybe we should allow :on to receive an array?

Contributor

bgentry commented May 11, 2011

I would be even happier if I could do :on => [ :create, :update ]

Contributor

josevalim commented May 11, 2011

@bgentry that is easier to implement. You just need to rewrite this:

https://github.com/rails/rails/blob/master/activemodel/lib/active_model/validations.rb#L136

As something like:

options[:if].unshift("#{Array.wrap(options[:on]).inspect}.include?(validation_context)")

Also in a couple other places like:

https://github.com/rails/rails/blob/master/activemodel/lib/active_model/validations/callbacks.rb
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/transactions.rb

@josevalim- I agree that hard coding :on is not appropriate. How about instead of white listing options that imply difference, we black list options that determine equivalence.

Contributor

josevalim commented May 12, 2011

@mandrews I believe black listing would work fine. +1

Member

sikachu commented Jun 15, 2011

Note: the target of this commit is currently goes to 3.0.6, which is so old. I believe there's no way to change it, so maybe @josevalim can merge it into master instead.

I believe this is a bugfix, so targets are for 3-0-stable, 3-0-9, 3-1-stable and master. And please don't forget the CHANGELOG entry. ;)

I rebased to master, ran the unit tests and created a new pull request:
#1777

Contributor

josevalim commented Jun 28, 2011

Closed in favor of #1777

@josevalim josevalim closed this Jun 28, 2011

@mandrews mandrews referenced this pull request Sep 20, 2012

Closed

Callback collision #1777

hisas pushed a commit to hisas/rails that referenced this pull request May 9, 2017

Merge pull request #269 from amatsuda/string_blank
define String#blank? only if not defined yet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment