ddr-models 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/app/models/collection.rb +20 -11
 - data/db/migrate/20150109192134_drop_workflow_state.rb~ +11 -0
 - data/db/migrate/20150110023410_drop_workflow_states.rb +11 -0
 - data/db/migrate/20150110023410_drop_workflow_states.rb~ +4 -0
 - data/lib/ddr/auth/user.rb +1 -1
 - data/lib/ddr/datastreams.rb +3 -2
 - data/lib/ddr/datastreams/admin_metadata_datastream.rb +21 -0
 - data/lib/ddr/datastreams/admin_metadata_datastream.rb~ +13 -0
 - data/lib/ddr/managers.rb +3 -0
 - data/lib/ddr/managers/manager.rb +14 -0
 - data/lib/ddr/managers/manager.rb~ +14 -0
 - data/lib/ddr/managers/role_manager.rb +31 -0
 - data/lib/ddr/managers/role_manager.rb~ +21 -0
 - data/lib/ddr/managers/workflow_manager.rb +33 -0
 - data/lib/ddr/managers/workflow_manager.rb~ +33 -0
 - data/lib/ddr/metadata.rb +0 -1
 - data/lib/ddr/metadata/#permanent_id_record.rb# +13 -0
 - data/lib/ddr/models.rb +1 -4
 - data/lib/ddr/models/#has_ezid_identifier.rb# +26 -0
 - data/lib/ddr/models/#has_permanent_identifier.rb# +9 -0
 - data/lib/ddr/models/base.rb +1 -3
 - data/lib/ddr/models/has_admin_metadata.rb +39 -0
 - data/lib/ddr/models/{has_preservation_metadata.rb → has_admin_metadata.rb~} +11 -5
 - data/lib/ddr/models/has_content.rb +1 -1
 - data/lib/ddr/models/solr_document.rb +1 -1
 - data/lib/ddr/models/version.rb +1 -1
 - data/lib/ddr/vocab.rb +2 -1
 - data/lib/ddr/vocab.rb~ +9 -0
 - data/lib/ddr/vocab/asset.rb +11 -0
 - data/lib/ddr/{metadata/roles_vocabulary.rb → vocab/roles.rb} +4 -2
 - data/lib/ddr/vocab/workflow.rb~ +7 -0
 - data/spec/dummy/db/development.sqlite3 +0 -0
 - data/spec/dummy/db/schema.rb +1 -11
 - data/spec/dummy/db/test.sqlite3 +0 -0
 - data/spec/dummy/log/development.log +2096 -3163
 - data/spec/dummy/log/test.log +77302 -77584
 - data/spec/models/ability_spec.rb +2 -2
 - data/spec/models/collection_spec.rb +8 -1
 - data/spec/models/has_admin_metadata_spec.rb +197 -0
 - data/spec/models/has_admin_metadata_spec.rb~ +144 -0
 - data/spec/models/user_spec.rb +6 -0
 - metadata +40 -17
 - data/lib/ddr/models/has_role_assignments.rb +0 -17
 - data/lib/ddr/models/has_workflow.rb +0 -29
 - data/lib/ddr/vocab/preservation.rb +0 -14
 - data/lib/ddr/workflow.rb +0 -8
 - data/lib/ddr/workflow/workflow_state.rb +0 -39
 - data/spec/models/has_preservation_metadata_spec.rb +0 -109
 - data/spec/models/has_role_assignments_spec.rb +0 -29
 - data/spec/models/has_workflow_spec.rb +0 -54
 - data/spec/models/role_assignments_datastream_spec.rb +0 -25
 
| 
         @@ -1,17 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Ddr
         
     | 
| 
       2 
     | 
    
         
            -
              module Models
         
     | 
| 
       3 
     | 
    
         
            -
                module HasRoleAssignments
         
     | 
| 
       4 
     | 
    
         
            -
                  extend ActiveSupport::Concern
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
                  included do
         
     | 
| 
       7 
     | 
    
         
            -
                    has_metadata name: "roleAssignments", 
         
     | 
| 
       8 
     | 
    
         
            -
                                 type: Ddr::Datastreams::RoleAssignmentsDatastream,
         
     | 
| 
       9 
     | 
    
         
            -
                                 versionable: true, 
         
     | 
| 
       10 
     | 
    
         
            -
                                 control_group: "M"
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                    delegate :principal_has_role?, to: :roleAssignments
         
     | 
| 
       13 
     | 
    
         
            -
                  end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                end
         
     | 
