Skip to content

Commit

Permalink
Using webmock for the first test
Browse files Browse the repository at this point in the history
  • Loading branch information
jrgriffiniii committed Feb 23, 2018
1 parent a652e0c commit fcf1014
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
30 changes: 26 additions & 4 deletions spec/services/plum_event_processor_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

RSpec.describe PlumEventProcessor, vcr: { cassette_name: "plum_events", allow_playback_repeats: true } do
RSpec.describe PlumEventProcessor do
subject(:processor) { described_class.new(event) }
let(:event) do
{
Expand All @@ -11,15 +11,37 @@
}
end
let(:collection_slugs) { ["first"] }
let(:url) { "https://hydra-dev.princeton.edu/concern/scanned_resources/1r66j1149/manifest" }
let(:url) { "https://figgy-staging.princeton.edu/concern/scanned_resources/1r66j1149/manifest" }

before do
end

context "when given an unknown event" do
let(:type) { "AWFULBADTHINGSHAPPENED" }

it "returns false" do
expect(processor.process).to eq false
end
end
context "when given a creation event" do

context "when given a creation event", fail: true do
let(:type) { "CREATED" }
let(:response) do
'{"@context":"http://iiif.io/api/presentation/2/context.json","@id":"https://hydra-dev.princeton.edu/concern/scanned_resources/1r66j1149/manifest","@type":"sc:Manifest","label":"Christopher and his kind, 1929-1939","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":"Log into Plum using CAS","profile":"http://iiif.io/api/auth/0/login","service":{"hsh":null}},"structures":[{"@id":"https://hydra-dev.princeton.edu/concern/scanned_resources/1r66j1149/manifest/range/g70272255683880","@type":"sc:Range","label":"Logical","viewingHint":"top"}],"metadata":[{"label":"Date created","value":[{"@value":"1976"}]}], "seeAlso":{"@id":"https://bibdata.princeton.edu/bibliographic/1234567/jsonld","format":"application/ld+json"}, "rendering":{"@id":"http://arks.princeton.edu/ark:88435/7w62fb79g", "format": "text/html"}}'
end

let(:bib_data_url) { 'https://bibdata.princeton.edu/bibliographic/1234567/jsonld' }
let(:bib_data_response) do
'{"@context":"http://bibdata.princeton.edu/context.json","@id":"http://bibdata.princeton.edu/bibliographic/1234567","title":{"@value":"Christopher and his kind, 1929-1939","@language":"eng"},"language":"eng","creator":"Isherwood, Christopher, 1904-1986","call_number":"PR6017.S5 Z498","extent":"339 p. ; 22 cm.","edition":"1st ed.","format":"Book","genre":"Biography","publisher":"New York : Farrar, Straus Giroux, 1976.","subject":["Isherwood, Christopher, 1904-1986","Authors, English—20th century—Biography"],"donor":["Copland, Aaron, 1900-1990"],"author":"Isherwood, Christopher, 1904-1986","created":"1976-01-01T00:00:00Z","date":"1976"}'
end

before do
stub_request(:get, url).to_return status: 200, headers: { 'Content-Type' => 'application/json; charset=utf-8' }, body: response
stub_request(:head, url).to_return status: 200, headers: { 'Content-Type' => 'application/json; charset=utf-8' }

stub_request(:get, bib_data_url).to_return status: 200, headers: { 'Content-Type' => 'application/ld+json; charset=utf-8' }, body: bib_data_response
end

it "builds the resource in that exhibit" do
exhibit = FactoryBot.create(:exhibit, slug: "first")

Expand All @@ -34,7 +56,7 @@
{
"id" => "1r66j1149",
"event" => "DELETED",
"manifest_url" => "https://hydra-dev.princeton.edu/concern/scanned_resources/1r66j1149/manifest"
"manifest_url" => url
}
end
it "deletes that resource" do
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
require 'pry-byebug'
require 'simplecov'
require 'webmock/rspec'

if ENV['CI']
require 'coveralls'
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
end

SimpleCov.start('rails') do
add_filter '/spec'
end

RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
Expand Down

0 comments on commit fcf1014

Please sign in to comment.