active-fedora 9.2.0 → 9.2.1

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: d06c266076a65780ab8db396bf9940d5c2350be2
4
- data.tar.gz: dc1ce79ba0ef5591a8fa580a77e70caa2785bbc5
3
+ metadata.gz: 912cef8852fb193d0e8c55b2996b060608b04426
4
+ data.tar.gz: a9b6e0994fbd8edefb197a93ca5031a3bd439f9f
5
5
  SHA512:
6
- metadata.gz: 54d49974e1ac5efc17a321e51455d0778e2712055acec83bd1efbf424f8c9302d98e8d4186d8cb1fb095d225e1a5075ac9549f0172fd13669423e170d0d6eb11
7
- data.tar.gz: 89731055f7e3b7f50873d26e9905926a4bd86f2da837a5e2903f017a52099750857de5a2ec3692641febc648023d3eb0299bd6281ff35f604276ba517702e952
6
+ metadata.gz: 0a8e668c4d8ce320ada6b10a9104a61ced5901802f24f9aeca5fbd5381ddb30573ef270dbbc0e42c9c0b0f51bd70df8d108deb285e34e15ce229abe644d48edd
7
+ data.tar.gz: 5a9bb242cf7d205c5f853457f4d458afdbfdf0862f041610ffc2705c9e2e32c04ca7c0fb32cf0730be078f3e4da22a3de37efe55137b0ba2673898822fe513b6
@@ -3,19 +3,17 @@ cache: bundler
3
3
  sudo: false
4
4
  rvm:
5
5
  - 2.2.1
6
-
7
6
  gemfile:
8
7
  - gemfiles/rails4.1.gemfile
9
8
  - gemfiles/rails4.2.gemfile
10
-
11
9
  matrix:
12
10
  include:
13
11
  - rvm: 2.1
14
12
  gemfile: gemfiles/rails4.2.gemfile
15
-
16
13
  notifications:
17
14
  irc: "irc.freenode.org#projecthydra"
18
-
19
15
  env:
20
16
  global:
21
17
  - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
18
+ before_script:
19
+ - jdk_switcher use oraclejdk8
@@ -1,3 +1,15 @@
1
+ v9.2.1
2
+ 2015-07-20: Don't delete objects not part of the association. [Trey Terrell]
3
+
4
+ 2015-07-19: Improve handling of imperfect profile_json when loading instances
5
+ from Solr. [Olli Lyytinen]
6
+
7
+ 2015-07-16: ChangeSet shouldn't record other subjects. [Trey Terrell]
8
+
9
+ 2015-07-15: Update unit test style [Mike Giarlo]
10
+
11
+ 2015-07-09: Relation should respond to enumerable methods [Justin Coyne]
12
+
1
13
  v9.2.0
2
14
  2015-07-08: Add comments to FedoraAttributes [ci skip] [Justin Coyne]
3
15
 
@@ -354,7 +354,7 @@ module ActiveFedora
354
354
  end
355
355
 
356
356
  def delete_or_destroy(records, method)
357
- records = records.flatten
357
+ records = records.flatten.select{|x| load_target.include?(x)}
358
358
  records.each { |record| raise_on_type_mismatch(record) }
359
359
  existing_records = records.select { |r| r.persisted? }
360
360
 
@@ -22,14 +22,14 @@ module ActiveFedora
22
22
  @changes ||= changed_attributes.each_with_object({}) do |key, result|
23
23
  if object.respond_to?(:association) && object.association(key.to_sym).present?
24
24
  predicate = object.association(key.to_sym).reflection.predicate
25
- result[predicate] = graph.query(predicate: predicate)
25
+ result[predicate] = graph.query(subject: object.rdf_subject, predicate: predicate)
26
26
  elsif object.class.properties.keys.include?(key)
27
27
  predicate = graph.reflections.reflect_on_property(key).predicate
28
- result[predicate] = graph.query(predicate: predicate)
28
+ result[predicate] = graph.query(subject: object.rdf_subject, predicate: predicate)
29
29
  elsif key == 'type'.freeze
