Refactor #13971
Change model.exists?(record) and .find(record) to use IDs
Description
Rails 4.2 contains the following deprecation:
Deprecated passing Active Record objects to .find or .exists?. Call id on the objects first.
(http://edgeguides.rubyonrails.org/4_2_release_notes.html#active-record-deprecations)
This causes:
> Domain.find(Domain.first)
2016-03-01T12:35:12 [app] [W] DEPRECATION WARNING: You are passing an instance of ActiveRecord::Base to `find`. Please pass the id of the object by calling `.id`. (called from irb_binding at (irb):1)
All instances where we pass objects into .find etc, mostly in tests, need to be changed to call .id.
This happens a lot in functional tests when a User is passed into the session object, e.g.
delete :destroy, {:id => user}, set_session_user.merge(:user => users(:admin))
causes
DEPRECATION WARNING: You are passing an instance of ActiveRecord::Base to `find`. Please pass the id of the object by calling `.id`. (called from authenticate at /home/dcleal/code/foreman/foreman/app/controllers/concerns/foreman/controller/authentication.rb:10)
Associated revisions
History
#1
Updated by The Foreman Bot about 6 years ago
- Status changed from Assigned to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/3256 added
#2
Updated by Dominic Cleal about 6 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset 331fcdca2550c46fbe7e451039ca6aa6a4859044.
#3
Updated by Dominic Cleal about 6 years ago
- Legacy Backlogs Release (now unused) set to 136
fixes #13971 - pass IDs to model.find and .exists?
AR objects should not be passed to .exists? or .find, the ID should be
given instead. Passing AR objects is deprecated in Rails 4.2.