Skip to content

Commit

Permalink
Merge pull request #1074 from projecthydra/fix_deprecations
Browse files Browse the repository at this point in the history
Use Deprecation.warn on AS::Concern ClassMethods
  • Loading branch information
mjgiarlo committed May 9, 2016
2 parents cb27774 + 35ef05a commit 355bf99
Show file tree
Hide file tree
Showing 36 changed files with 328 additions and 361 deletions.
9 changes: 3 additions & 6 deletions lib/active_fedora/attached_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,10 @@ def accessor_name(file_path)
end

module ClassMethods
extend Deprecation
self.deprecation_horizon = 'active-fedora version 10.0'

def ds_specs
Deprecation.warn(self, "ds_specs is deprecated and will be removed in ActiveFedora 10.0")
child_resource_reflections
end
deprecation_deprecate :ds_specs

# This method is used to specify the details of a datastream.
# You can pass the name as the first argument and a hash of options as the second argument
Expand All @@ -177,6 +174,7 @@ def ds_specs
# @option args [Boolean] :autocreate Always create this datastream on new objects
# @yield block executed by some kinds of datastreams
def has_metadata(*args, &block)
Deprecation.warn(self, "has_metadata is deprecated and will be removed in ActiveFedora 10.0. Use has_subresource instead.")
if args.first.is_a? String
name = args.first
args = args[1] || {}
Expand All @@ -189,7 +187,6 @@ def has_metadata(*args, &block)
args[:class_name] = args.delete(:type).to_s
has_subresource(name, args, &block)
end
deprecation_deprecate :has_metadata

# @overload has_file_datastream(name, args)
# Declares a file datastream exists for objects of this type
Expand All @@ -204,6 +201,7 @@ def has_metadata(*args, &block)
# @option args :type (ActiveFedora::File) The class the datastream should have
# @option args [Boolean] :autocreate Always create this datastream on new objects
def has_file_datastream(*args)
Deprecation.warn(self, "has_file_datastream is deprecated and will be removed in ActiveFedora 10.0. Use has_subresource instead.")
if args.first.is_a? String
name = args.first
args = args[1] || {}
Expand All @@ -215,7 +213,6 @@ def has_file_datastream(*args)
args[:class_name] = args.delete(:type).to_s
has_subresource(name, args)
end
deprecation_deprecate :has_file_datastream
end
end
end
89 changes: 74 additions & 15 deletions spec/integration/attached_files_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,91 @@ class FooHistory < ActiveFedora::Base
end
end
end
describe "serializing datastreams" do
before do
class TestingMetadataSerializing < ActiveFedora::Base
has_metadata "nokogiri_autocreate_on", autocreate: true, type: ActiveFedora::OmDatastream
has_metadata "nokogiri_autocreate_off", autocreate: false, type: ActiveFedora::OmDatastream

describe "#has_metadata" do
describe "autosave" do
before :each do
class MockAFBaseRelationship < ActiveFedora::Base
extend Deprecation
Deprecation.silence(MockAFBaseRelationship) do
has_metadata 'foo', type: Hydra::ModsArticleDatastream
end
end
end
end
after :each do
Object.send(:remove_const, :MockAFBaseRelationship)
end
describe "a new document" do
before do
@obj = MockAFBaseRelationship.new

after do
Object.send(:remove_const, :TestingMetadataSerializing)
@obj.foo.person = "bob"
@obj.save
end

it "saves the datastream." do
obj = MockAFBaseRelationship.find(@obj.id)
expect(obj.foo).to_not be_new_record
expect(obj.foo.person).to eq ['bob']
person_field = ActiveFedora.index_field_mapper.solr_name('foo__person', type: :string)
solr_result = ActiveFedora::SolrService.query("{!field f=id}#{@obj.id}", fl: "id #{person_field}").first
expect(solr_result).to eq("id" => @obj.id, person_field => ['bob'])
end
end

describe "that already exists in the repo" do
before do
@release = MockAFBaseRelationship.create
@release.foo.person = "test foo content"
@release.save
end
describe "and has been changed" do
before do
@release.foo.person = 'frank'
@release.save!
end
it "saves the datastream." do
expect(MockAFBaseRelationship.find(@release.id).foo.person).to eq ['frank']
person_field = ActiveFedora.index_field_mapper.solr_name('foo__person', type: :string)
expect(ActiveFedora::SolrService.query("id:\"#{@release.id}\"", fl: "id #{person_field}").first).to eq("id" => @release.id, person_field => ['frank'])
end
end
end
end

