active-fedora 8.0.0.rc2 → 8.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 710c459d62cf64e2975040193d8624a00be7e14a
4
- data.tar.gz: 97b7060f025c35853ea63295f017c1332947422d
3
+ metadata.gz: 0a1de80932b343143d4dafbcb2255cb2b0c4d171
4
+ data.tar.gz: 6fc87f6d95515b4fd6756733d3f8393242b64466
5
5
  SHA512:
6
- metadata.gz: b31a571799cf3edb9b4549aa80e6159830e0393c54c9e6198415e45cd71e13854988a84b55055dc1123a085000116ee2ffbb3ebcca14d282331584c97b1e05f2
7
- data.tar.gz: 8e91e8ab4f91264e7c76d092984671925dd6143e69b6fb7a5507555a3d2a01667954622cb9191f2c483463da34e157f75744e156da3c96349051845a90d86eb4
6
+ metadata.gz: d1376858b32294906301a9a32250970100391dfd007b8b77b7e472ee7cc1fdd5c11eb45347ae24d6929cd4b0511d6e3b4c67958e46abb74e8dde0f169c2e62ac
7
+ data.tar.gz: b481db866def8a92febf742fa95ea7a6256ab30c9cf4f0eff39dae2b67352fdab8d6cdd5ca2931002987f5634beb20b6fb4a49afc0d0415ed80b00cab06c1023
@@ -83,11 +83,13 @@ module ActiveFedora
83
83
  end
84
84
  raise UnknownAttributeError, "#{self.class} does not have an attribute `#{field}'" unless self.class.defined_attributes.key?(field)
85
85
  if self.class.multiple?(field)
86
- unless args.nil? || args.respond_to?(:each)
87
- raise ArgumentError, "Cannot set the multi-valued attribute `#{field}' to a scalar value."
86
+ unless args.nil? || ( args.respond_to?(:each) && !args.kind_of?(ActiveTriples::Resource) )
87
+ raise ArgumentError, "Cannot set the multi-valued attribute `#{field}' to a single value."
88
88
  end
89
89
  elsif args.respond_to?(:each) # unique
90
- raise ArgumentError, "Cannot set the single-valued attribute `#{field}' to an enumerable value."
90
+ unless args.kind_of?(ActiveTriples::Resource)
91
+ raise ArgumentError, "Cannot set the single-valued attribute `#{field}' to multiple values."
92
+ end
91
93
  end
92
94
  self.class.defined_attributes[field].writer(self, args)
93
95
  end
@@ -134,6 +134,11 @@ module ActiveFedora
134
134
  end
135
135
 
136
136
 
137
+ # Creates a datastream to be added to the object
138
+ # @param type [Class] the class of the datastream object to be created (or a String that can eval to a class)
139
+ # @param dsid [String] the dsid of the datastream to be created, or a generated value if false
140
+ # @param opts [Hash] the ds options to be assigned to the created object, cf. Rubydora::Datastream.DS_ATTRIBUTES
141
+ # @return [ActiveFedora::Datastream] a datastream object of the type indicated in the parameters
137
142
  def create_datastream(type, dsid, opts={})
138
143
  klass = type.kind_of?(Class) ? type : type.constantize
139
144
  raise ArgumentError, "Argument dsid must be of type string" if dsid && !dsid.kind_of?(String)
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "8.0.0.rc2"
2
+ VERSION = "8.0.0.rc3"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  APP_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../")
2
2
 
3
3
  require 'jettywrapper'
4
- JETTY_ZIP_BASENAME = 'master'
4
+ JETTY_ZIP_BASENAME = '7.x-stable'
5
5
  Jettywrapper.url = "https://github.com/projecthydra/hydra-jetty/archive/#{JETTY_ZIP_BASENAME}.zip"
6
6
 
7
7
  namespace :active_fedora do
@@ -7,8 +7,8 @@ describe ActiveFedora::Datastreams do
7
7
  describe "serializing datastreams" do
8
8
  before :all do
9
9
  class TestingMetadataSerializing < ActiveFedora::Base
10
- has_metadata :name => "nokogiri_autocreate_on", :autocreate => true, :type => ActiveFedora::OmDatastream
11
- has_metadata :name => "nokogiri_autocreate_off", :autocreate => false, :type => ActiveFedora::OmDatastream
10
+ has_metadata name: "nokogiri_autocreate_on", autocreate: true, type: ActiveFedora::OmDatastream
11
+ has_metadata name: "nokogiri_autocreate_off", autocreate: false, type: ActiveFedora::OmDatastream
12
12
  end
13
13
  end
14
14
 
