<commit_before>import Vue from 'vue'
import { AbilityBuilder } from '@casl/ability'
import { abilitiesPlugin } from '../src'

class Post {
  constructor(attrs) {
    Object.assign(this, attrs)
  }
}

describe('Abilities plugin', () => {
  let ability
  let Component

  beforeAll(() => {
    ability = AbilityBuilder.define(can => {
      can('read', 'Post')
      can(['update', 'delete'], 'Post', { userId: 'me' })
    })
    Vue.use(abilitiesPlugin, ability)

    Component = Vue.extend({
      props: {
        post: { default: () => new Post() }
      },
      render(h) {
        return h('div', this.$can('read', this.post) ? 'Yes' : 'No')
      }
    })
  })

  it('defines `$can` for each component', () => {
    const vm = new Component()

    expect(vm.$can).to.be.a('function')
  })

  describe('`$can`', () => {
    let vm

    beforeEach(() => {
      vm = new Component().$mount()
    })

    it('calls `can` method of underlying ability instance', () => {
      spy.on(ability, 'can')
      vm.$can('read', vm.post)<commit_msg>chore(vue): removes redandunt permission definition<commit_after>import Vue from 'vue'
import { AbilityBuilder } from '@casl/ability'
import { abilitiesPlugin } from '../src'

class Post {
  constructor(attrs) {
    Object.assign(this, attrs)
  }
}

describe('Abilities plugin', () => {
  let ability
  let Component

  beforeAll(() => {
    ability = AbilityBuilder.define(can => can('read', 'Post'))
    Vue.use(abilitiesPlugin, ability)

    Component = Vue.extend({
      props: {
        post: { default: () => new Post() }
      },
      render(h) {
        return h('div', this.$can('read', this.post) ? 'Yes' : 'No')
      }
    })
  })

  it('defines `$can` for each component', () => {
    const vm = new Component()

    expect(vm.$can).to.be.a('function')
  })

  describe('`$can`', () => {
    let vm

    beforeEach(() => {
      vm = new Component().$mount()
    })

    it('calls `can` method of underlying ability instance', () => {
      spy.on(ability, 'can')
      vm.$can('read', vm.post)
{'fraction_non_alphanumeric': 0.1915204678362573, 'fraction_numerical': 0.0, 'mean_word_length': 2.7192028985507246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2349283', 'n_tokens_mistral': 681, 'n_tokens_neox': 669, 'n_words': 152}