Testing CanCanCan attribute level grant in Ruby on Rails

13 views Asked by At

In My ability file for a given role i have: can :read, Order, [:PO_NO, :SO_NO]

I my test file i have following (with test result as a comment at the end of each line):

      assert @forwarder_ability.can?(:read, @o_1, :PO_NO ), "can read order PO_NO" #pass
      assert @forwarder_ability.can?(:read, @o_1, :SO_NO ), "can read order SO_NO" #pass
      assert @forwarder_ability.cannot?(:read, @o_1, :status ), "cant read order status" #pass
      assert @forwarder_ability.cannot?(:read, @o_1, :id ), "cant read order id" #pass
      assert @forwarder_ability.cannot?(:read, @o_1, :agreement_id ), "cant read order agreement_id" #pass
      assert @forwarder_ability.cannot?(:read, @o_1, :receiver_id ), "cant read order receiver_id" #pass
      assert @forwarder_ability.cannot?(:read, @o_1, :terms ), "cant read order terms" #pass
      assert @forwarder_ability.cannot?(:read, @o_1, :receiver_co_id ), "cant read order receiver_co_id" #pass
      assert @forwarder_ability.cannot?(:read, @o_1, :manufacturer_co_id ), "cant read order manufacturer_co_id" #pass
      assert @forwarder_ability.cannot?(:read, @o_1), "cant read order in general" #fails

Is the part of the CanCanCan solution that granting read on 2 specific attributes in a Model general leads to can? :read, Model to be true?

0

There are 0 answers