@@ -19,7 +19,7 @@ describe ActiveFedora::Datastreams do
19
19
  subject { TestingMetadataSerializing.new }
20
20
 
21
21
  it "should work" do
22
- subject.save(:validate => false)
22
+ subject.save(validate: false)
23
23
  subject.nokogiri_autocreate_on.should_not be_new
24
24
  subject.nokogiri_autocreate_off.should be_new
25
25
  end
@@ -29,43 +29,43 @@ describe ActiveFedora::Datastreams do
29
29
  describe "#has_metadata" do
30
30
  before :all do
31
31
  class HasMetadata < ActiveFedora::Base
32
- has_metadata :name => "with_versions", :autocreate => true, :label => "Versioned DS", :type => ActiveFedora::SimpleDatastream
33
- has_metadata :name => "without_versions", :autocreate => true, :versionable => false, :type => ActiveFedora::SimpleDatastream
32
+ has_metadata name: "with_versions", autocreate: true, label: "Versioned DS", type: ActiveFedora::SimpleDatastream
33
+ has_metadata name: "without_versions", autocreate: true, versionable: false, type: ActiveFedora::SimpleDatastream
34
34
  end
35
35
  end
36
36
  after :all do
37
37
  Object.send(:remove_const, :HasMetadata)
38
38
  end
39
- before :each do
40
- @base = ActiveFedora::Base.new(:pid=>"test:has_metadata_base")
41
- @base.add_datastream(@base.create_datastream(ActiveFedora::Datastream, "testDS", :dsLabel => "Test DS"))
39
+ before do
40
+ @base = ActiveFedora::Base.new(pid:"test:has_metadata_base")
41
+ @base.add_datastream(@base.create_datastream(ActiveFedora::Datastream, "testDS", dsLabel: "Test DS"))
42
42
  @base.datastreams["testDS"].content = "blah blah blah"
43
43
  @base.save
44
- @test = HasMetadata.new(:pid=>"test:has_metadata_model")
44
+ @test = HasMetadata.new(pid:"test:has_metadata_model")
45
45
  @test.save
46
46
  end
47
47
 
48
- after :each do
48
+ after do
49
49
  @base.delete
50
50
  @test.delete
51
51
  end
52
52
 
53
53
  it "should create datastreams from the spec on new objects" do
54
- @test.without_versions.versionable.should be_false
55
- @test.with_versions.versionable.should be_true
56
- @test.with_versions.dsLabel.should == "Versioned DS"
54
+ expect(@test.without_versions.versionable).to be_false
55
+ expect(@test.with_versions.versionable).to be_true
56
+ expect(@test.with_versions.dsLabel).to eql "Versioned DS"
57
57
  @test.without_versions.content= "blah blah blah"
58
58
  @test.save
59
- HasMetadata.find(@test.pid).without_versions.versionable.should be_false
59
+ expect(HasMetadata.find(@test.pid).without_versions.versionable).to be_false
60
60
  end
61
61
 
62
62
  it "should use ds_specs and preserve existing datastreams on migrated objects" do
63
63
  test_obj = HasMetadata.find(@base.pid)
64
- test_obj.datastreams["testDS"].dsLabel.should == "Test DS"
65
- test_obj.datastreams["testDS"].new?.should be_false
66
- test_obj.with_versions.dsLabel.should == "Versioned DS"
67
- test_obj.without_versions.versionable.should be_false
68
- test_obj.with_versions.new?.should be_true
64
+ expect(test_obj.datastreams["testDS"].dsLabel).to eql "Test DS"
65
+ expect(test_obj.datastreams["testDS"].new?).to be_false
66
+ expect(test_obj.with_versions.dsLabel).to eql "Versioned DS"
67
+ expect(test_obj.without_versions.versionable).to be_false
68
+ expect(test_obj.with_versions.new?).to be_true
69
69
  end
70
70
 
71
71
  end
@@ -73,60 +73,101 @@ describe ActiveFedora::Datastreams do
73
73
  describe "#has_file_datastream" do
74
74
  before :all do
75
75
  class HasFile < ActiveFedora::Base
76
- has_file_datastream :name => "file_ds", :versionable => false
77
- has_file_datastream :name => "file_ds2", :versionable => false, :autocreate => false
76
+ has_file_datastream name: "file_ds", versionable: false
77
+ has_file_datastream name: "file_ds2", versionable: false, autocreate: false
78
78
  end
79
79
  end
80
80
  after :all do
81
81
  Object.send(:remove_const, :HasFile)
82
82
  end
