ActiveRecord::QueryMethods#where_values_hash to include NotEqual wheres?


For testing purposes I’d say it would be useful to have #where_values_hash return the not conditions too in either:

  • a separate method (#where_not_values_hash),

  • by modifying the currently returned hash’s structure from #where_values_hash.

Relevant code parts

Current Rails 4.2.5 implementation -

Current Rails 5.x.x implementation -


Example that returns not conditions in #where_values_hash :

> User.where(active: true).where.not(name: 'joe').where_values_hash

=> {"positive" => {"active": true}, "negative" => {"name": "joe"} }

Example that returns not conditions in new method #where_not_values_hash:

> User.where(active: true).where.not(name: 'joe').where_not_values_hash

=> {"name": "joe"}


If you agree with this idea, I’ll gladly work on a PR.