Project

General

Profile

« Previous | Next » 

Revision 02e4c535

Added by Daniel Lobato Garcia over 8 years ago

Fixes #11924 - Substitute .scoped by .where(nil) to force return relation

On Rails 4 .scoped is deprecated. Calling .all on the model returns the
equivalent ActiveRecord relation object on Rails 4, but on Rails 3 it
returns an Array right away.

A proper replacement we can use is where(nil) - it's ugly but it returns
the same relation in both Rails 3 and 4. There are a couple of fixes too
on models such as bookmark.rb which return where conditions ({} and
similar) instead of a relation, which is also a deprecated behavior.

We could possibly substitute these by .all after the Rails 4 migration
if they feel too 'unidiomatic'.

View differences:

db/migrate/20150521121315_rename_config_template_to_provisioning_template.rb
old_name = 'ConfigTemplate'
new_name = 'ProvisioningTemplate'
Template.update_all "type = '#{new_name}'", "type = '#{old_name}'"
Audit.update_all "auditable_type = '#{new_name}'", "auditable_type = '#{old_name}'"
TaxableTaxonomy.update_all "taxable_type = '#{new_name}'", "taxable_type = '#{old_name}'"
Permission.update_all "resource_type = '#{new_name}'", "resource_type = '#{old_name}'"
Template.where(:type => old_name).update_all(:type => new_name)
Audit.where(:auditable_type => old_name).update_all(:auditable_type => new_name)
TaxableTaxonomy.where(:taxable_type => old_name).update_all(:taxable_type => new_name)
Permission.where(:resource_type => old_name).update_all(:resource_type => new_name)
PERMISSIONS.each do |from|
to = from.sub('templates', 'provisioning_templates')
say "renaming permission #{from} to #{to}"
Permission.update_all "name = '#{to}'", "name = '#{from}'"
Permission.where(:name => from).update_all(:name => to)
end
if foreign_keys('os_default_templates').find { |f| f.options[:name] == 'os_default_templates_config_template_id_fk' }.present?
......
PERMISSIONS.each do |to|
from = to.sub('provisioning_templates', 'templates')
say "renaming permission #{from} to #{to}"
Permission.update_all "name = '#{to}'", "name = '#{from}'"
Permission.where(:name => from).update_all(:name => to)
end
old_name = 'ConfigTemplate'
new_name = 'ProvisioningTemplate'
Template.update_all "type = '#{old_name}'", "type = '#{new_name}'"
Audit.update_all "auditable_type = '#{old_name}'", "auditable_type = '#{new_name}'"
TaxableTaxonomy.update_all "taxable_type = '#{old_name}'", "taxable_type = '#{new_name}'"
Permission.update_all "resource_type = '#{old_name}'", "resource_type = '#{new_name}'"
Template.where(:type => new_name).update_all(:type => old_name)
Audit.where(:auditable_type => new_name).update_all(:auditable_type => old_name)
TaxableTaxonomy.where(:taxable_type => new_name).update_all(:taxable_type => old_name)
Permission.where(:resource_type => new_name).update_all(:resource_type => old_name)
end
end

Also available in: Unified diff