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

Check :scope input in Uniqueness validator #30214

Merged
merged 1 commit into from Aug 14, 2017

Conversation

Projects
None yet
4 participants
@kirs
Member

kirs commented Aug 12, 2017

Fixes #30156

This patch adds validation for :scope option of the Uniqueness validator.
Without this patch, calling something like validates_uniqueness_of :code, :scope => [:archived => false] would cause NoMethodError with a trace into AR internals.

@rails-bot

This comment has been minimized.

Show comment
Hide comment
@rails-bot

rails-bot Aug 12, 2017

r? @schneems

(@rails-bot has picked a reviewer for you, use r? to override)

rails-bot commented Aug 12, 2017

r? @schneems

(@rails-bot has picked a reviewer for you, use r? to override)

@@ -8,6 +8,10 @@ def initialize(options)
raise ArgumentError, "#{options[:conditions]} was passed as :conditions but is not callable. " \
"Pass a callable instead: `conditions: -> { where(approved: true) }`"
end
unless Array(options[:scope]).all? { |scope| scope.respond_to?(:to_sym) }

This comment has been minimized.

@kirs

kirs Aug 12, 2017

Member

This check is called on boot time when the code is loaded.

@kirs

kirs Aug 12, 2017

Member

This check is called on boot time when the code is loaded.

Show outdated Hide outdated activerecord/lib/active_record/validations/uniqueness.rb
@kirs

This comment has been minimized.

Show comment
Hide comment
@kirs

kirs Aug 13, 2017

Member

Thanks, updated the error message.

Member

kirs commented Aug 13, 2017

Thanks, updated the error message.

@rafaelfranca rafaelfranca merged commit 509dfdc into rails:master Aug 14, 2017

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
codeclimate All good!
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment