Skip to content

Commit

Permalink
Allow OpenURI to Redirect from HTTP to HTTPS
Browse files Browse the repository at this point in the history
Production Plum redirects manifest URLs to https, which was breaking
auto-updates in Pomegranate. This allows for that behavior.
  • Loading branch information
tpendragon committed Feb 25, 2016
1 parent 8f6ce96 commit bb346e1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,4 @@ gem 'devise_invitable'
gem 'iiif-presentation'
gem 'omniauth-cas'
gem 'sneakers'
gem 'open_uri_redirections'
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ GEM
addressable (~> 2.3)
nokogiri (~> 1.5)
omniauth (~> 1.2.0)
open_uri_redirections (0.2.1)
openseadragon (0.2.1)
rails (> 3.2.0)
orm_adapter (0.5.0)
Expand Down Expand Up @@ -522,6 +523,7 @@ DEPENDENCIES
jettywrapper (>= 2.0)
jquery-rails
omniauth-cas
open_uri_redirections
pg
poltergeist
pry-rails
Expand Down
3 changes: 2 additions & 1 deletion app/models/iiif_resource.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'iiif/presentation'
require 'open-uri'
require 'open_uri_redirections'

class IIIFResource < Spotlight::Resource
belongs_to :exhibit, class_name: 'Spotlight::Exhibit'
Expand All @@ -21,7 +22,7 @@ def field_name(name)

def manifest
return {} if url.blank?
@manifest ||= ::IIIF::Service.parse(open(url).read)
@manifest ||= ::IIIF::Service.parse(open(url, allow_redirections: :safe).read)
end

def to_solr
Expand Down
4 changes: 2 additions & 2 deletions spec/models/iiif_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
let(:exhibit) { Spotlight::Exhibit.create title: 'Exhibit A' }

before do
allow_any_instance_of(described_class).to receive(:open).with(url).and_return(StringIO.new(json))
allow_any_instance_of(described_class).to receive(:open).with(url, allow_redirections: :safe).and_return(StringIO.new(json))
end

describe '#initialize' do
Expand Down Expand Up @@ -75,7 +75,7 @@
expect(solr_doc[:creator_ssim]).to eq(['Author, Alice, 1954-'])
expect(solr_doc[:date_created_ssim]).to eq(['1985'])

allow_any_instance_of(described_class).to receive(:open).with(url).and_return(StringIO.new(updated_json))
allow_any_instance_of(described_class).to receive(:open).with(url, allow_redirections: :safe).and_return(StringIO.new(updated_json))
subject.instance_variable_set :@manifest, nil
updated_doc = subject.to_solr
expect(updated_doc[:full_title_ssim]).to eq('Updated Manifest')
Expand Down

0 comments on commit bb346e1

Please sign in to comment.