Commit 5d548151 authored by Jasper Maes's avatar Jasper Maes

Rails5: Passing a class as a value in an Active Record query is deprecated

parent 29d8179b
...@@ -58,7 +58,7 @@ class EventsFinder ...@@ -58,7 +58,7 @@ class EventsFinder
def by_target_type(events) def by_target_type(events)
return events unless Event::TARGET_TYPES[params[:target_type]] return events unless Event::TARGET_TYPES[params[:target_type]]
events.where(target_type: Event::TARGET_TYPES[params[:target_type]]) events.where(target_type: Event::TARGET_TYPES[params[:target_type]].name)
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -98,7 +98,7 @@ module Ci ...@@ -98,7 +98,7 @@ module Ci
scope :matches_tag_ids, -> (tag_ids) do scope :matches_tag_ids, -> (tag_ids) do
matcher = ::ActsAsTaggableOn::Tagging matcher = ::ActsAsTaggableOn::Tagging
.where(taggable_type: CommitStatus) .where(taggable_type: CommitStatus.name)
.where(context: 'tags') .where(context: 'tags')
.where('taggable_id = ci_builds.id') .where('taggable_id = ci_builds.id')
.where.not(tag_id: tag_ids).select('1') .where.not(tag_id: tag_ids).select('1')
...@@ -108,7 +108,7 @@ module Ci ...@@ -108,7 +108,7 @@ module Ci
scope :with_any_tags, -> do scope :with_any_tags, -> do
matcher = ::ActsAsTaggableOn::Tagging matcher = ::ActsAsTaggableOn::Tagging
.where(taggable_type: CommitStatus) .where(taggable_type: CommitStatus.name)
.where(context: 'tags') .where(context: 'tags')
.where('taggable_id = ci_builds.id').select('1') .where('taggable_id = ci_builds.id').select('1')
......
...@@ -86,7 +86,7 @@ module Avatarable ...@@ -86,7 +86,7 @@ module Avatarable
params[:model].upload_paths(params[:identifier]) params[:model].upload_paths(params[:identifier])
end end
Upload.where(uploader: AvatarUploader, path: paths).find_each do |upload| Upload.where(uploader: AvatarUploader.name, path: paths).find_each do |upload|
model = model_class.instantiate('id' => upload.model_id) model = model_class.instantiate('id' => upload.model_id)
loader.call({ model: model, identifier: File.basename(upload.path) }, upload) loader.call({ model: model, identifier: File.basename(upload.path) }, upload)
......
...@@ -45,7 +45,7 @@ module Todos ...@@ -45,7 +45,7 @@ module Todos
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def remove_confidential_issue_todos def remove_confidential_issue_todos
Todo.where( Todo.where(
target_id: confidential_issues.select(:id), target_type: Issue, user_id: user.id target_id: confidential_issues.select(:id), target_type: Issue.name, user_id: user.id
).delete_all ).delete_all
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -14,9 +14,9 @@ module Todos ...@@ -14,9 +14,9 @@ module Todos
def execute def execute
ProjectFeature.where(project_id: project_ids).each do |project_features| ProjectFeature.where(project_id: project_ids).each do |project_features|
target_types = [] target_types = []
target_types << Issue if private?(project_features.issues_access_level) target_types << Issue.name if private?(project_features.issues_access_level)
target_types << MergeRequest if private?(project_features.merge_requests_access_level) target_types << MergeRequest.name if private?(project_features.merge_requests_access_level)
target_types << Commit if private?(project_features.repository_access_level) target_types << Commit.name if private?(project_features.repository_access_level)
next if target_types.empty? next if target_types.empty?
......
---
title: 'Rails5: Passing a class as a value in an Active Record query is deprecated'
merge_request: 23164
author: Jasper Maes
type: other
...@@ -46,7 +46,7 @@ describe PendingTodosFinder do ...@@ -46,7 +46,7 @@ describe PendingTodosFinder do
create(:todo, :pending, user: user, target: note) create(:todo, :pending, user: user, target: note)
todos = described_class.new(user, target_type: issue.class).execute todos = described_class.new(user, target_type: issue.class.name).execute
expect(todos).to eq([todo]) expect(todos).to eq([todo])
end end
......
...@@ -226,7 +226,7 @@ describe Todo do ...@@ -226,7 +226,7 @@ describe Todo do
create(:todo, target: create(:merge_request)) create(:todo, target: create(:merge_request))
expect(described_class.for_type(Issue)).to eq([todo]) expect(described_class.for_type(Issue.name)).to eq([todo])
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment