4

I have a problem that CanCan (in past and CanCanCan now) adds some strange SQL code to queries in tests.

My models:

class Company < ActiveRecord::Base
  has_many :machines,           dependent: :destroy
end

class Machine < ActiveRecord::Base
  belongs_to :company
end

And I have CanCanCan abilities:

can :manage, :all
cannot [:manage, :read], Machine
can [:manage, :read], Machine, company_id: user.company_id
# other abilities also described as cannot / can pairs (legacy code) 

If I run code snippet:

user.company_id 
> 170
puts Machine.accessible_by(Ability.new(user)).to_sql

In development/production I have:

SELECT "machines".* FROM "machines" WHERE "company_id" = 170

In specs:

SELECT "machines".* FROM "machines"  WHERE ('t'='f')

Other abilities works well (except models that belongs to machine).

Maybe I must add some other information - than ask please.

UPD: Adding :index to #accessible_by do not help:

puts Machine.accessible_by(Ability.new(user), :index).to_sql

CanCanCan v1.10.1

Sergey Vernidub
  • 422
  • 5
  • 14

0 Answers0