| 
       16 
     | 
    
         
            -
              end
         
     | 
| 
       17 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,29 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Ddr
         
     | 
| 
       2 
     | 
    
         
            -
              module Models
         
     | 
| 
       3 
     | 
    
         
            -
                module HasWorkflow
         
     | 
| 
       4 
     | 
    
         
            -
                  extend ActiveSupport::Concern
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
                  PUBLISHED = Ddr::Workflow::WorkflowState::PUBLISHED
         
     | 
| 
       7 
     | 
    
         
            -
                  UNPUBLISHED = nil
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
                  def workflow_state
         
     | 
| 
       10 
     | 
    
         
            -
                    Ddr::Workflow::WorkflowState.workflow_state_for_object(self)
         
     | 
| 
       11 
     | 
    
         
            -
                  end
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                  def published?
         
     | 
| 
       14 
     | 
    
         
            -
                    self.workflow_state == PUBLISHED
         
     | 
| 
       15 
     | 
    
         
            -
                  end
         
     | 
| 
       16 
     | 
    
         
            -
                  
         
     | 
| 
       17 
     | 
    
         
            -
                  def publish!
         
     | 
| 
       18 
     | 
    
         
            -
                    Ddr::Workflow::WorkflowState.set_for_object(self, PUBLISHED)
         
     | 
| 
       19 
     | 
    
         
            -
                    update_index
         
     | 
| 
       20 
     | 
    
         
            -
                  end
         
     | 
| 
       21 
     | 
    
         
            -
                  
         
     | 
| 
       22 
     | 
    
         
            -
                  def unpublish!
         
     | 
| 
       23 
     | 
    
         
            -
                    Ddr::Workflow::WorkflowState.set_for_object(self, UNPUBLISHED)
         
     | 
| 
       24 
     | 
    
         
            -
                    update_index
         
     | 
| 
       25 
     | 
    
         
            -
                  end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                end
         
     | 
| 
       28 
     | 
    
         
            -
              end
         
     | 
| 
       29 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,14 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Ddr
         
     | 
| 
       2 
     | 
    
         
            -
              module Vocab
         
     | 
| 
       3 
     | 
    
         
            -
                class Preservation < RDF::StrictVocabulary("http://repository.lib.duke.edu/vocab/preservation/")
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
                  property "permanentId", 
         
     | 
| 
       6 
     | 
    
         
            -
                  label: "Permanent Identifier",
         
     | 
| 
       7 
     | 
    
         
            -
                  subPropertyOf: RDF::DC.identifier
         
     | 
| 
       8 
     | 
    
         
            -
                  
         
     | 
| 
       9 
     | 
    
         
            -
                  property "permanentUrl",
         
     | 
| 
       10 
     | 
    
         
            -
                  label: "Permanent URL"
         
     | 
| 
       11 
     | 
    
         
            -
                                              
         
     | 
| 
       12 
     | 
    
         
            -
                end
         
     | 
| 
       13 
     | 
    
         
            -
              end
         
     | 
| 
       14 
     | 
    
         
            -
            end
         
     | 
    
        data/lib/ddr/workflow.rb
    DELETED
    
    
| 
         @@ -1,39 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Ddr
         
     | 
| 
       2 
     | 
    
         
            -
              module Workflow
         
     | 
| 
       3 
     | 
    
         
            -
                class WorkflowState < ActiveRecord::Base
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
                  PUBLISHED = "published"
         
     | 
| 
       6 
     | 
    
         
            -
                  
         
     | 
| 
       7 
     | 
    
         
            -
                  def self.workflow_state_for_object(obj)
         
     | 
| 
       8 
     | 
    
         
            -
                    workflow_state_for_pid(obj.pid)
         
     | 
| 
       9 
     | 
    
         
            -
                  end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
                  def self.workflow_state_for_pid(pid)
         
     | 
| 
       12 
     | 
    
         
            -
                    for_pid(pid).present? ? for_pid(pid).first.workflow_state : nil
         
     | 
| 
       13 
     | 
    
         
            -
                  end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                  def self.set_for_object(obj, state)
         
     | 
| 
       16 
     | 
    
         
            -
                    set_for_pid(obj.pid, state)
         
     | 
| 
       17 
     | 
    
         
            -
                  end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
                  def self.set_for_pid(pid, state)
         
     | 
| 
       20 
     | 
    
         
            -
                    if for_pid(pid).present?
         
     | 
