Sha256: 5cbdde5c76b56772bd2ba23bed9db71d061ec92c8137c6e329e89fe029839c51

Contents?: true

Size: 1.84 KB

Versions: 35

Compression:

Stored size: 1.84 KB

Contents

require 'rails_helper'

module Adeia
  RSpec.describe Permission, type: :model do

    let(:user) { create(:user) }

    describe "#add" do

      it "creates a permission with default attributes" do
        permission = Permission.add!(owner: user, element: "adeia/permissions", read: true)
        expect(permission.owner).to eq user
        expect(permission.element.name).to eq "adeia/permissions"
        expect(permission.permission_type).to eq "all_entries"
        expect(permission.read_right).to be true
        expect(permission.create_right).to be false
        expect(permission.resource_id).to be_nil
        expect(permission.actions).to be_empty
      end

      it "creates a permission with good attributes" do
        permission = Permission.add!(owner: user, element: "adeia/permissions", type: "on_entry", read: true, resource_id: 1, actions: ["share"])
        expect(permission.permission_type).to eq "on_entry"
        expect(permission.read_right).to be true
        expect(permission.resource_id).to eq 1
        expect(permission.actions.first.name).to eq "share"
      end

      it "creates a permission with all the rights when using the full option" do
        permission = Permission.add!(owner: user, element: "adeia/permissions", full: true)
        expect(permission.read_right).to be true
        expect(permission.create_right).to be true
        expect(permission.update_right).to be true
        expect(permission.destroy_right).to be true
      end

    end

    describe "#find_or_add_by" do

      it "returns a permission when it already exists" do
        permission = Permission.add!(owner: user, element: "adeia/permissions", type: "on_entry", read: true, resource_id: 1, actions: ["share"])
        expect(Permission.find_or_add_by!(owner: user, element: "adeia/permissions", type: "on_entry")).to eq permission
      end

    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
adeia-1.0.0 spec/models/adeia/permission_spec.rb
adeia-0.15.4 spec/models/adeia/permission_spec.rb
adeia-0.15.3 spec/models/adeia/permission_spec.rb
adeia-0.15.2 spec/models/adeia/permission_spec.rb
adeia-0.15.1 spec/models/adeia/permission_spec.rb
adeia-0.15.0 spec/models/adeia/permission_spec.rb
adeia-0.14.0 spec/models/adeia/permission_spec.rb
adeia-0.13.1 spec/models/adeia/permission_spec.rb
adeia-0.13.0 spec/models/adeia/permission_spec.rb
adeia-0.12.0 spec/models/adeia/permission_spec.rb
adeia-0.11.11 spec/models/adeia/permission_spec.rb
adeia-0.11.10 spec/models/adeia/permission_spec.rb
adeia-0.11.9 spec/models/adeia/permission_spec.rb
adeia-0.11.8 spec/models/adeia/permission_spec.rb
adeia-0.11.7 spec/models/adeia/permission_spec.rb
adeia-0.11.6 spec/models/adeia/permission_spec.rb
adeia-0.11.5 spec/models/adeia/permission_spec.rb
adeia-0.11.4 spec/models/adeia/permission_spec.rb
adeia-0.11.3 spec/models/adeia/permission_spec.rb
adeia-0.11.2 spec/models/adeia/permission_spec.rb