Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Commit

Permalink
Fix specs for updated geo_works event behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotjordan committed Mar 15, 2017
1 parent de63db2 commit e8288e8
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ gem 'rsolr', '~> 1.1.0'
gem 'devise' , '~> 4.2.0'
gem 'devise-guests', '~> 0.3'
gem 'iiif-presentation', github: 'iiif/osullivan', branch: 'development'
gem 'geo_works', github: 'geoconcerns/geo_works', branch: '8-refactor-messaging'
gem 'geo_works', github: 'geoconcerns/geo_works', branch: 'master'

# PDF generation
gem 'prawn'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ GIT

GIT
remote: git://github.com/geoconcerns/geo_works.git
revision: e9e790f90c2ea49ef29b8db623be9e8b83db150d
branch: 8-refactor-messaging
revision: 762b26a7e12f1c810ac1db9496ce7caf2d642f2c
branch: master
specs:
geo_works (0.3.4)
hyrax
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
##
# Delivers derivatives to external services, like GeoServer
##
class DeliveryJob < ActiveJob::Base
class GeoserverDeliveryJob < ActiveJob::Base
queue_as Hyrax.config.ingest_queue_name

attr_reader :file_set
Expand Down
24 changes: 0 additions & 24 deletions app/services/geo_works/events_generator.rb

This file was deleted.

50 changes: 50 additions & 0 deletions spec/controllers/hyrax/file_sets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
let(:parent) { FactoryGirl.create(:scanned_resource) }
let(:user) { FactoryGirl.create(:admin) }
let(:file) { fixture_file_upload("files/color.tif", "image/tiff") }
let(:generator) { instance_double(GeoWorks::EventsGenerator) }

before do
allow_any_instance_of(described_class).to receive(:curation_concern).and_return(file_set)
allow(file_set).to receive(:parent).and_return(parent)
allow(GeoWorks::EventsGenerator).to receive(:new).and_return(generator)
end

describe "#update" do
before do
sign_in user
Expand All @@ -31,6 +39,18 @@
patch :update, params: { id: file_set.id, file_set: { viewing_hint: 'non-paged' } }
expect(response).to redirect_to(Rails.application.class.routes.url_helpers.file_manager_hyrax_scanned_resource_path(parent.id, locale: 'en'))
end

context "with a geo work" do
let(:parent) { FactoryGirl.create(:vector_work) }

before do
allow(parent).to receive(:workflow_state).and_return('complete')
end
it "sends an update message for the parent" do
expect(generator).to receive(:record_updated)
patch :update, params: { id: file_set.id, file_set: { title: ["test"] } }
end
end
end

describe "#create" do
Expand All @@ -46,6 +66,36 @@
expect(FileSet.all.length).to eq 1
expect(manifest_generator).to have_received(:record_updated).with(parent)
end

context "with a geo work" do
let(:parent) { FactoryGirl.create(:vector_work) }

before do
allow(parent).to receive(:workflow_state).and_return('complete')
end
it "sends an update message for the parent" do
expect(generator).to receive(:record_updated)
post :create, params: { parent_id: parent, file_set: { files: [file], title: ['test title'], visibility: 'restricted' } }, xhr: true
end
end
end

describe "#destroy" do
before do
sign_in user
end
context "with a geo work" do
let(:parent) { FactoryGirl.create(:vector_work) }
let(:actor) { double }
before do
file_set.save
allow(parent).to receive(:workflow_state).and_return('complete')
end
it "sends an update message for the parent" do
expect(generator).to receive(:record_updated)
delete :destroy, params: { id: file_set }
end
end
end

describe "#text" do
Expand Down
16 changes: 16 additions & 0 deletions spec/controllers/hyrax/vector_works_controller_spec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,20 @@
end
end
end

describe '#geoblacklight' do
# Tell RSpec where to find the geoblacklight route.
routes { GeoWorks::Engine.routes }
let(:builder) { instance_double(GeoWorks::Discovery::DocumentBuilder, to_hash: { id: 'test' }) }
let(:document) { instance_double(Discovery::GeoblacklightDocument) }
before do
sign_in user
allow(Discovery::GeoblacklightDocument).to receive(:new).and_return(document)
end

it 'uses the plum document builder class' do
expect(GeoWorks::Discovery::DocumentBuilder).to receive(:new).with(anything, document).and_return(builder)
get :geoblacklight, params: { id: vector_work.id, format: :json }
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

describe DeliveryJob do
describe GeoserverDeliveryJob do
let(:id) { 'ab' }
let(:file_set) { instance_double(FileSet, id: id, geo_mime_type: file_format) }

Expand Down
7 changes: 7 additions & 0 deletions spec/models/file_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
end

describe "#create_derivatives" do
let(:delivery_service) { instance_double(GeoWorks::DeliveryService) }

before do
allow(delivery_service).to receive(:publish)
allow(GeoWorks::DeliveryService).to receive(:new).and_return(delivery_service)
end

let(:path) { Pathname.new(PairtreeDerivativePath.derivative_path_for_reference(subject, 'intermediate_file')) }
let(:thumbnail_path) { Pathname.new(PairtreeDerivativePath.derivative_path_for_reference(subject, 'thumbnail')) }
let(:ocr_path) { Pathname.new(PairtreeDerivativePath.derivative_path_for_reference(subject, 'ocr')) }
Expand Down
10 changes: 10 additions & 0 deletions spec/services/discovery/geoblacklight_document_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'rails_helper'

RSpec.describe Discovery::GeoblacklightDocument do
subject { described_class.new }
describe '#references' do
it 'adds a iiif reference to the geoblacklight document' do
expect(subject.references).to have_key('http://iiif.io/api/image')
end
end
end
6 changes: 3 additions & 3 deletions spec/services/workflow/publish_to_geo_blacklight_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

RSpec.describe Workflow::PublishToGeoBlacklight do
let(:work) { FactoryGirl.create(:vector_work) }
let(:messenger) { instance_double(GeoWorks::EventsGenerator) }
let(:generator) { instance_double(GeoWorks::EventsGenerator) }

describe '#call' do
before do
allow(GeoWorks::Messaging).to receive(:messenger).and_return(messenger)
allow(GeoWorks::EventsGenerator).to receive(:new).and_return(generator)
end

it 'updates geoblacklight with the target work' do
expect(messenger).to receive(:record_updated).with(instance_of(VectorWorkShowPresenter))
expect(generator).to receive(:record_updated).with(instance_of(VectorWorkShowPresenter))
described_class.call(target: work)
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/services/workflow/remove_from_geo_blacklight_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

RSpec.describe Workflow::RemoveFromGeoBlacklight do
let(:work) { FactoryGirl.create(:vector_work) }
let(:messenger) { instance_double(GeoWorks::EventsGenerator) }
let(:generator) { instance_double(GeoWorks::EventsGenerator) }

describe '#call' do
before do
allow(GeoWorks::Messaging).to receive(:messenger).and_return(messenger)
allow(GeoWorks::EventsGenerator).to receive(:new).and_return(generator)
end

it 'removes target work from geoblacklight' do
expect(messenger).to receive(:record_deleted).with(instance_of(VectorWorkShowPresenter))
expect(generator).to receive(:record_deleted).with(instance_of(VectorWorkShowPresenter))
described_class.call(target: work)
end
end
Expand Down

0 comments on commit e8288e8

Please sign in to comment.