| 
       21 
     | 
    
         
            -
                      for_pid(pid).first.update(workflow_state: state)
         
     | 
| 
       22 
     | 
    
         
            -
                    else
         
     | 
| 
       23 
     | 
    
         
            -
                      create(pid: pid, workflow_state: state)
         
     | 
| 
       24 
     | 
    
         
            -
                    end
         
     | 
| 
       25 
     | 
    
         
            -
                  end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                  private
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                  def self.for_object(obj)
         
     | 
| 
       30 
     | 
    
         
            -
                    for_pid(obj.pid)
         
     | 
| 
       31 
     | 
    
         
            -
                  end
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                  def self.for_pid(pid)
         
     | 
| 
       34 
     | 
    
         
            -
                    where(pid: pid)
         
     | 
| 
       35 
     | 
    
         
            -
                  end
         
     | 
| 
       36 
     | 
    
         
            -
                  
         
     | 
| 
       37 
     | 
    
         
            -
                end
         
     | 
| 
       38 
     | 
    
         
            -
              end
         
     | 
| 
       39 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,109 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            module Ddr
         
     | 
| 
       4 
     | 
    
         
            -
              module Models
         
     | 
| 
       5 
     | 
    
         
            -
                RSpec.describe HasPreservationMetadata, type: :model do
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                  before(:all) do
         
     | 
| 
       8 
     | 
    
         
            -
                    class PermanentlyIdentifiable < ActiveFedora::Base
         
     | 
| 
       9 
     | 
    
         
            -
                      include Ddr::Models::Describable
         
     | 
| 
       10 
     | 
    
         
            -
                      include Ddr::Models::Indexing
         
     | 
| 
       11 
     | 
    
         
            -
                      include Ddr::Models::HasWorkflow
         
     | 
| 
       12 
     | 
    
         
            -
                      include Ddr::Models::HasPreservationMetadata
         
     | 
| 
       13 
     | 
    
         
            -
                      include Ddr::Models::EventLoggable
         
     | 
| 
       14 
     | 
    
         
            -
                    end
         
     | 
| 
       15 
     | 
    
         
            -
                  end
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
                  subject { PermanentlyIdentifiable.new }
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
                  describe "permanent_id" do
         
     | 
| 
       20 
     | 
    
         
            -
                    describe "when a permanent id has not been assigned" do
         
     | 
| 
       21 
     | 
    
         
            -
                      it "should be nil" do
         
     | 
| 
       22 
     | 
    
         
            -
                        expect(subject.permanent_id).to be_nil
         
     | 
| 
       23 
     | 
    
         
            -
                      end
         
     | 
| 
       24 
     | 
    
         
            -
                    end
         
     | 
| 
       25 
     | 
    
         
            -
                  end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                  describe "object lifecycle" do
         
     | 
| 
       28 
     | 
    
         
            -
                    context "when created" do
         
     | 
| 
       29 
     | 
    
         
            -
                      context "and auto-assignment is enabled" do
         
     | 
| 
       30 
     | 
    
         
            -
                        before { allow(Ddr::Models).to receive(:auto_assign_permanent_ids) { true } }
         
     | 
| 
       31 
     | 
    
         
            -
                        it "should assign a permanent id" do
         
     | 
| 
       32 
     | 
    
         
            -
                          expect_any_instance_of(PermanentlyIdentifiable).to receive(:assign_permanent_id!) { nil }
         
     | 
| 
       33 
     | 
    
         
            -
                          PermanentlyIdentifiable.create
         
     | 
| 
       34 
     | 
    
         
            -
                        end
         
     | 
| 
       35 
     | 
    
         
            -
                      end
         
     | 
| 
       36 
     | 
    
         
            -
                      context "and auto-assignment is disabled" do
         
     | 
| 
       37 
     | 
    
         
            -
                        before { allow(Ddr::Models).to receive(:auto_assign_permanent_ids) { false } }
         
     | 
| 
       38 
     | 
    
         
            -
                        it "should not assign a permanent id" do
         
     | 
| 
       39 
     | 
    
         
            -
                          expect_any_instance_of(PermanentlyIdentifiable).not_to receive(:assign_permanent_id!)
         
     | 
| 
       40 
     | 
    
         
            -
                          PermanentlyIdentifiable.create
         
     | 
| 
       41 
     | 
    
         
            -
                        end
         
     | 
| 
       42 
     | 
    
         
            -
                      end
         
     | 
| 
       43 
     | 
    
         
            -
                    end        
         
     | 
