Skip to content

Commit

Permalink
Test both versions of Fedora together.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpendragon committed Dec 4, 2018
1 parent 08c32f3 commit 73d9106
Show file tree
Hide file tree
Showing 7 changed files with 308 additions and 265 deletions.
14 changes: 8 additions & 6 deletions spec/support/fedora_helper.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# frozen_string_literal: true
module FedoraHelper
def fedora_adapter_config(base_path:, schema: nil)
def fedora_adapter_config(base_path:, schema: nil, fedora_version: 4)
port = fedora_version == 4 ? 8988 : 8998
opts = {
base_path: base_path,
connection: ::Ldp::Client.new("http://localhost:8988/rest"),
fedora_version: ENV["FEDORA5_COMPAT"].present? ? 5 : 4
connection: ::Ldp::Client.new("http://localhost:#{port}/rest"),
fedora_version: fedora_version
}
opts[:schema] = schema if schema
opts
end

def wipe_fedora!(base_path:)
Valkyrie::Persistence::Fedora::MetadataAdapter.new(fedora_adapter_config(base_path: base_path)).persister.wipe!
def wipe_fedora!(base_path:, fedora_version: 4)
Valkyrie::Persistence::Fedora::MetadataAdapter.new(fedora_adapter_config(base_path: base_path, fedora_version: fedora_version)).persister.wipe!
end
end

RSpec.configure do |config|
config.before do
wipe_fedora!(base_path: "test_fed")
wipe_fedora!(base_path: "test_fed", fedora_version: 4)
wipe_fedora!(base_path: "test_fed", fedora_version: 5)
end
config.include FedoraHelper
end
98 changes: 52 additions & 46 deletions spec/valkyrie/persistence/fedora/metadata_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,66 @@
require 'valkyrie/specs/shared_specs'

RSpec.describe Valkyrie::Persistence::Fedora::MetadataAdapter do
let(:adapter) { described_class.new(fedora_adapter_config(base_path: "test_fed")) }
it_behaves_like "a Valkyrie::MetadataAdapter"
[4, 5].each do |fedora_version|
context "fedora #{fedora_version}" do
let(:version) { fedora_version }
let(:adapter) { described_class.new(fedora_adapter_config(base_path: "test_fed", fedora_version: version)) }
it_behaves_like "a Valkyrie::MetadataAdapter"

describe "#schema" do
context "by default" do
specify { expect(adapter.schema).to be_a Valkyrie::Persistence::Fedora::PermissiveSchema }
end
describe "#schema" do
context "by default" do
specify { expect(adapter.schema).to be_a Valkyrie::Persistence::Fedora::PermissiveSchema }
end

context "with a custom schema" do
let(:adapter) { described_class.new(fedora_adapter_config(base_path: "test_fed", schema: "custom-schema")) }
specify { expect(adapter.schema).to eq("custom-schema") }
end
end
context "with a custom schema" do
let(:adapter) { described_class.new(fedora_adapter_config(base_path: "test_fed", schema: "custom-schema", fedora_version: version)) }
specify { expect(adapter.schema).to eq("custom-schema") }
end
end

describe "#id_to_uri" do
it "converts ids with a slash" do
id = "test/default"
if adapter.fedora_version == 4

describe "#id_to_uri" do
it "converts ids with a slash" do
id = "test/default"
if adapter.fedora_version == 5
expect(adapter.id_to_uri(id).to_s).to eq "http://localhost:8988/rest/test_fed/test%2Fdefault"
else
expect(adapter.id_to_uri(id).to_s).to eq "http://localhost:8988/rest/test_fed/te/st/test%2Fdefault"
expect(adapter.id_to_uri(id).to_s).to eq "http://localhost:8988/rest/test_fed/te/st/test%2Fdefault"
else
expect(adapter.id_to_uri(id).to_s).to eq "http://localhost:8998/rest/test_fed/test%2Fdefault"
end
end
end
end
end

describe "#uri_to_id" do
it "converts ids with a slash" do
uri = adapter.id_to_uri("test/default")
expect(adapter.uri_to_id(uri).to_s).to eq "test/default"
end
end
describe "#uri_to_id" do
it "converts ids with a slash" do
uri = adapter.id_to_uri("test/default")
expect(adapter.uri_to_id(uri).to_s).to eq "test/default"
end
end

