diff options
author | Kir Shatrov <shatrov@me.com> | 2017-08-12 21:11:58 +0300 |
---|---|---|
committer | Kir Shatrov <shatrov@me.com> | 2017-08-13 19:39:55 +0300 |
commit | 883b2a8ceef5dc23cfb6ea60a616c93c3dbc0fd1 (patch) | |
tree | ee2e6967661afa0c67ee28e2a6d3b7e59a86eba6 /activerecord/lib | |
parent | 98360a96cc1e0bb6ab9eb31f421a36439e66eefc (diff) | |
download | rails-883b2a8ceef5dc23cfb6ea60a616c93c3dbc0fd1.tar.gz rails-883b2a8ceef5dc23cfb6ea60a616c93c3dbc0fd1.tar.bz2 rails-883b2a8ceef5dc23cfb6ea60a616c93c3dbc0fd1.zip |
Check :scope input in Uniqueness validator
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/validations/uniqueness.rb | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb index 2677fade18..baeb653c61 100644 --- a/activerecord/lib/active_record/validations/uniqueness.rb +++ b/activerecord/lib/active_record/validations/uniqueness.rb @@ -8,6 +8,10 @@ module ActiveRecord 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) } + raise ArgumentError, "#{options[:scope]} is not supported format for :scope option. " \ + "Pass a symbol or an array of symbols instead: `scope: :user_id`" + end super({ case_sensitive: true }.merge!(options)) @klass = options[:class] end |