83
- before :each do
84
- @base = ActiveFedora::Base.new(:pid=>"test:ds_versionable_base")
83
+ before do
84
+ @base = ActiveFedora::Base.new(pid:"test:ds_versionable_base")
85
85
  @base.save
86
- @base2 = ActiveFedora::Base.new(:pid=>"test:ds_versionable_base2")
87
- @base2.add_datastream(@base2.create_datastream(ActiveFedora::Datastream,"file_ds", :versionable=>true,:dsLabel=>"Pre-existing DS"))
86
+ @base2 = ActiveFedora::Base.new(pid:"test:ds_versionable_base2")
87
+ @base2.add_datastream(@base2.create_datastream(ActiveFedora::Datastream,"file_ds", versionable:true,dsLabel:"Pre-existing DS"))
88
88
  @base2.datastreams["file_ds"].content = "blah blah blah"
89
89
  @base2.save
90
- @has_file = HasFile.new(:pid=>"test:ds_versionable_has_file")
90
+ @has_file = HasFile.new(pid:"test:ds_versionable_has_file")
91
91
  @has_file.save
92
92
  end
93
93
 
94
- after :each do
94
+ after do
95
95
  @base.delete
96
96
  @base2.delete
97
97
  @has_file.delete
98
98
  end
99
99
 
100
100
  it "should create datastreams from the spec on new objects" do
101
- @has_file.file_ds.versionable.should be_false
101
+ expect(@has_file.file_ds.versionable).to be_false
102
102
  @has_file.file_ds.content = "blah blah blah"
103
- @has_file.file_ds.changed?.should be_true
104
- @has_file.file_ds2.changed?.should be_false # no autocreate
105
- @has_file.file_ds2.new?.should be_true
103
+ expect(@has_file.file_ds.changed?).to be_true
104
+ expect(@has_file.file_ds2.changed?).to be_false # no autocreate
105
+ expect(@has_file.file_ds2.new?).to be_true
106
106
  @has_file.save
107
- @has_file.file_ds.versionable.should be_false
107
+ expect(@has_file.file_ds.versionable).to be_false
108
108
  test_obj = HasFile.find(@has_file.pid)
109
- test_obj.file_ds.versionable.should be_false
110
- test_obj.rels_ext.changed?.should be_false
111
- test_obj.file_ds.changed?.should be_false
112
- test_obj.file_ds2.changed?.should be_false
113
- test_obj.file_ds2.new?.should be_true
109
+ expect(test_obj.file_ds.versionable).to be_false
110
+ expect(test_obj.rels_ext.changed?).to be_false
111
+ expect(test_obj.file_ds.changed?).to be_false
112
+ expect(test_obj.file_ds2.changed?).to be_false
113
+ expect(test_obj.file_ds2.new?).to be_true
114
114
  end
115
115
 
116
116
  it "should use ds_specs on migrated objects" do
117
117
  test_obj = HasFile.find(@base.pid)
118
- test_obj.file_ds.versionable.should be_false
119
- test_obj.file_ds.new?.should be_true
118
+ expect(test_obj.file_ds.versionable).to be_false
119
+ expect(test_obj.file_ds.new?).to be_true
120
120
  test_obj.file_ds.content = "blah blah blah"
121
121
  test_obj.save
122
- test_obj.file_ds.versionable.should be_false
122
+ expect(test_obj.file_ds.versionable).to be_false
123
123
  # look it up again to check datastream profile
124
124
  test_obj = HasFile.find(@base.pid)
125
- test_obj.file_ds.versionable.should be_false
126
- test_obj.file_ds.dsLabel.should == "File Datastream"
125
+ expect(test_obj.file_ds.versionable).to be_false
126
+ expect(test_obj.file_ds.dsLabel).to eql "File Datastream"
127
127
  test_obj = HasFile.find(@base2.pid)
128
- test_obj.file_ds.versionable.should be_true
129
- test_obj.file_ds.dsLabel.should == "Pre-existing DS"
128
+ expect(test_obj.file_ds.versionable).to be_true
129
+ expect(test_obj.file_ds.dsLabel).to eql "Pre-existing DS"
130
130
  end
131
131
  end