describe "#pair_path" do
it "creates pairs until the first dash" do
expect(adapter.pair_path('abcdef-ghijkl')).to eq('ab/cd/ef')
end
it "creates pairs until the first slash" do
expect(adapter.pair_path('admin_set/default')).to eq('ad/mi/n_/se/t')
end
end
describe "#pair_path" do
it "creates pairs until the first dash" do
expect(adapter.pair_path('abcdef-ghijkl')).to eq('ab/cd/ef')
end
it "creates pairs until the first slash" do
expect(adapter.pair_path('admin_set/default')).to eq('ad/mi/n_/se/t')
end
end

describe "#id" do
it "creates an md5 hash from the connection_prefix" do
expected = Digest::MD5.hexdigest adapter.connection_prefix
expect(adapter.id.to_s).to eq expected
end
end
describe "#id" do
it "creates an md5 hash from the connection_prefix" do
expected = Digest::MD5.hexdigest adapter.connection_prefix
expect(adapter.id.to_s).to eq expected
end
end

# rubocop:disable Metrics/LineLength
describe "#standardize_query_result?" do
it "throws a deprecation warning when it's set to false" do
allow(Valkyrie.config).to receive(:standardize_query_result).and_return(false)
expect { adapter.standardize_query_result? }.to output(/Please enable query normalization to avoid inconsistent results between different adapters by adding `standardize_query_results: true` to your environment block in config\/valkyrie.yml. This will be the behavior in Valkyrie 2.0./).to_stderr
# rubocop:disable Metrics/LineLength
describe "#standardize_query_result?" do
it "throws a deprecation warning when it's set to false" do
allow(Valkyrie.config).to receive(:standardize_query_result).and_return(false)
expect { adapter.standardize_query_result? }.to output(/Please enable query normalization to avoid inconsistent results between different adapters by adding `standardize_query_results: true` to your environment block in config\/valkyrie.yml. This will be the behavior in Valkyrie 2.0./).to_stderr
end
end
# rubocop:enable Metrics/LineLength
end
end
# rubocop:enable Metrics/LineLength
end
75 changes: 40 additions & 35 deletions spec/valkyrie/persistence/fedora/persister/model_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,46 @@
require 'spec_helper'

RSpec.describe Valkyrie::Persistence::Fedora::Persister::ModelConverter do
let(:adapter) do
Valkyrie::Persistence::Fedora::MetadataAdapter.new(
fedora_adapter_config(base_path: "test_fed", schema: schema)
)
end

let(:resource) { SampleResource.new(title: "My Title") }
let(:converter) { described_class.new(resource: resource, adapter: adapter) }

before do
class SampleResource < Valkyrie::Resource
include Valkyrie::Resource::AccessControls
attribute :title
end
end

after do
Object.send(:remove_const, :SampleResource)
end

context "with the default schema" do
let(:schema) { Valkyrie::Persistence::Fedora::PermissiveSchema.new }
let(:query) { converter.convert.graph.query(predicate: RDF::URI("http://example.com/predicate/title")) }

it "persists to Fedora using a fake predicate" do
expect(query.first.object.to_s).to eq("My Title")
end
end

context "with a defined schema" do
let(:schema) { Valkyrie::Persistence::Fedora::PermissiveSchema.new(title: ::RDF::Vocab::DC.title) }
let(:query) { converter.convert.graph.query(predicate: ::RDF::Vocab::DC.title) }

it "persists to Fedora using the defined predicate" do
expect(query.first.object.to_s).to eq("My Title")
[4, 5].each do |fedora_version|
context "fedora #{fedora_version}" do
let(:version) { fedora_version }
let(:adapter) do
Valkyrie::Persistence::Fedora::MetadataAdapter.new(
fedora_adapter_config(base_path: "test_fed", schema: schema, fedora_version: version)
)
end

let(:resource) { SampleResource.new(title: "My Title") }
let(:converter) { described_class.new(resource: resource, adapter: adapter) }

before do
class SampleResource < Valkyrie::Resource
include Valkyrie::Resource::AccessControls
attribute :title
end
end

after do
Object.send(:remove_const, :SampleResource)
end

context "with the default schema" do
let(:schema) { Valkyrie::Persistence::Fedora::PermissiveSchema.new }
let(:query) { converter.convert.graph.query(predicate: RDF::URI("http://example.com/predicate/title")) }

it "persists to Fedora using a fake predicate" do
expect(query.first.object.to_s).to eq("My Title")
end
end

context "with a defined schema" do
let(:schema) { Valkyrie::Persistence::Fedora::PermissiveSchema.new(title: ::RDF::Vocab::DC.title) }
let(:query) { converter.convert.graph.query(predicate: ::RDF::Vocab::DC.title) }

it "persists to Fedora using the defined predicate" do
expect(query.first.object.to_s).to eq("My Title")
end
end
end
end
end

0 comments on commit 73d9106

Please sign in to comment.