diff --git a/app/decorators/applies_title_from_slug.rb b/app/decorators/applies_title_from_slug.rb index a2f4b8ab..ae4a50d7 100644 --- a/app/decorators/applies_title_from_slug.rb +++ b/app/decorators/applies_title_from_slug.rb @@ -7,9 +7,16 @@ def initialize(record, slug) end def save(*args) - __getobj__.title = title __getobj__.slug = slug + __getobj__.title = title + return false unless valid? + super + end + + def valid?(*args) super + errors.add :slug, "can't be blank" if slug.blank? + errors.blank? end private @@ -19,6 +26,6 @@ def manifest end def title - manifest.label + manifest.try(:label) end end diff --git a/app/queries/external_collections_query.rb b/app/queries/external_collections_query.rb index 96a68616..542b0464 100644 --- a/app/queries/external_collections_query.rb +++ b/app/queries/external_collections_query.rb @@ -17,8 +17,8 @@ def initialize(remote_url) end def collection_manifests - @collection_manifests ||= manifest_urls.map do |url| - CollectionManifest.load(url) + @collection_manifests ||= all_manifest.collections.map do |collection| + CollectionManifest.new(collection.send(:data)) end end @@ -27,10 +27,4 @@ def collection_manifests def all_manifest @all_manifest ||= ExternalManifest.load(remote_url) end - - def manifest_urls - all_manifest.manifests.map do |manifest| - manifest['@id'] - end - end end diff --git a/spec/cassettes/all_collections.yml b/spec/cassettes/all_collections.yml index 0204defa..80bf889d 100644 --- a/spec/cassettes/all_collections.yml +++ b/spec/cassettes/all_collections.yml @@ -33,17 +33,17 @@ http_interactions: X-Xss-Protection: - 1; mode=block X-Request-Id: - - 1220de90-1693-4c4f-ab88-4b02d9247d16 + - 7ab2a9f4-d1be-4863-ab17-dea369362ffd Etag: - - W/"2fc1c01183eb74d9e5e2c08e87d9f59d" + - W/"b28cbc9dc3c54f85fa4aefaa38cf0298" X-Frame-Options: - SAMEORIGIN X-Runtime: - - '0.044988' + - '0.167548' X-Content-Type-Options: - nosniff Date: - - Thu, 14 Jan 2016 18:55:20 GMT + - Mon, 18 Jan 2016 16:57:48 GMT X-Powered-By: - Phusion Passenger 5.0.23 Server: @@ -57,135 +57,58 @@ http_interactions: Access-Control-Allow-Headers: - DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type body: - encoding: UTF-8 - string: '{"@context":"http://iiif.io/api/presentation/2/context.json","@id":"https://hydra-dev.princeton.edu/collections/manifest","@type":"sc:Collection","label":"Plum - Collections","description":"All collections which are a part of Plum.","viewingHint":"individuals","structures":[{"@id":"https://hydra-dev.princeton.edu/collections/manifest/range/g70309271427520","@type":"sc:Range","label":"Logical","viewingHint":"top"}],"manifests":[{"@id":"https://hydra-dev.princeton.edu/collections/5d86p020k/manifest","@type":"sc:Manifest","label":"Test - Collection 2","viewingHint":"individuals","viewingDirection":"left-to-right"},{"@id":"https://hydra-dev.princeton.edu/collections/2b88qc199/manifest","@type":"sc:Manifest","label":"princeton","viewingHint":"individuals","viewingDirection":"left-to-right"}]}' + encoding: ASCII-8BIT + string: !binary |- + eyJAY29udGV4dCI6Imh0dHA6Ly9paWlmLmlvL2FwaS9wcmVzZW50YXRpb24v + Mi9jb250ZXh0Lmpzb24iLCJAaWQiOiJodHRwczovL2h5ZHJhLWRldi5wcmlu + Y2V0b24uZWR1L2NvbGxlY3Rpb25zL21hbmlmZXN0IiwiQHR5cGUiOiJzYzpD + b2xsZWN0aW9uIiwibGFiZWwiOiJQbHVtIENvbGxlY3Rpb25zIiwiZGVzY3Jp + cHRpb24iOiJBbGwgY29sbGVjdGlvbnMgd2hpY2ggYXJlIGEgcGFydCBvZiBQ + bHVtLiIsInZpZXdpbmdIaW50IjoiaW5kaXZpZHVhbHMiLCJzdHJ1Y3R1cmVz + IjpbeyJAaWQiOiJodHRwczovL2h5ZHJhLWRldi5wcmluY2V0b24uZWR1L2Nv + bGxlY3Rpb25zL21hbmlmZXN0L3JhbmdlL2c3MDI3MjI1MTMxODIyMCIsIkB0 + eXBlIjoic2M6UmFuZ2UiLCJsYWJlbCI6IkxvZ2ljYWwiLCJ2aWV3aW5nSGlu + dCI6InRvcCJ9XSwiY29sbGVjdGlvbnMiOlt7IkBpZCI6Imh0dHBzOi8vaH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kZXYucHJpbmNldG9uLmVkdS9jb25jZXJuL3NjYW5u + ZWRfcmVzb3VyY2VzLzY5Njl6MDc5cC9tYW5pZmVzdCIsIkB0eXBlIjoic2M6 + TWFuaWZlc3QiLCJsYWJlbCI6IlRlc3QgUmVzb3VyY2UiLCJ2aWV3aW5nSGlu + dCI6ImluZGl2aWR1YWxzIiwidmlld2luZ0RpcmVjdGlvbiI6ImxlZnQtdG8t + cmlnaHQifV0sIm1ldGFkYXRhIjpbeyJsYWJlbCI6IkV4aGliaXQiLCJ2YWx1 + ZSI6W3siQHZhbHVlIjoidGVzdC1jb2xsZWN0aW9uLTIifV19XX1dfQ== http_version: - recorded_at: Thu, 14 Jan 2016 18:55:20 GMT -- request: - method: get - uri: https://hydra-dev.princeton.edu/collections/5d86p020k/manifest - body: - encoding: US-ASCII - string: '' - headers: - Accept-Encoding: - - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 - Accept: - - "*/*" - User-Agent: - - Ruby - response: - status: - code: 200 - message: OK - headers: - Content-Type: - - application/json; charset=utf-8 - Transfer-Encoding: - - chunked - Connection: - - keep-alive - Status: - - 200 OK - Cache-Control: - - max-age=0, private, must-revalidate - Vary: - - Accept - X-Xss-Protection: - - 1; mode=block - X-Request-Id: - - 7785efb2-2311-4189-bacd-7d11e6f2d70e - Etag: - - W/"a4296c841bb94d176daf27ff572e2264" - X-Frame-Options: - - SAMEORIGIN - X-Runtime: - - '0.147972' - X-Content-Type-Options: - - nosniff - Date: - - Thu, 14 Jan 2016 18:56:20 GMT - X-Powered-By: - - Phusion Passenger 5.0.23 - Server: - - nginx/1.8.0 + Phusion Passenger 5.0.23 - Access-Control-Allow-Origin: - - "*" - Access-Control-Allow-Credentials: - - 'true' - Access-Control-Allow-Methods: - - GET, POST, OPTIONS - Access-Control-Allow-Headers: - - DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type - body: - encoding: UTF-8 - string: '{"@context":"http://iiif.io/api/presentation/2/context.json","@id":"https://hydra-dev.princeton.edu/collections/5d86p020k/manifest","@type":"sc:Manifest","label":"Test - Collection 2","viewingHint":"individuals","viewingDirection":"left-to-right","service":{"@context":"http://iiif.io/api/auth/0/context.json","@id":"https://hydra-dev.princeton.edu/users/auth/cas","label":"Login - to Plum using CAS","profile":"http://iiif.io/api/auth/0/login","service":{"hsh":null}},"structures":[{"@id":"https://hydra-dev.princeton.edu/collections/5d86p020k/manifest/range/g70309456906720","@type":"sc:Range","label":"Logical","viewingHint":"top"}],"metadata":[{"label":"Exhibit","value":[{"@value":"test-collection-2"}]}]}' - http_version: - recorded_at: Thu, 14 Jan 2016 18:56:20 GMT -- request: - method: get - uri: https://hydra-dev.princeton.edu/collections/2b88qc199/manifest - body: - encoding: US-ASCII - string: '' - headers: - Accept-Encoding: - - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 - Accept: - - "*/*" - User-Agent: - - Ruby - response: - status: - code: 200 - message: OK - headers: - Content-Type: - - application/json; charset=utf-8 - Transfer-Encoding: - - chunked - Connection: - - keep-alive - Status: - - 200 OK - Cache-Control: - - max-age=0, private, must-revalidate - Vary: - - Accept - X-Xss-Protection: - - 1; mode=block - X-Request-Id: - - 21a92eff-1881-498b-a366-71b382349ebf - Etag: - - W/"db6f22e3faddc639d095898b2aa3b5d4" - X-Frame-Options: - - SAMEORIGIN - X-Runtime: - - '0.177122' - X-Content-Type-Options: - - nosniff - Date: - - Thu, 14 Jan 2016 18:56:20 GMT - X-Powered-By: - - Phusion Passenger 5.0.23 - Server: - - nginx/1.8.0 + Phusion Passenger 5.0.23 - Access-Control-Allow-Origin: - - "*" - Access-Control-Allow-Credentials: - - 'true' - Access-Control-Allow-Methods: - - GET, POST, OPTIONS - Access-Control-Allow-Headers: - - DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type - body: - encoding: UTF-8 - string: '{"@context":"http://iiif.io/api/presentation/2/context.json","@id":"https://hydra-dev.princeton.edu/collections/2b88qc199/manifest","@type":"sc:Manifest","label":"princeton","viewingHint":"individuals","viewingDirection":"left-to-right","service":{"@context":"http://iiif.io/api/auth/0/context.json","@id":"https://hydra-dev.princeton.edu/users/auth/cas","label":"Login - to Plum using CAS","profile":"http://iiif.io/api/auth/0/login","service":{"hsh":null}},"structures":[{"@id":"https://hydra-dev.princeton.edu/collections/2b88qc199/manifest/range/g70309282360200","@type":"sc:Range","label":"Logical","viewingHint":"top"}],"metadata":[{"label":"Exhibit","value":[{"@value":"princeton-best"}]}]}' - http_version: - recorded_at: Thu, 14 Jan 2016 18:56:20 GMT + recorded_at: Mon, 18 Jan 2016 16:57:48 GMT recorded_with: VCR 3.0.0 diff --git a/spec/controllers/exhibits_controller_spec.rb b/spec/controllers/exhibits_controller_spec.rb index 121424e5..613e5f7e 100644 --- a/spec/controllers/exhibits_controller_spec.rb +++ b/spec/controllers/exhibits_controller_spec.rb @@ -23,5 +23,20 @@ expect(last_exhibit.slug).to eq "princeton-best" end end + context "when not given a slug" do + let(:params) do + { + exhibit: { + slug: "" + } + } + end + it "renders an error" do + post :create, params + + expect(response).to render_template "new" + expect(assigns["exhibit"].errors.messages[:slug]).to eq ["can't be blank"] + end + end end end diff --git a/spec/models/external_manifest_spec.rb b/spec/models/external_manifest_spec.rb index 35f39ccf..d5ce3415 100644 --- a/spec/models/external_manifest_spec.rb +++ b/spec/models/external_manifest_spec.rb @@ -5,7 +5,7 @@ subject { described_class.load(manifest_url) } let(:manifest_url) { "https://hydra-dev.princeton.edu/collections/manifest" } it "loads up a manifest" do - expect(subject.manifests.length).to eql 2 + expect(subject.collections.length).to eql 2 end end end diff --git a/spec/queries/external_collections_query_spec.rb b/spec/queries/external_collections_query_spec.rb index 0d79de8d..382ae77d 100644 --- a/spec/queries/external_collections_query_spec.rb +++ b/spec/queries/external_collections_query_spec.rb @@ -4,7 +4,7 @@ subject { described_class } describe ".all" do it "queries plum for all collections" do - expect(subject.all.map(&:slug)).to eq ["test-collection-2", "princeton-best"] + expect(subject.all.map(&:slug)).to eq ["princeton-best", "test-collection-2"] end end end