active-fedora 3.2.0.pre3 → 3.2.0.pre4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/History.txt +3 -0
- data/active-fedora.gemspec +1 -1
- data/lib/active_fedora.rb +4 -0
- data/lib/active_fedora/base.rb +35 -126
- data/lib/active_fedora/callbacks.rb +252 -0
- data/lib/active_fedora/model.rb +0 -3
- data/lib/active_fedora/persistence.rb +116 -0
- data/lib/active_fedora/rubydora_connection.rb +1 -1
- data/lib/active_fedora/solr_digital_object.rb +19 -0
- data/lib/active_fedora/unsaved_digital_object.rb +6 -3
- data/lib/active_fedora/validations.rb +82 -0
- data/lib/active_fedora/version.rb +1 -1
- data/spec/integration/base_loader_spec.rb +1 -2
- data/spec/integration/full_featured_model_spec.rb +1 -0
- data/spec/support/mock_fedora.rb +3 -3
- data/spec/unit/base_active_model_spec.rb +2 -2
- data/spec/unit/base_delegate_spec.rb +1 -1
- data/spec/unit/base_extra_spec.rb +2 -2
- data/spec/unit/base_spec.rb +77 -97
- data/spec/unit/callback_spec.rb +44 -0
- data/spec/unit/relationship_graph_spec.rb +2 -7
- data/spec/unit/relationships_spec.rb +4 -2
- data/spec/unit/service_definitions_spec.rb +6 -4
- data/spec/unit/solr_config_options_spec.rb +1 -1
- data/spec/unit/solr_service_spec.rb +3 -2
- data/spec/unit/validations_spec.rb +43 -0
- metadata +13 -4
data/lib/active_fedora/model.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'active_fedora/fedora_object'
|
2
|
-
|
3
1
|
SOLR_DOCUMENT_ID = "id" unless defined?(SOLR_DOCUMENT_ID)
|
4
2
|
|
5
3
|
module ActiveFedora
|
@@ -7,7 +5,6 @@ module ActiveFedora
|
|
7
5
|
# This module mixes various methods into the including class,
|
8
6
|
# much in the way ActiveRecord does.
|
9
7
|
module Model
|
10
|
-
extend ActiveFedora::FedoraObject
|
11
8
|
DEFAULT_NS = 'afmodel'
|
12
9
|
|
13
10
|
def self.included(klass) # :nodoc:
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module ActiveFedora
|
2
|
+
# = Active Fedora Persistence
|
3
|
+
module Persistence
|
4
|
+
|
5
|
+
#Saves a Base object, and any dirty datastreams, then updates
|
6
|
+
#the Solr index for this object.
|
7
|
+
def save(*)
|
8
|
+
# If it's a new object, set the conformsTo relationship for Fedora CMA
|
9
|
+
if new_object?
|
10
|
+
result = create
|
11
|
+
else
|
12
|
+
result = update
|
13
|
+
end
|
14
|
+
update_index if @metadata_is_dirty == true && ENABLE_SOLR_UPDATES
|
15
|
+
@metadata_is_dirty = false
|
16
|
+
return result
|
17
|
+
end
|
18
|
+
|
19
|
+
def save!(*)
|
20
|
+
save
|
21
|
+
end
|
22
|
+
|
23
|
+
# This can be overriden to assert a different model
|
24
|
+
# It's normally called once in the lifecycle, by #create#
|
25
|
+
def assert_content_model
|
26
|
+
add_relationship(:has_model, ActiveFedora::ContentModel.pid_from_ruby_class(self.class))
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def update_attributes(properties)
|
31
|
+
self.attributes=properties
|
32
|
+
save
|
33
|
+
end
|
34
|
+
|
35
|
+
# Refreshes the object's info from Fedora
|
36
|
+
# Note: Currently just registers any new datastreams that have appeared in fedora
|
37
|
+
def refresh
|
38
|
+
# inner_object.load_attributes_from_fedora
|
39
|
+
end
|
40
|
+
|
41
|
+
#Deletes a Base object, also deletes the info indexed in Solr, and
|
42
|
+
#the underlying inner_object. If this object is held in any relationships (ie inbound relationships
|
43
|
+
#outside of this object it will remove it from those items rels-ext as well
|
44
|
+
def delete
|
45
|
+
inbound_relationships(:objects).each_pair do |predicate, objects|
|
46
|
+
objects.each do |obj|
|
47
|
+
if obj.respond_to?(:remove_relationship)
|
48
|
+
obj.remove_relationship(predicate,self)
|
49
|
+
obj.save
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
#Fedora::Repository.instance.delete(@inner_object)
|
55
|
+
pid = self.pid ## cache so it's still available after delete
|
56
|
+
begin
|
57
|
+
@inner_object.delete
|
58
|
+
rescue RestClient::ResourceNotFound =>e
|
59
|
+
raise ObjectNotFoundError, "Unable to find #{pid} in the repository"
|
60
|
+
end
|
61
|
+
if ENABLE_SOLR_UPDATES
|
62
|
+
ActiveFedora::SolrService.instance.conn.delete(pid)
|
63
|
+
# if defined?( Solrizer::Solrizer )
|
64
|
+
# solrizer = Solrizer::Solrizer.new
|
65
|
+
# solrizer.solrize_delete(pid)
|
66
|
+
# end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
# Updates Solr index with self.
|
75
|
+
def update_index
|
76
|
+
if defined?( Solrizer::Fedora::Solrizer )
|
77
|
+
#logger.info("Trying to solrize pid: #{pid}")
|
78
|
+
solrizer = Solrizer::Fedora::Solrizer.new
|
79
|
+
solrizer.solrize( self )
|
80
|
+
else
|
81
|
+
#logger.info("Trying to update solr for pid: #{pid}")
|
82
|
+
SolrService.instance.conn.update(self.to_solr)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Deals with preparing new object to be saved to Fedora, then pushes it and its datastreams into Fedora.
|
87
|
+
def create
|
88
|
+
@inner_object = @inner_object.save #replace the unsaved digital object with a saved digital object
|
89
|
+
assert_content_model
|
90
|
+
@metadata_is_dirty = true
|
91
|
+
persist
|
92
|
+
end
|
93
|
+
|
94
|
+
# Pushes the object and all of its new or dirty datastreams into Fedora
|
95
|
+
def update
|
96
|
+
persist
|
97
|
+
end
|
98
|
+
|
99
|
+
def persist
|
100
|
+
datastreams.each {|k, ds| ds.serialize! }
|
101
|
+
@metadata_is_dirty = datastreams.any? {|k,ds| ds.changed? && (ds.class.included_modules.include?(ActiveFedora::MetadataDatastreamHelper) || ds.instance_of?(ActiveFedora::RelsExtDatastream))}
|
102
|
+
|
103
|
+
result = @inner_object.save
|
104
|
+
|
105
|
+
### Rubydora re-inits the datastreams after a save, so ensure our copy stays in synch
|
106
|
+
@inner_object.datastreams.each do |dsid, ds|
|
107
|
+
datastreams[dsid] = ds
|
108
|
+
ds.model = self if ds.kind_of? RelsExtDatastream
|
109
|
+
end
|
110
|
+
refresh
|
111
|
+
return !!result
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ActiveFedora
|
2
|
+
class SolrDigitalObject
|
3
|
+
attr_accessor :pid, :attributes, :datastreams
|
4
|
+
|
5
|
+
def initialize(attr)
|
6
|
+
self.datastreams = {}
|
7
|
+
self.attributes = attr
|
8
|
+
self.pid = attr[:pid]
|
9
|
+
end
|
10
|
+
|
11
|
+
def new?
|
12
|
+
false
|
13
|
+
end
|
14
|
+
|
15
|
+
def profile
|
16
|
+
attributes
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -3,14 +3,15 @@ module ActiveFedora
|
|
3
3
|
class UnsavedDigitalObject
|
4
4
|
attr_accessor :original_class, :datastreams, :label, :namespace
|
5
5
|
|
6
|
-
def initialize(original_class, namespace)
|
6
|
+
def initialize(original_class, namespace, pid=nil)
|
7
|
+
@pid = pid
|
7
8
|
self.original_class = original_class
|
8
9
|
self.namespace = namespace
|
9
10
|
self.datastreams = {}
|
10
11
|
end
|
11
12
|
|
12
13
|
def pid
|
13
|
-
'__DO_NOT_USE__'
|
14
|
+
@pid || '__DO_NOT_USE__'
|
14
15
|
end
|
15
16
|
|
16
17
|
def new?
|
@@ -28,9 +29,11 @@ module ActiveFedora
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def assign_pid
|
32
|
+
return @pid if @pid
|
31
33
|
args = {}
|
32
34
|
args[:namespace] = self.namespace if self.namespace
|
33
|
-
RubydoraConnection.instance.nextid args
|
35
|
+
@pid = RubydoraConnection.instance.nextid args
|
36
|
+
@pid
|
34
37
|
end
|
35
38
|
|
36
39
|
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module ActiveFedora
|
2
|
+
# = Active Fedora RecordInvalid, adapted from Active Record
|
3
|
+
#
|
4
|
+
# Raised by <tt>save!</tt> and <tt>create!</tt> when the record is invalid. Use the
|
5
|
+
# +record+ method to retrieve the record which did not validate.
|
6
|
+
#
|
7
|
+
# begin
|
8
|
+
# complex_operation_that_calls_save!_internally
|
9
|
+
# rescue ActiveFedora::RecordInvalid => invalid
|
10
|
+
# puts invalid.record.errors
|
11
|
+
# end
|
12
|
+
class RecordInvalid < StandardError
|
13
|
+
attr_reader :record
|
14
|
+
def initialize(record)
|
15
|
+
@record = record
|
16
|
+
errors = @record.errors.full_messages.join(", ")
|
17
|
+
super(I18n.t("activefedora.errors.messages.record_invalid", :errors => errors))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# = Active Fedora Validations, adapted from Active Record
|
22
|
+
#
|
23
|
+
# Active Fedora includes the majority of its validations from <tt>ActiveModel::Validations</tt>
|
24
|
+
# all of which accept the <tt>:on</tt> argument to define the context where the
|
25
|
+
# validations are active. Active Record will always supply either the context of
|
26
|
+
# <tt>:create</tt> or <tt>:update</tt> dependent on whether the model is a
|
27
|
+
# <tt>new_record?</tt>.
|
28
|
+
module Validations
|
29
|
+
extend ActiveSupport::Concern
|
30
|
+
include ActiveModel::Validations
|
31
|
+
|
32
|
+
module ClassMethods
|
33
|
+
# Creates an object just like Base.create but calls <tt>save!</tt> instead of +save+
|
34
|
+
# so an exception is raised if the record is invalid.
|
35
|
+
def create!(attributes = nil, options = {}, &block)
|
36
|
+
if attributes.is_a?(Array)
|
37
|
+
attributes.collect { |attr| create!(attr, options, &block) }
|
38
|
+
else
|
39
|
+
object = new(attributes, options)
|
40
|
+
yield(object) if block_given?
|
41
|
+
object.save!
|
42
|
+
object
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# The validation process on save can be skipped by passing <tt>:validate => false</tt>. The regular Base#save method is
|
48
|
+
# replaced with this when the validations module is mixed in, which it is by default.
|
49
|
+
def save(options={})
|
50
|
+
perform_validations(options) ? super : false
|
51
|
+
end
|
52
|
+
|
53
|
+
# Attempts to save the record just like Base#save but will raise a +RecordInvalid+ exception instead of returning false
|
54
|
+
# if the record is not valid.
|
55
|
+
def save!(options={})
|
56
|
+
perform_validations(options) ? super : raise(RecordInvalid.new(self))
|
57
|
+
end
|
58
|
+
|
59
|
+
# Runs all the validations within the specified context. Returns true if no errors are found,
|
60
|
+
# false otherwise.
|
61
|
+
#
|
62
|
+
# If the argument is false (default is +nil+), the context is set to <tt>:create</tt> if
|
63
|
+
# <tt>new_record?</tt> is true, and to <tt>:update</tt> if it is not.
|
64
|
+
#
|
65
|
+
# Validations with no <tt>:on</tt> option will run no matter the context. Validations with
|
66
|
+
# some <tt>:on</tt> option will only run in the specified context.
|
67
|
+
def valid?(context = nil)
|
68
|
+
context ||= (new_record? ? :create : :update)
|
69
|
+
output = super(context)
|
70
|
+
errors.empty? && output
|
71
|
+
end
|
72
|
+
|
73
|
+
protected
|
74
|
+
|
75
|
+
def perform_validations(options={})
|
76
|
+
perform_validation = options[:validate] != false
|
77
|
+
perform_validation ? valid?(options[:context]) : true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
@@ -26,8 +26,7 @@ describe ActiveFedora::Base do
|
|
26
26
|
|
27
27
|
describe "load_instance" do
|
28
28
|
it "should retain all datastream attributes pulled from fedora" do
|
29
|
-
|
30
|
-
raw_object = ActiveFedora::Base.new(:pid=>@test_object.pid, :new_object=>false)
|
29
|
+
raw_object = ActiveFedora::Base.find(@test_object.pid)
|
31
30
|
loaded = OralHistorySampleModel.load_instance(@test_object.pid)
|
32
31
|
raw_datastreams = raw_object.datastreams
|
33
32
|
loaded_datastreams = loaded.datastreams
|
data/spec/support/mock_fedora.rb
CHANGED
@@ -17,9 +17,9 @@ def stub_get(pid, datastreams=nil, record_exists=false)
|
|
17
17
|
mock_client.stubs(:[]).with("objects/#{pid}/datastreams/#{dsid}?format=xml").returns(@getter)
|
18
18
|
end
|
19
19
|
end
|
20
|
-
def stub_ingest(pid)
|
21
|
-
n = pid.gsub(/:/, '%3A')
|
22
|
-
mock_client.
|
20
|
+
def stub_ingest(pid=nil)
|
21
|
+
n = pid ? pid.gsub(/:/, '%3A') : nil
|
22
|
+
mock_client.expects(:[]).with("objects/#{n || 'new'}").returns(stub("ingester", :post=>pid))
|
23
23
|
end
|
24
24
|
|
25
25
|
def stub_add_ds(pid, dsids)
|
@@ -33,7 +33,7 @@ describe ActiveFedora::Base do
|
|
33
33
|
delegate :duck, :to=>'xmlish', :unique=>true
|
34
34
|
end
|
35
35
|
before :each do
|
36
|
-
@n = BarHistory.new(
|
36
|
+
@n = BarHistory.new()
|
37
37
|
end
|
38
38
|
describe "attributes=" do
|
39
39
|
it "should set attributes" do
|
@@ -47,7 +47,7 @@ describe ActiveFedora::Base do
|
|
47
47
|
describe "update_attributes" do
|
48
48
|
it "should set attributes and save " do
|
49
49
|
@n.update_attributes(:fubar=>"baz", :duck=>"Quack")
|
50
|
-
@q = BarHistory.find(
|
50
|
+
@q = BarHistory.find(@n.pid)
|
51
51
|
@q.fubar.should == "baz"
|
52
52
|
@q.duck.should == "Quack"
|
53
53
|
end
|
@@ -48,7 +48,7 @@ describe ActiveFedora::Base do
|
|
48
48
|
delegate :duck, :to=>'xmlish', :at=>[:waterfowl, :ducks]
|
49
49
|
end
|
50
50
|
before :each do
|
51
|
-
@n = BarHistory2.new(
|
51
|
+
@n = BarHistory2.new()
|
52
52
|
end
|
53
53
|
it "should save a delegated property uniquely" do
|
54
54
|
@n.fubar="Quack"
|
@@ -84,12 +84,12 @@ describe ActiveFedora::Base do
|
|
84
84
|
|
85
85
|
@test_object.expects(:datastreams).returns(mock_datastreams)
|
86
86
|
@test_object.expects(:solrize_relationships)
|
87
|
-
@test_object.update_index
|
87
|
+
@test_object.send :update_index
|
88
88
|
end
|
89
89
|
|
90
90
|
it "should retrieve a solr Connection and call Connection.update" do
|
91
91
|
ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock("SolrConnection", :update)))
|
92
|
-
@test_object.update_index
|
92
|
+
@test_object.send :update_index
|
93
93
|
end
|
94
94
|
|
95
95
|
end
|
data/spec/unit/base_spec.rb
CHANGED
@@ -1,28 +1,37 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
require 'active_fedora'
|
4
|
-
require 'active_fedora/base'
|
5
|
-
require 'active_fedora/metadata_datastream'
|
6
|
-
require 'time'
|
7
|
-
require 'date'
|
8
|
-
|
9
|
-
has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"someData" do |m|
|
10
|
-
m.field "fubar", :string
|
11
|
-
m.field "swank", :text
|
12
|
-
end
|
13
|
-
has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"withText" do |m|
|
14
|
-
m.field "fubar", :text
|
15
|
-
end
|
16
|
-
has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"withText2", :label=>"withLabel" do |m|
|
17
|
-
m.field "fubar", :text
|
18
|
-
end
|
19
|
-
end
|
20
|
-
class FooAdaptation < ActiveFedora::Base
|
21
|
-
end
|
22
|
-
|
3
|
+
# require 'active_fedora'
|
4
|
+
# require 'active_fedora/base'
|
5
|
+
# require 'active_fedora/metadata_datastream'
|
6
|
+
# require 'time'
|
7
|
+
# require 'date'
|
8
|
+
#
|
23
9
|
@@last_pid = 0
|
24
10
|
|
25
11
|
describe ActiveFedora::Base do
|
12
|
+
before :all do
|
13
|
+
class FooHistory < ActiveFedora::Base
|
14
|
+
has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"someData" do |m|
|
15
|
+
m.field "fubar", :string
|
16
|
+
m.field "swank", :text
|
17
|
+
end
|
18
|
+
has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"withText" do |m|
|
19
|
+
m.field "fubar", :text
|
20
|
+
end
|
21
|
+
has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"withText2", :label=>"withLabel" do |m|
|
22
|
+
m.field "fubar", :text
|
23
|
+
end
|
24
|
+
delegate :fubar, :to=>'withText'
|
25
|
+
delegate :swank, :to=>'someData'
|
26
|
+
end
|
27
|
+
class FooAdaptation < ActiveFedora::Base
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
after :all do
|
32
|
+
Object.send(:remove_const, :FooHistory)
|
33
|
+
Object.send(:remove_const, :FooAdaptation)
|
34
|
+
end
|
26
35
|
|
27
36
|
def increment_pid
|
28
37
|
@@last_pid += 1
|
@@ -46,21 +55,23 @@ describe ActiveFedora::Base do
|
|
46
55
|
end
|
47
56
|
|
48
57
|
describe '#new' do
|
49
|
-
it "should create
|
50
|
-
Rubydora::DigitalObject.any_instance.expects(:save).never
|
51
|
-
stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
|
52
|
-
|
53
|
-
result = ActiveFedora::Base.new(:pid=>@this_pid)
|
54
|
-
result.inner_object.should be_kind_of(Rubydora::DigitalObject)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should allow initialization with nil" do
|
58
|
+
it "should create an inner object" do
|
58
59
|
# for doing AFObject.new(params[:foo]) when nothing is in params[:foo]
|
59
60
|
Rubydora::DigitalObject.any_instance.expects(:save).never
|
60
61
|
result = ActiveFedora::Base.new(nil)
|
61
62
|
result.inner_object.should be_kind_of(ActiveFedora::UnsavedDigitalObject)
|
62
63
|
end
|
63
64
|
|
65
|
+
it "should not save or get an pid on init" do
|
66
|
+
Rubydora::DigitalObject.any_instance.expects(:save).never
|
67
|
+
ActiveFedora::RubydoraConnection.instance.expects(:nextid).never
|
68
|
+
f = FooHistory.new
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should be able to create with a custom pid" do
|
72
|
+
f = FooHistory.new(:pid=>'numbnuts:1')
|
73
|
+
f.pid.should == 'numbnuts:1'
|
74
|
+
end
|
64
75
|
end
|
65
76
|
|
66
77
|
describe ".internal_uri" do
|
@@ -104,17 +115,10 @@ describe ActiveFedora::Base do
|
|
104
115
|
describe "has_metadata" do
|
105
116
|
describe "creates datastreams" do
|
106
117
|
before :each do
|
107
|
-
|
108
|
-
@
|
109
|
-
|
110
|
-
#Update record
|
111
|
-
@mock_client.stubs(:[]).with("objects/monkey%3A99").returns(stub('post', :post=>'monkey:99'))
|
112
|
-
#Update datastream
|
113
|
-
['someData', 'withText', 'withText2', 'RELS-EXT'].each do |dsid|
|
114
|
-
@mock_client.stubs(:[]).with {|params| /objects\/monkey%3A99\/datastreams\/#{dsid}/.match(params)}.returns(stub('post', :post=>'monkey:99', :get=>''))
|
115
|
-
end
|
118
|
+
stub_ingest(@this_pid)
|
119
|
+
stub_add_ds(@this_pid, ['RELS-EXT', 'someData', 'withText', 'withText2'])
|
116
120
|
|
117
|
-
@n = FooHistory.new(
|
121
|
+
@n = FooHistory.new()
|
118
122
|
@n.datastreams['RELS-EXT'].expects(:changed?).returns(true).at_least_once
|
119
123
|
@n.expects(:update_index)
|
120
124
|
@n.save
|
@@ -130,9 +134,10 @@ describe ActiveFedora::Base do
|
|
130
134
|
|
131
135
|
|
132
136
|
it "should create specified datastreams with appropriate control group" do
|
133
|
-
|
134
|
-
|
135
|
-
|
137
|
+
ActiveFedora::RubydoraConnection.instance.options.stubs(:[]).returns({:url=>'sub_url'})
|
138
|
+
stub_ingest(@this_pid)
|
139
|
+
stub_add_ds(@this_pid, ['RELS-EXT', 'DC', 'rightsMetadata', 'properties', 'descMetadata', 'UKETD_DC'])
|
140
|
+
stub_get(@this_pid, ['RELS-EXT', 'DC', 'rightsMetadata', 'properties', 'descMetadata', 'UKETD_DC'])
|
136
141
|
class UketdObject < ActiveFedora::Base
|
137
142
|
has_metadata :name => "rightsMetadata", :label=>"Rights metadata", :type => ActiveFedora::NokogiriDatastream
|
138
143
|
|
@@ -151,7 +156,7 @@ describe ActiveFedora::Base do
|
|
151
156
|
end
|
152
157
|
|
153
158
|
end
|
154
|
-
@n = UketdObject.new(
|
159
|
+
@n = UketdObject.new()
|
155
160
|
@n.save
|
156
161
|
@n.datastreams["DC"].controlGroup.should eql("X")
|
157
162
|
@n.datastreams["rightsMetadata"].controlGroup.should eql("X")
|
@@ -162,7 +167,7 @@ describe ActiveFedora::Base do
|
|
162
167
|
|
163
168
|
context ":control_group => 'E'" do
|
164
169
|
before do
|
165
|
-
|
170
|
+
stub_get(@this_pid)
|
166
171
|
stub_add_ds(@this_pid, ['RELS-EXT', 'externalDisseminator', 'externalUrl'])
|
167
172
|
end
|
168
173
|
|
@@ -181,6 +186,7 @@ describe ActiveFedora::Base do
|
|
181
186
|
class MoreFooHistory < ActiveFedora::Base
|
182
187
|
has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "E", :url => "http://exampl.com/mypic.jpg"
|
183
188
|
end
|
189
|
+
stub_ingest(@this_pid)
|
184
190
|
@n = MoreFooHistory.new
|
185
191
|
@n.save
|
186
192
|
end
|
@@ -199,7 +205,7 @@ describe ActiveFedora::Base do
|
|
199
205
|
|
200
206
|
context ":control_group => 'R'" do
|
201
207
|
before do
|
202
|
-
|
208
|
+
stub_get(@this_pid)
|
203
209
|
stub_add_ds(@this_pid, ['RELS-EXT', 'externalDisseminator' ])
|
204
210
|
end
|
205
211
|
it "should raise an error without :url option" do
|
@@ -210,6 +216,7 @@ describe ActiveFedora::Base do
|
|
210
216
|
end
|
211
217
|
|
212
218
|
it "should work with a valid :url option" do
|
219
|
+
stub_ingest(@this_pid)
|
213
220
|
class MoreFooHistory < ActiveFedora::Base
|
214
221
|
has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "R", :url => "http://exampl.com/mypic.jpg"
|
215
222
|
end
|
@@ -356,14 +363,10 @@ describe ActiveFedora::Base do
|
|
356
363
|
|
357
364
|
describe '#remove_relationship' do
|
358
365
|
it 'should remove a relationship from the relationships hash' do
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
@
|
363
|
-
next_pid = increment_pid.to_s
|
364
|
-
ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(next_pid)
|
365
|
-
stub_get(next_pid)
|
366
|
-
@test_object4 = ActiveFedora::Base.new(:pid=>next_pid)
|
366
|
+
@test_object3 = ActiveFedora::Base.new()
|
367
|
+
@test_object3.stubs(:pid=>'7')
|
368
|
+
@test_object4 = ActiveFedora::Base.new()
|
369
|
+
@test_object4.stubs(:pid=>'8')
|
367
370
|
@test_object.add_relationship(:has_part,@test_object3)
|
368
371
|
@test_object.add_relationship(:has_part,@test_object4)
|
369
372
|
#check both are there
|
@@ -390,7 +393,7 @@ describe ActiveFedora::Base do
|
|
390
393
|
|
391
394
|
describe '.assert_content_model' do
|
392
395
|
it "should default to the name of the class" do
|
393
|
-
|
396
|
+
stub_get(@this_pid)
|
394
397
|
stub_add_ds(@this_pid, ['RELS-EXT'])
|
395
398
|
@test_object.assert_content_model
|
396
399
|
@test_object.relationships(:has_model).should == ["info:fedora/afmodel:ActiveFedora_Base"]
|
@@ -402,7 +405,7 @@ describe ActiveFedora::Base do
|
|
402
405
|
|
403
406
|
|
404
407
|
it "should return true and set persisted if object and datastreams all save successfully" do
|
405
|
-
|
408
|
+
stub_get(@this_pid)
|
406
409
|
stub_add_ds(@this_pid, ['RELS-EXT'])
|
407
410
|
@test_object.persisted?.should be false
|
408
411
|
@test_object.expects(:update_index)
|
@@ -511,6 +514,19 @@ describe ActiveFedora::Base do
|
|
511
514
|
end
|
512
515
|
end
|
513
516
|
|
517
|
+
describe "#create" do
|
518
|
+
before do
|
519
|
+
stub_ingest(@this_pid)
|
520
|
+
stub_add_ds(@this_pid, ['someData', 'withText', 'withText2', 'RELS-EXT'])
|
521
|
+
end
|
522
|
+
it "should build a new record and save it" do
|
523
|
+
@hist = FooHistory.create(:fubar=>'ta', :swank=>'da')
|
524
|
+
@hist.fubar.should == ['ta']
|
525
|
+
@hist.swank.should == ['da']
|
526
|
+
end
|
527
|
+
|
528
|
+
end
|
529
|
+
|
514
530
|
describe "#create_datastream" do
|
515
531
|
it 'should create a datastream object using the type of object supplied in the string (does reflection)' do
|
516
532
|
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
|
@@ -554,30 +570,16 @@ describe ActiveFedora::Base do
|
|
554
570
|
end
|
555
571
|
|
556
572
|
describe ".adapt_to" do
|
557
|
-
before(:each) do
|
558
|
-
@mock_client.stubs(:[]).with("objects/monkey%3A99/datastreams?format=xml").returns(@getter)
|
559
|
-
@mock_client.stubs(:[]).with("objects/monkey%3A99/datastreams/MY_DSID?format=xml").returns(@getter)
|
560
|
-
@mock_client.stubs(:[]).with("objects/monkey%3A99/datastreams/RELS-EXT/content").returns(@getter)
|
561
|
-
@mock_client.stubs(:[]).with("objects/monkey%3A99/datastreams/MY_DSID/content").returns("XXX")
|
562
|
-
#Update record
|
563
|
-
@mock_client.stubs(:[]).with("objects/monkey%3A99").returns(stub('post', :post=>'monkey:99'))
|
564
|
-
#Update datastream
|
565
|
-
['someData', 'withText', 'withText2', 'RELS-EXT'].each do |dsid|
|
566
|
-
@mock_client.stubs(:[]).with {|params| /objects\/monkey%3A99\/datastreams\/#{dsid}/.match(params)}.returns(stub('post', :post=>'monkey:99', :get=>''))
|
567
|
-
end
|
568
|
-
@mock_file = mock('file')
|
569
|
-
end
|
570
573
|
it "should return an adapted object of the requested type" do
|
571
|
-
@test_object = FooHistory.new(
|
574
|
+
@test_object = FooHistory.new()
|
572
575
|
@test_object.adapt_to(FooAdaptation).class.should == FooAdaptation
|
573
576
|
end
|
574
577
|
it "should not make an additional call to fedora to create the adapted object" do
|
575
|
-
@
|
576
|
-
@test_object = FooHistory.new(:pid=>"monkey:99")
|
578
|
+
@test_object = FooHistory.new()
|
577
579
|
adapted = @test_object.adapt_to(FooAdaptation)
|
578
580
|
end
|
579
581
|
it "should propagate new datastreams to the adapted object" do
|
580
|
-
@test_object = FooHistory.new(
|
582
|
+
@test_object = FooHistory.new()
|
581
583
|
@test_object.add_file_datastream("XXX", :dsid=>'MY_DSID')
|
582
584
|
adapted = @test_object.adapt_to(FooAdaptation)
|
583
585
|
adapted.datastreams.keys.should include 'MY_DSID'
|
@@ -585,7 +587,7 @@ describe ActiveFedora::Base do
|
|
585
587
|
adapted.datastreams['MY_DSID'].changed?.should be_true
|
586
588
|
end
|
587
589
|
it "should propagate modified datastreams to the adapted object" do
|
588
|
-
@test_object = FooHistory.new(
|
590
|
+
@test_object = FooHistory.new()
|
589
591
|
@test_object.datastreams['someData'].content="YYY"
|
590
592
|
adapted = @test_object.adapt_to(FooAdaptation)
|
591
593
|
adapted.datastreams.keys.should include 'someData'
|
@@ -649,7 +651,7 @@ describe ActiveFedora::Base do
|
|
649
651
|
it "should add self.class as the :active_fedora_model" do
|
650
652
|
stub_get(@this_pid)
|
651
653
|
stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
|
652
|
-
@test_history = FooHistory.new(
|
654
|
+
@test_history = FooHistory.new()
|
653
655
|
solr_doc = @test_history.to_solr
|
654
656
|
solr_doc["active_fedora_model_s"].should eql("FooHistory")
|
655
657
|
end
|
@@ -696,13 +698,6 @@ describe ActiveFedora::Base do
|
|
696
698
|
end
|
697
699
|
|
698
700
|
end
|
699
|
-
|
700
|
-
|
701
|
-
describe ".update_index" do
|
702
|
-
it "should provide .update_index" do
|
703
|
-
@test_object.should respond_to(:update_index)
|
704
|
-
end
|
705
|
-
end
|
706
701
|
|
707
702
|
describe ".label" do
|
708
703
|
it "should return the label of the inner object" do
|
@@ -719,21 +714,6 @@ describe ActiveFedora::Base do
|
|
719
714
|
end
|
720
715
|
end
|
721
716
|
|
722
|
-
it "should not save or get an pid on init" do
|
723
|
-
Rubydora::DigitalObject.any_instance.expects(:save).never
|
724
|
-
ActiveFedora::RubydoraConnection.instance.expects(:nextid).never
|
725
|
-
f = FooHistory.new
|
726
|
-
end
|
727
|
-
it "should not clobber a pid if i'm creating!" do
|
728
|
-
@mock_client.stubs(:[]).with("objects/numbnuts%3A1/datastreams?format=xml").returns(@getter)
|
729
|
-
|
730
|
-
['someData', 'withText', 'withText2', 'RELS-EXT'].each do |dsid|
|
731
|
-
@mock_client.stubs(:[]).with {|params| /objects\/numbnuts%3A1\/datastreams\/#{dsid}/.match(params)}.returns(@getter)
|
732
|
-
end
|
733
|
-
f = FooHistory.new(:pid=>'numbnuts:1')
|
734
|
-
f.pid.should == 'numbnuts:1'
|
735
|
-
|
736
|
-
end
|
737
717
|
|
738
718
|
describe "get_values_from_datastream" do
|
739
719
|
it "should look up the named datastream and call get_values with the given pointer/field_name" do
|
@@ -797,7 +777,7 @@ describe ActiveFedora::Base do
|
|
797
777
|
att= {"fubar"=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}
|
798
778
|
stub_get(@this_pid)
|
799
779
|
stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
|
800
|
-
m = FooHistory.new(
|
780
|
+
m = FooHistory.new()
|
801
781
|
m.update_indexed_attributes(att, :datastreams=>"withText")
|
802
782
|
m.should_not be_nil
|
803
783
|
m.datastreams['someData'].fubar_values.should == []
|