Ruby on Rails - quickly test an ability in ruby on rails- ruby on rails tutorial - rails guides - rails tutorial - ruby rails
If wed like to quickly test if an ability class is giving the correct permissions,we can initialize an ability in the console or on another context with the rails environment loaded, just pass an user instance to test against
test_ability = Ability.new(User.first)
test_ability.can?(:show, Post) #=> true
other_ability = Ability.new(RestrictedUser.first)
other_ability.cannot?(:show, Post) #=> true
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
For more infomattion about test: https://github.com/ryanb/cancan/wiki/Testing-Abilities