30
30
  # working around https://github.com/ActiveTriples/ActiveTriples/issues/122
31
31
  predicate = ::RDF.type
32
- result[predicate] = graph.query(predicate: predicate)
32
+ result[predicate] = graph.query(subject: object.rdf_subject, predicate: predicate)
33
33
  elsif object.local_attributes.include?(key)
34
34
  raise "Unable to find a graph predicate corresponding to the attribute: \"#{key}\""
35
35
  end
@@ -117,7 +117,7 @@ module ActiveFedora
117
117
  attached_files[key] = SolrBackedMetadataFile.new
118
118
  end
119
119
  @resource = SolrBackedResource.new(self.class)
120
- self.attributes = attrs.slice(*self.class.attribute_names)
120
+ self.attributes = adapt_attributes(attrs)
121
121
  # TODO Should we clear the change tracking, or make this object Read-only?
122
122
 
123
123
  run_callbacks :find
@@ -126,5 +126,38 @@ module ActiveFedora
126
126
  self
127
127
  end
128
128
 
129
+ private
130
+
131
+ # Adapt attributes read from Solr to possible minor changes in data model
132
+ # since the attributes were saved.
133
+ # @param attrs [Hash] attributes read from Solr
134
+ # @return [Hash] the adapted attributes
135
+ def adapt_attributes(attrs)
136
+ self.class.attribute_names.each_with_object({}) do |attribute_name, new_attributes|
137
+ new_attributes[attribute_name] = adapt_attribute_value(attrs, attribute_name)
138
+ end
139
+ end
140
+
141
+ # Adapts a single attribute value from the given attributes hash to match
142
+ # minor changes in the data model.
143
+ # @param attrs [Hash] attributes read from Solr
144
+ # @param attribute_name [String] the name of the attribute to adapt
145
+ # @return [Object] the adapted value
146
+ def adapt_attribute_value(attrs, attribute_name)
147
+ reflection = self.class.reflect_on_property(attribute_name)
148
+ if !reflection
149
+ return attrs[attribute_name] # if this isn't a property, copy value verbatim
150
+ else
151
+ multiple = reflection.multiple?
152
+ if !attrs.key?(attribute_name)
153
+ # value is missing in attrs, add [] or nil
154
+ return multiple ? [] : nil
155
+ else
156
+ # convert an existing scalar to an array if needed
157
+ return multiple ? Array(attrs[attribute_name]) : attrs[attribute_name]
158
+ end
159
+ end
160
+ end
161
+
129
162
  end
130
163
  end
@@ -1,6 +1,7 @@
1
1
  module ActiveFedora
2
2
  class Relation
3
3
 
4
+ include Enumerable
4
5
  include FinderMethods, Calculations, SpawnMethods, QueryMethods, Delegation
5
6
 
6
7
 
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "9.2.0"
2
+ VERSION = "9.2.1"
3
3
  end
@@ -42,6 +42,22 @@ describe ActiveFedora::Base do
42
42
  end
43
43
  end
44
44
 
45
+ describe "#delete" do
46
+ context "when given items not in collection" do
47
+ it "should return an empty set" do
48
+ expect(library.books.delete(Book.new)).to eq []
49
+ end
50
+ it "should not act on it" do
51
+ b = Book.new
52
+ allow(b).to receive(:persisted?).and_return(true)
53
+
54
+ library.books.delete(b)
55
+
56
+ expect(b).not_to have_received(:persisted?)
57
+ end
58
+ end
59
+ end
60
+
45
61
  describe "#destroy_all" do
46
62
  it "should delete em" do
47
63
  expect {
@@ -17,10 +17,14 @@ describe ActiveFedora::Base do
17
17
 
18
18
  subject { Library.all }
19
19
 
20
- it "should be a relation" do
20
+ it "is a relation" do
21
21
  expect(subject.class).to be ActiveFedora::Relation
22
22
  end
23
23
 
24
+ it "is enumerable" do
25
+ expect(subject).to respond_to(:each_with_index)
26
+ end
27
+
24
28
  context "when some records exist" do
25
29
  before do
26
30
  Library.create
@@ -87,12 +87,37 @@ describe ActiveFedora::SolrInstanceLoader do
87
87
  end
88
88
  end
89
89
 
90
- context "when the model has extra values in its json" do
91
- let(:profile) { { "foo"=>["baz"], "bar"=>"quix", "title"=>"My Title", "extra_value"=>"Bonus values!"}.to_json }
90
+ context "when the model has imperfect json" do
92
91
  let(:doc) { { 'id' => 'test-123', 'has_model_ssim'=>['Foo'], 'object_profile_ssm' => profile } }
93
92
  let(:loader) { ActiveFedora::SolrInstanceLoader.new(Foo, obj.id, doc) }
94
- it "should load the object without trouble" do
95
- expect(loader.object).to be_instance_of Foo
93
+ context "when the json has extra values in it" do
94
+ let(:profile) { { "foo"=>["baz"], "bar"=>"quix", "title"=>"My Title", "extra_value"=>"Bonus values!"}.to_json }
95
+ it "should load the object without trouble" do
96
+ expect(loader.object).to be_instance_of Foo
97
+ end
98
+ end
99
+
100
+ context "when the json is missing values" do
101
+ let(:profile) { { "foo"=>["baz"], "bar"=>"quix" }.to_json }
102
+ it "should load the object without trouble" do
103
+ expect(loader.object).to be_instance_of Foo
104
+ end
105
+ it "missing scalar should be nil" do
106
+ expect(loader.object.title).to be_nil
107
+ end
108
+ it "missing multi-value should be []" do
109
+ expect(loader.object.description).to eql( [] )
110
+ end
111
+ end
112
+
113
+ context "when the json has scalar where multi-value is expected" do
114
+ let(:profile) { { "foo"=>["baz"], "bar"=>"quix", "description"=>"test description" }.to_json }
115
+ it "should load the object without trouble" do
116
+ expect(loader.object).to be_instance_of Foo
117
+ end
118
+ it "should convert the scalar to an array" do
119
+ expect(loader.object.description).to eql( ["test description"] )
120
+ end
96
121
  end
97
122
  end
98
123
  end
@@ -41,6 +41,11 @@ describe ActiveFedora::ChangeSet do
41
41
  it "should have three elements" do
42
42
  expect(subject.size).to eq 3
43
43
  end
44
+ it "should not include URIs from other objects" do
45
+ base.resource << RDF::Statement.new(RDF::URI("http://wrong.com"), RDF::DC.title, "bad")
46
+ base.title = nil
47
+ expect(subject[RDF::DC.title].to_a).to eq []
48
+ end
44
49
  end
45
50
 
46
51
  it { is_expected.to_not be_empty }
@@ -1,39 +1,48 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ActiveFedora::Datastream do
4
- let(:datastream) { ActiveFedora::Datastream.new }
3
+ describe ActiveFedora::File do
4
+ let(:file) { described_class.new }
5
5
 
6
- subject { datastream }
6
+ subject { file }
7
7
 
8
- it { should_not be_metadata }
8
+ it { is_expected.not_to be_metadata }
9
9
 
10
10
  describe "#behaves_like_io?" do
11
- subject { datastream.send(:behaves_like_io?, object) }
11
+ subject { file.send(:behaves_like_io?, object) }
12
12
 
13
13
  context "with a File" do
14
14
  let(:object) { File.new __FILE__ }
15
- it { should be true }
15
+ it { is_expected.to be true }
16
16
  end
17
17
 
18
18
  context "with a Tempfile" do
19
19
  after { object.close; object.unlink }
20
20
  let(:object) { Tempfile.new('foo') }
21
- it { should be true }
21
+ it { is_expected.to be true }
22
22
  end
23
23
 
24
24
  context "with a StringIO" do
25
25
  let(:object) { StringIO.new('foo') }
26
- it { should be true }
26
+ it { is_expected.to be true }
27
27
  end
28
28
  end
29
29
 
30
30
  describe "#uri" do
31
- let(:parent) { ActiveFedora::Base.new(id: '1234') }
32
- before { allow(Deprecation).to receive(:warn) }
33
- subject { ActiveFedora::Datastream.new(parent, 'FOO1') }
34
31
 
35
- it "should set the uri" do
36
- expect(subject.uri).to eq "#{ActiveFedora.fedora.host}#{ActiveFedora.fedora.base_path}/1234/FOO1"
32
+ subject { file.uri }
33
+
34
+ context "when the file is in an ldp:BasicContainer" do
35
+ let(:parent) { ActiveFedora::Base.new(id: '1234') }
36
+ before { allow(Deprecation).to receive(:warn) }
37
+ let(:file) { described_class.new(parent, 'FOO1') }
38
+
39
+ it "sets the uri using the parent as the base" do
40
+ expect(subject).to eq "#{ActiveFedora.fedora.host}#{ActiveFedora.fedora.base_path}/1234/FOO1"
41
+ end
42
+ end
43
+
44
+ context "when the file doesn't have a uri" do
45
+ it { is_expected.to eq ::RDF::URI(nil) }
37
46
  end
38
47
  end
39
48
 
@@ -64,7 +73,7 @@ describe ActiveFedora::Datastream do
64
73
  end
65
74
 
66
75
  describe '#persisted_size' do
67
- it 'should load the datastream size attribute from the fedora repository' do
76
+ it 'should load the file size attribute from the fedora repository' do
68
77
  expect(subject.size).to eq 9999
69
78
  end
70
79
 
@@ -152,25 +161,25 @@ describe ActiveFedora::Datastream do
152
161
  end
153
162
  end
154
163
 
155
- context "when the datastream has local content" do
164
+ context "when the file has local content" do
156
165
 
157
166
  before do
158
- datastream.uri = "http://localhost:8983/fedora/rest/test/1234/abcd"
159
- datastream.content = "hi there"
167
+ file.uri = "http://localhost:8983/fedora/rest/test/1234/abcd"
168
+ file.content = "hi there"
160
169
  end
161
170
 
162
171
  describe "#inspect" do
163
- subject { datastream.inspect }
164
- it { should eq "#<ActiveFedora::Datastream uri=\"http://localhost:8983/fedora/rest/test/1234/abcd\" >" }
172
+ subject { file.inspect }
173
+ it { is_expected.to eq "#<ActiveFedora::File uri=\"http://localhost:8983/fedora/rest/test/1234/abcd\" >" }
165
174
  end
166
175
  end
167
176
 
168
177
  context "original_name" do
169
- subject { datastream.original_name }
178
+ subject { file.original_name }
170
179
 
171
- context "on a new datastream" do
180
+ context "on a new file" do
172
181
  context "that has a name set locally" do
173
- before { datastream.original_name = "my_image.png" }
182
+ before { file.original_name = "my_image.png" }
174
183
  it { is_expected.to eq "my_image.png" }
175
184
  end
176
185
 
@@ -204,10 +213,10 @@ describe ActiveFedora::Datastream do
204
213
  end
205
214
 
206
215
  context "digest" do
207
- subject { datastream.digest }
216
+ subject { file.digest }
208
217
 
209
- context "on a new datastream" do
210
- it { should be_empty }
218
+ context "on a new file" do
219
+ it { is_expected.to be_empty }
211
220
  end
212
221
 
213
222
  context "when it's saved" do
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: 9.2.0
4
+ version: 9.2.1
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: 2015-07-08 00:00:00.000000000 Z
13
+ date: 2015-07-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr
@@ -603,7 +603,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
603
603
  version: '0'
604
604
  requirements: []
605
605
  rubyforge_project:
606
- rubygems_version: 2.4.8
606
+ rubygems_version: 2.4.5
607
607
  signing_key:
608
608
  specification_version: 4
609
609
  summary: A convenience libary for manipulating documents in the Fedora Repository.