Sha256: a2cfce58b0d3b9a187942b4d270424a14f9eacfc6bf40e6eaa06dec585f52a87

Contents?: true

Size: 1.97 KB

Versions: 13

Compression:

Stored size: 1.97 KB

Contents

require 'spec_helper'

module CurationConcerns
  module Workflow
    RSpec.describe PermissionGenerator do
      let(:user) { FactoryGirl.create(:user) }
      let(:role) { Sipity::Role.create!(name: 'creating_user') }
      let(:workflow) { Sipity::Workflow.create!(name: 'workflow') }
      let(:workflow_state) { workflow.initial_workflow_state }
      let(:entity) do
        Sipity::Entity.create!(proxy_for_global_id: "gid://work/1", workflow: workflow, workflow_state: workflow_state)
      end
      let(:another_entity) do
        Sipity::Entity.create!(proxy_for_global_id: "gid://work/2", workflow: workflow, workflow_state: workflow_state)
      end
      let(:action_name) { 'show' }

      it 'will grant workflow responsible to agent as the given role' do
        expect do
          described_class.call(agents: user, roles: role.name, workflow: workflow)
        end.to change { Sipity::WorkflowRole.count }.by(1)
          .and change { Sipity::WorkflowResponsibility.count }.by(1)
      end

      it 'will grant entity responsiblity to agent as the given role' do
        expect do
          described_class.call(agents: user, roles: role.name, workflow: workflow, entity: entity)
        end.to change { Sipity::WorkflowRole.count }.by(1)
          .and change { Sipity::EntitySpecificResponsibility.count }.by(1)
          .and change { Sipity::WorkflowResponsibility.count }.by(0)
      end

      it 'will be idempotent' do
        builder = lambda do
          described_class.call(
            agents: user,
            roles: role.name,
            entity: entity,
            workflow: workflow,
            workflow_state: workflow_state,
            action_names: action_name
          )
        end
        builder.call
        [:update_attribute, :update_attributes, :update_attributes!, :save, :save!, :update, :update!].each do |method_names|
          expect_any_instance_of(ActiveRecord::Base).to_not receive(method_names)
        end
        builder.call
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
curation_concerns-1.7.8 spec/services/curation_concerns/workflow/permission_generator_spec.rb
curation_concerns-1.7.7 spec/services/curation_concerns/workflow/permission_generator_spec.rb
curation_concerns-2.0.0 spec/services/curation_concerns/workflow/permission_generator_spec.rb
curation_concerns-2.0.0.rc2 spec/services/curation_concerns/workflow/permission_generator_spec.rb
curation_concerns-1.7.6 spec/services/curation_concerns/workflow/permission_generator_spec.rb
curation_concerns-1.7.5 spec/services/curation_concerns/workflow/permission_generator_spec.rb
curation_concerns-1.7.4 spec/services/curation_concerns/workflow/permission_generator_spec.rb
curation_concerns-1.7.3 spec/services/curation_concerns/workflow/permission_generator_spec.rb
curation_concerns-1.7.2 spec/services/curation_concerns/workflow/permission_generator_spec.rb
curation_concerns-2.0.0.rc1 spec/services/curation_concerns/workflow/permission_generator_spec.rb
curation_concerns-1.7.1 spec/services/curation_concerns/workflow/permission_generator_spec.rb
curation_concerns-1.7.0 spec/services/curation_concerns/workflow/permission_generator_spec.rb
curation_concerns-1.7.0.beta1 spec/services/curation_concerns/workflow/permission_generator_spec.rb