subject { TestingMetadataSerializing.new }
describe "serializing datastreams" do
before do
class TestingMetadataSerializing < ActiveFedora::Base
extend Deprecation
Deprecation.silence(TestingMetadataSerializing) do
has_metadata "nokogiri_autocreate_on", autocreate: true, type: ActiveFedora::OmDatastream
has_metadata "nokogiri_autocreate_off", autocreate: false, type: ActiveFedora::OmDatastream
end
end
end

it "works" do
subject.save(validate: false)
expect(subject.nokogiri_autocreate_on).to_not be_new_record
expect(subject.nokogiri_autocreate_off).to be_new_record
after do
Object.send(:remove_const, :TestingMetadataSerializing)
end

subject { TestingMetadataSerializing.new }

it "works" do
subject.save(validate: false)
expect(subject.nokogiri_autocreate_on).to_not be_new_record
expect(subject.nokogiri_autocreate_off).to be_new_record
end
end
end

describe "#has_file_datastream" do
before do
class HasFile < ActiveFedora::Base
has_file_datastream "file_ds"
has_file_datastream "file_ds2", autocreate: false
extend Deprecation
Deprecation.silence(HasFile) do
has_file_datastream "file_ds"
has_file_datastream "file_ds2", autocreate: false
end
end
end

Expand Down
9 changes: 7 additions & 2 deletions spec/integration/attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ class PropertiesDatastream < ActiveFedora::OmDatastream
end
end
class TitledObject < ActiveFedora::Base
has_metadata 'foo', type: ActiveFedora::SimpleDatastream do |m|
m.field "title", :string
extend Deprecation

Deprecation.silence(TitledObject) do
has_metadata 'foo', type: ActiveFedora::SimpleDatastream do |m|
m.field "title", :string
end
end
Deprecation.silence(ActiveFedora::Attributes) do
has_attributes :title, datastream: 'foo', multiple: false
end
end

class RdfObject < ActiveFedora::Base
has_subresource 'foo', class_name: 'PropertiesDatastream'
Deprecation.silence(ActiveFedora::Attributes) do
Expand Down
1 change: 0 additions & 1 deletion spec/integration/autosave_association_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
describe ActiveFedora::Base do
before :all do
class MockAFBaseRelationship < ActiveFedora::Base
has_metadata name: 'foo', type: Hydra::ModsArticleDatastream
end
end
after :all do
Expand Down
85 changes: 19 additions & 66 deletions spec/integration/base_spec.rb
Original file line number Diff line number Diff line change
@@ -1,79 +1,32 @@
require 'spec_helper'

describe ActiveFedora::Base do
describe "A base object with metadata" do
before :each do
class MockAFBaseRelationship < ActiveFedora::Base
has_metadata 'foo', type: Hydra::ModsArticleDatastream
describe '#reload' do
before do
class Foo < ActiveFedora::Base
property :person, predicate: ::RDF::Vocab::DC.creator
end
end
after :each do
Object.send(:remove_const, :MockAFBaseRelationship)
after do
Object.send(:remove_const, :Foo)
end
describe "a new document" do
context "when persisted" do
let(:object) { Foo.create(person: ['bob']) }
let(:object2) { Foo.find(object.id) }
before do
@obj = MockAFBaseRelationship.new

@obj.foo.person = "bob"
@obj.save
end

it "saves the datastream." do
obj = described_class.find(@obj.id)
expect(obj.foo).to_not be_new_record
expect(obj.foo.person).to eq ['bob']
person_field = ActiveFedora.index_field_mapper.solr_name('foo__person', type: :string)
solr_result = ActiveFedora::SolrService.query("{!field f=id}#{@obj.id}", fl: "id #{person_field}").first
expect(solr_result).to eq("id" => @obj.id, person_field => ['bob'])
object2.update(person: ['dave'])
end
end

