active-fedora 5.7.1 → 6.0.0.pre1
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/.gitmodules +1 -1
- data/Gemfile +2 -1
- data/History.txt +0 -14
- data/Rakefile +1 -2
- data/active-fedora.gemspec +2 -2
- data/lib/active_fedora.rb +1 -16
- data/lib/active_fedora/associations.rb +8 -11
- data/lib/active_fedora/associations/association_collection.rb +2 -4
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +3 -12
- data/lib/active_fedora/associations/has_many_association.rb +0 -4
- data/lib/active_fedora/base.rb +6 -6
- data/lib/active_fedora/config.rb +0 -7
- data/lib/active_fedora/datastream.rb +0 -37
- data/lib/active_fedora/datastream_collections.rb +0 -10
- data/lib/active_fedora/datastreams.rb +0 -17
- data/lib/active_fedora/digital_object.rb +1 -1
- data/lib/active_fedora/file_configurator.rb +0 -22
- data/lib/active_fedora/fixture_loader.rb +1 -1
- data/lib/active_fedora/nokogiri_datastream.rb +9 -51
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +1 -1
- data/lib/active_fedora/querying.rb +8 -4
- data/lib/active_fedora/rdf_datastream.rb +10 -9
- data/lib/active_fedora/rdf_node.rb +1 -1
- data/lib/active_fedora/rdf_node/term_proxy.rb +9 -5
- data/lib/active_fedora/relation.rb +1 -1
- data/lib/active_fedora/rels_ext_datastream.rb +1 -8
- data/lib/active_fedora/semantic_node.rb +0 -35
- data/lib/active_fedora/simple_datastream.rb +1 -1
- data/lib/active_fedora/solr_service.rb +6 -8
- data/lib/active_fedora/version.rb +1 -1
- data/lib/tasks/active_fedora_dev.rake +11 -3
- data/solr/conf/schema.xml +10 -1
- data/spec/integration/base_spec.rb +2 -347
- data/spec/integration/complex_rdf_datastream_spec.rb +1 -1
- data/spec/integration/full_featured_model_spec.rb +1 -9
- data/spec/integration/ntriples_datastream_spec.rb +4 -4
- data/spec/integration/om_datastream_spec.rb +2 -1
- data/spec/integration/rels_ext_datastream_spec.rb +1 -89
- data/spec/integration/scoped_query_spec.rb +4 -4
- data/spec/samples/hydra-mods_article_datastream.rb +2 -2
- data/spec/spec_helper.rb +3 -0
- data/spec/unit/base_spec.rb +7 -81
- data/spec/unit/datastream_spec.rb +0 -25
- data/spec/unit/has_many_collection_spec.rb +2 -27
- data/spec/unit/ntriples_datastream_spec.rb +28 -39
- data/spec/unit/om_datastream_spec.rb +13 -13
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +1 -1
- data/spec/unit/query_spec.rb +1 -24
- data/spec/unit/semantic_node_spec.rb +0 -2
- data/spec/unit/simple_datastream_spec.rb +2 -2
- data/spec/unit/solr_config_options_spec.rb +1 -1
- metadata +76 -57
- checksums.yaml +0 -7
- data/.travis.yml +0 -8
- data/lib/active_fedora/file_management.rb +0 -81
- data/lib/active_fedora/metadata_datastream_helper.rb +0 -43
- data/lib/active_fedora/named_relationships.rb +0 -99
- data/lib/active_fedora/relationships.rb +0 -663
- data/spec/integration/base_file_management_spec.rb +0 -24
- data/spec/integration/has_many_associations_spec.rb +0 -64
- data/spec/integration/metadata_datastream_helper_spec.rb +0 -100
- data/spec/integration/semantic_node_spec.rb +0 -457
- data/spec/unit/base_file_management_spec.rb +0 -95
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +0 -59
- data/spec/unit/relationships_spec.rb +0 -871
@@ -1,95 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::Base do
|
4
|
-
before(:all) do
|
5
|
-
@behavior = ActiveFedora::FileManagement.deprecation_behavior
|
6
|
-
ActiveFedora::FileManagement.deprecation_behavior = :silence
|
7
|
-
end
|
8
|
-
|
9
|
-
after :all do
|
10
|
-
ActiveFedora::FileManagement.deprecation_behavior = @behavior
|
11
|
-
end
|
12
|
-
|
13
|
-
before(:all) do
|
14
|
-
class FileMgmt < ActiveFedora::Base
|
15
|
-
include ActiveFedora::FileManagement
|
16
|
-
end
|
17
|
-
@base = FileMgmt.new
|
18
|
-
end
|
19
|
-
|
20
|
-
before(:each) do
|
21
|
-
@base.stub(:create_date).and_return("2008-07-02T05:09:42.015Z")
|
22
|
-
@base.stub(:modified_date).and_return("2008-09-29T21:21:52.892Z")
|
23
|
-
end
|
24
|
-
|
25
|
-
describe ".file_objects" do
|
26
|
-
it "should wrap .collection_members and .parts" do
|
27
|
-
@base.should_receive(:collection_members).and_return([])
|
28
|
-
@base.should_receive(:parts).and_return(["Foo"])
|
29
|
-
@base.file_objects
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe ".file_objects_append" do
|
34
|
-
it "should make the file object being appended assert isPartOf pointing back at the current object and save the child" do
|
35
|
-
mock_child = ActiveFedora::Base.new
|
36
|
-
mock_child.should_receive(:add_relationship).with(:is_part_of, @base)
|
37
|
-
mock_child.should_receive(:save)
|
38
|
-
@base.file_objects_append(mock_child)
|
39
|
-
end
|
40
|
-
it "should load the file object being appended if only a pid is provided and save the child" do
|
41
|
-
mock_child = mock("object")
|
42
|
-
mock_child.should_receive(:add_relationship).with(:is_part_of, @base)
|
43
|
-
mock_child.should_receive(:save)
|
44
|
-
ActiveFedora::Base.should_receive(:find).with("_PID_").and_return(mock_child)
|
45
|
-
@base.file_objects_append("_PID_")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe ".parts" do
|
50
|
-
it "should search for both (outbound) has_part and (inbound) is_part_of relationships, removing duplicates" do
|
51
|
-
@base.should_receive(:parts_outbound).and_return(["A", "B"])
|
52
|
-
@base.should_receive(:parts_inbound).and_return(["B", "C"])
|
53
|
-
@base.parts.should == ["B", "C", "A"]
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe ".collection_members" do
|
58
|
-
it "should return an array" do
|
59
|
-
@base.collection_members.should be_kind_of(Array)
|
60
|
-
end
|
61
|
-
describe "_append" do
|
62
|
-
it "should be a supported method" do
|
63
|
-
@base.should respond_to(:collection_members_append)
|
64
|
-
end
|
65
|
-
it "should assert hasCollectionMember for the given object/pid" do
|
66
|
-
mocko = mock("object")
|
67
|
-
@base.should_receive(:add_relationship).with(:has_collection_member, mocko)
|
68
|
-
@base.collection_members_append(mocko)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
describe "_remove" do
|
72
|
-
it "should be a supported method" do
|
73
|
-
@base.should respond_to(:collection_members_remove)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe ".add_file_datastream" do
|
79
|
-
it "should create a new datastream with the file as its content" do
|
80
|
-
mock_file = mock()
|
81
|
-
ds = mock()
|
82
|
-
@base.should_receive(:create_datastream).with(ActiveFedora::Datastream, nil, hash_including(:blob => mock_file)).and_return(ds)
|
83
|
-
@base.should_receive(:add_datastream).with(ds)
|
84
|
-
@base.add_file_datastream(mock_file)
|
85
|
-
end
|
86
|
-
it "should set :dsid and :label when supplied" do
|
87
|
-
mock_file = mock()
|
88
|
-
ds = mock()
|
89
|
-
@base.should_receive(:create_datastream).with(ActiveFedora::Datastream, 'Foo', hash_including(:dsLabel => 'My Label', :blob => mock_file)).and_return(ds)
|
90
|
-
@base.should_receive(:add_datastream).with(ds)
|
91
|
-
@base.add_file_datastream(mock_file, :label => 'My Label', :dsid => 'Foo')
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::Associations::HasAndBelongsToManyAssociation do
|
4
|
-
it "should call add_relationship" do
|
5
|
-
subject = stub("subject", :new_record? => false, :pid => 'subject:a', :internal_uri => 'info:fedora/subject:a', :ids_for_outbound => [])
|
6
|
-
predicate = stub(:klass => mock.class, :options=>{:property=>'predicate'}, :class_name=> nil)
|
7
|
-
ActiveFedora::SolrService.stub(:query).and_return([])
|
8
|
-
ac = ActiveFedora::Associations::HasAndBelongsToManyAssociation.new(subject, predicate)
|
9
|
-
object = stub("object", :new_record? => false, :pid => 'object:b', :save => nil)
|
10
|
-
|
11
|
-
subject.should_receive(:add_relationship).with('predicate', object)
|
12
|
-
|
13
|
-
ac << object
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should call add_relationship on subject and object when inverse_of given" do
|
18
|
-
subject = stub("subject", :new_record? => false, :pid => 'subject:a', :internal_uri => 'info:fedora/subject:a', :ids_for_outbound => [])
|
19
|
-
predicate = stub(:klass => mock.class, :options=>{:property=>'predicate', :inverse_of => 'inverse_predicate'}, :class_name=> nil)
|
20
|
-
ActiveFedora::SolrService.stub(:query).and_return([])
|
21
|
-
ac = ActiveFedora::Associations::HasAndBelongsToManyAssociation.new(subject, predicate)
|
22
|
-
object = stub("object", :new_record? => false, :pid => 'object:b', :save => nil)
|
23
|
-
|
24
|
-
subject.should_receive(:add_relationship).with('predicate', object)
|
25
|
-
|
26
|
-
object.should_receive(:add_relationship).with('inverse_predicate', subject)
|
27
|
-
|
28
|
-
ac << object
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should call remove_relationship" do
|
33
|
-
subject = stub("subject", :new_record? => false, :pid => 'subject:a', :internal_uri => 'info:fedora/subject:a')
|
34
|
-
predicate = stub(:klass => mock.class, :options=>{:property=>'predicate'}, :class_name=> nil)
|
35
|
-
ActiveFedora::SolrService.stub(:query).and_return([])
|
36
|
-
ac = ActiveFedora::Associations::HasAndBelongsToManyAssociation.new(subject, predicate)
|
37
|
-
object = stub("object", :new_record? => false, :pid => 'object:b', :save => nil)
|
38
|
-
|
39
|
-
subject.should_receive(:remove_relationship).with('predicate', object)
|
40
|
-
|
41
|
-
ac.delete(object)
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should call remove_relationship on subject and object when inverse_of given" do
|
46
|
-
subject = stub("subject", :new_record? => false, :pid => 'subject:a', :internal_uri => 'info:fedora/subject:a')
|
47
|
-
predicate = stub(:klass => mock.class, :options=>{:property=>'predicate', :inverse_of => 'inverse_predicate'}, :class_name=> nil)
|
48
|
-
ActiveFedora::SolrService.stub(:query).and_return([])
|
49
|
-
ac = ActiveFedora::Associations::HasAndBelongsToManyAssociation.new(subject, predicate)
|
50
|
-
object = stub("object", :new_record? => false, :pid => 'object:b', :save => nil)
|
51
|
-
|
52
|
-
subject.should_receive(:remove_relationship).with('predicate', object)
|
53
|
-
object.should_receive(:remove_relationship).with('inverse_predicate', subject)
|
54
|
-
|
55
|
-
ac.delete(object)
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
@@ -1,871 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
@@last_pid = 0
|
4
|
-
|
5
|
-
describe ActiveFedora::Relationships do
|
6
|
-
before(:all) do
|
7
|
-
@behavior = ActiveFedora::Relationships.deprecation_behavior
|
8
|
-
@c_behavior = ActiveFedora::Relationships::ClassMethods.deprecation_behavior
|
9
|
-
ActiveFedora::Relationships.deprecation_behavior = :silence
|
10
|
-
ActiveFedora::Relationships::ClassMethods.deprecation_behavior = :silence
|
11
|
-
end
|
12
|
-
|
13
|
-
after :all do
|
14
|
-
ActiveFedora::Relationships.deprecation_behavior = @behavior
|
15
|
-
ActiveFedora::Relationships::ClassMethods.deprecation_behavior = @c_behavior
|
16
|
-
end
|
17
|
-
|
18
|
-
def increment_pid
|
19
|
-
@@last_pid += 1
|
20
|
-
end
|
21
|
-
|
22
|
-
before(:all) do
|
23
|
-
@part_of_sample = ActiveFedora::SolrService.solr_name("is_part_of", :symbol) + ":#{solr_uri("info:fedora/test:sample_pid")}"
|
24
|
-
@constituent_of_sample = ActiveFedora::SolrService.solr_name("is_constituent_of", :symbol) + ":#{solr_uri("info:fedora/test:sample_pid")}"
|
25
|
-
@is_part_query = ActiveFedora::SolrService.solr_name("has_model", :symbol) + ":#{solr_uri("info:fedora/SpecialPart")}"
|
26
|
-
end
|
27
|
-
|
28
|
-
before(:each) do
|
29
|
-
class SpecNode
|
30
|
-
include ActiveFedora::Relationships
|
31
|
-
include ActiveFedora::SemanticNode
|
32
|
-
include ActiveFedora::Model
|
33
|
-
extend ActiveFedora::Querying
|
34
|
-
|
35
|
-
attr_accessor :pid
|
36
|
-
def init_with(inner_obj)
|
37
|
-
self.pid = inner_obj.pid
|
38
|
-
self
|
39
|
-
end
|
40
|
-
def self.connection_for_pid(pid)
|
41
|
-
end
|
42
|
-
|
43
|
-
def internal_uri
|
44
|
-
'info:fedora/' + pid.to_s
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
after(:each) do
|
49
|
-
Object.send(:remove_const, :SpecNode)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'should provide #has_relationship' do
|
53
|
-
SpecNode.should respond_to(:has_relationship)
|
54
|
-
SpecNode.should respond_to(:has_relationship)
|
55
|
-
end
|
56
|
-
describe '#relationships' do
|
57
|
-
|
58
|
-
it "should return a hash" do
|
59
|
-
SpecNode.relationships.class.should == Hash
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '#has_relationship' do
|
65
|
-
it "should create finders based on provided relationship name" do
|
66
|
-
SpecNode.has_relationship("parts", :is_part_of, :inbound => true)
|
67
|
-
local_node = SpecNode.new
|
68
|
-
local_node.should respond_to(:parts_ids)
|
69
|
-
local_node.should respond_to(:parts_query)
|
70
|
-
# local_node.should respond_to(:parts)
|
71
|
-
local_node.should_not respond_to(:containers)
|
72
|
-
SpecNode.has_relationship("containers", :is_member_of)
|
73
|
-
local_node.should respond_to(:containers_ids)
|
74
|
-
local_node.should respond_to(:containers_query)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should add a subject and predicate to the relationships array" do
|
78
|
-
SpecNode.has_relationship("parents", :is_part_of)
|
79
|
-
SpecNode.relationships.should have_key(:self)
|
80
|
-
SpecNode.relationships[:self].should have_key(:is_part_of)
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should use :inbound as the subject if :inbound => true" do
|
84
|
-
SpecNode.has_relationship("parents", :is_part_of, :inbound => true)
|
85
|
-
SpecNode.relationships.should have_key(:inbound)
|
86
|
-
SpecNode.relationships[:inbound].should have_key(:is_part_of)
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'should create inbound relationship finders' do
|
90
|
-
SpecNode.should_receive(:create_inbound_relationship_finders)
|
91
|
-
SpecNode.has_relationship("parts", :is_part_of, :inbound => true)
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'should create outbound relationship finders' do
|
95
|
-
SpecNode.should_receive(:create_outbound_relationship_finders).exactly(2).times
|
96
|
-
SpecNode.has_relationship("parts", :is_part_of, :inbound => false)
|
97
|
-
SpecNode.has_relationship("container", :is_member_of)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should create outbound relationship finders that return an array of fedora PIDs" do
|
101
|
-
SpecNode.has_relationship("containers", :is_member_of, :inbound => false)
|
102
|
-
local_node = SpecNode.new
|
103
|
-
#local_node.internal_uri = "info:fedora/#{@pid}"
|
104
|
-
local_node.pid = @pid
|
105
|
-
|
106
|
-
local_node.stub(:rels_ext).and_return(stub("rels_ext", :content_will_change! => true, :content=>''))
|
107
|
-
local_node.add_relationship(:is_member_of, "info:fedora/container:A")
|
108
|
-
local_node.add_relationship(:is_member_of, "info:fedora/container:B")
|
109
|
-
|
110
|
-
containers_result = local_node.containers_ids
|
111
|
-
containers_result.should be_instance_of(Array)
|
112
|
-
containers_result.should include("container:A")
|
113
|
-
containers_result.should include("container:B")
|
114
|
-
end
|
115
|
-
|
116
|
-
describe "has_relationship" do
|
117
|
-
before do
|
118
|
-
class MockHasRelationship
|
119
|
-
include ActiveFedora::SemanticNode
|
120
|
-
include ActiveFedora::Relationships
|
121
|
-
has_relationship "testing", :has_part, :type=>String
|
122
|
-
has_relationship "testing2", :has_member, :type=>String
|
123
|
-
has_relationship "testing_inbound", :has_part, :type=>String, :inbound=>true
|
124
|
-
attr_accessor :pid
|
125
|
-
def internal_uri
|
126
|
-
'info:fedora/' + pid.to_s
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
after(:each) do
|
131
|
-
Object.send(:remove_const, :MockHasRelationship)
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'should create relationship descriptions both inbound and outbound' do
|
135
|
-
@test_object2 = MockHasRelationship.new
|
136
|
-
@test_object2.pid = increment_pid
|
137
|
-
@test_object2.stub(:testing_inbound).and_return({})
|
138
|
-
@test_object2.stub(:rels_ext).and_return(stub("rels_ext", :content_will_change! => true, :content =>''))
|
139
|
-
@test_object2.add_relationship(:has_model, SpecNode.to_class_uri)
|
140
|
-
@test_object2.should respond_to(:testing_append)
|
141
|
-
@test_object2.should respond_to(:testing_remove)
|
142
|
-
@test_object2.should respond_to(:testing2_append)
|
143
|
-
@test_object2.should respond_to(:testing2_remove)
|
144
|
-
#make sure append/remove method not created for inbound rel
|
145
|
-
@test_object2.should_not respond_to(:testing_inbound_append)
|
146
|
-
@test_object2.should_not respond_to(:testing_inbound_remove)
|
147
|
-
|
148
|
-
@test_object2.class.relationships_desc.should ==
|
149
|
-
{:inbound=>{"testing_inbound"=>{:type=>String,
|
150
|
-
:predicate=>:has_part,
|
151
|
-
:inbound=>true,
|
152
|
-
:singular=>nil}},
|
153
|
-
:self=>{"testing"=>{:type=>String,
|
154
|
-
:predicate=>:has_part,
|
155
|
-
:inbound=>false,
|
156
|
-
:singular=>nil},
|
157
|
-
"testing2"=>{:type=>String,
|
158
|
-
:predicate=>:has_member,
|
159
|
-
:inbound=>false,
|
160
|
-
:singular=>nil}}}
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
describe '#create_inbound_relationship_finders' do
|
166
|
-
|
167
|
-
it 'should respond to #create_inbound_relationship_finders' do
|
168
|
-
SpecNode.should respond_to(:create_inbound_relationship_finders)
|
169
|
-
end
|
170
|
-
|
171
|
-
it "should create finders based on provided relationship name" do
|
172
|
-
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
173
|
-
local_node = SpecNode.new
|
174
|
-
local_node.should respond_to(:parts_ids)
|
175
|
-
local_node.should_not respond_to(:containers)
|
176
|
-
SpecNode.create_inbound_relationship_finders("containers", :is_member_of, :inbound => true)
|
177
|
-
local_node.should respond_to(:containers_ids)
|
178
|
-
local_node.should respond_to(:containers)
|
179
|
-
local_node.should respond_to(:containers_from_solr)
|
180
|
-
local_node.should respond_to(:containers_query)
|
181
|
-
end
|
182
|
-
|
183
|
-
it "resulting finder should search against solr and use Model#find to build an array of objects" do
|
184
|
-
@sample_solr_hits = [{"id"=>"_PID1_", ActiveFedora::SolrService.solr_name('has_model', :symbol)=>["info:fedora/afmodel:AudioRecord"]},
|
185
|
-
{"id"=>"_PID2_", ActiveFedora::SolrService.solr_name('has_model', :symbol)=>["info:fedora/afmodel:AudioRecord"]},
|
186
|
-
{"id"=>"_PID3_", ActiveFedora::SolrService.solr_name('has_model', :symbol)=>["info:fedora/afmodel:AudioRecord"]}]
|
187
|
-
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
188
|
-
local_node = SpecNode.new()
|
189
|
-
local_node.should_receive(:pid).and_return("test:sample_pid")
|
190
|
-
SpecNode.stub(:relationships_desc).and_return({:inbound=>{"parts"=>{:predicate=>:is_part_of}}})
|
191
|
-
ActiveFedora::SolrService.should_receive(:query).with(@part_of_sample, :rows=>25).and_return(@sample_solr_hits)
|
192
|
-
local_node.parts_ids.should == ["_PID1_", "_PID2_", "_PID3_"]
|
193
|
-
end
|
194
|
-
|
195
|
-
it "resulting finder should accept :solr as :response_format value and return the raw Solr Result" do
|
196
|
-
solr_result = mock("solr result")
|
197
|
-
SpecNode.create_inbound_relationship_finders("constituents", :is_constituent_of, :inbound => true)
|
198
|
-
local_node = SpecNode.new
|
199
|
-
mock_repo = mock("repo")
|
200
|
-
mock_repo.should_receive(:find).never
|
201
|
-
local_node.should_receive(:pid).and_return("test:sample_pid")
|
202
|
-
SpecNode.stub(:relationships_desc).and_return({:inbound=>{"constituents"=>{:predicate=>:is_constituent_of}}})
|
203
|
-
instance = stub(:conn=>stub(:conn))
|
204
|
-
ActiveFedora::SolrService.should_receive(:query).with(@constituent_of_sample, :raw=>true, :rows=>101).and_return(solr_result)
|
205
|
-
local_node.constituents(:response_format => :solr, :rows=>101).should == solr_result
|
206
|
-
end
|
207
|
-
|
208
|
-
|
209
|
-
it "resulting _ids finder should search against solr and return an array of fedora PIDs" do
|
210
|
-
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
211
|
-
local_node = SpecNode.new
|
212
|
-
local_node.should_receive(:pid).and_return("test:sample_pid")
|
213
|
-
SpecNode.stub(:relationships_desc).and_return({:inbound=>{"parts"=>{:predicate=>:is_part_of}}})
|
214
|
-
ActiveFedora::SolrService.should_receive(:query).with(@part_of_sample, :rows=>25).and_return([Hash["id"=>"pid1"], Hash["id"=>"pid2"]])
|
215
|
-
local_node.parts(:response_format => :id_array).should == ["pid1", "pid2"]
|
216
|
-
end
|
217
|
-
|
218
|
-
it "resulting _ids finder should call the basic finder with :result_format => :id_array" do
|
219
|
-
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
220
|
-
local_node = SpecNode.new
|
221
|
-
local_node.should_receive(:parts).with(:response_format => :id_array)
|
222
|
-
local_node.parts_ids
|
223
|
-
end
|
224
|
-
|
225
|
-
it "resulting _query finder should call relationship_query" do
|
226
|
-
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
227
|
-
local_node = SpecNode.new
|
228
|
-
local_node.should_receive(:relationship_query).with("parts")
|
229
|
-
local_node.parts_query
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
describe '#create_outbound_relationship_finders' do
|
234
|
-
|
235
|
-
it 'should respond to #create_outbound_relationship_finders' do
|
236
|
-
SpecNode.should respond_to(:create_outbound_relationship_finders)
|
237
|
-
end
|
238
|
-
|
239
|
-
it "should create finders based on provided relationship name" do
|
240
|
-
SpecNode.create_outbound_relationship_finders("parts", :is_part_of)
|
241
|
-
local_node = SpecNode.new
|
242
|
-
local_node.should respond_to(:parts_ids)
|
243
|
-
#local_node.should respond_to(:parts) #.with(:type => "AudioRecord")
|
244
|
-
local_node.should_not respond_to(:containers)
|
245
|
-
SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
|
246
|
-
local_node.should respond_to(:containers_ids)
|
247
|
-
local_node.should respond_to(:containers)
|
248
|
-
local_node.should respond_to(:containers_from_solr)
|
249
|
-
local_node.should respond_to(:containers_query)
|
250
|
-
end
|
251
|
-
|
252
|
-
describe " resulting finder" do
|
253
|
-
it "should read from relationships array and use Repository.find to build an array of objects" do
|
254
|
-
SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
|
255
|
-
local_node = SpecNode.new
|
256
|
-
local_node.should_receive(:ids_for_outbound).with(:is_member_of).and_return(["my:_PID1_", "my:_PID2_", "my:_PID3_"])
|
257
|
-
|
258
|
-
#ActiveFedora::ContentModel.should_receive(:known_models_for).and_return([SpecNode]).times(3)
|
259
|
-
ActiveFedora::SolrService.should_receive(:query).with("id:my\\:_PID1_ OR id:my\\:_PID2_ OR id:my\\:_PID3_").and_return([{"id"=> "my:_PID1_", ActiveFedora::SolrService.solr_name('has_model', :symbol)=>["info:fedora/afmodel:SpecNode"]},
|
260
|
-
{"id"=> "my:_PID2_", ActiveFedora::SolrService.solr_name('has_model', :symbol)=>["info:fedora/afmodel:SpecNode"]},
|
261
|
-
{"id"=> "my:_PID3_", ActiveFedora::SolrService.solr_name('has_model', :symbol)=>["info:fedora/afmodel:SpecNode"]}])
|
262
|
-
ActiveFedora::DigitalObject.should_receive(:find).with(SpecNode, 'my:_PID1_').and_return(stub("inner obj", :'new?'=>false, :pid=>'my:_PID1_'))
|
263
|
-
ActiveFedora::DigitalObject.should_receive(:find).with(SpecNode, 'my:_PID2_').and_return(stub("inner obj", :'new?'=>false, :pid=>'my:_PID2_'))
|
264
|
-
ActiveFedora::DigitalObject.should_receive(:find).with(SpecNode, 'my:_PID3_').and_return(stub("inner obj", :'new?'=>false, :pid=>'my:_PID3_'))
|
265
|
-
local_node.containers.map(&:pid).should == ["my:_PID1_", "my:_PID2_", "my:_PID3_"]
|
266
|
-
end
|
267
|
-
|
268
|
-
it "should accept :solr as :response_format value and return the raw Solr Result" do
|
269
|
-
solr_result = mock("solr result")
|
270
|
-
SpecNode.create_outbound_relationship_finders("constituents", :is_constituent_of)
|
271
|
-
local_node = SpecNode.new
|
272
|
-
mock_repo = mock("repo")
|
273
|
-
mock_repo.should_receive(:find).never
|
274
|
-
local_node.should_receive(:rels_ext).and_return(stub('rels-ext', :content=>''))
|
275
|
-
ActiveFedora::SolrService.should_receive(:query).and_return(solr_result)
|
276
|
-
local_node.constituents(:response_format => :solr).should == solr_result
|
277
|
-
end
|
278
|
-
|
279
|
-
it "(:response_format => :id_array) should read from relationships array" do
|
280
|
-
SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
|
281
|
-
local_node = SpecNode.new
|
282
|
-
local_node.should_receive(:ids_for_outbound).with(:is_member_of).and_return([])
|
283
|
-
local_node.containers_ids
|
284
|
-
end
|
285
|
-
|
286
|
-
it "(:response_format => :id_array) should return an array of fedora PIDs" do
|
287
|
-
SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
|
288
|
-
local_node = SpecNode.new
|
289
|
-
local_node.stub(:rels_ext => mock("rels_ext", :content_will_change! => true, :content=>''))
|
290
|
-
local_node.add_relationship(:is_member_of, "demo:10")
|
291
|
-
result = local_node.containers_ids
|
292
|
-
result.should be_instance_of(Array)
|
293
|
-
result.should include("demo:10")
|
294
|
-
end
|
295
|
-
|
296
|
-
end
|
297
|
-
|
298
|
-
describe " resulting _ids finder" do
|
299
|
-
it "should call the basic finder with :result_format => :id_array" do
|
300
|
-
SpecNode.create_outbound_relationship_finders("parts", :is_part_of)
|
301
|
-
local_node = SpecNode.new
|
302
|
-
local_node.should_receive(:parts).with(:response_format => :id_array)
|
303
|
-
local_node.parts_ids
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
it "resulting _query finder should call relationship_query" do
|
308
|
-
SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
|
309
|
-
local_node = SpecNode.new
|
310
|
-
local_node.should_receive(:relationship_query).with("containers")
|
311
|
-
local_node.containers_query
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
describe ".create_bidirectional_relationship_finder" do
|
316
|
-
before(:each) do
|
317
|
-
SpecNode.create_bidirectional_relationship_finders("all_parts", :has_part, :is_part_of)
|
318
|
-
@local_node = SpecNode.new
|
319
|
-
@pid = "test:sample_pid"
|
320
|
-
@local_node.pid = @pid
|
321
|
-
#@local_node.internal_uri = @uri
|
322
|
-
end
|
323
|
-
it "should create inbound & outbound finders" do
|
324
|
-
@local_node.should respond_to(:all_parts_inbound)
|
325
|
-
@local_node.should respond_to(:all_parts_outbound)
|
326
|
-
end
|
327
|
-
it "should rely on inbound & outbound finders" do
|
328
|
-
@local_node.should_receive(:all_parts_inbound).with(:rows => 25).and_return(["foo1"])
|
329
|
-
@local_node.should_receive(:all_parts_outbound).with(:rows => 25).and_return(["foo2"])
|
330
|
-
@local_node.all_parts.should == ["foo1", "foo2"]
|
331
|
-
end
|
332
|
-
it "(:response_format => :id_array) should rely on inbound & outbound finders" do
|
333
|
-
@local_node.should_receive(:all_parts_inbound).with(:response_format=>:id_array, :rows => 34).and_return(["fooA"])
|
334
|
-
@local_node.should_receive(:all_parts_outbound).with(:response_format=>:id_array, :rows => 34).and_return(["fooB"])
|
335
|
-
@local_node.all_parts(:response_format=>:id_array, :rows => 34).should == ["fooA", "fooB"]
|
336
|
-
end
|
337
|
-
it "(:response_format => :solr) should construct a solr query that combines inbound and outbound searches" do
|
338
|
-
# get the id array for outbound relationships then construct solr query by combining id array with inbound relationship search
|
339
|
-
@local_node.should_receive(:ids_for_outbound).with(:has_part).and_return(["mypid:1"])
|
340
|
-
id_array_query = ActiveFedora::SolrService.construct_query_for_pids(["mypid:1"])
|
341
|
-
solr_result = mock("solr result")
|
342
|
-
ActiveFedora::SolrService.should_receive(:query).with("#{id_array_query} OR (#{@part_of_sample})", :rows=>25).and_return(solr_result)
|
343
|
-
@local_node.all_parts(:response_format=>:solr)
|
344
|
-
end
|
345
|
-
|
346
|
-
it "should register both inbound and outbound predicate components" do
|
347
|
-
@local_node.class.relationships[:inbound].has_key?(:is_part_of).should == true
|
348
|
-
@local_node.class.relationships[:self].has_key?(:has_part).should == true
|
349
|
-
end
|
350
|
-
|
351
|
-
it "should register finder methods for the bidirectional relationship name" do
|
352
|
-
@local_node.should respond_to(:all_parts)
|
353
|
-
@local_node.should respond_to(:all_parts_ids)
|
354
|
-
@local_node.should respond_to(:all_parts_query)
|
355
|
-
@local_node.should respond_to(:all_parts_from_solr)
|
356
|
-
end
|
357
|
-
|
358
|
-
it "resulting _query finder should call relationship_query" do
|
359
|
-
SpecNode.create_bidirectional_relationship_finders("containers", :is_member_of, :has_member)
|
360
|
-
local_node = SpecNode.new
|
361
|
-
local_node.should_receive(:relationship_query).with("containers")
|
362
|
-
local_node.containers_query
|
363
|
-
end
|
364
|
-
end
|
365
|
-
|
366
|
-
describe "#has_bidirectional_relationship" do
|
367
|
-
it "should ..." do
|
368
|
-
SpecNode.should_receive(:create_bidirectional_relationship_finders).with("all_parts", :has_part, :is_part_of, {})
|
369
|
-
SpecNode.has_bidirectional_relationship("all_parts", :has_part, :is_part_of)
|
370
|
-
end
|
371
|
-
|
372
|
-
it "should have relationships_by_name and relationships hashes contain bidirectionally related objects" do
|
373
|
-
SpecNode.has_bidirectional_relationship("all_parts", :has_part, :is_part_of)
|
374
|
-
@local_node = SpecNode.new
|
375
|
-
@local_node.pid = "mypid1"
|
376
|
-
@local_node2 = SpecNode.new
|
377
|
-
@local_node2.pid = "mypid2"
|
378
|
-
model_def = SpecNode.to_class_uri
|
379
|
-
@local_node.stub(:rels_ext => mock("rels_ext", :content_will_change! => true, :content=>''))
|
380
|
-
@local_node.add_relationship(:has_model, model_def)
|
381
|
-
@local_node2.stub(:rels_ext => mock("rels_ext", :content_will_change! => true, :content=>''))
|
382
|
-
@local_node2.add_relationship(:has_model, model_def)
|
383
|
-
@local_node.add_relationship(:has_part, @local_node2)
|
384
|
-
@local_node2.add_relationship(:has_part, @local_node)
|
385
|
-
@local_node.ids_for_outbound(:has_part).should == [@local_node2.pid]
|
386
|
-
@local_node.ids_for_outbound(:has_model).should == ['afmodel:SpecNode']
|
387
|
-
@local_node2.ids_for_outbound(:has_part).should == [@local_node.pid]
|
388
|
-
@local_node2.ids_for_outbound(:has_model).should == ['afmodel:SpecNode']
|
389
|
-
@local_node.relationships_by_name(false).should == {:self=>{"all_parts_outbound"=>[@local_node2.internal_uri]},:inbound=>{"all_parts_inbound"=>[]}}
|
390
|
-
@local_node2.relationships_by_name(false).should == {:self=>{"all_parts_outbound"=>[@local_node.internal_uri]},:inbound=>{"all_parts_inbound"=>[]}}
|
391
|
-
end
|
392
|
-
end
|
393
|
-
|
394
|
-
|
395
|
-
it 'should provide #inbound_relationship_names' do
|
396
|
-
SpecNode.new.should respond_to(:inbound_relationship_names)
|
397
|
-
end
|
398
|
-
|
399
|
-
describe '#inbound_relationship_names' do
|
400
|
-
before do
|
401
|
-
class MockRelationshipNames < SpecNode
|
402
|
-
include ActiveFedora::Relationships
|
403
|
-
register_relationship_desc(:self, "testing", :has_part, :type=>SpecNode)
|
404
|
-
create_relationship_name_methods("testing")
|
405
|
-
register_relationship_desc(:self, "testing2", :has_member, :type=>SpecNode)
|
406
|
-
create_relationship_name_methods("testing2")
|
407
|
-
register_relationship_desc(:inbound, "testing_inbound", :has_part, :type=>SpecNode)
|
408
|
-
register_relationship_desc(:inbound, "testing_inbound2", :has_member, :type=>SpecNode)
|
409
|
-
end
|
410
|
-
end
|
411
|
-
it 'should return an array of inbound relationship names for this model' do
|
412
|
-
@test_object2 = MockRelationshipNames.new
|
413
|
-
@test_object2.pid = increment_pid
|
414
|
-
@test_object2.inbound_relationship_names.include?("testing_inbound").should == true
|
415
|
-
@test_object2.inbound_relationship_names.include?("testing_inbound2").should == true
|
416
|
-
@test_object2.inbound_relationship_names.size.should == 2
|
417
|
-
end
|
418
|
-
end
|
419
|
-
|
420
|
-
it 'should provide #outbound_relationship_names' do
|
421
|
-
SpecNode.new.should respond_to(:outbound_relationship_names)
|
422
|
-
end
|
423
|
-
|
424
|
-
describe '#outbound_relationship_names' do
|
425
|
-
it 'should return an array of outbound relationship names for this model' do
|
426
|
-
@test_object2 = MockRelationshipNames.new
|
427
|
-
@test_object2.pid = increment_pid
|
428
|
-
@test_object2.outbound_relationship_names.include?("testing").should == true
|
429
|
-
@test_object2.outbound_relationship_names.include?("testing2").should == true
|
430
|
-
@test_object2.outbound_relationship_names.size.should == 2
|
431
|
-
end
|
432
|
-
end
|
433
|
-
|
434
|
-
it 'should provide #inbound_relationships_by_name' do
|
435
|
-
#testing execution of this in integration since touches solr
|
436
|
-
SpecNode.new.should respond_to(:inbound_relationships_by_name)
|
437
|
-
end
|
438
|
-
|
439
|
-
it 'should provide #find_relationship_by_name' do
|
440
|
-
SpecNode.new.should respond_to(:find_relationship_by_name)
|
441
|
-
end
|
442
|
-
|
443
|
-
describe '#find_relationship_by_name' do
|
444
|
-
it 'should return an array of object uri for a given relationship name' do
|
445
|
-
@test_object2 = MockRelationshipNames.new
|
446
|
-
@test_object2.pid = increment_pid
|
447
|
-
@test_object3 = SpecNode.new
|
448
|
-
@test_object3.pid = increment_pid
|
449
|
-
@test_object4 = SpecNode.new
|
450
|
-
@test_object4.pid = increment_pid
|
451
|
-
#add relationships that mirror 'testing' and 'testing2'
|
452
|
-
graph = RDF::Graph.new
|
453
|
-
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
454
|
-
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_model), RDF::URI.new(MockRelationshipNames.to_class_uri))
|
455
|
-
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_member), RDF::URI.new(@test_object4.internal_uri))
|
456
|
-
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_part), RDF::URI.new(@test_object3.internal_uri))
|
457
|
-
@test_object2.stub(:relationships =>graph)
|
458
|
-
@test_object2.find_relationship_by_name("testing").should == [@test_object3.internal_uri]
|
459
|
-
end
|
460
|
-
end
|
461
|
-
|
462
|
-
describe "relationship_query" do
|
463
|
-
before do
|
464
|
-
class MockNamedRelationshipQuery < SpecNode
|
465
|
-
register_relationship_desc(:inbound, "testing_inbound_query", :is_part_of, :type=>SpecNode, :solr_fq=>"#{ActiveFedora::SolrService.solr_name('has_model', :symbol)}:info\\:fedora/SpecialPart")
|
466
|
-
register_relationship_desc(:inbound, "testing_inbound_no_solr_fq", :is_part_of, :type=>SpecNode)
|
467
|
-
register_relationship_desc(:self, "testing_outbound_query", :is_part_of, :type=>SpecNode, :solr_fq=>"#{ActiveFedora::SolrService.solr_name('has_model', :symbol)}:info\\:fedora/SpecialPart")
|
468
|
-
register_relationship_desc(:self, "testing_outbound_no_solr_fq", :is_part_of, :type=>SpecNode)
|
469
|
-
#for bidirectional relationship testing need to register both outbound and inbound names
|
470
|
-
register_relationship_desc(:self, "testing_bi_query_outbound", :has_part, :type=>SpecNode, :solr_fq=>"#{ActiveFedora::SolrService.solr_name('has_model', :symbol)}:info\\:fedora/SpecialPart")
|
471
|
-
register_relationship_desc(:inbound, "testing_bi_query_inbound", :is_part_of, :type=>SpecNode, :solr_fq=>"#{ActiveFedora::SolrService.solr_name('has_model', :symbol)}:info\\:fedora/SpecialPart")
|
472
|
-
register_relationship_desc(:self, "testing_bi_no_solr_fq_outbound", :has_part, :type=>SpecNode)
|
473
|
-
register_relationship_desc(:inbound, "testing_bi_no_solr_fq_inbound", :is_part_of, :type=>SpecNode)
|
474
|
-
end
|
475
|
-
end
|
476
|
-
after do
|
477
|
-
Object.send(:remove_const, :MockNamedRelationshipQuery)
|
478
|
-
end
|
479
|
-
|
480
|
-
before(:each) do
|
481
|
-
@mockrelsquery = MockNamedRelationshipQuery.new
|
482
|
-
end
|
483
|
-
|
484
|
-
it "should call bidirectional_relationship_query if a bidirectional relationship" do
|
485
|
-
ids = ["changeme:1","changeme:2","changeme:3","changeme:4"]
|
486
|
-
@mockrelsquery.stub(:ids_for_outbound).with(:has_part).and_return(ids)
|
487
|
-
@mockrelsquery.should_receive(:pid).and_return("changeme:5")
|
488
|
-
MockNamedRelationshipQuery.should_receive(:bidirectional_relationship_query).with("changeme:5","testing_bi_query",ids)
|
489
|
-
@mockrelsquery.relationship_query("testing_bi_query")
|
490
|
-
end
|
491
|
-
|
492
|
-
it "should call outbound_relationship_query if an outbound relationship" do
|
493
|
-
ids = ["changeme:1","changeme:2","changeme:3","changeme:4"]
|
494
|
-
@mockrelsquery.stub(:ids_for_outbound).with(:is_part_of).and_return(ids)
|
495
|
-
MockNamedRelationshipQuery.should_receive(:outbound_relationship_query).with("testing_outbound_no_solr_fq",ids)
|
496
|
-
@mockrelsquery.relationship_query("testing_outbound_no_solr_fq")
|
497
|
-
end
|
498
|
-
|
499
|
-
it "should call inbound_relationship_query if an inbound relationship" do
|
500
|
-
@mockrelsquery.should_receive(:pid).and_return("changeme:5")
|
501
|
-
MockNamedRelationshipQuery.should_receive(:inbound_relationship_query).with("changeme:5","testing_inbound_query")
|
502
|
-
@mockrelsquery.relationship_query("testing_inbound_query")
|
503
|
-
end
|
504
|
-
end
|
505
|
-
|
506
|
-
describe '#relationship_predicates' do
|
507
|
-
before do
|
508
|
-
class MockNamedRelationshipPredicates < SpecNode
|
509
|
-
register_relationship_desc(:self, "testing", :has_part, :type=>SpecNode)
|
510
|
-
create_relationship_name_methods("testing")
|
511
|
-
register_relationship_desc(:self, "testing2", :has_member, :type=>SpecNode)
|
512
|
-
create_relationship_name_methods("testing2")
|
513
|
-
register_relationship_desc(:inbound, "testing_inbound", :has_part, :type=>SpecNode)
|
514
|
-
end
|
515
|
-
end
|
516
|
-
after do
|
517
|
-
Object.send(:remove_const, :MockNamedRelationshipPredicates)
|
518
|
-
end
|
519
|
-
|
520
|
-
it 'should provide #relationship_predicates' do
|
521
|
-
SpecNode.new.should respond_to(:relationship_predicates)
|
522
|
-
end
|
523
|
-
|
524
|
-
it 'should return a map of subject to relationship name to fedora ontology relationship predicate' do
|
525
|
-
@test_object2 = MockNamedRelationshipPredicates.new
|
526
|
-
@test_object2.relationship_predicates.should == {:self=>{"testing"=>:has_part,"testing2"=>:has_member},
|
527
|
-
:inbound=>{"testing_inbound"=>:has_part}}
|
528
|
-
|
529
|
-
end
|
530
|
-
end
|
531
|
-
|
532
|
-
describe '#conforms_to?' do
|
533
|
-
before do
|
534
|
-
@test_object = SpecNode.new
|
535
|
-
end
|
536
|
-
it 'should provide #conforms_to?' do
|
537
|
-
@test_object.should respond_to(:conforms_to?)
|
538
|
-
end
|
539
|
-
|
540
|
-
it 'should check if current object is the kind of model class supplied' do
|
541
|
-
#has_model relationship does not get created until save called
|
542
|
-
graph = RDF::Graph.new
|
543
|
-
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
544
|
-
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_model), RDF::URI.new(SpecNode.to_class_uri))
|
545
|
-
@test_object.stub(:relationships).and_return(graph)
|
546
|
-
@test_object.conforms_to?(SpecNode).should == true
|
547
|
-
end
|
548
|
-
end
|
549
|
-
|
550
|
-
describe '#assert_conforms_to' do
|
551
|
-
before do
|
552
|
-
@test_object = SpecNode.new
|
553
|
-
end
|
554
|
-
it 'should provide #assert_conforms_to' do
|
555
|
-
@test_object.should respond_to(:assert_conforms_to)
|
556
|
-
end
|
557
|
-
|
558
|
-
it 'should correctly assert if an object is the type of model supplied' do
|
559
|
-
@test_object3 = SpecNode.new
|
560
|
-
@test_object3.pid = increment_pid
|
561
|
-
#has_model relationship does not get created until save called so need to add the has model rel here, is fine since not testing save
|
562
|
-
graph = RDF::Graph.new
|
563
|
-
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
564
|
-
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_model), RDF::URI.new(SpecNode.to_class_uri))
|
565
|
-
@test_object.stub(:relationships).and_return(graph)
|
566
|
-
@test_object3.assert_conforms_to('object',@test_object,SpecNode)
|
567
|
-
end
|
568
|
-
end
|
569
|
-
|
570
|
-
it 'should provide #class_from_name' do
|
571
|
-
SpecNode.new.should respond_to(:class_from_name)
|
572
|
-
end
|
573
|
-
|
574
|
-
describe '#class_from_name' do
|
575
|
-
it 'should return a class constant for a string passed in' do
|
576
|
-
SpecNode.new.class_from_name("SpecNode").should == SpecNode
|
577
|
-
end
|
578
|
-
end
|
579
|
-
|
580
|
-
describe '#relationships_by_name' do
|
581
|
-
|
582
|
-
before do
|
583
|
-
class MockNamedRelationships3 < SpecNode
|
584
|
-
register_relationship_desc(:self, "testing", :has_part, :type=>SpecNode)
|
585
|
-
create_relationship_name_methods("testing")
|
586
|
-
register_relationship_desc(:self, "testing2", :has_member, :type=>SpecNode)
|
587
|
-
create_relationship_name_methods("testing2")
|
588
|
-
register_relationship_desc(:inbound, "testing_inbound", :has_part, :type=>SpecNode)
|
589
|
-
end
|
590
|
-
end
|
591
|
-
after do
|
592
|
-
Object.send(:remove_const, :MockNamedRelationships3)
|
593
|
-
end
|
594
|
-
|
595
|
-
it 'should provide #relationships_by_name' do
|
596
|
-
@test_object = SpecNode.new
|
597
|
-
@test_object.should respond_to(:relationships_by_name)
|
598
|
-
end
|
599
|
-
|
600
|
-
it 'should return current named relationships' do
|
601
|
-
@test_object = SpecNode.new
|
602
|
-
@test_object.pid = increment_pid
|
603
|
-
@test_object2 = MockNamedRelationships3.new
|
604
|
-
@test_object2.pid = increment_pid
|
605
|
-
@test_object3 = MockNamedRelationships3.new
|
606
|
-
@test_object3.pid = increment_pid
|
607
|
-
model_pid = MockNamedRelationships3.to_class_uri
|
608
|
-
graph = RDF::Graph.new
|
609
|
-
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
610
|
-
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_model), RDF::URI.new(model_pid))
|
611
|
-
@test_object2.stub(:relationships).and_return(graph)
|
612
|
-
#should return expected named relationships
|
613
|
-
@test_object2.relationships_by_name.should == {:self=>{"testing"=>[],"testing2"=>[]}}
|
614
|
-
graph = RDF::Graph.new
|
615
|
-
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
616
|
-
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_model), RDF::URI.new(model_pid))
|
617
|
-
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_part), RDF::URI.new(@test_object.internal_uri))
|
618
|
-
@test_object3.stub(:relationships).and_return(graph)
|
619
|
-
@test_object3.relationships_by_name.should == {:self=>{"testing"=>[@test_object.internal_uri],"testing2"=>[]}}
|
620
|
-
end
|
621
|
-
end
|
622
|
-
describe '#relationship_has_solr_filter_query' do
|
623
|
-
before do
|
624
|
-
class RelsHasSolrFilter < SpecNode
|
625
|
-
register_relationship_desc :self, "testing", :is_part_of, :solr_fq=>"testing:value"
|
626
|
-
register_relationship_desc :self, "no_query_testing", :is_part_of
|
627
|
-
register_relationship_desc :inbound, "inbound_testing", :has_part, :solr_fq=>"in_testing:value_in"
|
628
|
-
register_relationship_desc :inbound, "inbound_testing_no_query", :has_part
|
629
|
-
end
|
630
|
-
@test_object = RelsHasSolrFilter.new
|
631
|
-
end
|
632
|
-
after do
|
633
|
-
Object.send(:remove_const, :RelsHasSolrFilter)
|
634
|
-
end
|
635
|
-
|
636
|
-
it 'should return true if an object has an inbound relationship with solr filter query' do
|
637
|
-
@test_object.relationship_has_solr_filter_query?(:inbound,"inbound_testing").should == true
|
638
|
-
end
|
639
|
-
|
640
|
-
it 'should return false if an object does not have inbound relationship with solr filter query' do
|
641
|
-
@test_object.relationship_has_solr_filter_query?(:inbound,"inbound_testing_no_query").should == false
|
642
|
-
end
|
643
|
-
|
644
|
-
it 'should return true if an object has an outbound relationship with solr filter query' do
|
645
|
-
@test_object.relationship_has_solr_filter_query?(:self,"testing").should == true
|
646
|
-
end
|
647
|
-
|
648
|
-
it 'should return false if an object does not have outbound relationship with solr filter query' do
|
649
|
-
@test_object.relationship_has_solr_filter_query?(:self,"testing_no_query").should == false
|
650
|
-
end
|
651
|
-
end
|
652
|
-
|
653
|
-
describe ActiveFedora::Relationships::ClassMethods do
|
654
|
-
|
655
|
-
after(:each) do
|
656
|
-
begin
|
657
|
-
@test_object2.delete
|
658
|
-
rescue
|
659
|
-
end
|
660
|
-
end
|
661
|
-
|
662
|
-
describe '#relationships_desc' do
|
663
|
-
it 'should initialize relationships_desc to a new hash containing self' do
|
664
|
-
@test_object2 = SpecNode.new
|
665
|
-
@test_object2.pid = increment_pid
|
666
|
-
@test_object2.relationships_desc.should == {:self=>{}}
|
667
|
-
end
|
668
|
-
end
|
669
|
-
|
670
|
-
describe '#register_relationship_desc_subject' do
|
671
|
-
|
672
|
-
before do
|
673
|
-
class MockRegisterNamedSubject < SpecNode
|
674
|
-
register_relationship_desc_subject :test
|
675
|
-
end
|
676
|
-
end
|
677
|
-
|
678
|
-
it 'should add a new named subject to the named relationships only if it does not already exist' do
|
679
|
-
@test_object2 = MockRegisterNamedSubject.new
|
680
|
-
@test_object2.pid = increment_pid
|
681
|
-
@test_object2.relationships_desc.should == {:self=>{}, :test=>{}}
|
682
|
-
end
|
683
|
-
end
|
684
|
-
|
685
|
-
describe '#register_relationship_desc' do
|
686
|
-
|
687
|
-
before do
|
688
|
-
class MockRegisterNamedRelationship < SpecNode
|
689
|
-
register_relationship_desc :self, "testing", :is_part_of, :type=>SpecNode
|
690
|
-
register_relationship_desc :inbound, "testing2", :has_part, :type=>SpecNode
|
691
|
-
end
|
692
|
-
end
|
693
|
-
|
694
|
-
it 'should add a new named subject to the named relationships only if it does not already exist' do
|
695
|
-
@test_object2 = MockRegisterNamedRelationship.new
|
696
|
-
@test_object2.pid = increment_pid
|
697
|
-
@test_object2.relationships_desc.should == {:inbound=>{"testing2"=>{:type=>SpecNode, :predicate=>:has_part}}, :self=>{"testing"=>{:type=>SpecNode, :predicate=>:is_part_of}}}
|
698
|
-
end
|
699
|
-
end
|
700
|
-
|
701
|
-
describe "#is_bidirectional_relationship?" do
|
702
|
-
|
703
|
-
before do
|
704
|
-
class MockIsBiRegisterNamedRelationship < SpecNode
|
705
|
-
register_relationship_desc(:self, "testing_outbound", :is_part_of, :type=>SpecNode)
|
706
|
-
register_relationship_desc(:inbound, "testing_inbound", :has_part, :type=>SpecNode)
|
707
|
-
register_relationship_desc(:self, "testing2", :is_member_of,{})
|
708
|
-
end
|
709
|
-
end
|
710
|
-
|
711
|
-
it "should return true if both inbound and outbound predicates exist, otherwise false" do
|
712
|
-
MockIsBiRegisterNamedRelationship.is_bidirectional_relationship?("testing").should == true
|
713
|
-
MockIsBiRegisterNamedRelationship.is_bidirectional_relationship?("testing2").should == false
|
714
|
-
#the inbound and outbound internal relationships will not be bidirectional by themselves
|
715
|
-
MockIsBiRegisterNamedRelationship.is_bidirectional_relationship?("testing_inbound").should == false
|
716
|
-
MockIsBiRegisterNamedRelationship.is_bidirectional_relationship?("testing_outbound").should == false
|
717
|
-
end
|
718
|
-
end
|
719
|
-
|
720
|
-
|
721
|
-
describe '#create_relationship_name_methods' do
|
722
|
-
before do
|
723
|
-
class MockCreateNamedRelationshipMethods < SpecNode
|
724
|
-
register_relationship_desc :self, "testing", :is_part_of, :type=>SpecNode
|
725
|
-
create_relationship_name_methods "testing"
|
726
|
-
end
|
727
|
-
end
|
728
|
-
after do
|
729
|
-
Object.send(:remove_const, :MockCreateNamedRelationshipMethods)
|
730
|
-
end
|
731
|
-
|
732
|
-
it 'should create an append and remove method for each outbound relationship' do
|
733
|
-
@test_object2 = MockCreateNamedRelationshipMethods.new
|
734
|
-
@test_object2.pid = increment_pid
|
735
|
-
@test_object2.should respond_to(:testing_append)
|
736
|
-
@test_object2.should respond_to(:testing_remove)
|
737
|
-
#test execution in base_spec since method definitions include methods in ActiveFedora::Base
|
738
|
-
end
|
739
|
-
end
|
740
|
-
|
741
|
-
describe '#create_bidirectional_relationship_name_methods' do
|
742
|
-
before do
|
743
|
-
class MockCreateNamedRelationshipMethods < SpecNode
|
744
|
-
register_relationship_desc(:self, "testing_outbound", :is_part_of, :type=>SpecNode)
|
745
|
-
create_bidirectional_relationship_name_methods "testing", "testing_outbound"
|
746
|
-
end
|
747
|
-
end
|
748
|
-
after do
|
749
|
-
Object.send(:remove_const, :MockCreateNamedRelationshipMethods)
|
750
|
-
end
|
751
|
-
|
752
|
-
it 'should create an append and remove method for each outbound relationship' do
|
753
|
-
@test_object2 = MockCreateNamedRelationshipMethods.new
|
754
|
-
@test_object2.pid = increment_pid
|
755
|
-
@test_object2.should respond_to(:testing_append)
|
756
|
-
@test_object2.should respond_to(:testing_remove)
|
757
|
-
#test execution in base_spec since method definitions include methods in ActiveFedora::Base
|
758
|
-
end
|
759
|
-
end
|
760
|
-
|
761
|
-
|
762
|
-
#
|
763
|
-
# HYDRA-541
|
764
|
-
#
|
765
|
-
|
766
|
-
describe "bidirectional_relationship_query" do
|
767
|
-
before do
|
768
|
-
class MockBiNamedRelationshipQuery < SpecNode
|
769
|
-
register_relationship_desc(:self, "testing_query_outbound", :has_part, :type=>SpecNode, :solr_fq=>"#{ActiveFedora::SolrService.solr_name('has_model', :symbol)}:info\\:fedora\\/SpecialPart")
|
770
|
-
register_relationship_desc(:inbound, "testing_query_inbound", :is_part_of, :type=>SpecNode, :solr_fq=>"#{ActiveFedora::SolrService.solr_name('has_model', :symbol)}:info\\:fedora\\/SpecialPart")
|
771
|
-
create_bidirectional_relationship_name_methods("testing","testing_outbound")
|
772
|
-
register_relationship_desc(:self, "testing_no_solr_fq_outbound", :has_part, :type=>SpecNode)
|
773
|
-
register_relationship_desc(:inbound, "testing_no_solr_fq_inbound", :is_part_of, :type=>SpecNode)
|
774
|
-
create_bidirectional_relationship_name_methods("testing_no_solr_fq","testing_no_solr_fq_outbound")
|
775
|
-
end
|
776
|
-
end
|
777
|
-
after do
|
778
|
-
Object.send(:remove_const, :MockBiNamedRelationshipQuery)
|
779
|
-
end
|
780
|
-
|
781
|
-
#
|
782
|
-
# HYDRA-541
|
783
|
-
#
|
784
|
-
it "should rely on outbound query if inbound query is empty" do
|
785
|
-
query = MockBiNamedRelationshipQuery.bidirectional_relationship_query("PID",:testing_query,[])
|
786
|
-
query.should_not include("OR ()")
|
787
|
-
query2 = MockBiNamedRelationshipQuery.bidirectional_relationship_query("PID",:testing_no_solr_fq,[])
|
788
|
-
query2.should_not include("OR ()")
|
789
|
-
end
|
790
|
-
|
791
|
-
it "should return a properly formatted query for a relationship that has a solr filter query defined" do
|
792
|
-
expected_string = ""
|
793
|
-
ids = ["changeme:1","changeme:2","changeme:3","changeme:4","changeme:5"]
|
794
|
-
ids.each_with_index do |id,index|
|
795
|
-
expected_string << " OR " if index > 0
|
796
|
-
expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND #{@is_part_query})"
|
797
|
-
end
|
798
|
-
expected_string << " OR "
|
799
|
-
expected_string << "(#{ActiveFedora::SolrService.solr_name('is_part_of', :symbol)}:info\\:fedora\\/changeme\\:6 AND #{@is_part_query})"
|
800
|
-
MockBiNamedRelationshipQuery.bidirectional_relationship_query("changeme:6","testing_query",ids).should == expected_string
|
801
|
-
end
|
802
|
-
|
803
|
-
it "should return a properly formatted query for a relationship that does not have a solr filter query defined" do
|
804
|
-
expected_string = ""
|
805
|
-
ids = ["changeme:1","changeme:2","changeme:3","changeme:4","changeme:5"]
|
806
|
-
ids.each_with_index do |id,index|
|
807
|
-
expected_string << " OR " if index > 0
|
808
|
-
expected_string << "id:" + id.gsub(/(:)/, '\\:')
|
809
|
-
end
|
810
|
-
expected_string << " OR "
|
811
|
-
expected_string << "(#{ActiveFedora::SolrService.solr_name('is_part_of', :symbol)}:info\\:fedora\\/changeme\\:6)"
|
812
|
-
MockBiNamedRelationshipQuery.bidirectional_relationship_query("changeme:6","testing_no_solr_fq",ids).should == expected_string
|
813
|
-
end
|
814
|
-
end
|
815
|
-
|
816
|
-
describe "inbound_relationship_query" do
|
817
|
-
before do
|
818
|
-
class MockInboundNamedRelationshipQuery < SpecNode
|
819
|
-
register_relationship_desc(:inbound, "testing_inbound_query", :is_part_of, :type=>SpecNode, :solr_fq=>"#{ActiveFedora::SolrService.solr_name('has_model', :symbol)}:#{solr_uri("info:fedora/SpecialPart")}")
|
820
|
-
register_relationship_desc(:inbound, "testing_inbound_no_solr_fq", :is_part_of, :type=>SpecNode)
|
821
|
-
end
|
822
|
-
end
|
823
|
-
after(:each) do
|
824
|
-
Object.send(:remove_const, :MockInboundNamedRelationshipQuery)
|
825
|
-
end
|
826
|
-
|
827
|
-
it "should return a properly formatted query for a relationship that has a solr filter query defined" do
|
828
|
-
MockInboundNamedRelationshipQuery.inbound_relationship_query("changeme:1","testing_inbound_query").should == "#{ActiveFedora::SolrService.solr_name('is_part_of', :symbol)}:info\\:fedora\\/changeme\\:1 AND #{@is_part_query}"
|
829
|
-
end
|
830
|
-
|
831
|
-
it "should return a properly formatted query for a relationship that does not have a solr filter query defined" do
|
832
|
-
MockInboundNamedRelationshipQuery.inbound_relationship_query("changeme:1","testing_inbound_no_solr_fq").should == "#{ActiveFedora::SolrService.solr_name('is_part_of', :symbol)}:info\\:fedora\\/changeme\\:1"
|
833
|
-
end
|
834
|
-
end
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
describe "outbound_relationship_query" do
|
840
|
-
before do
|
841
|
-
class MockOutboundNamedRelationshipQuery < SpecNode
|
842
|
-
register_relationship_desc(:self, "testing_query", :is_part_of, :type=>SpecNode, :solr_fq=>"#{ActiveFedora::SolrService.solr_name('has_model', :symbol)}:#{solr_uri("info:fedora/SpecialPart")}")
|
843
|
-
register_relationship_desc(:self,"testing_no_solr_fq", :is_part_of, :type=>SpecNode)
|
844
|
-
end
|
845
|
-
end
|
846
|
-
after(:each) do
|
847
|
-
Object.send(:remove_const, :MockOutboundNamedRelationshipQuery)
|
848
|
-
end
|
849
|
-
|
850
|
-
it "should return a properly formatted query for a relationship that has a solr filter query defined" do
|
851
|
-
ids = ["changeme:1","changeme:2","changeme:3","changeme:4"]
|
852
|
-
expected_string = ""
|
853
|
-
ids.each_with_index do |id,index|
|
854
|
-
expected_string << " OR " if index > 0
|
855
|
-
expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND #{ActiveFedora::SolrService.solr_name('has_model', :symbol)}:#{solr_uri("info:fedora/SpecialPart")})"
|
856
|
-
end
|
857
|
-
MockOutboundNamedRelationshipQuery.outbound_relationship_query("testing_query",ids).should == expected_string
|
858
|
-
end
|
859
|
-
|
860
|
-
it "should return a properly formatted query for a relationship that does not have a solr filter query defined" do
|
861
|
-
expected_string = ""
|
862
|
-
ids = ["changeme:1","changeme:2","changeme:3","changeme:4"]
|
863
|
-
ids.each_with_index do |id,index|
|
864
|
-
expected_string << " OR " if index > 0
|
865
|
-
expected_string << "id:" + id.gsub(/(:)/, '\\:')
|
866
|
-
end
|
867
|
-
MockOutboundNamedRelationshipQuery.outbound_relationship_query("testing_no_solr_fq",ids).should == expected_string
|
868
|
-
end
|
869
|
-
end
|
870
|
-
end
|
871
|
-
end
|