| 
       44 
     | 
    
         
            -
                    context "when saved" do
         
     | 
| 
       45 
     | 
    
         
            -
                      context "and auto-assignment is enabled" do
         
     | 
| 
       46 
     | 
    
         
            -
                        before { allow(Ddr::Models).to receive(:auto_assign_permanent_ids) { true } }
         
     | 
| 
       47 
     | 
    
         
            -
                        it "should assign a permanent id once" do
         
     | 
| 
       48 
     | 
    
         
            -
                          expect(subject).to receive(:assign_permanent_id!).once { nil }
         
     | 
| 
       49 
     | 
    
         
            -
                          subject.save
         
     | 
| 
       50 
     | 
    
         
            -
                          subject.title = ["New Title"]
         
     | 
| 
       51 
     | 
    
         
            -
                          subject.save
         
     | 
| 
       52 
     | 
    
         
            -
                        end
         
     | 
| 
       53 
     | 
    
         
            -
                      end
         
     | 
| 
       54 
     | 
    
         
            -
                      context "and auto-assignment is disabled" do
         
     | 
| 
       55 
     | 
    
         
            -
                        before { allow(Ddr::Models).to receive(:auto_assign_permanent_ids) { false } }
         
     | 
| 
       56 
     | 
    
         
            -
                        it "should not assign a permanent id" do
         
     | 
| 
       57 
     | 
    
         
            -
                          expect(subject).not_to receive(:assign_permanent_id!)
         
     | 
| 
       58 
     | 
    
         
            -
                          subject.save
         
     | 
| 
       59 
     | 
    
         
            -
                        end
         
     | 
| 
       60 
     | 
    
         
            -
                      end
         
     | 
| 
       61 
     | 
    
         
            -
                    end
         
     | 
| 
       62 
     | 
    
         
            -
                  end
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
                  describe "#assign_permanent_id!" do
         
     | 
| 
       65 
     | 
    
         
            -
                    it "should assign the permanent id later" do
         
     | 
| 
       66 
     | 
    
         
            -
                      expect(subject.permanent_id_manager).to receive(:assign_later) { nil }
         
     | 
| 
       67 
     | 
    
         
            -
                      subject.assign_permanent_id!
         
     | 
| 
       68 
     | 
    
         
            -
                    end
         
     | 
| 
       69 
     | 
    
         
            -
                  end
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
                  describe "events" do
         
     | 
| 
       72 
     | 
    
         
            -
                    before { allow(Ddr::Models).to receive(:auto_assign_permanent_ids) { true } }  
         
     | 
| 
       73 
     | 
    
         
            -
                    context "when the operation succeeds" do
         
     | 
| 
       74 
     | 
    
         
            -
                      let(:stub_identifier) { double(id: "ark:/99999/fk4zzz", metadata: "_target: http://example.com") }
         
     | 
| 
       75 
     | 
    
         
            -
                      before { allow_any_instance_of(Ddr::Managers::PermanentIdManager).to receive(:mint) { stub_identifier } }
         
     | 
| 
       76 
     | 
    
         
            -
                      it "should create a success event" do
         
     | 
| 
       77 
     | 
    
         
            -
                        expect { subject.save }.to change { subject.update_events.count }.by(1)
         
     | 
| 
       78 
     | 
    
         
            -
                      end
         
     | 
| 
       79 
     | 
    
         
            -
                    end
         
     | 
| 
       80 
     | 
    
         
            -
                    context "when there's an exception" do
         
     | 
| 
       81 
     | 
    
         
            -
                      before { allow(Ezid::Identifier).to receive(:create).and_raise(Ezid::Error) }
         
     | 
| 
       82 
     | 
    
         
            -
                      it "should create a failure event" do
         
     | 
| 
       83 
     | 
    
         
            -
                        begin
         
     | 
| 
       84 
     | 
    
         
            -
                          subject.save
         
     | 
| 
       85 
     | 
    
         
            -
                        rescue Ezid::Error
         
     | 
| 
       86 
     | 
    
         
            -
                        end
         
     | 
| 
       87 
     | 
    
         
            -
                        expect(subject.update_events.last).to be_failure
         
     | 
| 
       88 
     | 
    
         
            -
                      end
         
     | 
| 
       89 
     | 
    
         
            -
                    end
         
     | 
| 
       90 
     | 
    
         
            -
                  end
         
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
                  describe "indexing" do
         
     | 
| 
       93 
     | 
    
         
            -
                    let(:permanent_id) { "ark:/99999/fk4zzz" }
         
     | 
