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

Ability to specify multiple contexts when defining a validation. #13754

Merged
merged 1 commit into from Jan 27, 2014

Conversation

Projects
None yet
6 participants
@vpuzzella
Contributor

vpuzzella commented Jan 18, 2014

Example:

validates_presence_of :name, on: [:update, :custom_validation_context]

@vpuzzella

This comment has been minimized.

Show comment
Hide comment
@vpuzzella

vpuzzella Jan 18, 2014

Contributor

This was requested in #9659, but I think it was closed by mistake.

Contributor

vpuzzella commented Jan 18, 2014

This was requested in #9659, but I think it was closed by mistake.

@robin850

View changes

Show outdated Hide outdated activemodel/lib/active_model/validations.rb
@robin850

View changes

Show outdated Hide outdated activemodel/lib/active_model/validations.rb
@robin850

View changes

Show outdated Hide outdated activemodel/test/cases/validations/validations_context_test.rb
@rbarazi

This comment has been minimized.

Show comment
Hide comment
@rbarazi

rbarazi commented Jan 19, 2014

👍

@senny

View changes

Show outdated Hide outdated activemodel/test/cases/validations/validations_context_test.rb
@@ -1,3 +1,11 @@
* Ability to specify multiple contexts when defining a validation.

This comment has been minimized.

@senny

senny Jan 20, 2014

Member

Can you add Example: before the example code? See other entries for reference.

@senny

senny Jan 20, 2014

Member

Can you add Example: before the example code? See other entries for reference.

This comment has been minimized.

@vpuzzella

vpuzzella Jan 20, 2014

Contributor

Example added to changelog.

@vpuzzella

vpuzzella Jan 20, 2014

Contributor

Example added to changelog.

@robin850

This comment has been minimized.

Show comment
Hide comment
@robin850

robin850 Jan 25, 2014

Member

@vpuzzella : For future contributions, could you post a comment once your patch is updated please ? :-) GitHub does not create notifications when you push the commit. Thank you!

This looks good to me so far!

Member

robin850 commented Jan 25, 2014

@vpuzzella : For future contributions, could you post a comment once your patch is updated please ? :-) GitHub does not create notifications when you push the commit. Thank you!

This looks good to me so far!

@vpuzzella

This comment has been minimized.

Show comment
Hide comment
@vpuzzella

vpuzzella Jan 25, 2014

Contributor

@robin850, will do. At this point I feel the patch is complete. Is there anything else required in order to have the PR accepted?

Contributor

vpuzzella commented Jan 25, 2014

@robin850, will do. At this point I feel the patch is complete. Is there anything else required in order to have the PR accepted?

@robin850

This comment has been minimized.

Show comment
Hide comment
@robin850

robin850 Jan 25, 2014

Member

@vpuzzella : Thanks! Everything seems fine to me but I'm not a merger, this decision is up to @senny.

Member

robin850 commented Jan 25, 2014

@vpuzzella : Thanks! Everything seems fine to me but I'm not a merger, this decision is up to @senny.

@senny

This comment has been minimized.

Show comment
Hide comment
@senny

senny Jan 27, 2014

Member

@vpuzzella the PR does no longer apply and needs a rebase.

Member

senny commented Jan 27, 2014

@vpuzzella the PR does no longer apply and needs a rebase.

Ability to specify multiple contexts when defining a validation.
Example:

validates_presence_of :name, on: [:update, :custom_validation_context]
@vpuzzella

This comment has been minimized.

Show comment
Hide comment
@vpuzzella

vpuzzella Jan 27, 2014

Contributor

@senny, rebased and CI build passing.

Contributor

vpuzzella commented Jan 27, 2014

@senny, rebased and CI build passing.

carlosantoniodasilva added a commit that referenced this pull request Jan 27, 2014

Merge pull request #13754 from vpuzzella/master
Ability to specify multiple contexts when defining a validation.

@carlosantoniodasilva carlosantoniodasilva merged commit 50d9717 into rails:master Jan 27, 2014

1 check passed

default The Travis CI build passed
Details
@carlosantoniodasilva

This comment has been minimized.

Show comment
Hide comment
@carlosantoniodasilva
Member

carlosantoniodasilva commented Jan 27, 2014

Thanks.

@pierre-pretorius

This comment has been minimized.

Show comment
Hide comment
@pierre-pretorius

pierre-pretorius Jun 6, 2014

This feature is very useful thank you. I have the following suggestion: when someone specifies a validation with context :save, it should be called for :create and :update.

For example, if you have two steps, the first step someone needs to enter his name, the second step his lastname, but it should only be able to save if name, surname and token is populated, you currently have to do it like this:

validates :name, presence: true, on: [:create, :update, :step1]
validates :lastname, presence: true, on: [:create, :update, :step2]
validates :token, presence: true, on: [:create, :update]

It would be much simpler if you could write it as:

validates :name, presence: true, on: [:save, :step1]
validates :lastname, presence: true, on: [:save, :step2]
validates :token, presence: true, on: :save

In fact, consider the how callbacks are specified (before_save, before_create, before_update) this actually seems like a bug.

pierre-pretorius commented Jun 6, 2014

This feature is very useful thank you. I have the following suggestion: when someone specifies a validation with context :save, it should be called for :create and :update.

For example, if you have two steps, the first step someone needs to enter his name, the second step his lastname, but it should only be able to save if name, surname and token is populated, you currently have to do it like this:

validates :name, presence: true, on: [:create, :update, :step1]
validates :lastname, presence: true, on: [:create, :update, :step2]
validates :token, presence: true, on: [:create, :update]

It would be much simpler if you could write it as:

validates :name, presence: true, on: [:save, :step1]
validates :lastname, presence: true, on: [:save, :step2]
validates :token, presence: true, on: :save

In fact, consider the how callbacks are specified (before_save, before_create, before_update) this actually seems like a bug.

@pierre-pretorius

This comment has been minimized.

Show comment
Hide comment
@pierre-pretorius

pierre-pretorius Jun 24, 2014

@vpuzzella Any comments on my suggestion above?

pierre-pretorius commented Jun 24, 2014

@vpuzzella Any comments on my suggestion above?

@robin850

This comment has been minimized.

Show comment
Hide comment
@robin850

robin850 Jun 25, 2014

Member

@pierre-pretorius : Please post feature requests to the rails-core mailing list or send a patch (unless I'm wrong, this seems straightforward here) ; thank you! :-)

Member

robin850 commented Jun 25, 2014

@pierre-pretorius : Please post feature requests to the rails-core mailing list or send a patch (unless I'm wrong, this seems straightforward here) ; thank you! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment