1

尝试使用can?方法和存根当前能力。

class UserDecorator < Draper::Decorator
  delegate_all

  def some_helper
    can? :read, object
  end
end
RSpec.describe UserDecorator, type: :decorator do
  before { allow(subject).to receive(:current_ability) { Ability.new } }
  subject { User.new.decorate }
  it { subject.some_helper }
end

但我得到错误:user does not implement: current_ability.

4

0 回答 0