active-fedora 6.3.0 → 6.4.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/History.txt +14 -0
- data/active-fedora.gemspec +1 -1
- data/lib/active_fedora.rb +2 -0
- data/lib/active_fedora/attributes.rb +3 -2
- data/lib/active_fedora/rdf.rb +6 -0
- data/lib/active_fedora/rdf/nested_attributes.rb +73 -0
- data/lib/active_fedora/rdf_node.rb +26 -1
- data/lib/active_fedora/rdf_node/term_proxy.rb +13 -9
- data/lib/active_fedora/version.rb +1 -1
- data/lib/generators/active_fedora/model/model_generator.rb +2 -0
- data/lib/generators/active_fedora/model/templates/model.rb.erb +25 -0
- data/lib/generators/active_fedora/model/templates/model_spec.rb.erb +0 -2
- data/spec/integration/mods_article_integration_spec.rb +4 -4
- data/spec/integration/rdf_nested_attributes_spec.rb +118 -0
- data/spec/integration/solr_service_spec.rb +1 -1
- data/spec/unit/base_spec.rb +6 -3
- data/spec/unit/om_datastream_spec.rb +7 -24
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a57c2dc577a4f6595cba76b441203b6d6663d083
|
4
|
+
data.tar.gz: d8192c0c8615c94caf0ebe10820866981eb870e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6e1153143dc1a2140c155fbffdfa17e721a05c187cdc54f97099a17dd4ff7db3c738eb2de016128b9f3aec119282bf91804f3d2baaa8a3ae95dcc4d54fd4a0b
|
7
|
+
data.tar.gz: 4492eb4d126ee07a15c43e9403722fa5dca9d26d111d8aa6fe680c78d7602bf48cacbf1fa93b4cb66fc551fbce1a61d59c89dbab0632ef365626b24fb4bf1ecf
|
data/.travis.yml
CHANGED
data/History.txt
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
6.4.0 (unreleased)
|
2
|
+
Bump dependency to om 3.0.0 [Justin Coyne]
|
3
|
+
|
4
|
+
Updating "active_fedora:model" rails generator [Jeremy Friesen]
|
5
|
+
|
6
|
+
Deprecated AF::Base#update_indexed_attributes [Justin Coyne]
|
7
|
+
|
8
|
+
Delegate all the array methods for RdfNode::TermProxy [Justin Coyne]
|
9
|
+
|
10
|
+
Updating travis config as per Travis instruction [Jeremy Friesen]
|
11
|
+
|
12
|
+
Added accepts_nested_attributes_for on RDFNodes [Justin Coyne]
|
13
|
+
|
14
|
+
|
1
15
|
6.3.0 (2013-06-14)
|
2
16
|
|
3
17
|
Added method: ActiveFedora::Base#required? [Justin Coyne]
|
data/active-fedora.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.required_ruby_version = '>= 1.9.3'
|
16
16
|
|
17
17
|
s.add_dependency('rsolr')
|
18
|
-
s.add_dependency('om', '~>
|
18
|
+
s.add_dependency('om', '~> 3.0.0')
|
19
19
|
s.add_dependency('nom-xml', '>=0.5.1')
|
20
20
|
s.add_dependency("activesupport", '>= 3.0.0')
|
21
21
|
s.add_dependency("mediashelf-loggable")
|
data/lib/active_fedora.rb
CHANGED
@@ -6,6 +6,7 @@ require 'active_fedora/rubydora_connection'
|
|
6
6
|
require 'active_support/core_ext/class/attribute'
|
7
7
|
require 'active_support/core_ext/object'
|
8
8
|
require 'active_support/core_ext/hash/indifferent_access'
|
9
|
+
require "active_support/core_ext/hash/except"
|
9
10
|
require 'rdf'
|
10
11
|
|
11
12
|
SOLR_DOCUMENT_ID = Solrizer.default_field_mapper.id_field unless defined?(SOLR_DOCUMENT_ID)
|
@@ -48,6 +49,7 @@ module ActiveFedora #:nodoc:
|
|
48
49
|
autoload :Persistence
|
49
50
|
autoload :QualifiedDublinCoreDatastream
|
50
51
|
autoload :Querying
|
52
|
+
autoload :Rdf
|
51
53
|
autoload :RDFDatastream
|
52
54
|
autoload :RdfList
|
53
55
|
autoload :RdfNode
|
@@ -37,6 +37,7 @@ module ActiveFedora
|
|
37
37
|
# m.update_attributes({"fubar"=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}, :datastreams=>["my_ds", "my_other_ds"])
|
38
38
|
#
|
39
39
|
def update_indexed_attributes(params={}, opts={})
|
40
|
+
Deprecation.warn(Attributes, 'update_indexed_attributes is deprecated and will be removed in ActiveFedora 7.0.0. Consider using dsid.update_indexed_attributes() instead.', caller)
|
40
41
|
if ds = opts[:datastreams]
|
41
42
|
ds_array = []
|
42
43
|
ds = [ds] unless ds.respond_to? :each
|
@@ -64,7 +65,7 @@ module ActiveFedora
|
|
64
65
|
# }
|
65
66
|
# article.update_datastream_attributes( ds_values_hash )
|
66
67
|
def update_datastream_attributes(params={}, opts={})
|
67
|
-
Deprecation.warn(Attributes, 'update_datastream_attributes is deprecated. Consider using delegate_to instead.', caller)
|
68
|
+
Deprecation.warn(Attributes, 'update_datastream_attributes is deprecated and will be removed in ActiveFedora 7.0.0. Consider using delegate_to instead.', caller)
|
68
69
|
result = params.dup
|
69
70
|
params.each_pair do |dsid, ds_params|
|
70
71
|
if datastreams.include?(dsid)
|
@@ -77,7 +78,7 @@ module ActiveFedora
|
|
77
78
|
end
|
78
79
|
|
79
80
|
def get_values_from_datastream(dsid,field_key,default=[])
|
80
|
-
Deprecation.warn(Attributes, 'get_values_from_datastream is deprecated. Consider using Datastream#get_values instead.', caller)
|
81
|
+
Deprecation.warn(Attributes, 'get_values_from_datastream is deprecated and will be removed in ActiveFedora 7.0.0. Consider using Datastream#get_values instead.', caller)
|
81
82
|
if datastreams.include?(dsid)
|
82
83
|
return datastreams[dsid].get_values(field_key,default)
|
83
84
|
else
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module ActiveFedora
|
2
|
+
module Rdf
|
3
|
+
module NestedAttributes
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
class_attribute :nested_attributes_options, :instance_writer => false
|
8
|
+
self.nested_attributes_options = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
UNASSIGNABLE_KEYS = %w( id _destroy )
|
14
|
+
|
15
|
+
def assign_nested_attributes_for_collection_association(association_name, attributes_collection)
|
16
|
+
options = self.nested_attributes_options[association_name]
|
17
|
+
|
18
|
+
# TODO
|
19
|
+
#check_record_limit!(options[:limit], attributes_collection)
|
20
|
+
|
21
|
+
if attributes_collection.is_a?(Hash) || attributes_collection.is_a?(String)
|
22
|
+
attributes_collection = [attributes_collection]
|
23
|
+
end
|
24
|
+
|
25
|
+
association = self.send(association_name)
|
26
|
+
|
27
|
+
attributes_collection.each do |attributes|
|
28
|
+
if attributes.instance_of? Hash
|
29
|
+
attributes = attributes.with_indifferent_access
|
30
|
+
association.build(attributes.except(*UNASSIGNABLE_KEYS))
|
31
|
+
else
|
32
|
+
association.build(attributes)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module ClassMethods
|
38
|
+
def accepts_nested_attributes_for *relationships
|
39
|
+
relationships.each do |association_name|
|
40
|
+
nested_attributes_options[association_name] = {}
|
41
|
+
generate_association_writer(association_name)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
# Generates a writer method for this association. Serves as a point for
|
48
|
+
# accessing the objects in the association. For example, this method
|
49
|
+
# could generate the following:
|
50
|
+
#
|
51
|
+
# def pirate_attributes=(attributes)
|
52
|
+
# assign_nested_attributes_for_collection_association(:pirate, attributes)
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# This redirects the attempts to write objects in an association through
|
56
|
+
# the helper methods defined below. Makes it seem like the nested
|
57
|
+
# associations are just regular associations.
|
58
|
+
def generate_association_writer(association_name)
|
59
|
+
class_eval <<-eoruby, __FILE__, __LINE__ + 1
|
60
|
+
if method_defined?(:#{association_name}_attributes=)
|
61
|
+
remove_method(:#{association_name}_attributes=)
|
62
|
+
end
|
63
|
+
def #{association_name}_attributes=(attributes)
|
64
|
+
unless attributes.nil?
|
65
|
+
assign_nested_attributes_for_collection_association(:#{association_name}, attributes)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
eoruby
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -2,6 +2,7 @@ module ActiveFedora
|
|
2
2
|
module RdfNode
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
extend ActiveSupport::Autoload
|
5
|
+
include ActiveFedora::Rdf::NestedAttributes
|
5
6
|
|
6
7
|
autoload :TermProxy
|
7
8
|
|
@@ -10,7 +11,17 @@ module ActiveFedora
|
|
10
11
|
@@rdf_registry ||= {}
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
|
+
# Comparison Operator
|
15
|
+
# Checks that
|
16
|
+
# * RDF subject id (URI) is same
|
17
|
+
# * Class is the same
|
18
|
+
# * Both objects reference the same RDF graph in memory
|
19
|
+
def ==(other_object)
|
20
|
+
self.class == other_object.class &&
|
21
|
+
self.rdf_subject.id == other_object.rdf_subject.id &&
|
22
|
+
self.graph.object_id == other_object.graph.object_id
|
23
|
+
end
|
24
|
+
|
14
25
|
##
|
15
26
|
# Get the subject for this rdf object
|
16
27
|
def rdf_subject
|
@@ -62,6 +73,19 @@ module ActiveFedora
|
|
62
73
|
|
63
74
|
TermProxy.new(self, subject, predicate, options)
|
64
75
|
end
|
76
|
+
|
77
|
+
# @option [Hash] values the values to assign to this rdf node.
|
78
|
+
def attributes=(values)
|
79
|
+
raise ArgumentError, "values must be a Hash, you provided #{values.class}" unless values.kind_of? Hash
|
80
|
+
self.class.config.keys.each do |key|
|
81
|
+
if values.has_key?(key)
|
82
|
+
set_value(rdf_subject, key, values[key])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
nested_attributes_options.keys.each do |key|
|
86
|
+
send("#{key}_attributes=".to_sym, values["#{key}_attributes".to_sym])
|
87
|
+
end
|
88
|
+
end
|
65
89
|
|
66
90
|
def delete_predicate(subject, predicate, values = nil)
|
67
91
|
predicate = find_predicate(predicate) unless predicate.kind_of? RDF::URI
|
@@ -164,6 +188,7 @@ module ActiveFedora
|
|
164
188
|
end
|
165
189
|
matching
|
166
190
|
end
|
191
|
+
|
167
192
|
class Builder
|
168
193
|
def initialize(parent)
|
169
194
|
@parent = parent
|
@@ -4,9 +4,7 @@ module ActiveFedora
|
|
4
4
|
|
5
5
|
attr_reader :graph, :subject, :predicate, :options
|
6
6
|
|
7
|
-
delegate :
|
8
|
-
:empty?, :as_json, :is_a?, :to_ary, :to_a, :inspect, :first,
|
9
|
-
:last, :include?, :count, :size, :join, :[], :to => :values
|
7
|
+
delegate *(Array.public_instance_methods - [:__send__, :__id__, :class, :object_id] + [:as_json]), :to => :values
|
10
8
|
|
11
9
|
# @param graph RDF::Graph
|
12
10
|
# @param subject RDF::URI
|
@@ -18,10 +16,12 @@ module ActiveFedora
|
|
18
16
|
@options = options
|
19
17
|
end
|
20
18
|
|
21
|
-
def build
|
19
|
+
def build(attributes=nil)
|
22
20
|
new_subject = RDF::Node.new
|
23
21
|
graph.graph.insert([subject, predicate, new_subject])
|
24
|
-
graph.target_class(predicate).new(graph.graph, new_subject)
|
22
|
+
graph.target_class(predicate).new(graph.graph, new_subject).tap do |node|
|
23
|
+
node.attributes = attributes if attributes
|
24
|
+
end
|
25
25
|
end
|
26
26
|
|
27
27
|
def <<(*values)
|
@@ -49,7 +49,7 @@ module ActiveFedora
|
|
49
49
|
# If the user provided options[:class_name], we should query to make sure this
|
50
50
|
# potential solution is of the right RDF.type
|
51
51
|
if options[:class_name]
|
52
|
-
klass = class_from_rdf_type(v
|
52
|
+
klass = class_from_rdf_type(v)
|
53
53
|
values << v if klass == ActiveFedora.class_from_string(options[:class_name], graph.class)
|
54
54
|
else
|
55
55
|
values << v
|
@@ -57,7 +57,7 @@ module ActiveFedora
|
|
57
57
|
end
|
58
58
|
|
59
59
|
if options[:class_name]
|
60
|
-
values = values.map{ |found_subject| class_from_rdf_type(found_subject
|
60
|
+
values = values.map{ |found_subject| class_from_rdf_type(found_subject).new(graph.graph, found_subject)}
|
61
61
|
end
|
62
62
|
|
63
63
|
values
|
@@ -65,10 +65,14 @@ module ActiveFedora
|
|
65
65
|
|
66
66
|
private
|
67
67
|
|
68
|
+
def target_class
|
69
|
+
graph.target_class(predicate)
|
70
|
+
end
|
71
|
+
|
68
72
|
# Look for a RDF.type assertion on this node to see if an RDF class is specified.
|
69
73
|
# Two classes may be valid for the same predicate (e.g. hasMember)
|
70
74
|
# If no RDF.type assertion is found, fall back to using target_class
|
71
|
-
def class_from_rdf_type(subject
|
75
|
+
def class_from_rdf_type(subject)
|
72
76
|
q = RDF::Query.new do
|
73
77
|
pattern [subject, RDF.type, :value]
|
74
78
|
end
|
@@ -79,7 +83,7 @@ module ActiveFedora
|
|
79
83
|
end
|
80
84
|
|
81
85
|
klass = ActiveFedora::RdfNode.rdf_registry[type_uri.first]
|
82
|
-
klass ||=
|
86
|
+
klass ||= target_class
|
83
87
|
klass
|
84
88
|
end
|
85
89
|
|
@@ -6,6 +6,8 @@ module ActiveFedora
|
|
6
6
|
check_class_collision
|
7
7
|
|
8
8
|
class_option :directory, :type => :string, :default => 'models', :desc => "Which directory to generate? (i.e. app/DIRECTORY)"
|
9
|
+
class_option :has_file_datastream, :type => :string, :default => nil, :desc => "Name a file datastream to create"
|
10
|
+
class_option :descMetadata, :type => :string, :default => nil, :desc => "Add a descMetadata metadata datastream"
|
9
11
|
|
10
12
|
def install
|
11
13
|
template('model.rb.erb',File.join('app', directory, "#{file_name}.rb"))
|
@@ -2,5 +2,30 @@
|
|
2
2
|
# `rails generate active_fedora::model <%= class_name %>`
|
3
3
|
require 'active_fedora/base'
|
4
4
|
class <%= class_name %> < ActiveFedora::Base
|
5
|
+
<% if options['descMetadata'] %>
|
6
|
+
has_metadata name: "descMetadata", type: <% options['descMetadata'] %>
|
7
|
+
<% else %>
|
8
|
+
# Uncomment the following lines to add a #descMetadata method that is a
|
9
|
+
# datastream. You will need to specify the :type:, which may involve
|
10
|
+
# creating a new Datastream object.
|
11
|
+
#
|
12
|
+
# has_metadata name: "descMetadata", type: <%= class_name %>MetadataDatastream
|
13
|
+
<%- end -%>
|
14
|
+
<% if options['has_file_datastream'] %>
|
15
|
+
has_file_datastream "<%= options['has_file_datastream'] %>"
|
16
|
+
<% else %>
|
17
|
+
# Uncomment the following lines to add an #attachment method that is a
|
18
|
+
# file_datastream:
|
19
|
+
#
|
20
|
+
# has_file_datastream "attachment"
|
21
|
+
<% end %>
|
22
|
+
# "If you need to add additional attributes to the SOLR document, define the
|
23
|
+
# #to_solr method and make sure to use super"
|
24
|
+
#
|
25
|
+
# def to_solr(solr_document={}, options={})
|
26
|
+
# super(solr_document, options)
|
27
|
+
# solr_document["my_attribute_s"] = my_attribute
|
28
|
+
# return solr_document
|
29
|
+
# end
|
5
30
|
|
6
31
|
end
|
@@ -4,15 +4,15 @@ describe ActiveFedora::Base do
|
|
4
4
|
describe ".update_indexed_attributes" do
|
5
5
|
before(:each) do
|
6
6
|
@test_article = ModsArticle.find("test:fixture_mods_article1")
|
7
|
-
@test_article.update_indexed_attributes({[{:person=>0}, :first_name] => "GIVEN NAMES"}
|
7
|
+
@test_article.descMetadata.update_indexed_attributes({[{:person=>0}, :first_name] => "GIVEN NAMES"})
|
8
8
|
end
|
9
9
|
after(:each) do
|
10
|
-
@test_article.update_indexed_attributes({[{:person=>0}, :first_name] => "GIVEN NAMES"}
|
10
|
+
@test_article.descMetadata.update_indexed_attributes({[{:person=>0}, :first_name] => "GIVEN NAMES"})
|
11
11
|
end
|
12
12
|
it "should update the xml in the specified datatsream and save those changes to Fedora" do
|
13
13
|
@test_article.get_values_from_datastream("descMetadata", [{:person=>0}, :first_name]).should == ["GIVEN NAMES"]
|
14
|
-
test_args = {
|
15
|
-
@test_article.update_indexed_attributes(test_args
|
14
|
+
test_args = {[{:person=>0}, :first_name]=>{"0"=>"Replacement FirstName"}}
|
15
|
+
@test_article.descMetadata.update_indexed_attributes(test_args)
|
16
16
|
@test_article.get_values_from_datastream("descMetadata", [{:person=>0}, :first_name]).should == ["Replacement FirstName"]
|
17
17
|
@test_article.save
|
18
18
|
retrieved_article = ModsArticle.find("test:fixture_mods_article1")
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveFedora::RDFDatastream do
|
4
|
+
before do
|
5
|
+
class DummyMADS < RDF::Vocabulary("http://www.loc.gov/mads/rdf/v1#")
|
6
|
+
# componentList and Types of components
|
7
|
+
property :componentList
|
8
|
+
property :Topic
|
9
|
+
property :Temporal
|
10
|
+
property :PersonalName
|
11
|
+
property :CorporateName
|
12
|
+
property :ComplexSubject
|
13
|
+
|
14
|
+
|
15
|
+
# elementList and elementList values
|
16
|
+
property :elementList
|
17
|
+
property :elementValue
|
18
|
+
property :TopicElement
|
19
|
+
property :TemporalElement
|
20
|
+
property :NameElement
|
21
|
+
property :FullNameElement
|
22
|
+
property :DateNameElement
|
23
|
+
end
|
24
|
+
|
25
|
+
class ComplexRDFDatastream < ActiveFedora::NtriplesRDFDatastream
|
26
|
+
map_predicates do |map|
|
27
|
+
map.topic(in: DummyMADS, to: "Topic", class_name:"Topic")
|
28
|
+
map.personalName(in: DummyMADS, to: "PersonalName", class_name:"PersonalName")
|
29
|
+
map.title(in: RDF::DC)
|
30
|
+
end
|
31
|
+
|
32
|
+
accepts_nested_attributes_for :topic, :personalName
|
33
|
+
|
34
|
+
class Topic
|
35
|
+
include ActiveFedora::RdfObject
|
36
|
+
map_predicates do |map|
|
37
|
+
map.elementList(in: DummyMADS, class_name:"ComplexRDFDatastream::ElementList")
|
38
|
+
end
|
39
|
+
accepts_nested_attributes_for :elementList
|
40
|
+
end
|
41
|
+
class PersonalName
|
42
|
+
include ActiveFedora::RdfObject
|
43
|
+
map_predicates do |map|
|
44
|
+
map.elementList(in: DummyMADS, to: "elementList", class_name:"ComplexRDFDatastream::ElementList")
|
45
|
+
map.extraProperty(in: DummyMADS, to: "elementValue", class_name:"ComplexRDFDatastream::Topic")
|
46
|
+
end
|
47
|
+
accepts_nested_attributes_for :elementList, :extraProperty
|
48
|
+
end
|
49
|
+
class ElementList
|
50
|
+
include ActiveFedora::RdfObject
|
51
|
+
rdf_type DummyMADS.elementList
|
52
|
+
map_predicates do |map|
|
53
|
+
map.topicElement(in: DummyMADS, to: "TopicElement")
|
54
|
+
map.temporalElement(in: DummyMADS, to: "TemporalElement")
|
55
|
+
map.fullNameElement(in: DummyMADS, to: "FullNameElement")
|
56
|
+
map.dateNameElement(in: DummyMADS, to: "DateNameElement")
|
57
|
+
map.nameElement(in: DummyMADS, to: "NameElement")
|
58
|
+
map.elementValue(in: DummyMADS)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
after do
|
64
|
+
Object.send(:remove_const, :ComplexRDFDatastream)
|
65
|
+
Object.send(:remove_const, :DummyMADS)
|
66
|
+
end
|
67
|
+
subject { ComplexRDFDatastream.new(stub('inner object', :pid=>'foo', :new? =>true), 'descMetadata') }
|
68
|
+
|
69
|
+
describe ".attributes=" do
|
70
|
+
describe "complex properties" do
|
71
|
+
let(:params) do
|
72
|
+
{ myResource:
|
73
|
+
{
|
74
|
+
topic_attributes: [
|
75
|
+
{
|
76
|
+
elementList_attributes: {
|
77
|
+
topicElement:"Cosmology"
|
78
|
+
}
|
79
|
+
},
|
80
|
+
{
|
81
|
+
elementList_attributes: {
|
82
|
+
topicElement:"Quantum Behavior"
|
83
|
+
}
|
84
|
+
}
|
85
|
+
],
|
86
|
+
personalName_attributes: [
|
87
|
+
{
|
88
|
+
elementList_attributes: {
|
89
|
+
fullNameElement: "Jefferson, Thomas",
|
90
|
+
dateNameElement: "1743-1826"
|
91
|
+
}
|
92
|
+
}
|
93
|
+
#, "Hemings, Sally"
|
94
|
+
],
|
95
|
+
}
|
96
|
+
}
|
97
|
+
end
|
98
|
+
it "should support mass-assignment" do
|
99
|
+
# Replace the graph's contents with the Hash
|
100
|
+
subject.attributes = params[:myResource]
|
101
|
+
|
102
|
+
# Here's how this would happen if we didn't have attributes=
|
103
|
+
# personal_name = subject.personalName.build
|
104
|
+
# elem_list = personal_name.elementList.build
|
105
|
+
# elem_list.fullNameElement = "Jefferson, Thomas"
|
106
|
+
# elem_list.dateNameElement = "1743-1826"
|
107
|
+
# topic = subject.topic.build
|
108
|
+
# elem_list = topic.elementList.build
|
109
|
+
# elem_list.fullNameElement = 'Cosmology'
|
110
|
+
|
111
|
+
subject.topic.first.elementList.first.topicElement.should == ["Cosmology"]
|
112
|
+
subject.topic[1].elementList.first.topicElement.should == ["Quantum Behavior"]
|
113
|
+
subject.personalName.first.elementList.first.fullNameElement.should == ["Jefferson, Thomas"]
|
114
|
+
subject.personalName.first.elementList.first.dateNameElement.should == ["1743-1826"]
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -24,7 +24,7 @@ describe ActiveFedora::SolrService do
|
|
24
24
|
"creator"=>{0=>"Linguist, A."},
|
25
25
|
"geography"=>{0=>"Italy"},
|
26
26
|
"title"=>{0=>"Italian and Spanish: A Comparison of Common Phrases"}}
|
27
|
-
@foo_object.update_indexed_attributes(attributes)
|
27
|
+
@foo_object.descMetadata.update_indexed_attributes(attributes)
|
28
28
|
@test_object.save
|
29
29
|
@foo_object.save
|
30
30
|
@profiles = {
|
data/spec/unit/base_spec.rb
CHANGED
@@ -532,6 +532,9 @@ pending "This is broken, and deprecated. I don't want to fix it - jcoyne"
|
|
532
532
|
end
|
533
533
|
|
534
534
|
describe "update_indexed_attributes" do
|
535
|
+
before do
|
536
|
+
Deprecation.should_receive(:warn).at_least(1).times
|
537
|
+
end
|
535
538
|
it "should call .update_indexed_attributes on all metadata datastreams & nokogiri datastreams" do
|
536
539
|
m = FooHistory.new
|
537
540
|
att= {"fubar"=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}
|
@@ -549,14 +552,14 @@ pending "This is broken, and deprecated. I don't want to fix it - jcoyne"
|
|
549
552
|
m.update_indexed_attributes(att, :datastreams=>"withText")
|
550
553
|
m.should_not be_nil
|
551
554
|
m.datastreams['someData'].fubar.should == []
|
552
|
-
m.datastreams["withText"].fubar.should == ['york', 'mangle']
|
555
|
+
m.datastreams["withText"].fubar.should == ['mork', 'york', 'mangle']
|
553
556
|
m.datastreams['withText2'].fubar.should == []
|
554
557
|
|
555
558
|
att= {"fubar"=>{"-1"=>"tork", "0"=>"work", "1"=>"bork"}}
|
556
559
|
m.update_indexed_attributes(att, :datastreams=>["someData", "withText2"])
|
557
560
|
m.should_not be_nil
|
558
|
-
m.datastreams['someData'].fubar.should == ['work', 'bork']
|
559
|
-
m.datastreams['withText2'].fubar.should == ['work', 'bork']
|
561
|
+
m.datastreams['someData'].fubar.should == ['tork', 'work', 'bork']
|
562
|
+
m.datastreams['withText2'].fubar.should == ['tork', 'work', 'bork']
|
560
563
|
end
|
561
564
|
end
|
562
565
|
|
@@ -76,18 +76,14 @@ describe ActiveFedora::OmDatastream do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should apply submitted hash to corresponding datastream field values" do
|
79
|
-
pending if ENV['HUDSON_BUILD'] == 'true' # This test fails en suite in hudson
|
80
79
|
result = @mods_ds.update_indexed_attributes( {[{":person"=>"0"}, "role"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"} })
|
81
|
-
result.should == {"person_0_role"=>
|
82
|
-
# xpath = ds.class.accessor_xpath(*field_key)
|
83
|
-
# result = ds.property_values(xpath)
|
84
|
-
|
80
|
+
result.should == {"person_0_role"=>["role1", "role2", "role3"]}
|
85
81
|
@mods_ds.property_values('//oxns:name[@type="personal"][1]/oxns:role').should == ["role1","role2","role3"]
|
86
82
|
end
|
87
83
|
it "should support single-value arguments (as opposed to a hash of values with array indexes as keys)" do
|
88
84
|
# In other words, { "fubar"=>"dork" } should have the same effect as { "fubar"=>{"0"=>"dork"} }
|
89
85
|
result = @mods_ds.update_indexed_attributes( { [{":person"=>"0"}, "role"]=>"the role" } )
|
90
|
-
result.should == {"person_0_role"=>
|
86
|
+
result.should == {"person_0_role"=>["the role"]}
|
91
87
|
@mods_ds.term_values('//oxns:name[@type="personal"][1]/oxns:role').first.should == "the role"
|
92
88
|
end
|
93
89
|
it "should do nothing if field key is a string (must be an array or symbol). Will not accept xpath queries!" do
|
@@ -105,40 +101,27 @@ describe ActiveFedora::OmDatastream do
|
|
105
101
|
### Examples copied over form metadata_datastream_spec
|
106
102
|
|
107
103
|
it "should work for text fields" do
|
108
|
-
pending if ENV['HUDSON_BUILD'] == 'true' # This test fails en suite in hudson
|
109
104
|
att= {[{"person"=>"0"},"description"]=>{"-1"=>"mork", "1"=>"york"}}
|
110
105
|
result = @mods_ds.update_indexed_attributes(att)
|
111
|
-
result.should == {"person_0_description"=>
|
106
|
+
result.should == {"person_0_description"=>["mork","york"]}
|
112
107
|
@mods_ds.get_values([{:person=>0},:description]).should == ['mork', 'york']
|
113
108
|
att= {[{"person"=>"0"},"description"]=>{"-1"=>"dork"}}
|
114
109
|
result2 = @mods_ds.update_indexed_attributes(att)
|
115
|
-
result2.should == {"person_0_description"=>
|
116
|
-
@mods_ds.get_values([{:person=>0},:description]).should == ['
|
110
|
+
result2.should == {"person_0_description"=>["dork"]}
|
111
|
+
@mods_ds.get_values([{:person=>0},:description]).should == ['dork']
|
117
112
|
end
|
118
113
|
|
119
|
-
it "should return the new index of any added values" do
|
120
|
-
@mods_ds.get_values([{:title_info=>0},:main_title]).should == ["ARTICLE TITLE", "TITLE OF HOST JOURNAL"]
|
121
|
-
result = @mods_ds.update_indexed_attributes [{"title_info"=>"0"},"main_title"]=>{"-1"=>"mork"}
|
122
|
-
result.should == {"title_info_0_main_title"=>{"2"=>"mork"}}
|
123
|
-
end
|
124
|
-
|
125
114
|
it "should allow deleting of values and should delete values so that to_xml does not return emtpy nodes" do
|
126
|
-
pending if ENV['HUDSON_BUILD'] == 'true' # This test fails en suite in hudson
|
127
115
|
att= {[{"person"=>"0"},"description"]=>{"0"=>"york", "1"=>"mangle","2"=>"mork"}}
|
128
116
|
@mods_ds.update_indexed_attributes(att)
|
129
117
|
@mods_ds.get_values([{"person"=>"0"},"description"]).should == ['york', 'mangle', 'mork']
|
130
118
|
|
131
|
-
@mods_ds.update_indexed_attributes({[{"person"=>"0"},"description"
|
119
|
+
@mods_ds.update_indexed_attributes({[{"person"=>"0"},{"description" => '1'} ]=> nil})
|
132
120
|
@mods_ds.get_values([{"person"=>"0"},"description"]).should == ['york', 'mork']
|
133
121
|
|
134
|
-
@mods_ds.update_indexed_attributes({[{"person"=>"0"},"description"
|
122
|
+
@mods_ds.update_indexed_attributes({[{"person"=>"0"},{"description" => '0'}]=>:delete})
|
135
123
|
@mods_ds.get_values([{"person"=>"0"},"description"]).should == ['mork']
|
136
124
|
end
|
137
|
-
# it "should delete values so that to_xml does not return emtpy nodes" do
|
138
|
-
# @test_ds.fubar_values = ["val1", nil, "val2"]
|
139
|
-
# @test_ds.update_indexed_attributes({{[{"person"=>"0"},"description"]=>{"1"=>""}})
|
140
|
-
# @test_ds.fubar_values.should == ["val1", "val2"]
|
141
|
-
# end
|
142
125
|
|
143
126
|
it "should set changed to true" do
|
144
127
|
@mods_ds.get_values([{:title_info=>0},:main_title]).should == ["ARTICLE TITLE", "TITLE OF HOST JOURNAL"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-fedora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.4.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Zumwalt
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-06-
|
13
|
+
date: 2013-06-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rsolr
|
@@ -32,14 +32,14 @@ dependencies:
|
|
32
32
|
requirements:
|
33
33
|
- - ~>
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version:
|
35
|
+
version: 3.0.0
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - ~>
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
42
|
+
version: 3.0.0
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: nom-xml
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -340,6 +340,8 @@ files:
|
|
340
340
|
- lib/active_fedora/qualified_dublin_core_datastream.rb
|
341
341
|
- lib/active_fedora/querying.rb
|
342
342
|
- lib/active_fedora/railtie.rb
|
343
|
+
- lib/active_fedora/rdf.rb
|
344
|
+
- lib/active_fedora/rdf/nested_attributes.rb
|
343
345
|
- lib/active_fedora/rdf_datastream.rb
|
344
346
|
- lib/active_fedora/rdf_list.rb
|
345
347
|
- lib/active_fedora/rdf_node.rb
|
@@ -427,6 +429,7 @@ files:
|
|
427
429
|
- spec/integration/ntriples_datastream_spec.rb
|
428
430
|
- spec/integration/om_datastream_spec.rb
|
429
431
|
- spec/integration/persistence_spec.rb
|
432
|
+
- spec/integration/rdf_nested_attributes_spec.rb
|
430
433
|
- spec/integration/rels_ext_datastream_spec.rb
|
431
434
|
- spec/integration/scoped_query_spec.rb
|
432
435
|
- spec/integration/solr_instance_loader_spec.rb
|
@@ -542,9 +545,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
542
545
|
version: 1.9.3
|
543
546
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
544
547
|
requirements:
|
545
|
-
- - '
|
548
|
+
- - '>'
|
546
549
|
- !ruby/object:Gem::Version
|
547
|
-
version:
|
550
|
+
version: 1.3.1
|
548
551
|
requirements: []
|
549
552
|
rubyforge_project:
|
550
553
|
rubygems_version: 2.0.3
|
@@ -591,6 +594,7 @@ test_files:
|
|
591
594
|
- spec/integration/ntriples_datastream_spec.rb
|
592
595
|
- spec/integration/om_datastream_spec.rb
|
593
596
|
- spec/integration/persistence_spec.rb
|
597
|
+
- spec/integration/rdf_nested_attributes_spec.rb
|
594
598
|
- spec/integration/rels_ext_datastream_spec.rb
|
595
599
|
- spec/integration/scoped_query_spec.rb
|
596
600
|
- spec/integration/solr_instance_loader_spec.rb
|