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:

app/models/role.rb
audited :allow_mass_assignment => true
scope :givable, -> { where(:builtin => 0).order(:name) }
scope :for_current_user, -> { User.current.admin? ? {} : where(:id => User.current.role_ids) }
scope :for_current_user, -> { User.current.admin? ? where('0 != 0') : where(:id => User.current.role_ids) }
scope :builtin, lambda { |*args|
compare = 'not' if args.first
where("#{compare} builtin = 0")

Also available in: Unified diff