| 
       94 
     | 
    
         
            -
                    let(:permanent_url) { "http://id.library.duke.edu/ark:/99999/fk4zzz" }
         
     | 
| 
       95 
     | 
    
         
            -
                    before do
         
     | 
| 
       96 
     | 
    
         
            -
                      subject.permanent_id = permanent_id
         
     | 
| 
       97 
     | 
    
         
            -
                      subject.permanent_url = permanent_url
         
     | 
| 
       98 
     | 
    
         
            -
                    end
         
     | 
| 
       99 
     | 
    
         
            -
                    it "should index the permanent id value" do
         
     | 
| 
       100 
     | 
    
         
            -
                      expect(subject.to_solr[Ddr::IndexFields::PERMANENT_ID]).to eq(permanent_id)
         
     | 
| 
       101 
     | 
    
         
            -
                    end
         
     | 
| 
       102 
     | 
    
         
            -
                    it "should index the permanent url" do
         
     | 
| 
       103 
     | 
    
         
            -
                      expect(subject.to_solr[Ddr::IndexFields::PERMANENT_URL]).to eq(permanent_url)
         
     | 
| 
       104 
     | 
    
         
            -
                    end
         
     | 
| 
       105 
     | 
    
         
            -
                  end
         
     | 
| 
       106 
     | 
    
         
            -
                
         
     | 
| 
       107 
     | 
    
         
            -
                end
         
     | 
| 
       108 
     | 
    
         
            -
              end
         
     | 
| 
       109 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,29 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            module Ddr
         
     | 
| 
       4 
     | 
    
         
            -
              module Models
         
     | 
| 
       5 
     | 
    
         
            -
                RSpec.describe HasRoleAssignments, type: :model do
         
     | 
| 
       6 
     | 
    
         
            -
                
         
     | 
| 
       7 
     | 
    
         
            -
                  before(:all) do
         
     | 
| 
       8 
     | 
    
         
            -
                    class RoleAssignable < ActiveFedora::Base
         
     | 
| 
       9 
     | 
    
         
            -
                      include HasRoleAssignments
         
     | 
| 
       10 
     | 
    
         
            -
                    end
         
     | 
| 
       11 
     | 
    
         
            -
                  end
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                  subject { RoleAssignable.new }
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                  describe "#principal_has_role?" do
         
     | 
| 
       16 
     | 
    
         
            -
                    it "should respond when given a list of principals and a valid role" do
         
     | 
| 
       17 
     | 
    
         
            -
                      expect { subject.principal_has_role?(["bob", "admins"], :administrator) }.not_to raise_error
         
     | 
| 
       18 
     | 
    
         
            -
                    end
         
     | 
| 
       19 
     | 
    
         
            -
                    it "should respond when given a principal name and a valid role" do
         
     | 
| 
       20 
     | 
    
         
            -
                      expect { subject.principal_has_role?("bob", :administrator) }.not_to raise_error
         
     | 
| 
       21 
     | 
    
         
            -
                    end
         
     | 
| 
       22 
     | 
    
         
            -
                    it "should raise an error when given an invalid role" do
         
     | 
| 
       23 
     | 
    
         
            -
                      expect { subject.principal_has_role?("bob", :foo) }.to raise_error
         
     | 
| 
       24 
     | 
    
         
            -
                    end
         
     | 
| 
       25 
     | 
    
         
            -
                  end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                end
         
     | 
| 
       28 
     | 
    
         
            -
              end
         
     | 
| 
       29 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,54 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            module Ddr
         
     | 
| 
       4 
     | 
    
         
            -
              module Models
         
     | 
| 
       5 
     | 
    
         
            -
                RSpec.describe HasWorkflow, type: :model do
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                  before(:all) do
         
     | 
| 
       8 
     | 
    
         
            -
                    class Workflowable < ActiveFedora::Base
         
     | 
| 
       9 
     | 
    
         
            -
                      include HasWorkflow
         
     | 
| 
       10 
     | 
    
         
            -
                    end
         
     | 
| 
       11 
     | 
    
         
            -
                  end
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                  subject { Workflowable.new(pid: 'test:1') }
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                  describe "#published?" do
         
     | 
| 
       16 
     | 
    
         
            -
                    context "object is published" do
         
     | 
| 
       17 
     | 
    
         
            -
                      before { Ddr::Workflow::WorkflowState.create(pid: subject.pid, workflow_state: Ddr::Workflow::WorkflowState::PUBLISHED) }
         
     | 
