Skip to content

Commit

Permalink
Deprecation in preparation for pg as an optional dependency, refs #640
Browse files Browse the repository at this point in the history
  • Loading branch information
hackartisan committed Jan 30, 2019
1 parent 304328f commit a9e3ca0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/valkyrie/persistence/postgres.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# frozen_string_literal: true
#
module Valkyrie::Persistence
# Implements the DataMapper Pattern to store metadata into Postgres
module Postgres
# Deprecation to allow us to make pg an optional dependency
path = Bundler.definition.gemfiles.first
matches = File.readlines(path).select { |l| l =~ /gem ['"]pg\b/ }
if matches.empty?
warn "[DEPRECATION] pg will not be included as a dependency in Valkyrie's gemspec as of the next major release. Please add the gem directly to your Gemfile if you use a postgres adapter."
end

require 'valkyrie/persistence/postgres/metadata_adapter'
end
end
27 changes: 27 additions & 0 deletions spec/valkyrie/persistence/postgres/persister_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,31 @@ class CustomResource < Valkyrie::Resource
end
end
end

describe "pg gem deprecation" do
let(:message) { /\[DEPRECATION\] pg will not be included/ }
let(:path) { Bundler.definition.gemfiles.first }

context "when the gemfile does not have an entry for pg" do
before do
end
it "gives a warning when the module loads" do
allow(File).to receive(:readlines).with(path).and_return(["gem \"rsolr\"\n"])
expect do
Valkyrie::Persistence.send(:remove_const, :Postgres)
load "lib/valkyrie/persistence/postgres.rb"
end.to output(message).to_stderr
end
end

context "when the gemfile does have an entry for pg" do
it "does not give a deprecation warning" do
allow(File).to receive(:readlines).with(path).and_return(["gem \"pg\", \"~> 1.0\"\n"])
expect do
Valkyrie::Persistence.send(:remove_const, :Postgres)
load "lib/valkyrie/persistence/postgres.rb"
end.not_to output(message).to_stderr
end
end
end
end

0 comments on commit a9e3ca0

Please sign in to comment.