ryanb / cancan

Authorization Gem for Ruby on Rails.
MIT License
6.27k stars 783 forks source link

DEPRECATION WARNING: Model.scoped is deprecated. Please use Model.all instead. #951

Open mattangriffel opened 10 years ago

mattangriffel commented 10 years ago

Is anyone else getting this annoying deprecation warning everywhere in their tests?

DEPRECATION WARNING: Model.scoped is deprecated. Please use Model.all instead. (called from set_accessible_courses at /Users/mgriffel/code/one_month_rails/app/controllers/application_controller.rb:41)

Here's what the relevant parts of my my application_controller look like:

before_filter :set_accessible_courses

  private

    # Sets courses to be looped over in header
    def set_accessible_courses
      @accessible_courses ||= Course.accessible_by(current_ability)
    end
mhw commented 10 years ago

Yes, I get that too. It's caused by the use of Model.scoped in lib/cancan/model_adapters/active_record_adapter.rb in the database_records method, but I'm not sure what the correct fix would be.

mattangriffel commented 10 years ago

@hitendrasingh line 101 still throws a deprecation warning:

@model_class.scoped.merge(override_scope)

Can't figure out how to get around this since @model_class.all returns an Array in < 1.9.3 and an ActiveRecord::Relation in > 2.0.0. The merge method doesn't work on arrays.

thejchap commented 10 years ago

Seems to be solved by

@model_class.where(nil).merge(override_scope)

Just opened PR #992