describe "that already exists in the repo" do
before do
@release = MockAFBaseRelationship.create
@release.foo.person = "test foo content"
@release.save
end
describe "and has been changed" do
before do
@release.foo.person = 'frank'
@release.save!
end
it "saves the datastream." do
expect(MockAFBaseRelationship.find(@release.id).foo.person).to eq ['frank']
person_field = ActiveFedora.index_field_mapper.solr_name('foo__person', type: :string)
expect(ActiveFedora::SolrService.query("id:\"#{@release.id}\"", fl: "id #{person_field}").first).to eq("id" => @release.id, person_field => ['frank'])
end
end
describe "when trying to create it again" do
it "raises an error" do
expect { MockAFBaseRelationship.create(id: @release.id) }.to raise_error(ActiveFedora::IllegalOperation, "Attempting to recreate existing ldp_source: `#{@release.uri}'")
@release.reload
expect(@release.foo.person).to include('test foo content')
end
it 're-queries Fedora' do
object.reload
expect(object.person).to eq ['dave']
end
end

describe '#reload' do
before do
@object = MockAFBaseRelationship.new
@object.foo.person = 'bob'
@object.save

@object2 = @object.class.find(@object.id)

@object2.foo.person = 'dave'
@object2.save
end

it 'requeries Fedora' do
@object.reload
expect(@object.foo.person).to eq ['dave']
end

it 'raises an error if not persisted' do
@object = MockAFBaseRelationship.new
expect { @object.reload }.to raise_error(ActiveFedora::ObjectNotFoundError)
context "when not persisted" do
let(:object) { Foo.new }
it 'raises an error' do
expect { object.reload }.to raise_error(ActiveFedora::ObjectNotFoundError)
end
end
end
Expand All @@ -93,12 +46,12 @@ class Book < ActiveFedora::Base

after { obj.destroy unless obj.destroyed? }

describe "errors" do
describe "#errors" do
subject { obj.errors }
it { should be_empty }
end

describe "id" do
describe "#id" do
subject { obj.id }
it { should_not be_nil }
end
Expand Down
40 changes: 0 additions & 40 deletions spec/integration/bug_spec.rb

This file was deleted.

23 changes: 12 additions & 11 deletions spec/integration/field_to_solr_name_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

describe "An object with RDF backed attributes" do
before do
class TestOne < ActiveFedora::Base
class MyMetadata < ActiveFedora::NtriplesRDFDatastream
Deprecation.silence(ActiveFedora::RDFDatastream) do
property :title, predicate: ::RDF::Vocab::DC.title do |index|
index.as :stored_searchable
end
property :date_uploaded, predicate: ::RDF::Vocab::DC.dateSubmitted do |index|
index.type :date
index.as :stored_searchable, :sortable
end
class MyMetadata < ActiveFedora::NtriplesRDFDatastream
Deprecation.silence(ActiveFedora::RDFDatastream) do
property :title, predicate: ::RDF::Vocab::DC.title do |index|
index.as :stored_searchable
end
property :date_uploaded, predicate: ::RDF::Vocab::DC.dateSubmitted do |index|
index.type :date
index.as :stored_searchable, :sortable
end
end
has_metadata 'descMetadata', type: MyMetadata
end
class TestOne < ActiveFedora::Base
has_subresource 'descMetadata', class_name: 'MyMetadata'
Deprecation.silence(ActiveFedora::Attributes) do
has_attributes :title, :date_uploaded, datastream: 'descMetadata'
end
Expand All @@ -23,6 +23,7 @@ class MyMetadata < ActiveFedora::NtriplesRDFDatastream

after do
Object.send(:remove_const, :TestOne)
Object.send(:remove_const, :MyMetadata)
end

it "is able to grab the solr name" do
Expand Down
5 changes: 4 additions & 1 deletion spec/integration/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def size
context "when autocreate is true" do
before do
class MockAFBase < ActiveFedora::Base
has_metadata "descMetadata", type: ActiveFedora::QualifiedDublinCoreDatastream, autocreate: true
extend Deprecation
Deprecation.silence(MockAFBase) do
has_metadata "descMetadata", type: ActiveFedora::QualifiedDublinCoreDatastream, autocreate: true
end
end
end

Expand Down
Loading

0 comments on commit 355bf99

Please sign in to comment.