| 
       18 
     | 
    
         
            -
                      it "should return true" do
         
     | 
| 
       19 
     | 
    
         
            -
                        expect(subject.published?).to eql(true)
         
     | 
| 
       20 
     | 
    
         
            -
                      end
         
     | 
| 
       21 
     | 
    
         
            -
                    end
         
     | 
| 
       22 
     | 
    
         
            -
                    context "object is not published" do
         
     | 
| 
       23 
     | 
    
         
            -
                      context "has never been published" do
         
     | 
| 
       24 
     | 
    
         
            -
                        it "should return false" do
         
     | 
| 
       25 
     | 
    
         
            -
                          expect(subject.published?).to eql(false)
         
     | 
| 
       26 
     | 
    
         
            -
                        end
         
     | 
| 
       27 
     | 
    
         
            -
                      end
         
     | 
| 
       28 
     | 
    
         
            -
                      context "has been published and unpublished" do
         
     | 
| 
       29 
     | 
    
         
            -
                        before { Ddr::Workflow::WorkflowState.create(pid: subject.pid, workflow_state: nil) }
         
     | 
| 
       30 
     | 
    
         
            -
                        it "should return false" do
         
     | 
| 
       31 
     | 
    
         
            -
                          expect(subject.published?).to eql(false)
         
     | 
| 
       32 
     | 
    
         
            -
                        end
         
     | 
| 
       33 
     | 
    
         
            -
                      end
         
     | 
| 
       34 
     | 
    
         
            -
                    end
         
     | 
| 
       35 
     | 
    
         
            -
                  end
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
                  describe "#publish!" do
         
     | 
| 
       38 
     | 
    
         
            -
                    it "should publish the object" do
         
     | 
| 
       39 
     | 
    
         
            -
                      subject.publish!
         
     | 
| 
       40 
     | 
    
         
            -
                      expect(subject.published?).to eql(true)
         
     | 
| 
       41 
     | 
    
         
            -
                    end
         
     | 
| 
       42 
     | 
    
         
            -
                  end
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                  describe "#unpublish!" do
         
     | 
| 
       45 
     | 
    
         
            -
                    before { subject.publish! }
         
     | 
| 
       46 
     | 
    
         
            -
                    it "should unpublish the object" do
         
     | 
| 
       47 
     | 
    
         
            -
                      subject.unpublish!
         
     | 
| 
       48 
     | 
    
         
            -
                      expect(subject.published?).to eql(false)
         
     | 
| 
       49 
     | 
    
         
            -
                    end
         
     | 
| 
       50 
     | 
    
         
            -
                  end
         
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
                end
         
     | 
| 
       53 
     | 
    
         
            -
              end
         
     | 
| 
       54 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,25 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            module Ddr
         
     | 
| 
       4 
     | 
    
         
            -
              module Datastreams
         
     | 
| 
       5 
     | 
    
         
            -
                RSpec.describe RoleAssignmentsDatastream do
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                  subject { described_class.new(nil) }
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
                  describe "#principal_has_role?" do
         
     | 
| 
       10 
     | 
    
         
            -
                    before do
         
     | 
| 
       11 
     | 
    
         
            -
                      subject.administrator = ["bob", "sally"]
         
     | 
| 
       12 
     | 
    
         
            -
                    end
         
     | 
| 
       13 
     | 
    
         
            -
                    it "should accept a single principal" do
         
     | 
| 
       14 
     | 
    
         
            -
                      expect(subject.principal_has_role?("sally", :administrator)).to be true
         
     | 
| 
       15 
     | 
    
         
            -
                      expect(subject.principal_has_role?("fred", :administrator)).to be false
         
     | 
| 
       16 
     | 
    
         
            -
                    end
         
     | 
| 
       17 
     | 
    
         
            -
                    it "should accept a list of principals and return if at least one of the principals has the role" do
         
     | 
| 
       18 
     | 
    
         
            -
                      expect(subject.principal_has_role?(["sally", "fred"], :administrator)).to be true
         
     | 
| 
       19 
     | 
    
         
            -
                      expect(subject.principal_has_role?(["wendy", "fred"], :administrator)).to be false
         
     | 
| 
       20 
     | 
    
         
            -
                    end
         
     | 
| 
       21 
     | 
    
         
            -
                  end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                end
         
     | 
| 
       24 
     | 
    
         
            -
              end
         
     | 
| 
       25 
     | 
    
         
            -
            end
         
     |