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:

test/unit/provisioning_template_test.rb
test '#preview_host_collection obeys view_hosts permission' do
provisioning_template = FactoryGirl.build(:provisioning_template)
Host.expects(:authorized).with(:view_hosts).returns(Host.scoped)
Host.expects(:authorized).with(:view_hosts).returns(Host.where(nil))
provisioning_template.preview_host_collection
end

Also available in: Unified diff