Rspec为能力模型

时间:2017-07-18 08:40:11

标签: ruby-on-rails rspec rspec-rails

class Ability
  include CanCan::Ability

  def initialize(user)
    if user.type == 'ABCD' && user.type_sec == 'ADMIN'
      can :manage, Data
      can :manage, Bills
      can :manage, Cash
      can :manage, Booklets
    elsif user.type == 'ABCD' && user.type_sec == 'USER' then
      can :manage, Data
      can :manage, Bills
    end
  end 
end

这是我的能力模型,我正在寻找这个模型的rspec,我试过

context "abcd admin" do
  let(:user) { create :user, :abcd_admin }
  it "can manage" do
    initialize(user)
    user.can?(:manage, Data).should be_true
    user.can?(:manage, Bills).should be_true
    user.can?(:manage, Cash).should be_true
    user.can?(:manage, Booklets).should be_true
  end
end

但是测试用例失败了,任何答案都会很明显,提前谢谢。

我得到的错误     失败/错误:让(:user){create:user,:abcd_admin}

 ActiveRecord::RecordInvalid:
   Validation failed: Email has already been taken

0 个答案:

没有答案