132
- end
132
+
133
+ describe "#create_datastream" do
134
+ before do
135
+ @base = ActiveFedora::Base.new(pid:"test:create_datastream")
136
+ @base.save
137
+ @ds_location = ActiveFedora.solr_config[:url] + "/admin/file/?file=schema.xml"
138
+ open(@ds_location) do |f|
139
+ @ds_content = f.read
140
+ end
141
+ end
142
+
143
+ after do
144
+ @base.delete
145
+ end
146
+ # external file datastreams require changes to XACML policies, but http URIs should work
147
+ it "should create external datastreams" do
148
+ # we should be albe to reliably download the solr schema
149
+ ds_opts = {mimeType:'text/xml',controlGroup:'E',dsLabel:'Some metadata',
150
+ dsLocation:@ds_location}
151
+ ds = @base.create_datastream('ActiveFedora::Datastream', 'someMetadata', ds_opts)
152
+ @base.add_datastream(ds)
153
+ @base.save
154
+ expect(@base.datastreams.keys.include?('someMetadata')).to be_true
155
+ test_obj = ActiveFedora::Base.find(@base.pid)
156
+ expect(test_obj.datastreams['someMetadata'].content).to eql @ds_content
157
+ expect(test_obj.datastreams['someMetadata'].controlGroup).to eql 'E'
158
+ end
159
+
160
+ # file:// URIs require changes to XACML policies, but http URIs should work
161
+ it "should create managed datastreams from a given URL" do
162
+ ds_opts = {mimeType:'text/xml',controlGroup:'M',dsLabel:'Some metadata',
163
+ dsLocation:@ds_location}
164
+ ds = @base.create_datastream('ActiveFedora::Datastream', 'someMetadata', ds_opts)
165
+ @base.add_datastream(ds)
166
+ @base.save
167
+ expect(@base.datastreams.keys.include?('someMetadata')).to be_true
168
+ test_obj = ActiveFedora::Base.find(@base.pid)
169
+ expect(test_obj.datastreams['someMetadata'].content).to eql @ds_content
170
+ expect(test_obj.datastreams['someMetadata'].controlGroup).to eql 'M'
171
+ end
172
+ end
173
+ end
@@ -220,17 +220,27 @@ describe ActiveFedora::Base do
220
220
  before :all do
221
221
  class BarRdfDatastream < ActiveFedora::NtriplesRDFDatastream
222
222
  property :title, :predicate => RDF::DC.title
223
- property :description, :predicate => RDF::DC.description, :multivalue => false
223
+ property :description, :predicate => RDF::DC.description
224
+ property :author, :predicate => RDF::FOAF.Person
225
+ property :editor, :predicate => RDF::FOAF.Person
224
226
  end
225
227
  class BarHistory4 < ActiveFedora::Base
226
228
  has_metadata 'rdfish', :type=>BarRdfDatastream
227
- has_attributes :title, :description, datastream: 'rdfish', multiple: true
229
+ has_attributes :title, datastream: 'rdfish', multiple: true
230
+ has_attributes :description, datastream: 'rdfish', multiple: false
231
+ has_attributes :author, datastream: 'rdfish', multiple: false
232
+ has_attributes :editor, datastream: 'rdfish', multiple: true
233
+ end
234
+ class PersonResource < ActiveTriples::Resource
235
+ configure type: RDF::FOAF.Person
236
+ property :person_name, predicate: RDF::FOAF.name
228
237
  end
229
238
  end
230
239
 
231
240
  after :all do
232
241
  Object.send(:remove_const, :BarHistory4)
233
242
  Object.send(:remove_const, :BarRdfDatastream)
243
+ Object.send(:remove_const, :PersonResource)
234
244
  end
235
245
 
236
246
  subject { BarHistory4.new }
@@ -241,13 +251,27 @@ describe ActiveFedora::Base do
241
251
  subject.title = ["Title1", "Title2"]
242
252
  subject.title_changed?.should be true
243
253
  end
254
+ it "should not accept a single literal value" do
255
+ expect { subject.title = "Title1" }.to raise_error
256
+ end
257
+ it "should not accept a single ActiveTriples::Resource" do
258
+ editor = PersonResource.new.tap { |p| p.person_name = "Sally" }
259
+ expect { subject.editor = editor }.to raise_error
260
+ end
244
261
  end
245
262
  describe "with a single-valued field" do
246
263
  it "should be able to track change status" do
247
264
  subject.description_changed?.should be false
248
- subject.description = ["A brief description"]
265
+ subject.description = "A brief description"
249
266
  subject.description_changed?.should be true
250
267
  end
268
+ it "should not accept an array of literal values" do
269
+ expect { subject.description = ["A brief description", "A longer description"] }.to raise_error
270
+ end
271
+ it "should accept an ActiveTriples::Resource" do
272
+ author = PersonResource.new.tap { |p| p.person_name = "Bob" }
273
+ expect { subject.author = author }.not_to raise_error
274
+ end
251
275
  end
252
276
  end
253
277
 
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: 8.0.0.rc2
4
+ version: 8.0.0.rc3
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: 2014-12-02 00:00:00.000000000 Z
13
+ date: 2015-01-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr