active-fedora 7.0.4 → 7.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/History.txt +51 -1
  4. data/active-fedora.gemspec +19 -19
  5. data/lib/active_fedora.rb +1 -6
  6. data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +1 -1
  7. data/lib/active_fedora/associations/collection_association.rb +1 -1
  8. data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +1 -1
  9. data/lib/active_fedora/attributes.rb +8 -0
  10. data/lib/active_fedora/base.rb +1 -1
  11. data/lib/active_fedora/callbacks.rb +1 -1
  12. data/lib/active_fedora/core.rb +13 -5
  13. data/lib/active_fedora/datastream_attribute.rb +1 -1
  14. data/lib/active_fedora/datastream_hash.rb +12 -6
  15. data/lib/active_fedora/fedora_attributes.rb +1 -1
  16. data/lib/active_fedora/file_configurator.rb +3 -3
  17. data/lib/active_fedora/fixture_loader.rb +2 -2
  18. data/lib/active_fedora/model.rb +2 -2
  19. data/lib/active_fedora/om_datastream.rb +2 -2
  20. data/lib/active_fedora/persistence.rb +22 -18
  21. data/lib/active_fedora/railtie.rb +5 -1
  22. data/lib/active_fedora/rdf.rb +11 -9
  23. data/lib/active_fedora/rdf/indexing.rb +1 -1
  24. data/lib/active_fedora/rdf/object_resource.rb +1 -1
  25. data/lib/active_fedora/rdf/rdf_datastream.rb +3 -3
  26. data/lib/active_fedora/relation/finder_methods.rb +16 -10
  27. data/lib/active_fedora/solr_instance_loader.rb +1 -1
  28. data/lib/active_fedora/solr_service.rb +1 -3
  29. data/lib/active_fedora/version.rb +1 -1
  30. data/spec/integration/attributes_spec.rb +4 -4
  31. data/spec/integration/base_spec.rb +32 -13
  32. data/spec/integration/complex_rdf_datastream_spec.rb +4 -4
  33. data/spec/integration/delete_all_spec.rb +1 -1
  34. data/spec/integration/load_from_solr_spec.rb +1 -1
  35. data/spec/integration/rdf_nested_attributes_spec.rb +4 -4
  36. data/spec/integration/scoped_query_spec.rb +6 -6
  37. data/spec/spec_helper.rb +5 -3
  38. data/spec/unit/attributes_spec.rb +19 -1
  39. data/spec/unit/builder/has_and_belongs_to_many_spec.rb +9 -0
  40. data/spec/unit/datastreams_spec.rb +4 -0
  41. data/spec/unit/file_configurator_spec.rb +5 -5
  42. data/spec/unit/logger_spec.rb +20 -0
  43. data/spec/unit/om_datastream_spec.rb +1 -1
  44. data/spec/unit/persistence_spec.rb +50 -0
  45. data/spec/unit/query_spec.rb +15 -5
  46. data/spec/unit/rdf_resource_datastream_spec.rb +3 -3
  47. data/spec/unit/rdfxml_rdf_datastream_spec.rb +1 -1
  48. data/spec/unit/solr_config_options_spec.rb +1 -1
  49. data/spec/unit/solr_service_spec.rb +1 -1
  50. metadata +33 -168
  51. data/lib/active_fedora/rdf/configurable.rb +0 -59
  52. data/lib/active_fedora/rdf/list.rb +0 -155
  53. data/lib/active_fedora/rdf/nested_attributes.rb +0 -130
  54. data/lib/active_fedora/rdf/node_config.rb +0 -57
  55. data/lib/active_fedora/rdf/properties.rb +0 -94
  56. data/lib/active_fedora/rdf/repositories.rb +0 -36
  57. data/lib/active_fedora/rdf/resource.rb +0 -328
  58. data/lib/active_fedora/rdf/term.rb +0 -188
  59. data/spec/unit/rdf_configurable_spec.rb +0 -37
  60. data/spec/unit/rdf_list_nested_attributes_spec.rb +0 -99
  61. data/spec/unit/rdf_list_spec.rb +0 -180
  62. data/spec/unit/rdf_properties_spec.rb +0 -81
  63. data/spec/unit/rdf_repositories_spec.rb +0 -28
  64. data/spec/unit/rdf_resource_spec.rb +0 -345
@@ -1,37 +0,0 @@
1
- require "spec_helper"
2
- describe ActiveFedora::Rdf::Configurable do
3
- before do
4
- class DummyConfigurable
5
- extend ActiveFedora::Rdf::Configurable
6
- end
7
- end
8
- after do
9
- Object.send(:remove_const, "DummyConfigurable")
10
- end
11
-
12
- describe '#configure' do
13
- before do
14
- DummyConfigurable.configure :base_uri => "http://example.org/base", :type => RDF.Class, :rdf_label => RDF::DC.title
15
- end
16
-
17
- it 'should set a base uri' do
18
- expect(DummyConfigurable.base_uri).to eq "http://example.org/base"
19
- end
20
-
21
- it 'should set an rdf_label' do
22
- expect(DummyConfigurable.rdf_label).to eq RDF::DC.title
23
- end
24
-
25
- it 'should set a type' do
26
- expect(DummyConfigurable.type).to eq RDF.Class
27
- end
28
- end
29
-
30
- describe '#rdf_type' do
31
- it "should set the type the old way" do
32
- DummyConfigurable.should_receive(:configure).with(:type => RDF.Class).and_call_original
33
- DummyConfigurable.rdf_type(RDF.Class)
34
- expect(DummyConfigurable.type).to eq RDF.Class
35
- end
36
- end
37
- end
@@ -1,99 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::Rdf::List do
4
- before :each do
5
- class MADS < RDF::Vocabulary("http://www.loc.gov/mads/rdf/v1#")
6
- property :MADSScheme
7
- property :isMemberOfMADSScheme
8
- property :authoritativeLabel
9
- property :elementList
10
- property :elementValue
11
- property :Topic
12
- property :TopicElement
13
- property :TemporalElement
14
- property :hasExactExternalAuthority
15
- end
16
-
17
- class TopicElement < ActiveFedora::Rdf::Resource
18
- configure :type => MADS.TopicElement
19
- property :elementValue, :predicate => MADS.elementValue
20
- end
21
- class TemporalElement < ActiveFedora::Rdf::Resource
22
- configure :type => MADS.TemporalElement
23
- property :elementValue, :predicate => MADS.elementValue
24
- end
25
- class ElementList < ActiveFedora::Rdf::List
26
- property :topicElement, :predicate => MADS.TopicElement, :class_name => 'TopicElement'
27
- property :temporalElement, :predicate => MADS.TemporalElement, :class_name => 'TemporalElement'
28
- accepts_nested_attributes_for :topicElement, :temporalElement
29
- end
30
-
31
- class Topic < ActiveFedora::Rdf::Resource
32
- configure :type => MADS.Topic
33
- configure :base_uri => "http://example.org/id_namespace#"
34
- property :name, :predicate => MADS.authoritativeLabel
35
- property :elementList, :predicate => MADS.elementList, :class_name => 'ElementList'
36
- property :externalAuthority, :predicate => MADS.hasExactExternalAuthority
37
-
38
- accepts_nested_attributes_for :elementList
39
- end
40
- end
41
- after(:each) do
42
- Object.send(:remove_const, :Topic)
43
- Object.send(:remove_const, :ElementList)
44
- Object.send(:remove_const, :TopicElement)
45
- Object.send(:remove_const, :TemporalElement)
46
- Object.send(:remove_const, :MADS)
47
- end
48
-
49
- describe "nested_attributes" do
50
- it "should insert new nodes into RdfLists (rather than calling .build)" do
51
- params = {
52
- topic: {
53
- name: "Baseball",
54
- externalAuthority: "http://id.loc.gov/authorities/subjects/sh85012026",
55
- elementList_attributes: [
56
- topicElement_attributes: [{ elementValue: "Baseball" }, elementValue: "Football"],
57
- ]
58
- }
59
- }
60
-
61
- topic = Topic.new
62
- topic.attributes = params[:topic]
63
- topic.elementList.first.size.should == 2
64
- topic.elementList.first[0].should be_kind_of(TopicElement)
65
- topic.elementList.first[0].elementValue.should == ["Baseball"]
66
- topic.elementList.first[1].should be_kind_of(TopicElement)
67
- topic.elementList.first[1].elementValue.should == ["Football"]
68
-
69
- # only one rdf:rest rdf:nil
70
- topic.query([nil, RDF.rest, RDF.nil]).size.should == 1
71
- end
72
- it "should insert new nodes of varying types into RdfLists (rather than calling .build)" do
73
- # It's Not clear what the syntax should be when an RDF list contains multiple types of sub-nodes.
74
- # This is a guess, which currently works.
75
- params = {
76
- topic: {
77
- name: "Baseball",
78
- externalAuthority: "http://id.loc.gov/authorities/subjects/sh85012026",
79
- elementList_attributes: [
80
- topicElement_attributes: [{ elementValue: "Baseball" }, elementValue: "Football"],
81
- temporalElement_attributes: [{elementValue: "1960"}, {elementValue:"Twentieth Century"}],
82
- ]
83
- }
84
- }
85
-
86
- topic = Topic.new
87
- topic.attributes = params[:topic]
88
- topic.elementList.first.size.should == 4
89
- topic.elementList.first[0].should be_kind_of(TopicElement)
90
- topic.elementList.first[0].elementValue.should == ["Baseball"]
91
- topic.elementList.first[1].should be_kind_of(TopicElement)
92
- topic.elementList.first[1].elementValue.should == ["Football"]
93
- topic.elementList.first[2].should be_kind_of(TemporalElement)
94
- topic.elementList.first[2].elementValue.should == ["1960"]
95
- topic.elementList.first[3].should be_kind_of(TemporalElement)
96
- topic.elementList.first[3].elementValue.should == ["Twentieth Century"]
97
- end
98
- end
99
- end
@@ -1,180 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::Rdf::List do
4
- before :each do
5
- class MADS < RDF::Vocabulary("http://www.loc.gov/mads/rdf/v1#")
6
- property :complexSubject
7
- property :authoritativeLabel
8
- property :elementList
9
- property :elementValue
10
- property :TopicElement
11
- property :TemporalElement
12
- end
13
- class DemoList < ActiveFedora::RdfxmlRDFDatastream
14
- property :elementList, :predicate => MADS.elementList, :class_name => 'DemoList::List'
15
- class List < ActiveFedora::Rdf::List
16
- property :topicElement, :predicate => MADS.TopicElement, :class_name => 'DemoList::List::TopicElement'
17
- property :temporalElement, :predicate => MADS.TemporalElement, :class_name => 'DemoList::List::TemporalElement'
18
-
19
- class TopicElement < ActiveFedora::Rdf::Resource
20
- configure :type => MADS.TopicElement
21
- property :elementValue, :predicate => MADS.elementValue
22
- end
23
- class TemporalElement < ActiveFedora::Rdf::Resource
24
- configure :type => MADS.TemporalElement
25
- property :elementValue, :predicate => MADS.elementValue
26
- end
27
- end
28
- end
29
- end
30
- after(:each) do
31
- Object.send(:remove_const, :DemoList)
32
- Object.send(:remove_const, :MADS)
33
- end
34
-
35
- describe "a new list" do
36
- let (:ds) { DemoList.new(double('inner object', :pid=>'foo', :new_record? =>true), 'descMetadata')}
37
- subject { ds.elementList.build}
38
-
39
- it "should insert at the end" do
40
- subject.should be_kind_of DemoList::List
41
- subject.size.should == 0
42
- subject[1] = DemoList::List::TopicElement.new
43
- subject.size.should == 2
44
- end
45
-
46
- it "should insert at the head" do
47
- subject.should be_kind_of DemoList::List
48
- subject.size.should == 0
49
- subject[0] = DemoList::List::TopicElement.new
50
- subject.size.should == 1
51
- end
52
-
53
- describe "that has 4 elements" do
54
- before do
55
- subject[3] = DemoList::List::TopicElement.new
56
- subject.size.should == 4
57
- end
58
- it "should insert in the middle" do
59
- subject[1] = DemoList::List::TopicElement.new
60
- subject.size.should == 4
61
- end
62
- end
63
-
64
- describe "return updated xml" do
65
- it "should be built" do
66
- subject[0] = RDF::URI.new "http://library.ucsd.edu/ark:/20775/bbXXXXXXX6"
67
- subject[1] = DemoList::List::TopicElement.new
68
- subject[1].elementValue = "Relations with Mexican Americans"
69
- subject[2] = RDF::URI.new "http://library.ucsd.edu/ark:/20775/bbXXXXXXX4"
70
- subject[3] = DemoList::List::TemporalElement.new
71
- subject[3].elementValue = "20th century"
72
- ds.elementList = subject
73
- doc = Nokogiri::XML(ds.content)
74
- ns = {rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#", mads: "http://www.loc.gov/mads/rdf/v1#"}
75
- expect(doc.xpath('/rdf:RDF/rdf:Description/@rdf:about', ns).map(&:value)).to eq ["info:fedora/foo"]
76
- expect(doc.xpath('//rdf:Description/mads:elementList/@rdf:parseType', ns).map(&:value)).to eq ["Collection"]
77
- expect(doc.xpath('//rdf:Description/mads:elementList/*[position() = 1]/@rdf:about', ns).map(&:value)).to eq ["http://library.ucsd.edu/ark:/20775/bbXXXXXXX6"]
78
- expect(doc.xpath('//rdf:Description/mads:elementList/*[position() = 2]/mads:elementValue', ns).map(&:text)).to eq ["Relations with Mexican Americans"]
79
- expect(doc.xpath('//rdf:Description/mads:elementList/*[position() = 3]/@rdf:about', ns).map(&:value)).to eq ["http://library.ucsd.edu/ark:/20775/bbXXXXXXX4"]
80
- expect(doc.xpath('//rdf:Description/mads:elementList/*[position() = 4]/mads:elementValue', ns).map(&:text)).to eq ["20th century"]
81
- end
82
- end
83
- end
84
-
85
- describe "an empty list" do
86
- subject { DemoList.new(double('inner object', :pid=>'foo', :new_record? =>true), 'descMd').elementList.build }
87
- it "should have to_ary" do
88
- subject.to_ary.should == []
89
- end
90
- end
91
-
92
- describe "a list that has a constructed element" do
93
- let(:ds) { DemoList.new(double('inner object', :pid=>'foo', :new_record? =>true), 'descMd') }
94
- let(:list) { ds.elementList.build }
95
- let!(:topic) { list.topicElement.build }
96
-
97
- it "should have to_ary" do
98
- list.to_ary.size.should == 1
99
- list.to_ary.first.class.should == DemoList::List::TopicElement
100
- end
101
-
102
- it "should be able to be cleared" do
103
- list.topicElement.build
104
- list.topicElement.build
105
- list.topicElement.build
106
- list.size.should == 4
107
- list.clear
108
- list.size.should == 0
109
- end
110
- end
111
-
112
- describe "a list with content" do
113
- subject do
114
- subject = DemoList.new(double('inner object', :pid=>'foo', :new_record? =>true), 'descMetadata')
115
- subject.content =<<END
116
- <rdf:RDF
117
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:mads="http://www.loc.gov/mads/rdf/v1#">
118
-
119
- <mads:ComplexSubject rdf:about="info:fedora/foo">
120
- <mads:elementList rdf:parseType="Collection">
121
- <rdf:Description rdf:about="http://library.ucsd.edu/ark:/20775/bbXXXXXXX6"/>
122
- <mads:TopicElement>
123
- <mads:elementValue>Relations with Mexican Americans</mads:elementValue>
124
- </mads:TopicElement>
125
- <rdf:Description rdf:about="http://library.ucsd.edu/ark:/20775/bbXXXXXXX4"/>
126
- <mads:TemporalElement>
127
- <mads:elementValue>20th century</mads:elementValue>
128
- </mads:TemporalElement>
129
- </mads:elementList>
130
- </mads:ComplexSubject>
131
- </rdf:RDF>
132
- END
133
-
134
- subject
135
- end
136
- it "should have a subject" do
137
- subject.rdf_subject.to_s.should == "info:fedora/foo"
138
- end
139
-
140
- let (:list) { subject.elementList.first }
141
-
142
- it "should have fields" do
143
- list.first.rdf_subject.should == "http://library.ucsd.edu/ark:/20775/bbXXXXXXX6"
144
- list[1].should be_kind_of DemoList::List::TopicElement
145
- list[1].elementValue.should == ["Relations with Mexican Americans"]
146
- list[2].rdf_subject.should == "http://library.ucsd.edu/ark:/20775/bbXXXXXXX4"
147
- list[3].should be_kind_of DemoList::List::TemporalElement
148
- list[3].elementValue.should == ["20th century"]
149
- end
150
-
151
- it "should have each" do
152
- foo = []
153
- list.each { |n| foo << n.class }
154
- foo.should == [ActiveFedora::Rdf::Resource, DemoList::List::TopicElement, ActiveFedora::Rdf::Resource, DemoList::List::TemporalElement]
155
- end
156
-
157
- it "should have to_ary" do
158
- ary = list.to_ary
159
- ary.size.should == 4
160
- ary[1].elementValue.should == ['Relations with Mexican Americans']
161
- end
162
-
163
- it "should have size" do
164
- list.size.should == 4
165
- end
166
-
167
- it "should update fields" do
168
- list[3].elementValue = ["1900s"]
169
- doc = Nokogiri::XML(subject.content)
170
- ns = {rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#", mads: "http://www.loc.gov/mads/rdf/v1#"}
171
- expect(doc.xpath('/rdf:RDF/mads:ComplexSubject/@rdf:about', ns).map(&:value)).to eq ["info:fedora/foo"]
172
- expect(doc.xpath('//mads:ComplexSubject/mads:elementList/@rdf:parseType', ns).map(&:value)).to eq ["Collection"]
173
- expect(doc.xpath('//mads:ComplexSubject/mads:elementList/*[position() = 1]/@rdf:about', ns).map(&:value)).to eq ["http://library.ucsd.edu/ark:/20775/bbXXXXXXX6"]
174
- expect(doc.xpath('//mads:ComplexSubject/mads:elementList/*[position() = 2]/mads:elementValue', ns).map(&:text)).to eq ["Relations with Mexican Americans"]
175
- expect(doc.xpath('//mads:ComplexSubject/mads:elementList/*[position() = 3]/@rdf:about', ns).map(&:value)).to eq ["http://library.ucsd.edu/ark:/20775/bbXXXXXXX4"]
176
- expect(doc.xpath('//mads:ComplexSubject/mads:elementList/*[position() = 4]/mads:elementValue', ns).map(&:text)).to eq ["1900s"]
177
- end
178
- end
179
- end
180
-
@@ -1,81 +0,0 @@
1
- require "spec_helper"
2
- describe ActiveFedora::Rdf::Properties do
3
- before do
4
- class DummyProperties
5
- extend ActiveFedora::Rdf::Properties
6
- end
7
- end
8
-
9
- after do
10
- Object.send(:remove_const, "DummyProperties")
11
- end
12
-
13
- describe '#map_predicates' do
14
- before do
15
- DummyProperties.map_predicates do |map|
16
- map.title(:in => RDF::DC, :class_name => RDF::Literal) do |index|
17
- index.as :facetable, :searchable
18
- end
19
- end
20
- end
21
-
22
- it 'should set a property' do
23
- expect(DummyProperties.properties).to include :title
24
- end
25
-
26
- it "should set index behaviors" do
27
- expect(DummyProperties.properties[:title][:behaviors]).to eq [:facetable, :searchable]
28
- end
29
-
30
- it "should set a class name" do
31
- expect(DummyProperties.properties[:title][:class_name]).to eq RDF::Literal
32
- end
33
- end
34
-
35
- describe '#property' do
36
- it 'should set a property' do
37
- DummyProperties.property :title, :predicate => RDF::DC.title
38
- expect(DummyProperties.properties).to include :title
39
- end
40
-
41
- it 'should set index behaviors' do
42
- DummyProperties.property :title, :predicate => RDF::DC.title do |index|
43
- index.as :facetable, :searchable
44
- end
45
- expect(DummyProperties.properties[:title][:behaviors]).to eq [:facetable, :searchable]
46
- end
47
-
48
- it 'should set class name' do
49
- DummyProperties.property :title, :predicate => RDF::DC.title, :class_name => RDF::Literal
50
- expect(DummyProperties.properties[:title][:class_name]).to eq RDF::Literal
51
- end
52
-
53
- it "should constantize string class names" do
54
- DummyProperties.property :title, :predicate => RDF::DC.title, :class_name => "RDF::Literal"
55
- expect(DummyProperties.properties[:title][:class_name]).to eq RDF::Literal
56
- end
57
-
58
- it "should keep strings which it can't constantize as strings" do
59
- DummyProperties.property :title, :predicate => RDF::DC.title, :class_name => "FakeClassName"
60
- expect(DummyProperties.properties[:title][:class_name]).to eq "FakeClassName"
61
- end
62
-
63
- end
64
-
65
- context "when using a subclass" do
66
- before do
67
- DummyProperties.property :title, :predicate => RDF::DC.title
68
- class DummySubClass < DummyProperties
69
- property :source, :predicate => RDF::DC11[:source]
70
- end
71
- end
72
-
73
- after do
74
- Object.send(:remove_const, "DummySubClass")
75
- end
76
-
77
- it 'should carry properties from superclass' do
78
- expect(DummySubClass.properties.keys).to eq ["title", "source"]
79
- end
80
- end
81
- end
@@ -1,28 +0,0 @@
1
- require "spec_helper"
2
- describe ActiveFedora::Rdf::Repositories do
3
- subject {ActiveFedora::Rdf::Repositories}
4
-
5
- after(:each) do
6
- subject.clear_repositories!
7
- subject.add_repository :default, RDF::Repository.new
8
- subject.add_repository :vocabs, RDF::Repository.new
9
- end
10
-
11
- describe '#add_repositories' do
12
- it 'should accept a new repository' do
13
- subject.add_repository :name, RDF::Repository.new
14
- expect(subject.repositories).to include :name
15
- end
16
- it 'should throw an error if passed something that is not a repository' do
17
- expect{subject.add_repository :name, :not_a_repo}.to raise_error
18
- end
19
- end
20
-
21
- describe '#clear_repositories!' do
22
- it 'should empty the repositories list' do
23
- subject.clear_repositories!
24
- expect(subject.repositories).to be_empty
25
- end
26
- end
27
-
28
- end
@@ -1,345 +0,0 @@
1
- require "spec_helper"
2
- describe ActiveFedora::Rdf::Resource do
3
-
4
- before do
5
- class DummyLicense < ActiveFedora::Rdf::Resource
6
- property :title, :predicate => RDF::DC.title
7
- end
8
-
9
- class DummyResource < ActiveFedora::Rdf::Resource
10
- configure :type => RDF::URI('http://example.org/SomeClass')
11
- property :license, :predicate => RDF::DC.license, :class_name => DummyLicense
12
- property :title, :predicate => RDF::DC.title
13
- end
14
- end
15
- after do
16
- Object.send(:remove_const, "DummyResource") if Object
17
- Object.send(:remove_const, "DummyLicense") if Object
18
- end
19
-
20
- subject { DummyResource.new }
21
-
22
- describe 'rdf_subject' do
23
- it "should be a blank node if we haven't set it" do
24
- expect(subject.rdf_subject.node?).to be_true
25
- end
26
-
27
- it "should be settable" do
28
- subject.set_subject! RDF::URI('http://example.org/moomin')
29
- expect(subject.rdf_subject).to eq RDF::URI('http://example.org/moomin')
30
- end
31
-
32
- it "should raise an error when setting to an invalid uri" do
33
- expect{ subject.set_subject!('not_a_uri') }.to raise_error "could not make a valid RDF::URI from not_a_uri"
34
- end
35
-
36
- describe 'when changing subject' do
37
- before do
38
- subject << RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland'))
39
- subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject)
40
- subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land')
41
- subject.set_subject! RDF::URI('http://example.org/moomin')
42
- end
43
-
44
- it 'should update graph subjects' do
45
- expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')))).to be_true
46
- end
47
-
48
- it 'should update graph objects' do
49
- expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject))).to be_true
50
- end
51
-
52
- it 'should leave other uris alone' do
53
- expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land'))).to be_true
54
- end
55
- end
56
-
57
- describe 'with URI subject' do
58
- before do
59
- subject.set_subject! RDF::URI('http://example.org/moomin')
60
- end
61
-
62
- it 'should not be settable' do
63
- expect{ subject.set_subject! RDF::URI('http://example.org/moomin2') }.to raise_error
64
- end
65
- end
66
- end
67
-
68
- describe "#persisted?" do
69
- before do
70
- repository = RDF::Repository.new
71
- subject.stub(:repository).and_return(repository)
72
- end
73
-
74
- context "when the object is new" do
75
- it "should return false" do
76
- expect(subject).not_to be_persisted
77
- end
78
- end
79
-
80
- context "when it is saved" do
81
- before do
82
- subject.title = "bla"
83
- subject.persist!
84
- end
85
-
86
- it "should return true" do
87
- expect(subject).to be_persisted
88
- end
89
-
90
- context "and then modified" do
91
- before do
92
- subject.title = "newbla"
93
- end
94
-
95
- it "should return true" do
96
- expect(subject).to be_persisted
97
- end
98
- end
99
- context "and then reloaded" do
100
- before do
101
- subject.reload
102
- end
103
-
104
- it "should reset the title" do
105
- expect(subject.title).to eq ["bla"]
106
- end
107
-
108
- it "should be persisted" do
109
- expect(subject).to be_persisted
110
- end
111
- end
112
- end
113
- end
114
-
115
- describe "#persist!" do
116
- context "when the repository is set" do
117
- context "and the item is not a blank node" do
118
-
119
- subject {DummyResource.new("info:fedora/example:pid")}
120
-
121
- before do
122
- @repo = RDF::Repository.new
123
- subject.class.stub(:repository).and_return(nil)
124
- subject.stub(:repository).and_return(@repo)
125
- subject.title = "bla"
126
- subject.persist!
127
- end
128
-
129
- it "should persist to the repository" do
130
- expect(@repo.statements.first).to eq subject.statements.first
131
- end
132
-
133
- it "should delete from the repository" do
134
- subject.reload
135
- expect(subject.title).to eq ["bla"]
136
- subject.title = []
137
- expect(subject.title).to eq []
138
- subject.persist!
139
- subject.reload
140
- expect(subject.title).to eq []
141
- expect(@repo.statements.to_a.length).to eq 1 # Only the type statement
142
- end
143
- end
144
- end
145
- end
146
-
147
- describe 'property methods' do
148
- it 'should set and get properties' do
149
- subject.title = 'Comet in Moominland'
150
- expect(subject.title).to eq ['Comet in Moominland']
151
- end
152
- end
153
-
154
- describe 'child nodes' do
155
- it 'should return an object of the correct class when the value is a URI' do
156
- subject.license = DummyLicense.new('http://example.org/license')
157
- expect(subject.license.first).to be_kind_of DummyLicense
158
- end
159
-
160
- it 'should return an object with the correct URI when the value is a URI ' do
161
- subject.license = DummyLicense.new('http://example.org/license')
162
- expect(subject.license.first.rdf_subject).to eq RDF::URI("http://example.org/license")
163
- end
164
-
165
- it 'should return an object of the correct class when the value is a bnode' do
166
- subject.license = DummyLicense.new
167
- expect(subject.license.first).to be_kind_of DummyLicense
168
- end
169
- end
170
-
171
- describe '#set_value' do
172
- it 'should set a value in the graph' do
173
- subject.set_value(RDF::DC.title, 'Comet in Moominland')
174
- subject.query(:subject => subject.rdf_subject, :predicate => RDF::DC.title).each_statement do |s|
175
- expect(s.object.to_s).to eq 'Comet in Moominland'
176
- end
177
- end
178
-
179
- it 'should set a value in the when given a registered property symbol' do
180
- subject.set_value(:title, 'Comet in Moominland')
181
- expect(subject.title).to eq ['Comet in Moominland']
182
- end
183
-
184
- it "raise an error if the value is not a URI, Node, Literal, RdfResource, or string" do
185
- expect{subject.set_value(RDF::DC.title, Object.new)}.to raise_error
186
- end
187
-
188
- it "should be able to accept a subject" do
189
- expect{subject.set_value(RDF::URI("http://opaquenamespace.org/jokes"), RDF::DC.title, 'Comet in Moominland')}.not_to raise_error
190
- expect(subject.query(:subject => RDF::URI("http://opaquenamespace.org/jokes"), :predicate => RDF::DC.title).statements.to_a.length).to eq 1
191
- end
192
- end
193
- describe '#get_values' do
194
- before do
195
- subject.title = ['Comet in Moominland', "Finn Family Moomintroll"]
196
- end
197
-
198
- it 'should return values for a predicate uri' do
199
- expect(subject.get_values(RDF::DC.title)).to eq ['Comet in Moominland', 'Finn Family Moomintroll']
200
- end
201
-
202
- it 'should return values for a registered predicate symbol' do
203
- expect(subject.get_values(:title)).to eq ['Comet in Moominland', 'Finn Family Moomintroll']
204
- end
205
-
206
- it "should return values for other subjects if asked" do
207
- expect(subject.get_values(RDF::URI("http://opaquenamespace.org/jokes"),:title)).to eq []
208
- subject.set_value(RDF::URI("http://opaquenamespace.org/jokes"), RDF::DC.title, 'Comet in Moominland')
209
- expect(subject.get_values(RDF::URI("http://opaquenamespace.org/jokes"),:title)).to eq ["Comet in Moominland"]
210
- end
211
- end
212
-
213
- describe '#type' do
214
- it 'should return the type configured on the parent class' do
215
- expect(subject.type).to eq [DummyResource.type]
216
- end
217
-
218
- it 'should set the type' do
219
- subject.type = RDF::URI('http://example.org/AnotherClass')
220
- expect(subject.type).to eq [RDF::URI('http://example.org/AnotherClass')]
221
- end
222
-
223
- it 'should be the type in the graph' do
224
- subject.query(:subject => subject.rdf_subject, :predicate => RDF.type).statements do |s|
225
- expect(s.object).to eq RDF::URI('http://example.org/AnotherClass')
226
- end
227
- end
228
- end
229
-
230
- describe '#rdf_label' do
231
- it 'should return an array of label values' do
232
- expect(subject.rdf_label).to be_kind_of Array
233
- end
234
-
235
- it 'should return the default label values' do
236
- subject.title = 'Comet in Moominland'
237
- expect(subject.rdf_label).to eq ['Comet in Moominland']
238
- end
239
-
240
- it 'should prioritize configured label values' do
241
- custom_label = RDF::URI('http://example.org/custom_label')
242
- subject.class.configure :rdf_label => custom_label
243
- subject << RDF::Statement(subject.rdf_subject, custom_label, RDF::Literal('New Label'))
244
- subject.title = 'Comet in Moominland'
245
- expect(subject.rdf_label).to eq ['New Label']
246
- end
247
- end
248
-
249
- describe '#solrize' do
250
- it 'should return a label for bnodes' do
251
- expect(subject.solrize).to eq subject.rdf_label
252
- end
253
-
254
- it 'should return a string of the resource uri' do
255
- subject.set_subject! 'http://example.org/moomin'
256
- expect(subject.solrize).to eq 'http://example.org/moomin'
257
- end
258
- end
259
-
260
- describe 'editing the graph' do
261
- it 'should write properties when statements are added' do
262
- subject << RDF::Statement.new(subject.rdf_subject, RDF::DC.title, 'Comet in Moominland')
263
- expect(subject.title).to include 'Comet in Moominland'
264
- end
265
-
266
- it 'should delete properties when statements are removed' do
267
- subject << RDF::Statement.new(subject.rdf_subject, RDF::DC.title, 'Comet in Moominland')
268
- subject.delete RDF::Statement.new(subject.rdf_subject, RDF::DC.title, 'Comet in Moominland')
269
- expect(subject.title).to eq []
270
- end
271
- end
272
-
273
- describe 'big complex graphs' do
274
- before do
275
- class DummyPerson < ActiveFedora::Rdf::Resource
276
- configure :type => RDF::URI('http://example.org/Person')
277
- property :name, :predicate => RDF::FOAF.name
278
- property :publications, :predicate => RDF::FOAF.publications, :class_name => 'DummyDocument'
279
- property :knows, :predicate => RDF::FOAF.knows, :class_name => DummyPerson
280
- end
281
-
282
- class DummyDocument < ActiveFedora::Rdf::Resource
283
- configure :type => RDF::URI('http://example.org/Document')
284
- property :title, :predicate => RDF::DC.title
285
- property :creator, :predicate => RDF::DC.creator, :class_name => 'DummyPerson'
286
- end
287
-
288
- DummyResource.property :item, :predicate => RDF::DC.relation, :class_name => DummyDocument
289
- end
290
-
291
- subject { DummyResource.new }
292
-
293
- let (:document1) do
294
- d = DummyDocument.new
295
- d.title = 'Document One'
296
- d
297
- end
298
-
299
- let (:document2) do
300
- d = DummyDocument.new
301
- d.title = 'Document Two'
302
- d
303
- end
304
-
305
- let (:person1) do
306
- p = DummyPerson.new
307
- p.name = 'Alice'
308
- p
309
- end
310
-
311
- let (:person2) do
312
- p = DummyPerson.new
313
- p.name = 'Bob'
314
- p
315
- end
316
-
317
- let (:data) { <<END
318
- _:1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/SomeClass> .
319
- _:1 <http://purl.org/dc/terms/relation> _:2 .
320
- _:2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Document> .
321
- _:2 <http://purl.org/dc/terms/title> "Document One" .
322
- _:2 <http://purl.org/dc/terms/creator> _:3 .
323
- _:2 <http://purl.org/dc/terms/creator> _:4 .
324
- _:4 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Person> .
325
- _:4 <http://xmlns.com/foaf/0.1/name> "Bob" .
326
- _:3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Person> .
327
- _:3 <http://xmlns.com/foaf/0.1/name> "Alice" .
328
- _:3 <http://xmlns.com/foaf/0.1/knows> _:4 ."
329
- END
330
- }
331
-
332
- after do
333
- Object.send(:remove_const, "DummyDocument")
334
- Object.send(:remove_const, "DummyPerson")
335
- end
336
-
337
- it 'should allow access to deep nodes' do
338
- document1.creator = [person1, person2]
339
- document2.creator = person1
340
- person1.knows = person2
341
- subject.item = [document1]
342
- expect(subject.item.first.creator.first.knows.first.name).to eq ['Bob']
343
- end
344
- end
345
- end