diff --git a/spec/models/concerns/deepblue/doi_behavior_spec.rb b/spec/models/concerns/deepblue/doi_behavior_spec.rb new file mode 100644 index 00000000..0a6aca4a --- /dev/null +++ b/spec/models/concerns/deepblue/doi_behavior_spec.rb @@ -0,0 +1,197 @@ +class DoiMock + include ::Deepblue::DoiBehavior + + def initialize + @doi = "doi_pending" + end + + def doi + @doi + end + + def doi=(value) + @doi = value + end + + def id + 1001 + end + + def file_sets + [] + end + + def save + end + + def reload + end +end + +class UserMock + + def email + "current_user@example.com" + end + + def to_s + "current_user" + end +end + +RSpec.describe Deepblue::DoiBehavior do + + let( :mock ) { DoiMock.new } + + describe 'constants' do + it do + expect( Deepblue::DoiBehavior::DOI_MINTING_ENABLED ).to eq true + expect( Deepblue::DoiBehavior::DOI_PENDING ).to eq "doi_pending" + expect( Deepblue::DoiBehavior::DOI_MINIMUM_FILE_COUNT ).to eq 1 + end + end + + describe "#doi_minted?" do + context "when doi is nil" do + before { + allow(mock).to receive(:doi).and_return nil + } + it "returns false" do + expect(mock.doi_minted?).to eq false + end + end + + context "when doi is not nil" do + it "returns true" do + expect(mock.doi_minted?).to eq true + end + end + + context "when !doi.nil? raises an error" do + before { + allow(mock).to receive(:doi).and_raise "Error" + } + it "returns nil" do + expect(mock.doi_minted?).to be_blank + end + end + end + + describe "#doi_minting_enabled?" do + it "returns true" do + expect(mock.doi_minting_enabled?).to eq true + end + end + + + describe "#doi_pending?" do + context "doi returns 'doi_pending'" do + it "returns true" do + expect(mock.doi_pending?).to eq true + end + end + + context "doi does not return 'doi_pending'" do + before { + allow(mock).to receive(:doi).and_return "doi" + } + it "returns false" do + expect(mock.doi_pending?).to eq false + end + end + end + + + describe "#doi_mint" do + before { + allow(Deepblue::LoggingHelper).to receive(:here).and_return "here" + allow(Deepblue::LoggingHelper).to receive(:called_from).and_return "called from" + } + + context "when doi is 'doi_pending'" do + before { + allow(Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "work.id=1001", "doi=doi_pending", "current_user=user", + "event_note=event note", "enforce_minimum_file_count=true", "job_delay=0"]) + } + it "returns false" do + expect(Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "work.id=1001", "doi=doi_pending", "current_user=user", + "event_note=event note", "enforce_minimum_file_count=true", "job_delay=0"]) + expect(mock.doi_mint(current_user: "user", event_note: "event note")).to eq false + end + end + + context "when doi_minted? returns true" do + before { + allow(mock).to receive(:doi).and_return "doi" + allow(Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "work.id=1001", "doi=doi", "current_user=user", + "event_note=event note", "enforce_minimum_file_count=true", "job_delay=0"]) + allow(mock).to receive(:doi_minted?).and_return true + } + it "returns false" do + expect(Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "work.id=1001", "doi=doi", "current_user=user", + "event_note=event note", "enforce_minimum_file_count=true", "job_delay=0"]) + expect(mock.doi_mint(current_user: "user", event_note: "event note")).to eq false + end + end + + context "when enforce_minimum_file_count param is true && zero file_sets" do + before { + allow(mock).to receive(:doi).and_return "doi" + allow(Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "work.id=1001", "doi=doi", "current_user=user", + "event_note=event note", "enforce_minimum_file_count=true", "job_delay=0"]) + allow(mock).to receive(:doi_minted?).and_return false + } + + it "returns false" do + expect(Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "work.id=1001", "doi=doi", "current_user=user", + "event_note=event note", "enforce_minimum_file_count=true", "job_delay=0"]) + expect(mock.doi_mint(current_user: "user", event_note: "event note")).to eq false + end + end + + context "when file_sets exist" do + user = UserMock.new + + before { + allow(mock).to receive(:doi).and_return "doi" + allow(Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "work.id=1001", "doi=doi", "current_user=current_user", + "event_note=event note", "enforce_minimum_file_count=true", "job_delay=0"]) + allow(mock).to receive(:doi_minted?).and_return false + allow(mock).to receive(:file_sets).and_return ["file_set1"] + allow(Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "work.id=1001", "doi=doi_pending", "about to call DoiMintingJob"]) + allow(::DoiMintingJob).to receive(:perform_later).with(1001, current_user: "current_user@example.com", job_delay: 0) + } + it "returns true" do + expect(Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "work.id=1001", "doi=doi", "current_user=current_user", + "event_note=event note", "enforce_minimum_file_count=true", "job_delay=0"]) + expect(mock).to receive(:save) + expect(mock).to receive(:reload) + + expect(mock.doi_mint(current_user: user, event_note: "event note")).to eq true + + subject.instance_variable_get(:@doi) == "doi_pending" + end + + it "verify doi_mint calls bold_debug a second time and perform_later once" do + skip "Add a test" + end + end + + + context "when Exception occurs" do + user = UserMock.new + + before { + exception = StandardError.new("Doi Mint Error") + exception.set_backtrace("backtrace") + allow(mock).to receive(:doi).and_raise exception + } + it "calls Rails.logger.error and returns nil" do + expect(Rails.logger).to receive(:error).with("DoiBehavior.doi_mint for curation_concern.id 1001 -- StandardError: Doi Mint Error at backtrace") + expect(mock.doi_mint(current_user: user, event_note: "event note")).to be_blank + end + end + + end + +end diff --git a/spec/models/concerns/deepblue/email_behavior_spec.rb b/spec/models/concerns/deepblue/email_behavior_spec.rb new file mode 100644 index 00000000..18665a92 --- /dev/null +++ b/spec/models/concerns/deepblue/email_behavior_spec.rb @@ -0,0 +1,570 @@ +require 'rails_helper' + +class EmailMock + include ::Deepblue::EmailBehavior + + def email_create(current_user:, event_note: "") + "user email" + end + + def email_key_values + end + + def email_key_values=(values) + end +end + +RSpec.describe Deepblue::EmailBehavior do + subject { EmailMock.new } + + describe '#attributes_all_for_email' do + it "returns blank" do + expect(subject.attributes_all_for_email).to be_blank + end + end + + describe '#attributes_brief_for_email' do + it "returns blank" do + expect(subject.attributes_brief_for_email).to be_blank + end + end + + describe '#attributes_standard_for_email' do + it "returns blank" do + expect(subject.attributes_standard_for_email).to be_blank + end + end + + describe '#attributes_for_email_rds_create' do + it "returns array of empty array and false" do + expect(subject.attributes_for_email_rds_create).to eq [[], false] + end + end + + describe '#attributes_for_email_rds_destroy' do + it "returns array of empty array and false" do + expect(subject.attributes_for_email_rds_destroy).to eq [[], false] + end + end + + describe '#attributes_for_email_rds_globus' do + it "returns array of empty array and true" do + expect(subject.attributes_for_email_rds_globus).to eq [[], true] + end + end + + describe '#attributes_for_email_rds_publish' do + it "returns array of empty array and false" do + expect(subject.attributes_for_email_rds_publish).to eq [[], false] + end + end + + describe '#attributes_for_email_rds_unpublish' do + it "returns array of empty array and false" do + expect(subject.attributes_for_email_rds_unpublish).to eq [[], false] + end + end + + describe '#attributes_for_email_user_create' do + it "returns blank" do + expect(subject.attributes_for_email_user_create).to be_blank + end + end + + describe "#email_attribute_values_for_snapshot" do + before { + allow(subject).to receive(:for_email_user).with("current user").and_return "for email user" + allow(subject).to receive(:map_email_attributes!).with( { event: "event", attributes: "attributes", ignore_blank_key_values: "ignore", + user_email: "for email user", event_note: "event note", to_note: "to note", + :added_email_key_values=>{:a=>1, :b=>2, :c=>3}} ).and_return "mapped" + } + + it "merges attributes and calls map_email_attributes!" do + expect(subject).to receive(:for_email_user).with("current user").and_return "for email user" + + expect(subject.email_attribute_values_for_snapshot(attributes: "attributes", current_user: "current user", event: "event", + event_note: "event note", to_note: "to note", + ignore_blank_key_values: "ignore", added_email_key_values: {a:1, b:2, c:3})).to eq "mapped" + end + end + + + describe '#email_address_rds' do + before { + allow(Deepblue::EmailHelper).to receive(:notification_email).and_return "notification email" + } + it "returns result of EmailHelper.notification_email" do + expect(subject.email_address_rds).to eq "notification email" + end + end + + describe '#email_address_rds_deepblue' do + before { + allow(Deepblue::EmailHelper).to receive(:contact_email).and_return "contact email" + } + it "returns result of EmailHelper.contact_email" do + expect(subject.email_address_rds_deepblue).to eq "contact email" + end + end + + + describe '#email_address_user' do + before { + allow(Deepblue::EmailHelper).to receive(:user_email_from).with("current user").and_return "email address" + } + it "returns result of EmailHelper.user_email_from" do + expect(subject.email_address_user "current user").to eq "email address" + end + end + + + describe '#email_compose_body' do + before { + allow(subject).to receive(:for_email_label).with("cake").and_return "celebration: " + allow(subject).to receive(:for_email_label).with("frosting").and_return "decoration: " + + allow(subject).to receive(:for_email_value).with("cake", "chocolate").and_return "ganache\n" + allow(subject).to receive(:for_email_value).with("frosting", "meringue").and_return "torched\n" + } + + context "message is nil and has no key value pairs" do + it "returns empty string" do + expect(subject.email_compose_body message:nil, email_key_values:{}) + .to be_blank + end + end + + context "message is nil and hash has key value pairs" do + it "returns hash key values as string" do + expect(subject.email_compose_body message:nil, email_key_values:{"cake" => "chocolate", "frosting" => "meringue"}) + .to eq "celebration: ganache\ndecoration: torched\n" + end + end + + context "message has value and hash has key value pairs" do + it "returns message and hash key values as string" do + expect(subject.email_compose_body message: "Hiya", email_key_values:{"cake" => "chocolate", "frosting" => "meringue"}) + .to eq "Hiya\ncelebration: ganache\ndecoration: torched\n" + end + end + end + + + describe '#email_rds_create' do + before { + allow(subject).to receive(:email_address_rds).and_return("rutabaga.imaginary@example.com") + allow(subject).to receive(:for_email_id).and_return("celery.imaginary@example.com") + + allow(subject).to receive(:map_email_attributes!).with(event:Deepblue::AbstractEventBehavior::EVENT_CREATE, attributes:[], ignore_blank_key_values:false) + + allow(subject).to receive(:email_event_notification).with(to:"rutabaga.imaginary@example.com", to_note:'RDS', from:"rutabaga.imaginary@example.com", + subject:Deepblue::EmailHelper.t( "hyrax.email.subject.work_created" ), attributes:[], current_user:"current user", + event:Deepblue::AbstractEventBehavior::EVENT_CREATE, event_note:'', id:"celery.imaginary@example.com", + ignore_blank_key_values:false, return_email_parameters:false, send_it:true, email_key_values: nil) + } + + it "calls map_email_attributes! and email_event_notification" do + expect(subject).to receive(:map_email_attributes!).with(event:Deepblue::AbstractEventBehavior::EVENT_CREATE, attributes:[], ignore_blank_key_values:false) + + expect(subject).to receive(:email_event_notification).with(to:"rutabaga.imaginary@example.com", to_note:'RDS', from:"rutabaga.imaginary@example.com", + subject:Deepblue::EmailHelper.t( "hyrax.email.subject.work_created" ), attributes:[], current_user:"current user", + event:Deepblue::AbstractEventBehavior::EVENT_CREATE, event_note:'', id:"celery.imaginary@example.com", + ignore_blank_key_values:false, return_email_parameters:false, send_it:true, email_key_values: nil) + + subject.email_rds_create current_user:"current user", event_note:'', return_email_parameters: false, send_it: true + end + end + + + describe '#email_rds_destroy' do + before { + allow(subject).to receive(:email_address_rds).and_return("rutabaga.imaginary@example.com") + allow(subject).to receive(:for_email_id).and_return("celery.imaginary@example.com") + + allow(subject).to receive(:email_event_notification).with(to:"rutabaga.imaginary@example.com", to_note:'RDS', from:"rutabaga.imaginary@example.com", + subject:Deepblue::EmailHelper.t( "hyrax.email.subject.work_deleted" ), attributes:[], + current_user:"current user", event:Deepblue::AbstractEventBehavior::EVENT_DESTROY, + event_note:'', id:"celery.imaginary@example.com", ignore_blank_key_values:false) + } + + it "calls email_event_notification" do + expect(subject).to receive(:email_event_notification).with(to:"rutabaga.imaginary@example.com", to_note:'RDS', from:"rutabaga.imaginary@example.com", + subject:Deepblue::EmailHelper.t( "hyrax.email.subject.work_deleted" ), attributes:[], + current_user:"current user", event:Deepblue::AbstractEventBehavior::EVENT_DESTROY, + event_note:'', id:"celery.imaginary@example.com", ignore_blank_key_values:false) + + subject.email_rds_destroy current_user:"current user", event_note:'' + end + end + + + describe '#email_rds_globus' do + before { + allow(subject).to receive(:email_address_rds).and_return("rutabaga.imaginary@example.com") + allow(subject).to receive(:for_email_id).and_return("celery.imaginary@example.com") + + allow(subject).to receive(:email_event_notification).with(to:"rutabaga.imaginary@example.com", to_note:'RDS', from:"rutabaga.imaginary@example.com", + subject:"DBD: Globus Notify", attributes:[], current_user:"current user", + event:Deepblue::AbstractEventBehavior::EVENT_GLOBUS, event_note:'Notify', + id:"celery.imaginary@example.com", ignore_blank_key_values:true) + } + + it "calls email_event_notification" do + expect(subject).to receive(:email_event_notification).with(to:"rutabaga.imaginary@example.com", to_note:'RDS', from:"rutabaga.imaginary@example.com", + subject:"DBD: Globus Notify", attributes:[], current_user:"current user", + event:Deepblue::AbstractEventBehavior::EVENT_GLOBUS, event_note:'Notify', + id:"celery.imaginary@example.com", ignore_blank_key_values:true) + + subject.email_rds_globus current_user:"current user", event_note:'Notify' + end + end + + + describe '#email_rds_publish' do + before { + allow(subject).to receive(:email_address_rds).and_return("rutabaga.imaginary@example.com") + allow(subject).to receive(:for_email_id).and_return("celery.imaginary@example.com") + + allow(subject).to receive(:email_event_notification).with(to:"rutabaga.imaginary@example.com", to_note:'RDS', from:"rutabaga.imaginary@example.com", + subject:Deepblue::EmailHelper.t( "hyrax.email.subject.work_published" ), attributes:[], + current_user:"current user", event:Deepblue::AbstractEventBehavior::EVENT_PUBLISH, + event_note:'Notify', message:"Messaging", id:"celery.imaginary@example.com", + ignore_blank_key_values:false) + } + + it "calls email_event_notification" do + expect(subject).to receive(:email_event_notification).with(to:"rutabaga.imaginary@example.com", to_note:'RDS', from:"rutabaga.imaginary@example.com", + subject:Deepblue::EmailHelper.t( "hyrax.email.subject.work_published" ), attributes:[], + current_user:"current user", event:Deepblue::AbstractEventBehavior::EVENT_PUBLISH, + event_note:'Notify', message:"Messaging", id:"celery.imaginary@example.com", + ignore_blank_key_values:false) + + subject.email_rds_publish current_user:"current user", event_note:'Notify', message:"Messaging" + end + end + + + describe '#email_rds_unpublish' do + before { + allow(subject).to receive(:email_address_rds).and_return("rutabaga.imaginary@example.com") + allow(subject).to receive(:for_email_id).and_return("celery.imaginary@example.com") + + allow(subject).to receive(:email_event_notification).with(to:"rutabaga.imaginary@example.com", to_note:'RDS', from:"rutabaga.imaginary@example.com", + subject:Deepblue::EmailHelper.t( "hyrax.email.subject.work_unpublished" ), attributes:[], + current_user:"current user", event:Deepblue::AbstractEventBehavior::EVENT_UNPUBLISH, + event_note:'', id:"celery.imaginary@example.com", ignore_blank_key_values:false) + } + + it "calls email_event_notification" do + expect(subject).to receive(:email_event_notification).with(to:"rutabaga.imaginary@example.com", to_note:'RDS', from:"rutabaga.imaginary@example.com", + subject:Deepblue::EmailHelper.t( "hyrax.email.subject.work_unpublished" ), attributes:[], + current_user:"current user", event:Deepblue::AbstractEventBehavior::EVENT_UNPUBLISH, + event_note:'', id:"celery.imaginary@example.com", ignore_blank_key_values:false) + + subject.email_rds_unpublish current_user:"current user" + end + end + + + describe '#email_user_create' do + before { + allow(subject).to receive(:email_address_user).with("current user").and_return("crinoline.imaginary@example.com") + allow(subject).to receive(:email_address_rds).and_return("rutabaga.imaginary@example.com") + allow(subject).to receive(:for_email_id).and_return("celery.imaginary@example.com") + allow(subject).to receive(:email_event_notification).with(to:"crinoline.imaginary@example.com", to_note:'user', from:"rutabaga.imaginary@example.com", + subject:Deepblue::EmailHelper.t( "hyrax.email.subject.work_created" ), attributes:[], + current_user:"current user", event:Deepblue::AbstractEventBehavior::EVENT_CREATE, + event_note:"Attention!", id:"celery.imaginary@example.com", ignore_blank_key_values:false) + + } + + it "calls email_event_notification" do + expect(subject).to receive(:email_event_notification).with(to:"crinoline.imaginary@example.com", to_note:'user', from:"rutabaga.imaginary@example.com", + subject:Deepblue::EmailHelper.t( "hyrax.email.subject.work_created" ), attributes:[], + current_user:"current user", event:Deepblue::AbstractEventBehavior::EVENT_CREATE, + event_note:"Attention!", id:"celery.imaginary@example.com", ignore_blank_key_values:false) + + subject.email_user_create current_user:"current user", event_note:"Attention!" + end + end + + + describe '#email_create_to_user' do + before { + allow(subject).to receive(:email_create).with(current_user:"current user", event_note:"to do").and_return "user email" + } + it "passes parameters to function" do + expect(subject).to receive(:email_create).with(current_user:"current user", event_note:"to do") + expect(subject.email_create_to_user current_user:"current user", event_note:"to do").to eq "user email" + end + end + + + describe '#for_email_class' do + before { + allow(subject).to receive(:for_email_object).and_return OpenStruct.new(class:"classy name") + } + it "returns for_email_object.class" do + expect(subject.for_email_class).to eq "classy name" + end + end + + + describe '#for_email_id' do + before { + allow(subject).to receive(:for_email_object).and_return OpenStruct.new(id:"ZZZ") + } + it "returns for_email_object.id" do + expect(subject.for_email_id).to eq "ZZZ" + end + end + + + describe "#for_email_ignore_empty_attributes" do + it "returns true" do + expect(subject.for_email_ignore_empty_attributes).to eq true + end + end + + + describe "#for_email_label" do + it "returns argument formatted as string" do + expect(subject.for_email_label "secret").to eq "secret: " + end + end + + + describe "#for_email_object" do + it "returns object self" do + expect(subject.for_email_object).to eq subject + end + end + + + describe "#for_email_route" do + before { + allow(subject).to receive(:for_email_object).and_return OpenStruct.new(id:"ZZZ") + } + + it "returns object self id formatted as string" do + expect(subject.for_email_route).to eq "route to ZZZ" + end + end + + + describe "#for_email_subject" do + it "returns argument formatted as string" do + expect(subject.for_email_subject subject_rest:"Subjective").to eq "DBD: Subjective" + end + end + + + describe "#for_email_value" do + context "when value empty" do + it "returns empty string" do + expect(subject.for_email_value "key", nil).to be_blank + end + end + + context "when called with single value in collection" do + it "returns value" do + expect(subject.for_email_value "key", ["value"]).to eq "value" + end + end + + context "when called with multiple values in collection" do + it "returns joined values" do + expect(subject.for_email_value "key", ["valu1", "valu2", "valu3"]).to eq "valu1; valu2; valu3" + end + end + + context "when called with single value" do + it "returns value" do + expect(subject.for_email_value "key", "spicy").to eq "spicy" + end + end + end + + + describe "#for_email_value_sep" do + context "when argument is title" do + it "returns whitespace" do + expect(subject.for_email_value_sep key: "title").to be_blank + end + end + + context "when argument is not title" do + it "returns semicolon and whitespace" do + expect(subject.for_email_value_sep key: "subject").to eq "; " + end + end + end + + + describe "#for_email_user" do + context "when parameter is blank" do + it "returns empty string" do + expect(Deepblue::EmailHelper).not_to receive(:user_email_from) + expect(subject.for_email_user " ").to be_blank + end + end + + context "when parameter is a string" do + it "returns parameter" do + expect(Deepblue::EmailHelper).not_to receive(:user_email_from) + expect(subject.for_email_user "nom de plume").to eq "nom de plume" + end + end + + context "when parameter is not a string" do + before { + allow(Deepblue::EmailHelper).to receive(:user_email_from).with(OpenStruct.new(email: 'twist@example.com')).and_return("object") + } + + it "returns empty string" do + expect(Deepblue::EmailHelper).to receive(:user_email_from).with OpenStruct.new(email: 'twist@example.com') + expect(subject.for_email_user OpenStruct.new(email: 'twist@example.com')).to eq "object" + end + end + end + + describe "#map_email_attributes!" do + context "when called without attributes" do + before { + allow(subject).to receive(:for_email_object) + } + it "returns unchanged email_key_values parameter" do + expect(subject.map_email_attributes! event: "event", attributes: [], ignore_blank_key_values: false, email_key_values: "C sharp") + .to eq :email_key_values => "C sharp" + end + end + + context "when called with attributes and not map_email_attributes_override!" do + before { + allow(subject).to receive(:for_email_object).and_return(:date_created => "date created value", "invented" => "invented value") + + allow(subject).to receive(:map_email_attributes_override!) + .with(event: "event", attribute: "id", ignore_blank_key_values: true, email_key_values: {}).and_return false + allow(subject).to receive(:map_email_attributes_override!) + .with(event: "event", attribute: "location", ignore_blank_key_values: true, email_key_values: {"id"=>"id value"}).and_return false + allow(subject).to receive(:map_email_attributes_override!) + .with(event: "event", attribute: "route", ignore_blank_key_values: true, + email_key_values: {"id"=>"id value", "location"=>"email value"}).and_return false + allow(subject).to receive(:map_email_attributes_override!) + .with(event: "event", attribute: "date_created", ignore_blank_key_values: true, + email_key_values: {"id"=>"id value", "location"=>"email value", "route"=>"email value"}).and_return false + allow(subject).to receive(:map_email_attributes_override!) + .with(event: "event", attribute: "invented", ignore_blank_key_values: true, + email_key_values: {"id"=>"id value", "location"=>"email value", "route"=>"email value", "date_created"=>"date created value"}) + .and_return false + + allow(subject).to receive(:for_email_id).and_return("id value") + allow(subject).to receive(:for_email_route).and_return("email value") + } + it "returns attributes with email key values" do + expect(subject.map_email_attributes! event: "event", attributes: ["id", "location", "route", "date_created", "invented"], ignore_blank_key_values: true) + .to eq "id" => "id value", "location" => "email value", "route" => "email value", "date_created" => "date created value", "invented" => "invented value" + end + end + + context "when called with attribute(s) and ignore_blank_key_values and not map_email_attributes_override!" do + before { + allow(subject).to receive(:for_email_object).and_return(:date_created => nil, "made_up" => " ") + + allow(subject).to receive(:map_email_attributes_override!) + .with(event: "event", attribute: "date_created", ignore_blank_key_values: true, email_key_values: {}).and_return false + allow(subject).to receive(:map_email_attributes_override!) + .with(event: "event", attribute: "made_up", ignore_blank_key_values: true, email_key_values: {}).and_return false + } + it "returns attributes with email key values excluding blanks" do + expect(subject.map_email_attributes! event: "event", attributes: ["date_created", "made_up"], ignore_blank_key_values: true).to be_blank + end + end + + context "when called with attribute(s) and not ignore_blank_key_values and not map_email_attributes_override!" do + before { + allow(subject).to receive(:for_email_object).and_return(:date_created => nil, "invention" => "") + + allow(subject).to receive(:map_email_attributes_override!) + .with(event: "event", attribute: "date_created", ignore_blank_key_values: false, email_key_values: {}).and_return false + allow(subject).to receive(:map_email_attributes_override!) + .with(event: "event", attribute: "invention", ignore_blank_key_values: false, email_key_values: {"date_created"=>""}).and_return false + } + it "returns attributes with email key values including blanks" do + expect(subject.map_email_attributes! event: "event", attributes: ["date_created", "invention"], ignore_blank_key_values: false) + .to eq "date_created" => "", "invention" => "" + end + end + + context "when called with attribute(s) and map_email_attributes_override!" do + before { + allow(subject).to receive(:for_email_object) + allow(subject).to receive(:map_email_attributes_override!) + .with(event: "event", attribute: "id", ignore_blank_key_values: false, email_key_values:{:email_key_values=>"C sharp"}).and_return true + } + + it "returns unchanged email_key_values parameter" do + expect(subject.map_email_attributes! event: "event", attributes: ["id"], ignore_blank_key_values: false, email_key_values: "C sharp") + .to eq :email_key_values => "C sharp" + end + end + end + + + describe "#map_email_attributes_override!" do + it "returns false" do + expect(subject.map_email_attributes_override! event: "event", attribute: [], ignore_blank_key_values: false, email_key_values: []).to eq false + end + end + + + # protected method()s) + + describe "#email_event_notification" do + context "when email_key_values are not blank, send_it is false, and return_email_parameters is false" do # minimal + before { + allow(subject).to receive(:event_attributes_cache_write).with(event: "event", id: "M-99", behavior: :EmailBehavior) + allow(subject).to receive(:email_compose_body).with(message: "message", email_key_values: "email key values").and_return "email body" + } + it "caches event attributes and does not send email" do + expect(subject).to receive(:event_attributes_cache_write).with(event: "event", id: "M-99", behavior: :EmailBehavior) + expect(subject).to receive(:email_compose_body).with(message: "message", email_key_values: "email key values").and_return "email body" + expect(Deepblue::EmailHelper).not_to receive(:send_email) + expect(Deepblue::EmailHelper).not_to receive(:log) + expect(subject.send(:email_event_notification, to: "to", to_note: "note", from: "from", subject: "subject", attributes: "attributes", + current_user: "current user", event: "event", event_note: "event note", message: "message", + ignore_blank_key_values: true, id: "M-99", return_email_parameters: false, send_it: false, + email_key_values: "email key values")).to be_blank + end + end + + context "when email_key_values are blank, send_it is true, and return_email_parameters is true" do # maximal + before { + allow(subject).to receive(:email_attribute_values_for_snapshot).with(attributes: "attributes", current_user: "current user", + event: "event", event_note: "event note", to_note: "note", ignore_blank_key_values: true).and_return "snapshot" => "email values" + allow(subject).to receive(:event_attributes_cache_write).with(event: "event", id: "N-98", behavior: :EmailBehavior) + allow(subject).to receive(:email_compose_body).with(message: "message", email_key_values: {"snapshot" => "email values"}) + .and_return "email body" + allow(Deepblue::EmailHelper).to receive(:send_email).with( to: "to", from: "from", subject: "subject", body: "email body" ) + allow(subject).to receive(:for_email_class).and_return OpenStruct.new(name: "email class name") + } + it "calls email_attribute_values_for_snapshot, caches attributes, sends email, returns parameters" do + expect(subject).to receive(:email_attribute_values_for_snapshot).with(attributes: "attributes", current_user: "current user", + event: "event", event_note: "event note", to_note: "note", ignore_blank_key_values: true) + expect(subject).to receive(:event_attributes_cache_write).with(event: "event", id: "N-98", behavior: :EmailBehavior) + expect(subject).to receive(:email_compose_body).with(message: "message", email_key_values: {"snapshot" => "email values"}) + expect(Deepblue::EmailHelper).to receive(:send_email) + expect(subject.send(:email_event_notification, to: "to", to_note: "note", from: "from", subject: "subject", attributes: "attributes", + current_user: "current user", event: "event", event_note: "event note", message: "message", + ignore_blank_key_values: true, id: "N-98", return_email_parameters: true, send_it: true, + email_key_values: "")).to eq to: "to", to_note: "note", from: "from", subject: "subject", message: "message", + body: "email body", current_user: "current user", event: "event", event_note: "event note", + id: "N-98", email_key_values: {"snapshot" => "email values"} + end + + skip "Add a test for email_event_notification EmailHelper.log" + end + end + + +end diff --git a/spec/models/concerns/deepblue/embargoable_behavior_spec.rb b/spec/models/concerns/deepblue/embargoable_behavior_spec.rb new file mode 100644 index 00000000..aab6495e --- /dev/null +++ b/spec/models/concerns/deepblue/embargoable_behavior_spec.rb @@ -0,0 +1,418 @@ +class BehaviorMock + include Deepblue::EmbargoableBehavior + include Deepblue::ProvenanceBehavior + + def initialize + @visibility = nil + @visibility_during_embargo = nil + @visibility_after_embargo = nil + @visibility_during_lease = nil + @visibility_after_lease = nil + end + + def embargo + end + + def visibility + "visibility" + end + + def visibility=(text) + @visibility = text + end + + def visibility_during_embargo=(text) + @visibility_during_embargo = text + end + + def visibility_after_embargo=(text) + @visibility_after_embargo = text + end + + def visibility_during_lease=(text) + @visibility_during_lease = text + end + + def visibility_after_lease=(text) + @visibility_after_lease = text + end + + def visibility_during_embargo + end + + def provenance_unembargo(current_user:, embargo_visibility:, embargo_visibility_after:) + end + + def visibility_after_embargo + end + + def visibility_will_change! + end + + def lease + end + + def visibility_after_lease + end + + def visibility_during_lease + end + + def embargo_release_date + end + + def under_embargo? + false + end + + def lease_expiration_date + end + + def active_lease? + false + end +end + +class EmbargoMock + + def deactivate! + end +end + +class MockLease + def deactivate! + end + + def visibility + end +end + + +RSpec.describe Deepblue::EmbargoableBehavior do + subject { BehaviorMock.new } + + describe "#deactivate_embargo!" do + context "when embargo is nil" do + before { + allow(subject).to receive(:embargo).and_return nil + } + it "returns nil" do + expect(subject.deactivate_embargo!).to be_blank + end + end + + context "when embargo has a value" do + embargo = EmbargoMock.new + before { + allow(subject).to receive(:visibility_after_embargo_default).and_return "embargo after default" + allow(subject).to receive(:provenance_unembargo).with(current_user: "Deepblue", embargo_visibility: "visibility", embargo_visibility_after: "embargo after default") + + allow(subject).to receive(:embargo).and_return embargo + allow(embargo).to receive(:deactivate!) + } + + context "when visibility_after_embargo returns nil" do + before { + allow(subject).to receive(:visibility_after_embargo).and_return nil + } + it "calls visibility_after_embargo_default and visibility_will_change!" do + expect(subject).to receive(:visibility_after_embargo_default) + expect(subject).to receive(:provenance_unembargo).with(current_user: "Deepblue", embargo_visibility: "visibility", embargo_visibility_after: "embargo after default") + expect(subject).to receive(:visibility_will_change!) + + subject.deactivate_embargo! + subject.instance_variable_get(:@visibility) == "embargo after default" + end + end + + context "when visibility_after_embargo returns a value" do + before { + allow(subject).to receive(:visibility_after_embargo).and_return "visibility after embargo" + } + it "calls visibility_will_change!" do + expect(subject).not_to receive(:visibility_after_embargo_default) + expect(subject).to receive(:provenance_unembargo).with(current_user: "Deepblue", embargo_visibility: "visibility", embargo_visibility_after: "visibility after embargo") + expect(subject).to receive(:visibility_will_change!) + + subject.deactivate_embargo! + subject.instance_variable_get(:@visibility) == "visibility after embargo" + end + end + + after { + expect(subject).to have_received(:visibility_after_embargo) + expect(embargo).to have_received(:deactivate!) + } + end + end + + + describe "#deactivate_lease!" do + context "when lease is nil" do + before { + allow(subject).to receive(:lease).and_return nil + } + it "returns nil" do + expect(subject.deactivate_lease!).to be_blank + end + end + + context "when lease has a value" do + lease = MockLease.new + before { + allow(subject).to receive(:lease).and_return lease + allow(subject).to receive(:visibility_after_lease_default).and_return "lease default" + allow(lease).to receive(:deactivate!) + allow(subject).to receive(:visibility_will_change!) + } + + context "when visibility_after_lease returns nil" do + before { + allow(subject).to receive(:visibility_after_lease).and_return nil + } + it "calls visibility_after_lease_default and visibility_will_change!" do + expect(subject).to receive(:visibility_after_lease) + expect(subject).to receive(:visibility_after_lease_default) + expect(lease).to receive(:deactivate!) + expect(subject).to receive(:visibility_will_change!) + + subject.deactivate_lease! + + subject.instance_variable_get(:@visibility) == "visibility after lease" + end + end + + context "when visibility_after_lease returns a value" do + before { + allow(subject).to receive(:visibility_after_lease).and_return "visibility after lease" + } + it "calls visibility_will_change!" do + expect(subject).to receive(:visibility_after_lease) + expect(subject).not_to receive(:visibility_after_lease_default) + expect(lease).to receive(:deactivate!) + expect(subject).to receive(:visibility_will_change!) + + subject.deactivate_lease! + + subject.instance_variable_get(:@visibility) == "lease default" + end + end + end + end + + describe "#embargo_visibility" do + context "when embargo_release_date has no value" do + it "returns nil" do + expect(subject.embargo_visibility!).to be_blank + end + end + + context "when embargo_release_date has a value" do + before { + allow(subject).to receive(:embargo_release_date).and_return "embargo release date" + } + + context "when under_embargo? is true" do + before { + allow(subject).to receive(:under_embargo?).and_return true + } + + context "when visibility_during_embargo has value" do + before { + allow(subject).to receive(:visibility_during_embargo).and_return "embargo during" + } + + it "sets @visibility_during_embargo to visibility_during_embargo" do + subject.embargo_visibility! + subject.instance_variable_get(:@visibility_during_embargo) == "embargo during" + end + + it "sets @visibility to visibility_during_embargo" do + subject.embargo_visibility! + subject.instance_variable_get(:@visibility) == "embargo during" + end + end + + context "when visibility_during_embargo has no value" do + before { + allow(subject).to receive(:visibility_during_embargo_default).and_return "embargo during default" + } + it "sets @visibility_during_embargo to visibility_during_embargo_default" do + subject.embargo_visibility! + subject.instance_variable_get(:@visibility_during_embargo) == "embargo during default" + end + + it "sets @visibility to nil" do + subject.embargo_visibility! + subject.instance_variable_get(:@visibility).blank? == true + end + end + + + context "when visibility_after_embargo has a value" do + before { + allow(subject).to receive(:visibility_after_embargo).and_return "embargo after" + } + it "sets @visibility_after_embargo to visibility_after_embargo" do + subject.embargo_visibility! + subject.instance_variable_get(:@visibility_after_embargo) == "embargo after" + end + end + + context "when visibility_after_embargo has no value" do + before { + allow(subject).to receive(:visibility_after_embargo_default).and_return "embargo after default" + } + it "sets @visibility_after_embargo to visibility_after_embargo_default" do + subject.embargo_visibility! + subject.instance_variable_get(:@visibility_after_embargo) == "embargo after default" + end + end + end + + + context "when under_embargo? is false" do + context "when visibility_after_embargo has no value" do + before { + allow(subject).to receive(:visibility_after_embargo_default).and_return "embargo after default" + } + it "sets @visibility to visibility_after_embargo_default" do + subject.embargo_visibility! + subject.instance_variable_get(:@visibility) == "embargo after default" + end + end + + context "when visibility_after_embargo has a value" do + before { + allow(subject).to receive(:visibility_after_embargo).and_return "prohibition restriction interdiction" + } + it "sets @visibility to visibility_after_embargo" do + subject.embargo_visibility! + subject.instance_variable_get(:@visibility) == "prohibition restriction interdiction" + end + end + + end + end + end + + + describe "#lease_visibility!" do + context "when lease_expiration_date has no value" do + it "returns nil" do + expect(subject.lease_visibility!).to be_blank + end + end + + context "when lease_expiration_date has a value" do + before { + allow(subject).to receive(:lease_expiration_date).and_return "lease expiration date" + } + + context "when active lease" do + before { + allow(subject).to receive(:active_lease?).and_return true + allow(subject).to receive(:visibility_during_lease_default).and_return "visibility during lease default" + allow(subject).to receive(:visibility_after_lease_default).and_return "visibility after lease default" + } + + context "when visibility_during_lease has a value" do + before { + allow(subject).to receive(:visibility_during_lease).and_return "visibility during lease" + } + + it "sets @visibility to visibility_during_lease" do + subject.lease_visibility! + subject.instance_variable_get(:@visibility) == "visibility during lease" + end + + it "sets @visibility_during_lease to visibility_during_lease" do + subject.lease_visibility! + subject.instance_variable_get(:@visibility_during_lease) == "visibility during lease" + end + end + + context "when visibility_during_lease does not have a value" do + it "sets @visibility to nil" do + subject.lease_visibility! + subject.instance_variable_get(:@visibility).blank? == true + end + + it "sets @visibility_during_lease to visibility_during_lease_default" do + subject.lease_visibility! + subject.instance_variable_get(:@visibility_during_lease) == "visibility during lease default" + end + end + + context "when visibility_after_lease has a value" do + before { + allow(subject).to receive(:visibility_after_lease).and_return "visibility after lease" + } + + it "sets @visibility to visibility_after_lease" do + subject.lease_visibility! + subject.instance_variable_get(:@visibility_after_lease) == "visibility after lease" + end + end + + context "when visibility_after_lease has no value" do + it "sets @visibility to visibility_after_lease_default" do + subject.lease_visibility! + subject.instance_variable_get(:@visibility_after_lease) == "visibility after lease default" + end + end + end + + context "when no active lease" do + context "when visibility_after_lease has a value" do + before { + allow(subject).to receive(:visibility_after_lease).and_return "visibility after lease" + } + it "sets @visibility to visibility_after_lease" do + subject.lease_visibility! + subject.instance_variable_get(:@visibility) == "visibility after lease" + end + end + + context "when visibility_after_lease has no value" do + before { + allow(subject).to receive(:visibility_after_lease_default).and_return "visibility after lease default" + } + it "sets @visibility to visibility_after_lease_default" do + subject.lease_visibility! + subject.instance_variable_get(:@visibility) == "visibility after lease default" + end + end + end + end + end + + + describe "#visibility_after_embargo_default" do + before { + allow(::DeepBlueDocs::Application.config).to receive(:embargo_visibility_after_default_status).and_return "status" + } + it "calls DeepBlueDocs::Application.config.embargo_visibility_after_default_status" do + expect(subject.visibility_after_embargo_default).to eq "status" + end + end + + describe "#visibility_after_lease_default" do + it "calls ::Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE" do + expect(subject.visibility_after_lease_default).to eq "restricted" + end + end + + describe "#visibility_during_embargo_default" do + it "calls ::DeepBlueDocs::Application.config.embargo_visibility_during_default_status" do + expect(subject.visibility_during_embargo_default).to eq "restricted" + end + end + + describe "#visibility_during_lease_default" do + it "calls ::Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED" do + expect(subject.visibility_during_embargo_default).to eq "restricted" + end + end + +end diff --git a/spec/models/concerns/deepblue/metadata_behavior_spec.rb b/spec/models/concerns/deepblue/metadata_behavior_spec.rb index d1e2aef0..29fbcaa0 100644 --- a/spec/models/concerns/deepblue/metadata_behavior_spec.rb +++ b/spec/models/concerns/deepblue/metadata_behavior_spec.rb @@ -54,6 +54,14 @@ def metadata_hash_override( key:, ignore_blank_values:, key_values: ) end +class OutputMock + def puts(text) + + end +end + + + RSpec.describe Deepblue::AbstractEventBehavior do let( :empty_mock ) { CurationConcernEmptyMock.new } @@ -68,6 +76,18 @@ def metadata_hash_override( key:, ignore_blank_values:, key_values: ) end end + describe '#for_metadata_id' do + it do + expect( mock.for_metadata_id ).to eq 'id123' + end + end + + describe '#for_metadata_title' do + it do + expect( mock.for_metadata_title ).to eq ['The Title', 'Part 2'] + end + end + describe 'default values' do it do expect( empty_mock.metadata_keys_all ).to eq [] @@ -83,7 +103,7 @@ def metadata_hash_override( key:, ignore_blank_values:, key_values: ) end end - describe 'metadata_hash' do + describe '#metadata_hash' do let( :empty_hash ) { {} } let( :expected_hash_all ) { { id: mock.id, title: mock.title, description: mock.description } } let( :expected_hash_brief ) { { id: mock.id, title: mock.title } } @@ -107,7 +127,56 @@ def metadata_hash_override( key:, ignore_blank_values:, key_values: ) end end - describe 'metadata_report_filename' do + + describe "#metadata_report" do + context "when dir is empty and out is empty" do + it "raises a MetadataError" do + expect { mock.metadata_report }.to raise_error("Either dir: or out: must be specified.") + end + end + + context "when out is empty" do + before { + allow(mock).to receive(:metadata_report_filename).with(pathname_dir: "directory", filename_pre: '', filename_post: '_metadata_report', filename_ext: '.txt').and_return "target file" + allow(mock).to receive(:open).with("target file", 'w').and_return "out 2" + } + + it "calls open on the result of calling metadata_report_filename" do + expect(mock).to receive(:metadata_report_filename).with(pathname_dir: "directory", filename_pre: '', filename_post: '_metadata_report', filename_ext: '.txt') + expect(mock).to receive(:open).with("target file", 'w') + + expect(mock.metadata_report(dir: "directory")).to eq "target file" + end + + it "calls metadata_report" do + skip "Add a test" + end + end + + context "when dir and out both have values" do + let( :out_obj ) { OutputMock.new } + + before { + allow(mock).to receive(:metadata_report_title).with(depth: 2).and_return "report title" + allow(out_obj).to receive(:puts).with "report title" + allow(mock).to receive(:metadata_report_keys).and_return ["ignore", "keys"] + allow(mock).to receive(:metadata_hash).with(metadata_keys: "keys", ignore_blank_values: "ignore").and_return "metadata hash" + allow(mock).to receive(:metadata_report_to).with(out: out_obj, metadata_hash: "metadata hash", depth: 2) + } + it "calls metadata_report_title" do + expect(mock).to receive(:metadata_report_title) + expect(out_obj).to receive(:puts).with "report title" + expect(mock).to receive(:metadata_report_keys) + expect(mock).to receive(:metadata_hash).with(metadata_keys: "keys", ignore_blank_values: "ignore") + expect(mock).to receive(:metadata_report_to).with(out: out_obj, metadata_hash: "metadata hash", depth: 2) + + expect(mock.metadata_report(dir: "directory", out: out_obj)).to be_blank + end + end + end + + + describe '#metadata_report_filename' do let( :pathname_dir ) { "/some/path" } let( :filename_pre ) { "pre_" } context 'basic parms' do @@ -126,4 +195,106 @@ def metadata_hash_override( key:, ignore_blank_values:, key_values: ) end end + + describe "#metadata_report_label" do + context "when metadata_key is blank" do + it "returns nil" do + expect(mock.metadata_report_label(metadata_key: "", metadata_value: nil)).to be_blank + end + end + + context "when metadata_report_label_override returns a label" do + before { + allow(mock).to receive(:metadata_report_label_override).with(metadata_key: "key", metadata_value: "value").and_return "label" + } + it "returns label" do + expect(mock).to receive(:metadata_report_label_override) + expect(mock.metadata_report_label(metadata_key: "key", metadata_value: "value")).to eq "label" + end + end + + context "when metadata_report_label_override does not return a label" do + metadata_labels = [{"key" => "id", "label" => "ID: "}, + {"key" => "location", "label" => "Location: "}, + {"key" => "route", "label" => "Route: "}, + {"key" => "title", "label" => "Title: "}, + {"key" => "visibility", "label" => "Visibility: "}, + {"key" => "outland BAGPIPES", "label" => "Outland Bagpipes"}] + + metadata_labels.each do |report| + before { + allow(mock).to receive(:metadata_report_label_override).with(metadata_key: report[:key], metadata_value: "value") + } + it "returns a label '#{report[:label]}' based on metadata_key '#{report[:key]}'" do + expect(mock.metadata_report_label(metadata_key: report[:key], metadata_value: "value")).to eq report[:label] + end + end + + end + end + + + describe "#metadata_report_to" do + context "when out argument passed in is nil" do + it "returns nil" do + expect(mock.metadata_report_to(out: nil, metadata_hash: "hash")).to be_blank + end + end + + context "when out is not nil and metadata_hash has pairs" do + before { + allow(mock).to receive(:metadata_report_item_to).with(out: "out", key: :a, value: 100, depth: 0) + allow(mock).to receive(:metadata_report_item_to).with(out: "out", key: :b, value: 200, depth: 0) + } + it "calls metadata_report_item_to for each pair" do + expect(mock).to receive(:metadata_report_item_to).with(out: "out", key: :a, value: 100, depth: 0) + expect(mock).to receive(:metadata_report_item_to).with(out: "out", key: :b, value: 200, depth: 0) + + expect(mock.metadata_report_to(out: "out", metadata_hash: { a: 100, b: 200 })) + end + end + + context "when out is not nil and metadata_hash does not have pairs" do + it "returns nil" do + expect(mock.metadata_report_to(out: "outside", metadata_hash: { })).to be_blank + end + end + end + + + describe "#metadata_report_item_to" do + before { + allow(mock).to receive(:metadata_report_label).with(metadata_key: "key", metadata_value: "value").and_return "label" + allow(Deepblue::MetadataHelper).to receive(:report_item).with("out", "label", "value") + } + it "calls MetadataHelper.report_item" do + expect(mock).to receive(:metadata_report_label) + expect(Deepblue::MetadataHelper).to receive(:report_item).with("out", "label", "value") + mock.metadata_report_item_to(out: "out", key: "key", value: "value", depth: 0) + end + end + + + describe "#metadata_report_visibility_value" do + context "when visibility is VISIBILITY_TEXT_VALUE_PUBLIC" do + it "returns published" do + expect(mock.metadata_report_visibility_value(Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC)).to eq "published" + end + end + + context "when visibility is VISIBILITY_TEXT_VALUE_PRIVATE" do + it "returns private" do + expect(mock.metadata_report_visibility_value(Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC)).to eq "published" + end + end + + context "when visibility is not public or private - other " do + + it "returns value of visibility" do + expect(mock.metadata_report_visibility_value("anything else")).to eq "anything else" + end + end + end + + end diff --git a/spec/models/concerns/deepblue/provenance_behavior_spec.rb b/spec/models/concerns/deepblue/provenance_behavior_spec.rb new file mode 100644 index 00000000..97578a6c --- /dev/null +++ b/spec/models/concerns/deepblue/provenance_behavior_spec.rb @@ -0,0 +1,487 @@ +require 'rails_helper' + +class ProvenanceMock + include ::Deepblue::ProvenanceBehavior + + def id + 1001 + end + + def has_attribute?(attr) + false + end + + def berry_farm + + end +end + +RSpec.describe Deepblue::ProvenanceBehavior do + subject { ProvenanceMock.new } + + describe "#attributes_all_for_provenance" do + it "returns empty array" do + expect(subject.attributes_all_for_provenance).to be_blank + end + end + + describe "#attributes_brief_for_provenance" do + it "returns empty array" do + expect(subject.attributes_brief_for_provenance).to be_blank + end + end + + describe "#attributes_virus_for_provenance" do + before { + allow(subject).to receive(:attributes_brief_for_provenance).and_return(["omega"]) + } + it "returns attributes_brief_for_provenance" do + expect(subject).to receive(:attributes_brief_for_provenance) + expect(subject.attributes_virus_for_provenance).to eq ["omega"] + end + end + + describe "#attributes_update_for_provenance" do + before { + allow(subject).to receive(:attributes_all_for_provenance).and_return(["uno", "dos", "tres"]) + } + it "returns attributes_all_for_provenance" do + expect(subject).to receive(:attributes_all_for_provenance) + expect(subject.attributes_update_for_provenance).to eq ["uno", "dos", "tres"] + end + end + + describe "#attributes_for_provenance_add" do + before { + allow(subject).to receive(:attributes_brief_for_provenance).and_return(["alpha", "beta", "gamma"]) + } + it "returns attributes_brief_for_provenance, IGNORE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_brief_for_provenance) + expect(subject.attributes_for_provenance_add).to eq [["alpha", "beta", "gamma"], true] + end + end + + describe "#attributes_for_provenance_characterize" do + before { + allow(subject).to receive(:attributes_brief_for_provenance).and_return([1,2,3]) + } + it "returns attributes_brief_for_provenance, IGNORE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_brief_for_provenance) + expect(subject.attributes_for_provenance_characterize).to eq [[1,2,3], true] + end + end + + describe "#attributes_for_provenance_create" do + before { + allow(subject).to receive(:attributes_all_for_provenance).and_return(["apple", "orange", "pomegranate"]) + } + it "returns attributes_all_for_provenance, USE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_all_for_provenance) + expect(subject.attributes_for_provenance_create).to eq [["apple", "orange", "pomegranate"], false] + end + end + + describe "#attributes_for_provenance_create_derivative" do + before { + allow(subject).to receive(:attributes_brief_for_provenance).and_return(["lemon", "lime", "bergamot"]) + } + it "returns attributes_brief_for_provenance, USE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_brief_for_provenance) + expect(subject.attributes_for_provenance_create_derivative).to eq [["lemon", "lime", "bergamot"], false] + end + end + + describe "#attributes_for_provenance_destroy" do + before { + allow(subject).to receive(:attributes_all_for_provenance).and_return(["un", "deux", "trois"]) + } + it "returns attributes_all_for_provenance, USE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_all_for_provenance) + expect(subject.attributes_for_provenance_destroy).to eq [["un", "deux", "trois"], false] + end + end + + describe "#attributes_for_provenance_embargo" do + before { + allow(subject).to receive(:attributes_all_for_provenance).and_return("ceci n'est pas un gateaux") + } + it "returns attributes_all_for_provenance, USE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_all_for_provenance) + expect(subject.attributes_for_provenance_embargo).to eq ["ceci n'est pas un gateaux", false] + end + end + + describe "#attributes_for_provenance_fixity_check" do + before { + allow(subject).to receive(:attributes_brief_for_provenance).and_return("brevity") + } + it "returns attributes_brief_for_provenance, IGNORE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_brief_for_provenance) + expect(subject.attributes_for_provenance_fixity_check).to eq ["brevity", true] + end + end + + describe "#attributes_for_provenance_ingest" do + before { + allow(subject).to receive(:attributes_all_for_provenance).and_return("Herbes de Provence") + } + it "returns attributes_all_for_provenance, USE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_all_for_provenance) + expect(subject.attributes_for_provenance_ingest).to eq ["Herbes de Provence", false] + end + end + + describe "#attributes_for_provenance_migrate" do + before { + allow(subject).to receive(:attributes_brief_for_provenance).and_return("lavender") + } + it "returns attributes_brief_for_provenance, IGNORE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_brief_for_provenance) + expect(subject.attributes_for_provenance_migrate).to eq ["lavender", true] + end + end + + describe "#attributes_for_provenance_mint_doi" do + before { + allow(subject).to receive(:attributes_all_for_provenance).and_return(1001) + } + it "returns attributes_all_for_provenance, USE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_all_for_provenance) + expect(subject.attributes_for_provenance_mint_doi).to eq [1001, false] + end + end + + describe "#attributes_for_provenance_publish" do + before { + allow(subject).to receive(:attributes_all_for_provenance).and_return(3.14159) + } + it "returns attributes_all_for_provenance, USE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_all_for_provenance) + expect(subject.attributes_for_provenance_publish).to eq [3.14159, false] + end + end + + describe "#attributes_for_provenance_tombstone" do + before { + allow(subject).to receive(:attributes_all_for_provenance).and_return(22) + } + it "returns attributes_all_for_provenance, USE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_all_for_provenance) + expect(subject.attributes_for_provenance_tombstone).to eq [22, false] + end + end + + describe "#attributes_for_provenance_unembargo" do + before { + allow(subject).to receive(:attributes_all_for_provenance).and_return("quixotic") + } + it "returns attributes_all_for_provenance, USE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_all_for_provenance) + expect(subject.attributes_for_provenance_unembargo).to eq ["quixotic", false] + end + end + + describe "#attributes_for_provenance_unpublish" do + before { + allow(subject).to receive(:attributes_all_for_provenance).and_return("tristesse") + } + it "returns attributes_all_for_provenance, USE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_all_for_provenance) + expect(subject.attributes_for_provenance_unpublish).to eq ["tristesse", false] + end + end + + describe "#attributes_for_provenance_update" do + before { + allow(subject).to receive(:attributes_update_for_provenance).and_return("impossible") + } + it "returns attributes_update_for_provenance, IGNORE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_update_for_provenance) + expect(subject.attributes_for_provenance_update).to eq ["impossible", true] + end + end + + describe "#attributes_for_provenance_update_version" do + before { + allow(subject).to receive(:attributes_update_for_provenance).and_return("betwixt and between") + } + it "returns attributes_update_for_provenance, IGNORE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_update_for_provenance) + expect(subject.attributes_for_provenance_update_version).to eq ["betwixt and between", true] + end + end + + describe "#attributes_for_provenance_upload" do + before { + allow(subject).to receive(:attributes_all_for_provenance).and_return("sabotage") + } + it "returns attributes_all_for_provenance, USE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_all_for_provenance) + expect(subject.attributes_for_provenance_upload).to eq ["sabotage", false] + end + end + + describe "#attributes_for_provenance_virus_scan" do + before { + allow(subject).to receive(:attributes_virus_for_provenance).and_return("virii is not latin") + } + it "returns attributes_virus_for_provenance, IGNORE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_virus_for_provenance) + expect(subject.attributes_for_provenance_virus_scan).to eq ["virii is not latin", true] + end + end + + describe "#attributes_for_provenance_workflow" do + before { + allow(subject).to receive(:attributes_brief_for_provenance).and_return("apparatchik") + } + it "returns attributes_brief_for_provenance, IGNORE_BLANK_KEY_VALUES" do + expect(subject).to receive(:attributes_brief_for_provenance) + expect(subject.attributes_for_provenance_workflow).to eq ["apparatchik", true] + end + end + + describe "#attributes_cache_fetch" do + before { + allow(subject).to receive(:attributes_cache_key).with(event: "event", id: "121").and_return("XYZ") + allow(Rails.cache).to receive(:fetch).with("XYZ").and_return("attributes") + } + it "returns attributes cache by event id" do + expect(subject).to receive(:attributes_cache_key).with(event: "event", id: "121") + expect(Rails.cache).to receive(:fetch) + expect(subject.attributes_cache_fetch event: "event", id: "121").to eq "attributes" + end + end + + describe "#attributes_cache_key" do + it "returns parameters as string" do + expect(subject.attributes_cache_key event: "event", id: "121").to eq "121.event" + end + end + + describe "#attributes_cache_write" do + before { + allow(subject).to receive(:attributes_cache_key).with(event: "event", id: "171").and_return("A.B-C") + } + it "calls Rails.cache.write" do + expect(subject).to receive(:attributes_cache_key).with(event: "event", id: "171") + expect(Rails.cache).to receive(:write).with("A.B-C", "attributes") + subject.attributes_cache_write( event: "event", id: "171", attributes: "attributes" ) + end + end + + describe "#for_provenance_event_cache_exist?" do + before { + allow(subject).to receive(:for_provenance_event_cache_key).with(event: "event", id: "181").and_return("key") + allow(Rails.cache).to receive(:exist?).with("key").and_return true + } + it "calls Rails.cache.exist?" do + expect(subject).to receive(:for_provenance_event_cache_key).with(event: "event", id: "181") + expect(Rails.cache).to receive(:exist?).with("key") + expect(subject.for_provenance_event_cache_exist? event: "event", id: "181" ).to eq true + end + end + + describe "#for_provenance_event_cache_fetch" do + before { + allow(subject).to receive(:for_provenance_event_cache_key).with(event: "event", id: "191").and_return("key") + allow(Rails.cache).to receive(:fetch).with("key").and_return "it was cached" + } + it "calls Rails.cache.fetch" do + expect(subject).to receive(:for_provenance_event_cache_key).with(event: "event", id: "191") + expect(Rails.cache).to receive(:fetch).with("key") + expect(subject.for_provenance_event_cache_fetch event: "event", id: "191" ).to eq "it was cached" + end + end + + describe "#for_provenance_event_cache_key" do + it "returns string" do + expect(subject.for_provenance_event_cache_key event: "evening_event", id: "202" ).to eq "202.evening_event.provenance" + end + end + + describe "#for_provenance_event_cache_key" do + it "returns string" do + expect(subject.for_provenance_event_cache_key event: "evening_event", id: "202" ).to eq "202.evening_event.provenance" + end + end + + describe "#for_provenance_class" do + it "returns type of object self" do + expect(subject.for_provenance_class).to eq ProvenanceMock + end + end + + describe "#for_provenance_id" do + it "returns id of object self" do + expect(subject.for_provenance_id).to eq 1001 + end + end + + describe "#for_provenance_ignore_empty_attributes" do + it "returns true" do + expect(subject.for_provenance_ignore_empty_attributes).to eq true + end + end + + describe "#for_provenance_object" do + it "returns self" do + expect(subject.for_provenance_object).to eq subject + end + end + + describe "#for_provenance_route" do + it "returns string" do + expect(subject.for_provenance_route).to eq "route to 1001" + end + end + + describe "#for_provenance_user" do + context "when current user is blank" do + it "returns empty string" do + expect(subject.for_provenance_user nil).to be_blank + end + end + + context "when current user is a string that is not blank" do + it "returns same parameter passed in" do + expect(subject.for_provenance_user "user1@example.com").to eq "user1@example.com" + end + end + + context "when current user is not a string" do + user_obj = OpenStruct.new(id: '33') + + before { + allow(Deepblue::EmailHelper).to receive(:user_email_from).with(user_obj).and_return "user2@example.com" + } + it "calls EmailHelper.user_email_from" do + expect(subject.for_provenance_user user_obj).to eq "user2@example.com" + end + end + end + + describe "#map_provenance_attributes!" do + context "when no attributes present" do + it "returns prov_key_values passed in" do + expect(subject.map_provenance_attributes! event: "event", attributes: [], ignore_blank_key_values: true, prov_key_values: ["buttercream", "toasted meringue", "ganache"]). + to eq :prov_key_values=>["buttercream", "toasted meringue", "ganache"] + end + end + + context "when attributes present and map_provenance_attributes_override! returns true" do + before { + allow(subject).to receive(:map_provenance_attributes_override!).with(event: "event", + attribute: "berry farm", + ignore_blank_key_values: true, + prov_key_values: {:prov_key_values=>"strawberry"}).and_return true + } + it "returns prov_key_values passed in" do + expect(subject.map_provenance_attributes! event: "event", attributes: ["berry farm"], ignore_blank_key_values: true, prov_key_values: "strawberry"). + to eq :prov_key_values=>"strawberry" + end + end + + context "when attribute(s) present and map_provenance_attributes_override! returns false and self object does not have attribute" do + before { + allow(subject).to receive(:berry_farm).and_return false + allow(subject).to receive(:map_provenance_attributes_override!).with(event: "event", + attribute: "berry_farm", + ignore_blank_key_values: true, + prov_key_values: {:prov_key_values=>"berry"}).and_return false + } + it "returns prov_key_values passed in and missing attribute" do + expect(subject.map_provenance_attributes! event: "event", attributes: ["berry_farm"], ignore_blank_key_values: true, prov_key_values: "berry"). + to eq "berry_farm"=>"MISSING_ATTRIBUTE", :prov_key_values=>"berry" + end + end + + context "when attribute(s) present and map_provenance_attributes_override! returns false and self object has attribute" do + skip "Add a test" + end + + context "when id attribute present and map_provenance_attributes_override! returns false" do + before { + allow(subject).to receive(:map_provenance_attributes_override!).with(event: "event", + attribute: "id", + ignore_blank_key_values: true, + prov_key_values: {:prov_key_values=>"berry"}).and_return false + } + it "returns prov_key_values passed in and id value" do + expect(subject.map_provenance_attributes! event: "event", attributes: ["id"], ignore_blank_key_values: true, prov_key_values: "berry"). + to eq "id"=>1001, :prov_key_values=>"berry" + end + end + + context "when location attribute present and map_provenance_attributes_override! returns false" do + before { + allow(subject).to receive(:map_provenance_attributes_override!).with(event: "event", + attribute: "location", + ignore_blank_key_values: true, + prov_key_values: {:prov_key_values=>"berry"}).and_return false + } + it "returns prov_key_values passed in and location value" do + expect(subject.map_provenance_attributes! event: "event", attributes: ["location"], ignore_blank_key_values: true, prov_key_values: "berry"). + to eq "location"=>"route to 1001", :prov_key_values=>"berry" + end + end + + context "when route attribute present and map_provenance_attributes_override! returns false" do + before { + allow(subject).to receive(:map_provenance_attributes_override!).with(event: "event", + attribute: "route", + ignore_blank_key_values: true, + prov_key_values: {:prov_key_values=>"berry"}).and_return false + } + it "returns prov_key_values passed in and route value" do + expect(subject.map_provenance_attributes! event: "event", attributes: ["route"], ignore_blank_key_values: true, prov_key_values: "berry"). + to eq "route"=>"route to 1001", :prov_key_values=>"berry" + end + end + + context "when date_created attribute present and map_provenance_attributes_override! returns false and date_created is blank and ignore_blank_key_values is true" do + before { + allow(subject).to receive(:for_provenance_object).and_return(:date_created => nil) + allow(subject).to receive(:map_provenance_attributes_override!).with(event: "event", + attribute: "date_created", + ignore_blank_key_values: true, + prov_key_values: {:prov_key_values=>"berry"}).and_return false + } + it "returns prov_key_values passed in" do + expect(subject.map_provenance_attributes! event: "event", attributes: ["date_created"], ignore_blank_key_values: true, prov_key_values: "berry"). + to eq :prov_key_values=>"berry" + end + end + + context "when date_created attribute present and map_provenance_attributes_override! returns false and date_created is blank and ignore_blank_key_values is false" do + before { + allow(subject).to receive(:for_provenance_object).and_return(:date_created => nil) + allow(subject).to receive(:map_provenance_attributes_override!).with(event: "event", + attribute: "date_created", + ignore_blank_key_values: false, + prov_key_values: {:prov_key_values=>"berry"}).and_return false + } + it "returns prov_key_values passed in and empty string for date_created" do + expect(subject.map_provenance_attributes! event: "event", attributes: ["date_created"], ignore_blank_key_values: false, prov_key_values: "berry"). + to eq "date_created"=>"", :prov_key_values=>"berry" + end + end + + context "when date_created attribute present and map_provenance_attributes_override! returns false and date_created has a value" do + before { + allow(subject).to receive(:for_provenance_object).and_return(:date_created => DateTime.new(2000, 12, 31)) + allow(subject).to receive(:map_provenance_attributes_override!).with(event: "event", + attribute: "date_created", + ignore_blank_key_values: true, + prov_key_values: {:prov_key_values=>"berry"}).and_return false + } + it "returns prov_key_values passed in and date_created value" do + expect(subject.map_provenance_attributes! event: "event", attributes: ["date_created"], ignore_blank_key_values: true, prov_key_values: "berry"). + to eq "date_created"=>DateTime.new(2000, 12, 31), :prov_key_values=>"berry" + end + end + + + end + +end diff --git a/spec/models/concerns/deepblue/workflow_event_behavior_spec.rb b/spec/models/concerns/deepblue/workflow_event_behavior_spec.rb new file mode 100644 index 00000000..8edc3b08 --- /dev/null +++ b/spec/models/concerns/deepblue/workflow_event_behavior_spec.rb @@ -0,0 +1,197 @@ +class WorkflowEventMockNoDatePublished + include Deepblue::WorkflowEventBehavior + + def initialize + @date_published = nil + @date_modified = nil + end + + def save! + end + + def date_published=(text) + @date_published = text + end + + def date_modified=(text) + @date_modified = text + end + + def provenance_publish(current_user:, event_note:, message:) + end + + def email_rds_publish(current_user:, event_note:, message:) + end +end + + +class WorkflowEventMock < WorkflowEventMockNoDatePublished + def id + end + + def provenance_create(current_user:, event_note:) + end + + def provenance_embargo(current_user:, event_note:) + end + + def provenance_destroy(current_user:, event_note:) + end + + def email_rds_create(current_user:, event_note:) + end + + def email_rds_destroy(current_user:, event_note:) + end + + def date_published + end +end + + +RSpec.describe Deepblue::WorkflowEventBehavior do + subject { WorkflowEventMock.new } + + describe '#workflow_create' do + before { + allow(Deepblue::LoggingHelper).to receive(:here).and_return "here" + allow(Deepblue::LoggingHelper).to receive(:called_from).and_return "called from" + allow(Deepblue::LoggingHelper).to receive(:obj_class).with('class', subject).and_return "class" + allow(::Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "class", "current_user=user", "event_note=note", ""]) + + allow(subject).to receive(:provenance_create).with(current_user: "user", event_note: "note") + allow(subject).to receive(:email_rds_create).with(current_user: "user", event_note: "note") + allow(subject).to receive(:id).and_return "work_id" + + allow(JiraNewTicketJob).to receive(:perform_later).with(work_id: 'work_id', current_user: "user") + } + + it "calls create functions" do + expect(Deepblue::LoggingHelper).to receive(:here) + expect(Deepblue::LoggingHelper).to receive(:called_from) + expect(Deepblue::LoggingHelper).to receive(:obj_class).with('class', subject) + expect(::Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "class", "current_user=user", "event_note=note", ""]) + + expect(subject).to receive(:provenance_create) + expect(subject).to receive(:email_rds_create) + allow(subject).to receive(:id).and_return "work_id" + + allow(JiraNewTicketJob).to receive(:perform_later).with(work_id: 'work_id', current_user: "user") + + subject.workflow_create(current_user: 'user', event_note: 'note') + end + end + + + describe '#workflow_embargo' do + before { + allow(Deepblue::LoggingHelper).to receive(:here).and_return "here" + allow(Deepblue::LoggingHelper).to receive(:called_from).and_return "called from" + allow(Deepblue::LoggingHelper).to receive(:obj_class).with('class', subject).and_return "class" + allow(::Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "class", "current_user=user", "event_note=note", ""]) + + allow(subject).to receive(:provenance_embargo).with(current_user: "user", event_note: "note") + } + it "calls embargo functions" do + expect(Deepblue::LoggingHelper).to receive(:here) + expect(Deepblue::LoggingHelper).to receive(:called_from) + expect(Deepblue::LoggingHelper).to receive(:obj_class).with('class', subject) + expect(::Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "class", "current_user=user", "event_note=note", ""]) + expect(subject).to receive(:provenance_embargo).with(current_user: "user", event_note: "note") + + subject.workflow_embargo(current_user: 'user', event_note: 'note') + end + end + + + describe '#workflow_destroy' do + before { + allow(Deepblue::LoggingHelper).to receive(:here).and_return "here" + allow(Deepblue::LoggingHelper).to receive(:called_from).and_return "called from" + allow(Deepblue::LoggingHelper).to receive(:obj_class).with('class', subject).and_return "class" + allow(::Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "class", "current_user=user", "event_note=note", ""]) + + allow(subject).to receive(:provenance_destroy).with(current_user: "user", event_note: "note") + allow(subject).to receive(:email_rds_destroy).with(current_user: "user", event_note: "note") + } + it "calls destroy functions" do + expect(Deepblue::LoggingHelper).to receive(:here) + expect(Deepblue::LoggingHelper).to receive(:called_from) + expect(Deepblue::LoggingHelper).to receive(:obj_class).with('class', subject) + expect(::Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "class", "current_user=user", "event_note=note", ""]) + + expect(subject).to receive(:provenance_destroy).with(current_user: "user", event_note: "note") + expect(subject).to receive(:email_rds_destroy).with(current_user: "user", event_note: "note") + + subject.workflow_destroy(current_user: 'user', event_note: 'note') + end + end + + + describe '#workflow_publish' do + before { + allow(Deepblue::LoggingHelper).to receive(:here).and_return "here" + allow(Deepblue::LoggingHelper).to receive(:called_from).and_return "called from" + allow(Deepblue::LoggingHelper).to receive(:obj_class).with('class', subject).and_return "class" + allow(::Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "class", "current_user=user", "event_note=note", + "message=message", ""]) + + allow(Hyrax::TimeService).to receive(:time_in_utc).and_return "time in utc" + allow(DateTime).to receive(:now).and_return "right now" + } + + context "when respond_to? :date_published" do + before { + allow(subject).to receive(:provenance_publish).with(current_user: "user", event_note: "note", message: "message") + allow(subject).to receive(:email_rds_publish).with(current_user: "user", event_note: "note", message: "message") + } + + it "calls publish functions" do + expect(Deepblue::LoggingHelper).to receive(:here).and_return "here" + expect(Deepblue::LoggingHelper).to receive(:called_from).and_return "called from" + expect(Deepblue::LoggingHelper).to receive(:obj_class).with('class', subject).and_return "class" + expect(::Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "class", "current_user=user", "event_note=note", + "message=message", ""]) + expect(subject).to receive(:save!) + + expect(subject).to receive(:provenance_publish).with(current_user: "user", event_note: "note", message: "message") + expect(subject).to receive(:email_rds_publish).with(current_user: "user", event_note: "note", message: "message") + + subject.workflow_publish(current_user: 'user', event_note: 'note', message: 'message') + + subject.instance_variable_get(:@date_published) == "time in utc" + subject.instance_variable_get(:@date_modified) == "right now" + end + end + + context "when respond_to? :date_published is false" do + subject { WorkflowEventMockNoDatePublished.new } + + before { + allow(::Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "does not respond to :date_published", ""]) + allow(subject).to receive(:provenance_publish).with(current_user: "user", event_note: "note", message: "message") + allow(subject).to receive(:email_rds_publish).with(current_user: "user", event_note: "note", message: "message") + } + + it "calls publish functions" do + expect(Deepblue::LoggingHelper).to receive(:here).and_return "here" + expect(Deepblue::LoggingHelper).to receive(:called_from).and_return "called from" + expect(Deepblue::LoggingHelper).to receive(:obj_class).with('class', subject).and_return "class" + expect(::Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "class", "current_user=user", "event_note=note", + "message=message", ""]) + expect(subject).not_to receive(:save!) + + expect(::Deepblue::LoggingHelper).to receive(:bold_debug).with(["here", "called from", "does not respond to :date_published", ""]) + + expect(subject).to receive(:provenance_publish).with(current_user: "user", event_note: "note", message: "message") + expect(subject).to receive(:email_rds_publish).with(current_user: "user", event_note: "note", message: "message") + + subject.workflow_publish(current_user: 'user', event_note: 'note', message: 'message') + + subject.instance_variable_get(:@date_published).blank? == true + subject.instance_variable_get(:@date_modified).blank? == true + end + end + end + +end