active-fedora 3.3.2 → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/Gemfile.lock +21 -22
  2. data/History.txt +9 -0
  3. data/README.textile +1 -1
  4. data/TODO +1 -0
  5. data/active-fedora.gemspec +3 -3
  6. data/config/fedora.yml +9 -3
  7. data/lib/active_fedora.rb +43 -33
  8. data/lib/active_fedora/base.rb +80 -31
  9. data/lib/active_fedora/config.rb +38 -0
  10. data/lib/active_fedora/content_model.rb +0 -6
  11. data/lib/active_fedora/datastream.rb +22 -0
  12. data/lib/active_fedora/delegating.rb +24 -25
  13. data/lib/active_fedora/digital_object.rb +2 -1
  14. data/lib/active_fedora/file_management.rb +1 -0
  15. data/lib/active_fedora/fixture_exporter.rb +1 -1
  16. data/lib/active_fedora/fixture_loader.rb +3 -3
  17. data/lib/active_fedora/metadata_datastream.rb +6 -0
  18. data/lib/active_fedora/model.rb +24 -5
  19. data/lib/active_fedora/nokogiri_datastream.rb +1 -0
  20. data/lib/active_fedora/ntriples_rdf_datastream.rb +0 -1
  21. data/lib/active_fedora/persistence.rb +2 -1
  22. data/lib/active_fedora/predicates.rb +27 -27
  23. data/lib/active_fedora/rdf_datastream.rb +104 -30
  24. data/lib/active_fedora/rels_ext_datastream.rb +14 -10
  25. data/lib/active_fedora/rubydora_connection.rb +4 -27
  26. data/lib/active_fedora/service_definitions.rb +2 -3
  27. data/lib/active_fedora/solr_digital_object.rb +22 -8
  28. data/lib/active_fedora/solr_service.rb +1 -1
  29. data/lib/active_fedora/unsaved_digital_object.rb +1 -4
  30. data/lib/active_fedora/version.rb +1 -1
  31. data/lib/tasks/active_fedora.rake +6 -6
  32. data/lib/tasks/active_fedora_dev.rake +0 -1
  33. data/spec/fixtures/mixed_rdf_descMetadata.nt +6 -0
  34. data/spec/fixtures/rails_root/config/fedora.yml +3 -1
  35. data/spec/fixtures/sharded_fedora.yml +11 -0
  36. data/spec/integration/base_file_management_spec.rb +6 -3
  37. data/spec/integration/base_find_by_fields_spec.rb +15 -16
  38. data/spec/integration/base_spec.rb +11 -178
  39. data/spec/integration/datastream_collections_spec.rb +1 -1
  40. data/spec/integration/full_featured_model_spec.rb +1 -2
  41. data/spec/integration/model_spec.rb +8 -9
  42. data/spec/integration/mods_article_integration_spec.rb +1 -1
  43. data/spec/integration/nokogiri_datastream_spec.rb +1 -1
  44. data/spec/integration/ntriples_datastream_spec.rb +80 -0
  45. data/spec/integration/rels_ext_datastream_spec.rb +0 -1
  46. data/spec/integration/semantic_node_spec.rb +18 -26
  47. data/spec/integration/solr_service_spec.rb +51 -1
  48. data/{lib/active_fedora → spec}/samples/hydra-mods_article_datastream.rb +0 -0
  49. data/{lib/active_fedora → spec}/samples/hydra-rights_metadata_datastream.rb +0 -0
  50. data/{lib/active_fedora → spec}/samples/marpa-dc_datastream.rb +0 -0
  51. data/spec/samples/models/hydrangea_article.rb +2 -2
  52. data/spec/samples/samples.rb +2 -0
  53. data/{lib/active_fedora → spec}/samples/special_thing.rb +3 -3
  54. data/spec/spec_helper.rb +1 -0
  55. data/spec/unit/active_fedora_spec.rb +17 -50
  56. data/spec/unit/base_extra_spec.rb +4 -0
  57. data/spec/unit/base_file_management_spec.rb +5 -2
  58. data/spec/unit/base_spec.rb +692 -628
  59. data/spec/unit/config_spec.rb +19 -0
  60. data/spec/unit/content_model_spec.rb +1 -24
  61. data/spec/unit/datastream_collections_spec.rb +11 -14
  62. data/spec/unit/datastreams_spec.rb +49 -54
  63. data/spec/unit/model_spec.rb +24 -53
  64. data/spec/unit/nokogiri_datastream_spec.rb +6 -1
  65. data/spec/unit/ntriples_datastream_spec.rb +73 -0
  66. data/spec/unit/qualified_dublin_core_datastream_spec.rb +1 -1
  67. data/spec/unit/relationships_spec.rb +6 -3
  68. data/spec/unit/rels_ext_datastream_spec.rb +19 -0
  69. data/spec/unit/rubydora_connection_spec.rb +2 -56
  70. data/spec/unit/solr_service_spec.rb +3 -1
  71. data/spec/unit/unsaved_digital_object_spec.rb +2 -2
  72. metadata +46 -33
  73. data/lib/active_fedora/dcrdf_datastream.rb +0 -11
  74. data/lib/active_fedora/relationship.rb +0 -47
  75. data/lib/active_fedora/samples.rb +0 -3
  76. data/spec/integration/dc_rdf_datastream_spec.rb +0 -24
  77. data/spec/unit/dc_rdf_datastream_spec.rb +0 -50
  78. data/spec/unit/relationship_spec.rb +0 -92
@@ -77,12 +77,16 @@ describe ActiveFedora::Base do
77
77
 
78
78
  mock_datastreams = {:ds1 => mock1, :ds2 => mock2, :rels_ext => mock3}
79
79
  mock_datastreams.values.each {|ds| ds.stubs(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(false)}
80
+ mock1.expects(:solrize_profile)
81
+ mock2.expects(:solrize_profile)
82
+ mock3.expects(:solrize_profile)
80
83
  mock1.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(true)
81
84
  mock2.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(true)
82
85
  mock3.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(false)
83
86
  #mock3.expects(:kind_of?).with(ActiveFedora::RelsExtDatastream).returns(true)
84
87
 
85
88
  @test_object.expects(:datastreams).returns(mock_datastreams)
89
+ @test_object.expects(:solrize_profile)
86
90
  @test_object.expects(:solrize_relationships)
87
91
  @test_object.send :update_index
88
92
  end
@@ -2,8 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::Base do
4
4
 
5
- before(:each) do
6
- @base = ActiveFedora::Base.new
5
+ before(:all) do
6
+ class FileMgmt < ActiveFedora::Base
7
+ include ActiveFedora::FileManagement
8
+ end
9
+ @base = FileMgmt.new
7
10
  @base.stubs(:create_date).returns("2008-07-02T05:09:42.015Z")
8
11
  @base.stubs(:modified_date).returns("2008-09-29T21:21:52.892Z")
9
12
  end
@@ -2,725 +2,789 @@ require 'spec_helper'
2
2
  @@last_pid = 0
3
3
 
4
4
  describe ActiveFedora::Base do
5
- before :all do
6
- class FooHistory < ActiveFedora::Base
7
- has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"someData" do |m|
8
- m.field "fubar", :string
9
- m.field "swank", :text
5
+ describe "sharding" do
6
+ it "should have a shard_index" do
7
+ ActiveFedora::Base.shard_index(@this_pid).should == 0
8
+ end
9
+
10
+ describe "should have a connection_for_pid" do
11
+ before do
12
+ ActiveFedora::Base.fedora_connection = {}
10
13
  end
11
- has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"withText" do |m|
12
- m.field "fubar", :text
14
+ context "When the server is not sharded" do
15
+ subject {ActiveFedora::Base.connection_for_pid('foo:bar')}
16
+ it { should be_kind_of Rubydora::Repository}
17
+ it "should be the standard connection" do
18
+ subject.client.url.should == 'http://127.0.0.1:8983/fedora-test'
19
+ end
20
+ end
21
+ context "When the repository is sharded" do
22
+ before :all do
23
+ class FooHistory < ActiveFedora::Base
24
+ def self.shard_index(pid)
25
+ pid == 'foo:bar' ? 0 : 1
26
+ end
27
+ end
28
+ end
29
+ before :each do
30
+ ActiveFedora.config.expects(:sharded?).returns(true)
31
+ end
32
+ after :all do
33
+ Object.send(:remove_const, :FooHistory)
34
+ end
35
+ describe "assign_pid" do
36
+ subject {FooHistory}
37
+ it "should raise an exception when assign_pid is not overridden" do
38
+ lambda {subject.assign_pid(stub(:namespace=>'changeme'))}.should raise_error(RuntimeError, "When using shards, you must override FooHistory.assign_pid()")
39
+ end
40
+ end
41
+ describe "the repository" do
42
+ before do
43
+ ActiveFedora.config.expects(:credentials).returns([{:url=>'shard1'}, {:url=>'shard2'} ])
44
+ end
45
+ describe "for foo:bar" do
46
+ subject {FooHistory.connection_for_pid('foo:bar')}
47
+ it "should be shard1" do
48
+ subject.client.url.should == 'shard1'
49
+ end
50
+ end
51
+ describe "for foo:baz" do
52
+ subject {FooHistory.connection_for_pid('foo:baz')}
53
+ it "should be shard1" do
54
+ subject.client.url.should == 'shard2'
55
+ end
56
+ end
57
+ end
13
58
  end
14
- has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"withText2", :label=>"withLabel" do |m|
15
- m.field "fubar", :text
16
- end
17
- delegate :fubar, :to=>'withText'
18
- delegate :swank, :to=>'someData'
19
- end
20
- class FooAdaptation < ActiveFedora::Base
21
- has_metadata :type=>ActiveFedora::NokogiriDatastream, :name=>'someData'
22
59
  end
23
60
  end
24
61
 
25
- after :all do
26
- Object.send(:remove_const, :FooHistory)
27
- Object.send(:remove_const, :FooAdaptation)
28
- end
29
-
30
- def increment_pid
31
- @@last_pid += 1
32
- end
33
-
34
- before(:each) do
35
- @this_pid = increment_pid.to_s
36
- stub_get(@this_pid)
37
- Rubydora::Repository.any_instance.stubs(:client).returns(@mock_client)
38
- ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(@this_pid)
39
-
40
- @test_object = ActiveFedora::Base.new
41
- end
42
-
43
- after(:each) do
44
- begin
45
- ActiveFedora::SolrService.stubs(:instance)
46
- #@test_object.delete
47
- rescue
62
+ describe "With a test class" do
63
+ before :all do
64
+ class FooHistory < ActiveFedora::Base
65
+ has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"someData" do |m|
66
+ m.field "fubar", :string
67
+ m.field "swank", :text
68
+ end
69
+ has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"withText" do |m|
70
+ m.field "fubar", :text
71
+ end
72
+ has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"withText2", :label=>"withLabel" do |m|
73
+ m.field "fubar", :text
74
+ end
75
+ delegate :fubar, :to=>'withText'
76
+ delegate :swank, :to=>'someData'
77
+ end
78
+ class FooAdaptation < ActiveFedora::Base
79
+ has_metadata :type=>ActiveFedora::NokogiriDatastream, :name=>'someData'
80
+ end
48
81
  end
49
- end
50
82
 
51
- describe '#new' do
52
- it "should create an inner object" do
53
- # for doing AFObject.new(params[:foo]) when nothing is in params[:foo]
54
- Rubydora::DigitalObject.any_instance.expects(:save).never
55
- result = ActiveFedora::Base.new(nil)
56
- result.inner_object.should be_kind_of(ActiveFedora::UnsavedDigitalObject)
83
+ after :all do
84
+ Object.send(:remove_const, :FooHistory)
85
+ Object.send(:remove_const, :FooAdaptation)
57
86
  end
58
-
59
- it "should not save or get an pid on init" do
60
- Rubydora::DigitalObject.any_instance.expects(:save).never
61
- ActiveFedora::RubydoraConnection.instance.expects(:nextid).never
62
- f = FooHistory.new
87
+
88
+ def increment_pid
89
+ @@last_pid += 1
63
90
  end
64
91
 
65
- it "should be able to create with a custom pid" do
66
- f = FooHistory.new(:pid=>'numbnuts:1')
67
- f.pid.should == 'numbnuts:1'
68
- end
69
- end
92
+ before(:each) do
93
+ @this_pid = increment_pid.to_s
94
+ stub_get(@this_pid)
95
+ Rubydora::Repository.any_instance.stubs(:client).returns(@mock_client)
96
+ ActiveFedora::Base.stubs(:assign_pid).returns(@this_pid)
70
97
 
71
- describe ".datastream_class_for_name" do
72
- it "should return the specifed class" do
73
- FooAdaptation.datastream_class_for_name('someData').should == ActiveFedora::NokogiriDatastream
74
- end
75
- it "should return the specifed class" do
76
- FooAdaptation.datastream_class_for_name('content').should == ActiveFedora::Datastream
98
+ @test_object = ActiveFedora::Base.new
77
99
  end
78
- end
79
100
 
80
- describe ".internal_uri" do
81
- it "should return pid as fedors uri" do
82
- @test_object.internal_uri.should eql("info:fedora/#{@test_object.pid}")
101
+ after(:each) do
102
+ begin
103
+ ActiveFedora::SolrService.stubs(:instance)
104
+ #@test_object.delete
105
+ rescue
106
+ end
83
107
  end
84
- end
85
108
 
86
- ### Methods for ActiveModel::Conversions
87
- it "should have to_param once it's saved" do
88
109
 
89
- @test_object.to_param.should be_nil
90
- @test_object.inner_object.expects(:new?).returns(false).at_least_once
91
- @test_object.to_param.should == @test_object.pid
92
- end
93
-
94
- it "should have to_key once it's saved" do
95
- @test_object.to_key.should be_nil
96
- @test_object.inner_object.expects(:new?).returns(false).at_least_once
97
- @test_object.to_key.should == [@test_object.pid]
98
- end
99
-
100
- it "should have to_model when it's saved" do
101
- @test_object.to_model.should be @test_object
102
- end
103
- ### end ActiveModel::Conversions
110
+ describe '#new' do
111
+ it "should create an inner object" do
112
+ # for doing AFObject.new(params[:foo]) when nothing is in params[:foo]
113
+ Rubydora::DigitalObject.any_instance.expects(:save).never
114
+ result = ActiveFedora::Base.new(nil)
115
+ result.inner_object.should be_kind_of(ActiveFedora::UnsavedDigitalObject)
116
+ end
104
117
 
105
- ### Methods for ActiveModel::Naming
106
- it "Should know the model_name" do
107
- FooHistory.model_name.should == 'FooHistory'
108
- FooHistory.model_name.human.should == 'Foo history'
109
- end
110
- ### End ActiveModel::Naming
111
-
118
+ it "should not save or get an pid on init" do
119
+ Rubydora::DigitalObject.any_instance.expects(:save).never
120
+ ActiveFedora::Base.expects(:assign_pid).never
121
+ f = FooHistory.new
122
+ end
112
123
 
113
- describe ".datastreams" do
114
- before do
115
- @test_history = FooHistory.new
116
- end
117
- it "should create dynamic accessors" do
118
- @test_history.withText.should == @test_history.datastreams['withText']
124
+ it "should be able to create with a custom pid" do
125
+ f = FooHistory.new(:pid=>'numbnuts:1')
126
+ f.pid.should == 'numbnuts:1'
127
+ end
119
128
  end
120
- it "dynamic accessors should convert dashes to underscores" do
121
- ds = stub('datastream', :dsid=>'eac-cpf')
122
- @test_history.add_datastream(ds)
123
- @test_history.eac_cpf.should == ds
129
+
130
+ describe ".datastream_class_for_name" do
131
+ it "should return the specifed class" do
132
+ FooAdaptation.datastream_class_for_name('someData').should == ActiveFedora::NokogiriDatastream
133
+ end
134
+ it "should return the specifed class" do
135
+ FooAdaptation.datastream_class_for_name('content').should == ActiveFedora::Datastream
136
+ end
124
137
  end
125
- it "dynamic accessors should not convert datastreams named with underscore" do
126
- ds = stub('datastream', :dsid=>'foo_bar')
127
- @test_history.add_datastream(ds)
128
- @test_history.foo_bar.should == ds
138
+
139
+ describe ".internal_uri" do
140
+ it "should return pid as fedors uri" do
141
+ @test_object.internal_uri.should eql("info:fedora/#{@test_object.pid}")
142
+ end
129
143
  end
130
- end
131
144
 
145
+ ### Methods for ActiveModel::Conversions
146
+ it "should have to_param once it's saved" do
132
147
 
148
+ @test_object.to_param.should be_nil
149
+ @test_object.inner_object.expects(:new?).returns(false).at_least_once
150
+ @test_object.to_param.should == @test_object.pid
151
+ end
133
152
 
134
- describe ".fields" do
135
- it "should provide fields" do
136
- @test_object.should respond_to(:fields)
153
+ it "should have to_key once it's saved" do
154
+ @test_object.to_key.should be_nil
155
+ @test_object.inner_object.expects(:new?).returns(false).at_least_once
156
+ @test_object.to_key.should == [@test_object.pid]
137
157
  end
138
- it "should add pid, system_create_date and system_modified_date from object attributes" do
139
- cdate = "2008-07-02T05:09:42.015Z"
140
- mdate = "2009-07-07T23:37:18.991Z"
141
- @test_object.expects(:create_date).returns(cdate)
142
- @test_object.expects(:modified_date).returns(mdate)
143
- fields = @test_object.fields
144
- fields[:system_create_date][:values].should eql([cdate])
145
- fields[:system_modified_date][:values].should eql([mdate])
146
- fields[:id][:values].should eql([@test_object.pid])
158
+
159
+ it "should have to_model when it's saved" do
160
+ @test_object.to_model.should be @test_object
147
161
  end
148
-
149
- it "should add self.class as the :active_fedora_model" do
150
- fields = @test_object.fields
151
- fields[:active_fedora_model][:values].should eql([@test_object.class.inspect])
162
+ ### end ActiveModel::Conversions
163
+
164
+ ### Methods for ActiveModel::Naming
165
+ it "Should know the model_name" do
166
+ FooHistory.model_name.should == 'FooHistory'
167
+ FooHistory.model_name.human.should == 'Foo history'
152
168
  end
169
+ ### End ActiveModel::Naming
153
170
 
154
- it "should call .fields on all MetadataDatastreams and return the resulting document" do
155
- mock1 = mock("ds1", :fields => {})
156
- mock2 = mock("ds2", :fields => {})
157
- mock1.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(true)
158
- mock2.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(true)
159
171
 
160
- @test_object.expects(:datastreams).returns({:ds1 => mock1, :ds2 => mock2})
161
- @test_object.fields
172
+ describe ".datastreams" do
173
+ before do
174
+ @test_history = FooHistory.new
175
+ end
176
+ it "should create dynamic accessors" do
177
+ @test_history.withText.should == @test_history.datastreams['withText']
178
+ end
179
+ it "dynamic accessors should convert dashes to underscores" do
180
+ ds = stub('datastream', :dsid=>'eac-cpf')
181
+ @test_history.add_datastream(ds)
182
+ @test_history.eac_cpf.should == ds
183
+ end
184
+ it "dynamic accessors should not convert datastreams named with underscore" do
185
+ ds = stub('datastream', :dsid=>'foo_bar')
186
+ @test_history.add_datastream(ds)
187
+ @test_history.foo_bar.should == ds
188
+ end
162
189
  end
163
- end
164
190
 
165
- it 'should provide #find' do
166
- ActiveFedora::Base.should respond_to(:find)
167
- end
168
-
169
- it "should provide .create_date" do
170
- @test_object.should respond_to(:create_date)
171
- end
172
191
 
173
- it "should provide .modified_date" do
174
- @test_object.should respond_to(:modified_date)
175
- end
176
192
 
177
- it 'should respond to .rels_ext' do
178
- @test_object.should respond_to(:rels_ext)
179
- end
193
+ describe ".fields" do
194
+ it "should provide fields" do
195
+ @test_object.should respond_to(:fields)
196
+ end
197
+ it "should add pid, system_create_date and system_modified_date from object attributes" do
198
+ cdate = "2008-07-02T05:09:42.015Z"
199
+ mdate = "2009-07-07T23:37:18.991Z"
200
+ @test_object.expects(:create_date).returns(cdate)
201
+ @test_object.expects(:modified_date).returns(mdate)
202
+ fields = @test_object.fields
203
+ fields[:system_create_date][:values].should eql([cdate])
204
+ fields[:system_modified_date][:values].should eql([mdate])
205
+ fields[:id][:values].should eql([@test_object.pid])
206
+ end
207
+
208
+ it "should add self.class as the :active_fedora_model" do
209
+ fields = @test_object.fields
210
+ fields[:active_fedora_model][:values].should eql([@test_object.class.inspect])
211
+ end
212
+
213
+ it "should call .fields on all MetadataDatastreams and return the resulting document" do
214
+ mock1 = mock("ds1", :fields => {})
215
+ mock2 = mock("ds2", :fields => {})
216
+ mock1.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(true)
217
+ mock2.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(true)
218
+
219
+ @test_object.expects(:datastreams).returns({:ds1 => mock1, :ds2 => mock2})
220
+ @test_object.fields
221
+ end
222
+ end
180
223
 
181
- describe '.rels_ext' do
224
+ it 'should provide #find' do
225
+ ActiveFedora::Base.should respond_to(:find)
226
+ end
182
227
 
183
- it 'should return the RelsExtDatastream object from the datastreams array' do
184
- @test_object.expects(:datastreams).returns({"RELS-EXT" => "foo"}).at_least_once
185
- @test_object.rels_ext.should == "foo"
228
+ it "should provide .create_date" do
229
+ @test_object.should respond_to(:create_date)
186
230
  end
187
- end
188
231
 
189
- it 'should provide #add_relationship' do
190
- @test_object.should respond_to(:add_relationship)
191
- end
232
+ it "should provide .modified_date" do
233
+ @test_object.should respond_to(:modified_date)
234
+ end
192
235
 
193
- describe '#add_relationship' do
194
- it 'should call #add_relationship on the rels_ext datastream' do
195
- @test_object.add_relationship("predicate", "info:fedora/object")
196
- pred = ActiveFedora::Predicates.vocabularies["info:fedora/fedora-system:def/relations-external#"]["predicate"]
197
- @test_object.relationships.should have_statement(RDF::Statement.new(RDF::URI.new(@test_object.internal_uri), pred, RDF::URI.new("info:fedora/object")))
236
+ it 'should respond to .rels_ext' do
237
+ @test_object.should respond_to(:rels_ext)
198
238
  end
199
239
 
200
- it "should update the RELS-EXT datastream and set the datastream as dirty when relationships are added" do
201
- mock_ds = mock("Rels-Ext")
202
- mock_ds.expects(:dirty=).with(true).times(2)
203
- @test_object.datastreams["RELS-EXT"] = mock_ds
204
- @test_object.add_relationship(:is_member_of, "info:fedora/demo:5")
205
- @test_object.add_relationship(:is_member_of, "info:fedora/demo:10")
240
+ describe '.rels_ext' do
241
+
242
+ it 'should return the RelsExtDatastream object from the datastreams array' do
243
+ @test_object.expects(:datastreams).returns({"RELS-EXT" => "foo"}).at_least_once
244
+ @test_object.rels_ext.should == "foo"
245
+ end
206
246
  end
207
-
208
- it 'should add a relationship to an object only if it does not exist already' do
209
- next_pid = increment_pid.to_s
210
- ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(next_pid)
211
- stub_get(next_pid)
212
247
 
213
- @test_object3 = ActiveFedora::Base.new
214
- @test_object.add_relationship(:has_part,@test_object3)
215
- @test_object.ids_for_outbound(:has_part).should == [@test_object3.pid]
216
- #try adding again and make sure not there twice
217
- @test_object.add_relationship(:has_part,@test_object3)
218
- @test_object.ids_for_outbound(:has_part).should == [@test_object3.pid]
248
+ it 'should provide #add_relationship' do
249
+ @test_object.should respond_to(:add_relationship)
219
250
  end
220
251
 
221
- it 'should add literal relationships if requested' do
222
- @test_object.add_relationship(:conforms_to,"AnInterface",true)
223
- @test_object.ids_for_outbound(:conforms_to).should == ["AnInterface"]
252
+ describe '#add_relationship' do
253
+ it 'should call #add_relationship on the rels_ext datastream' do
254
+ @test_object.add_relationship("predicate", "info:fedora/object")
255
+ pred = ActiveFedora::Predicates.vocabularies["info:fedora/fedora-system:def/relations-external#"]["predicate"]
256
+ @test_object.relationships.should have_statement(RDF::Statement.new(RDF::URI.new(@test_object.internal_uri), pred, RDF::URI.new("info:fedora/object")))
257
+ end
258
+
259
+ it "should update the RELS-EXT datastream and set the datastream as dirty when relationships are added" do
260
+ mock_ds = mock("Rels-Ext")
261
+ mock_ds.expects(:dirty=).with(true).times(2)
262
+ @test_object.datastreams["RELS-EXT"] = mock_ds
263
+ @test_object.add_relationship(:is_member_of, "info:fedora/demo:5")
264
+ @test_object.add_relationship(:is_member_of, "info:fedora/demo:10")
265
+ end
266
+
267
+ it 'should add a relationship to an object only if it does not exist already' do
268
+ next_pid = increment_pid.to_s
269
+ ActiveFedora::Base.stubs(:assign_pid).returns(next_pid)
270
+ stub_get(next_pid)
271
+
272
+ @test_object3 = ActiveFedora::Base.new
273
+ @test_object.add_relationship(:has_part,@test_object3)
274
+ @test_object.ids_for_outbound(:has_part).should == [@test_object3.pid]
275
+ #try adding again and make sure not there twice
276
+ @test_object.add_relationship(:has_part,@test_object3)
277
+ @test_object.ids_for_outbound(:has_part).should == [@test_object3.pid]
278
+ end
279
+
280
+ it 'should add literal relationships if requested' do
281
+ @test_object.add_relationship(:conforms_to,"AnInterface",true)
282
+ @test_object.ids_for_outbound(:conforms_to).should == ["AnInterface"]
283
+ end
224
284
  end
225
- end
226
-
227
- it 'should provide #remove_relationship' do
228
- @test_object.should respond_to(:remove_relationship)
229
- end
230
-
231
- describe '#remove_relationship' do
232
- it 'should remove a relationship from the relationships hash' do
233
- @test_object3 = ActiveFedora::Base.new()
234
- @test_object3.stubs(:pid=>'7')
235
- @test_object4 = ActiveFedora::Base.new()
236
- @test_object4.stubs(:pid=>'8')
237
- @test_object.add_relationship(:has_part,@test_object3)
238
- @test_object.add_relationship(:has_part,@test_object4)
239
- #check both are there
240
- @test_object.ids_for_outbound(:has_part).should == [@test_object3.pid,@test_object4.pid]
241
- @test_object.remove_relationship(:has_part,@test_object3)
242
- #check only one item removed
243
- @test_object.ids_for_outbound(:has_part).should == [@test_object4.pid]
244
- @test_object.remove_relationship(:has_part,@test_object4)
245
- #check last item removed and predicate removed since now emtpy
246
- @test_object.relationships.size.should == 0
285
+
286
+ it 'should provide #remove_relationship' do
287
+ @test_object.should respond_to(:remove_relationship)
288
+ end
289
+
290
+ describe '#remove_relationship' do
291
+ it 'should remove a relationship from the relationships hash' do
292
+ @test_object3 = ActiveFedora::Base.new()
293
+ @test_object3.stubs(:pid=>'7')
294
+ @test_object4 = ActiveFedora::Base.new()
295
+ @test_object4.stubs(:pid=>'8')
296
+ @test_object.add_relationship(:has_part,@test_object3)
297
+ @test_object.add_relationship(:has_part,@test_object4)
298
+ #check both are there
299
+ @test_object.ids_for_outbound(:has_part).should == [@test_object3.pid,@test_object4.pid]
300
+ @test_object.remove_relationship(:has_part,@test_object3)
301
+ #check only one item removed
302
+ @test_object.ids_for_outbound(:has_part).should == [@test_object4.pid]
303
+ @test_object.remove_relationship(:has_part,@test_object4)
304
+ #check last item removed and predicate removed since now emtpy
305
+ @test_object.relationships.size.should == 0
306
+ end
247
307
  end
248
- end
249
308
 
250
- it 'should provide #relationships' do
251
- @test_object.should respond_to(:relationships)
252
- end
309
+ it 'should provide #relationships' do
310
+ @test_object.should respond_to(:relationships)
311
+ end
253
312
 
254
- describe '#relationships' do
255
- it 'should return a graph' do
256
- @test_object.relationships.kind_of?(RDF::Graph).should be_true
257
- @test_object.relationships.size.should == 0
313
+ describe '#relationships' do
314
+ it 'should return a graph' do
315
+ @test_object.relationships.kind_of?(RDF::Graph).should be_true
316
+ @test_object.relationships.size.should == 0
317
+ end
258
318
  end
259
- end
260
319
 
261
- describe '.assert_content_model' do
262
- it "should default to the name of the class" do
263
- stub_get(@this_pid)
264
- stub_add_ds(@this_pid, ['RELS-EXT'])
265
- @test_object.assert_content_model
266
- @test_object.relationships(:has_model).should == ["info:fedora/afmodel:ActiveFedora_Base"]
267
-
320
+ describe '.assert_content_model' do
321
+ it "should default to the name of the class" do
322
+ stub_get(@this_pid)
323
+ stub_add_ds(@this_pid, ['RELS-EXT'])
324
+ @test_object.assert_content_model
325
+ @test_object.relationships(:has_model).should == ["info:fedora/afmodel:ActiveFedora_Base"]
326
+
327
+ end
268
328
  end
269
- end
270
329
 
271
- describe '.save' do
272
-
273
-
274
- it "should return true and set persisted if object and datastreams all save successfully" do
275
- stub_get(@this_pid)
276
- stub_add_ds(@this_pid, ['RELS-EXT'])
277
- @test_object.persisted?.should be false
278
- @test_object.expects(:update_index)
279
- stub_get(@this_pid, nil, true)
280
- @test_object.save.should == true
281
- @test_object.persisted?.should be true
282
- end
283
-
284
- it "should call assert_content_model" do
285
- stub_ingest(@this_pid)
286
- stub_add_ds(@this_pid, ['RELS-EXT'])
287
- @test_object.expects(:assert_content_model)
288
- @test_object.save.should == true
289
-
330
+ describe '.save' do
290
331
 
291
- end
292
-
293
- it "should call .save on any datastreams that are dirty" do
294
- stub_ingest(@this_pid)
295
- stub_add_ds(@this_pid, ['withText2', 'withText', 'RELS-EXT'])
296
- to = FooHistory.new
297
- to.expects(:update_index)
298
-
299
- to.datastreams["someData"].stubs(:changed?).returns(true)
300
- to.datastreams["someData"].stubs(:new_object?).returns(true)
301
- to.datastreams["someData"].expects(:save)
302
- to.expects(:refresh)
303
- to.save
304
- end
305
- it "should call .save on any datastreams that are new" do
306
- stub_ingest(@this_pid)
307
- stub_add_ds(@this_pid, ['RELS-EXT'])
308
- ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'ds_to_add')
309
- ds.content = "DS CONTENT"
310
- @test_object.add_datastream(ds)
311
- ds.expects(:save)
312
- @test_object.instance_variable_set(:@new_object, false)
313
- @test_object.expects(:refresh)
314
- @test_object.expects(:update_index)
315
- @test_object.save
316
- end
317
- it "should not call .save on any datastreams that are not dirty" do
318
- stub_ingest(@this_pid)
319
- @test_object = FooHistory.new
320
- @test_object.expects(:update_index)
321
- @test_object.expects(:refresh)
322
-
323
- @test_object.datastreams["someData"].should_not be_nil
324
- @test_object.datastreams['someData'].stubs(:changed?).returns(false)
325
- @test_object.datastreams['someData'].stubs(:new?).returns(false)
326
- @test_object.datastreams['someData'].expects(:save).never
327
- @test_object.datastreams['withText2'].expects(:save)
328
- @test_object.datastreams['withText'].expects(:save)
329
- @test_object.datastreams['RELS-EXT'].expects(:save)
330
- @test_object.save
331
- end
332
- it "should update solr index with all metadata if any MetadataDatastreams have changed" do
333
- stub_ingest(@this_pid)
334
- stub_add_ds(@this_pid, ['ds1', 'RELS-EXT'])
335
-
336
- dirty_ds = ActiveFedora::MetadataDatastream.new(@test_object.inner_object, 'ds1')
337
- rels_ds = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
338
- rels_ds.model = @test_object
339
- @test_object.add_datastream(rels_ds)
340
- @test_object.add_datastream(dirty_ds)
341
- @test_object.expects(:update_index)
342
332
 
343
- @test_object.save
344
- end
345
- it "should NOT update solr index if no MetadataDatastreams have changed" do
346
- pending ## Rels-ext is getting automatically added so we can't test this.
347
- ActiveFedora::DigitalObject.any_instance.stubs(:save)
348
- mock1 = mock("ds1")
349
- mock1.expects( :changed?).returns(false).at_least_once
350
- mock1.expects(:serialize!)
351
- mock2 = mock("ds2")
352
- mock2.expects( :changed?).returns(false).at_least_once
353
- mock2.expects(:serialize!)
354
- @test_object.stubs(:datastreams).returns({:ds1 => mock1, :ds2 => mock2})
355
- @test_object.expects(:update_index).never
356
- @test_object.expects(:refresh)
357
- @test_object.instance_variable_set(:@new_object, false)
358
-
359
- @test_object.save
360
- end
361
- it "should update solr index if relationships have changed" do
362
- stub_ingest(@this_pid)
363
-
364
- rels_ext = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
365
- rels_ext.model = @test_object
366
- rels_ext.expects(:changed?).returns(true).twice
367
- rels_ext.expects(:save).returns(true)
368
- rels_ext.expects(:serialize!)
369
- clean_ds = mock("ds2", :digital_object=)
370
- clean_ds.stubs(:dirty? => false, :changed? => false, :new? => false)
371
- clean_ds.expects(:serialize!)
372
- @test_object.datastreams["RELS-EXT"] = rels_ext
373
- @test_object.datastreams[:clean_ds] = clean_ds
374
- # @test_object.inner_object.stubs(:datastreams).returns({"RELS-EXT" => rels_ext, :clean_ds => clean_ds})
375
- # @test_object.stubs(:datastreams).returns({"RELS-EXT" => rels_ext, :clean_ds => clean_ds})
376
- @test_object.instance_variable_set(:@new_object, false)
377
- @test_object.expects(:refresh)
378
- @test_object.expects(:update_index)
333
+ it "should return true and set persisted if object and datastreams all save successfully" do
334
+ stub_get(@this_pid)
335
+ stub_add_ds(@this_pid, ['RELS-EXT'])
336
+ @test_object.persisted?.should be false
337
+ @test_object.expects(:update_index)
338
+ stub_get(@this_pid, nil, true)
339
+ @test_object.save.should == true
340
+ @test_object.persisted?.should be true
341
+ end
342
+
343
+ it "should call assert_content_model" do
344
+ stub_ingest(@this_pid)
345
+ stub_add_ds(@this_pid, ['RELS-EXT'])
346
+ @test_object.expects(:assert_content_model)
347
+ @test_object.save.should == true
348
+
349
+
350
+ end
379
351
 
380
- @test_object.save
352
+ it "should call .save on any datastreams that are dirty" do
353
+ stub_ingest(@this_pid)
354
+ stub_add_ds(@this_pid, ['withText2', 'withText', 'RELS-EXT'])
355
+ to = FooHistory.new
356
+ to.expects(:update_index)
357
+
358
+ to.datastreams["someData"].stubs(:changed?).returns(true)
359
+ to.datastreams["someData"].stubs(:new_object?).returns(true)
360
+ to.datastreams["someData"].expects(:save)
361
+ to.expects(:refresh)
362
+ FooHistory.expects(:assign_pid).with(to.inner_object).returns(@this_pid)
363
+ to.save
364
+ end
365
+ it "should call .save on any datastreams that are new" do
366
+ stub_ingest(@this_pid)
367
+ stub_add_ds(@this_pid, ['RELS-EXT'])
368
+ ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'ds_to_add')
369
+ ds.content = "DS CONTENT"
370
+ @test_object.add_datastream(ds)
371
+ ds.expects(:save)
372
+ @test_object.instance_variable_set(:@new_object, false)
373
+ @test_object.expects(:refresh)
374
+ @test_object.expects(:update_index)
375
+ @test_object.save
376
+ end
377
+ it "should not call .save on any datastreams that are not dirty" do
378
+ stub_ingest(@this_pid)
379
+ @test_object = FooHistory.new
380
+ @test_object.expects(:update_index)
381
+ @test_object.expects(:refresh)
382
+
383
+ @test_object.datastreams["someData"].should_not be_nil
384
+ @test_object.datastreams['someData'].stubs(:changed?).returns(false)
385
+ @test_object.datastreams['someData'].stubs(:new?).returns(false)
386
+ @test_object.datastreams['someData'].expects(:save).never
387
+ @test_object.datastreams['withText2'].expects(:save)
388
+ @test_object.datastreams['withText'].expects(:save)
389
+ @test_object.datastreams['RELS-EXT'].expects(:save)
390
+ FooHistory.expects(:assign_pid).with(@test_object.inner_object).returns(@this_pid)
391
+ @test_object.save
392
+ end
393
+ it "should update solr index with all metadata if any MetadataDatastreams have changed" do
394
+ stub_ingest(@this_pid)
395
+ stub_add_ds(@this_pid, ['ds1', 'RELS-EXT'])
396
+
397
+ dirty_ds = ActiveFedora::MetadataDatastream.new(@test_object.inner_object, 'ds1')
398
+ rels_ds = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
399
+ rels_ds.model = @test_object
400
+ @test_object.add_datastream(rels_ds)
401
+ @test_object.add_datastream(dirty_ds)
402
+ @test_object.expects(:update_index)
403
+
404
+ @test_object.save
405
+ end
406
+ it "should NOT update solr index if no MetadataDatastreams have changed" do
407
+ pending "Rels-ext is getting automatically added so we can't test this."
408
+ ActiveFedora::DigitalObject.any_instance.stubs(:save)
409
+ mock1 = mock("ds1")
410
+ mock1.expects( :changed?).returns(false).at_least_once
411
+ mock1.expects(:serialize!)
412
+ mock2 = mock("ds2")
413
+ mock2.expects( :changed?).returns(false).at_least_once
414
+ mock2.expects(:serialize!)
415
+ @test_object.stubs(:datastreams).returns({:ds1 => mock1, :ds2 => mock2})
416
+ @test_object.expects(:update_index).never
417
+ @test_object.expects(:refresh)
418
+ @test_object.instance_variable_set(:@new_object, false)
419
+
420
+ @test_object.save
421
+ end
422
+ it "should update solr index if relationships have changed" do
423
+ stub_ingest(@this_pid)
424
+
425
+ rels_ext = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
426
+ rels_ext.model = @test_object
427
+ rels_ext.expects(:changed?).returns(true).twice
428
+ rels_ext.expects(:save).returns(true)
429
+ rels_ext.expects(:serialize!)
430
+ clean_ds = mock("ds2", :digital_object=)
431
+ clean_ds.stubs(:dirty? => false, :changed? => false, :new? => false)
432
+ clean_ds.expects(:serialize!)
433
+ @test_object.datastreams["RELS-EXT"] = rels_ext
434
+ @test_object.datastreams[:clean_ds] = clean_ds
435
+ # @test_object.inner_object.stubs(:datastreams).returns({"RELS-EXT" => rels_ext, :clean_ds => clean_ds})
436
+ # @test_object.stubs(:datastreams).returns({"RELS-EXT" => rels_ext, :clean_ds => clean_ds})
437
+ @test_object.instance_variable_set(:@new_object, false)
438
+ @test_object.expects(:refresh)
439
+ @test_object.expects(:update_index)
440
+
441
+ @test_object.save
442
+ end
381
443
  end
382
- end
383
444
 
384
- describe "#create" do
385
- before do
386
- stub_ingest(@this_pid)
387
- stub_add_ds(@this_pid, ['someData', 'withText', 'withText2', 'RELS-EXT'])
388
- end
389
- it "should build a new record and save it" do
390
- @hist = FooHistory.create(:fubar=>'ta', :swank=>'da')
391
- @hist.fubar.should == ['ta']
392
- @hist.swank.should == ['da']
445
+ describe "#create" do
446
+ before do
447
+ stub_ingest(@this_pid)
448
+ stub_add_ds(@this_pid, ['someData', 'withText', 'withText2', 'RELS-EXT'])
449
+ end
450
+ it "should build a new record and save it" do
451
+ FooHistory.expects(:assign_pid).returns(@this_pid)
452
+ @hist = FooHistory.create(:fubar=>'ta', :swank=>'da')
453
+ @hist.fubar.should == ['ta']
454
+ @hist.swank.should == ['da']
455
+ end
456
+
393
457
  end
394
-
395
- end
396
458
 
397
- describe ".adapt_to" do
398
- it "should return an adapted object of the requested type" do
399
- @test_object = FooHistory.new()
400
- @test_object.adapt_to(FooAdaptation).class.should == FooAdaptation
401
- end
402
- it "should not make an additional call to fedora to create the adapted object" do
403
- @test_object = FooHistory.new()
404
- adapted = @test_object.adapt_to(FooAdaptation)
405
- end
406
- it "should propagate new datastreams to the adapted object" do
407
- @test_object = FooHistory.new()
408
- @test_object.add_file_datastream("XXX", :dsid=>'MY_DSID')
409
- adapted = @test_object.adapt_to(FooAdaptation)
410
- adapted.datastreams.keys.should include 'MY_DSID'
411
- adapted.datastreams['MY_DSID'].content.should == "XXX"
412
- adapted.datastreams['MY_DSID'].changed?.should be_true
413
- end
414
- it "should propagate modified datastreams to the adapted object" do
415
- @test_object = FooHistory.new()
416
- orig_ds = @test_object.datastreams['someData']
417
- orig_ds.content="YYY"
418
- adapted = @test_object.adapt_to(FooAdaptation)
419
- adapted.datastreams.keys.should include 'someData'
420
- adapted.datastreams['someData'].should == orig_ds
421
- adapted.datastreams['someData'].content.should == "YYY"
422
- adapted.datastreams['someData'].changed?.should be_true
423
- end
424
- it "should use the datastream definitions from the adapted object" do
425
- @test_object = FooHistory.new()
426
- adapted = @test_object.adapt_to(FooAdaptation)
427
- adapted.datastreams.keys.should include 'someData'
428
- adapted.datastreams['someData'].class.should == ActiveFedora::NokogiriDatastream
459
+ describe ".adapt_to" do
460
+ it "should return an adapted object of the requested type" do
461
+ @test_object = FooHistory.new()
462
+ @test_object.adapt_to(FooAdaptation).class.should == FooAdaptation
463
+ end
464
+ it "should not make an additional call to fedora to create the adapted object" do
465
+ @test_object = FooHistory.new()
466
+ adapted = @test_object.adapt_to(FooAdaptation)
467
+ end
468
+ it "should propagate new datastreams to the adapted object" do
469
+ @test_object = FooHistory.new()
470
+ @test_object.add_file_datastream("XXX", :dsid=>'MY_DSID')
471
+ adapted = @test_object.adapt_to(FooAdaptation)
472
+ adapted.datastreams.keys.should include 'MY_DSID'
473
+ adapted.datastreams['MY_DSID'].content.should == "XXX"
474
+ adapted.datastreams['MY_DSID'].changed?.should be_true
475
+ end
476
+ it "should propagate modified datastreams to the adapted object" do
477
+ @test_object = FooHistory.new()
478
+ orig_ds = @test_object.datastreams['someData']
479
+ orig_ds.content="YYY"
480
+ adapted = @test_object.adapt_to(FooAdaptation)
481
+ adapted.datastreams.keys.should include 'someData'
482
+ adapted.datastreams['someData'].should == orig_ds
483
+ adapted.datastreams['someData'].content.should == "YYY"
484
+ adapted.datastreams['someData'].changed?.should be_true
485
+ end
486
+ it "should use the datastream definitions from the adapted object" do
487
+ @test_object = FooHistory.new()
488
+ adapted = @test_object.adapt_to(FooAdaptation)
489
+ adapted.datastreams.keys.should include 'someData'
490
+ adapted.datastreams['someData'].class.should == ActiveFedora::NokogiriDatastream
491
+ end
429
492
  end
430
- end
431
493
 
432
- describe ".to_xml" do
433
- it "should provide .to_xml" do
434
- @test_object.should respond_to(:to_xml)
435
- end
494
+ describe ".to_xml" do
495
+ it "should provide .to_xml" do
496
+ @test_object.should respond_to(:to_xml)
497
+ end
436
498
 
437
- it "should add pid, system_create_date and system_modified_date from object attributes" do
438
- @test_object.expects(:create_date).returns("cDate")
439
- @test_object.expects(:modified_date).returns("mDate")
440
- solr_doc = @test_object.to_solr
441
- solr_doc["system_create_dt"].should eql("cDate")
442
- solr_doc["system_modified_dt"].should eql("mDate")
443
- solr_doc[:id].should eql("#{@test_object.pid}")
444
- end
499
+ it "should add pid, system_create_date and system_modified_date from object attributes" do
500
+ @test_object.expects(:create_date).returns("cDate")
501
+ @test_object.expects(:modified_date).returns("mDate")
502
+ solr_doc = @test_object.to_solr
503
+ solr_doc["system_create_dt"].should eql("cDate")
504
+ solr_doc["system_modified_dt"].should eql("mDate")
505
+ solr_doc[:id].should eql("#{@test_object.pid}")
506
+ end
445
507
 
446
- it "should call .to_xml on all MetadataDatastreams and return the resulting document" do
447
- ds1 = ActiveFedora::MetadataDatastream.new(@test_object.inner_object, 'ds1')
448
- ds2 = ActiveFedora::MetadataDatastream.new(@test_object.inner_object, 'ds2')
449
- [ds1,ds2].each {|ds| ds.expects(:to_xml)}
508
+ it "should call .to_xml on all MetadataDatastreams and return the resulting document" do
509
+ ds1 = ActiveFedora::MetadataDatastream.new(@test_object.inner_object, 'ds1')
510
+ ds2 = ActiveFedora::MetadataDatastream.new(@test_object.inner_object, 'ds2')
511
+ [ds1,ds2].each {|ds| ds.expects(:to_xml)}
450
512
 
451
- @test_object.expects(:datastreams).returns({:ds1 => ds1, :ds2 => ds2})
452
- @test_object.to_xml
453
- end
454
- end
455
-
456
- describe ".to_solr" do
457
- after(:all) do
458
- # Revert to default mappings after running tests
459
- ActiveFedora::SolrService.load_mappings
513
+ @test_object.expects(:datastreams).returns({:ds1 => ds1, :ds2 => ds2})
514
+ @test_object.to_xml
515
+ end
460
516
  end
461
517
 
462
- it "should provide .to_solr" do
463
- @test_object.should respond_to(:to_solr)
464
- end
518
+ describe ".to_solr" do
519
+ after(:all) do
520
+ # Revert to default mappings after running tests
521
+ ActiveFedora::SolrService.load_mappings
522
+ end
523
+
524
+ it "should provide .to_solr" do
525
+ @test_object.should respond_to(:to_solr)
526
+ end
527
+
528
+ it "should add pid, system_create_date and system_modified_date from object attributes" do
529
+ @test_object.expects(:create_date).returns("cDate")
530
+ @test_object.expects(:modified_date).returns("mDate")
531
+ solr_doc = @test_object.to_solr
532
+ solr_doc["system_create_dt"].should eql("cDate")
533
+ solr_doc["system_modified_dt"].should eql("mDate")
534
+ solr_doc[:id].should eql("#{@test_object.pid}")
535
+ end
465
536
 
466
- it "should add pid, system_create_date and system_modified_date from object attributes" do
467
- @test_object.expects(:create_date).returns("cDate")
468
- @test_object.expects(:modified_date).returns("mDate")
469
- solr_doc = @test_object.to_solr
470
- solr_doc["system_create_dt"].should eql("cDate")
471
- solr_doc["system_modified_dt"].should eql("mDate")
472
- solr_doc[:id].should eql("#{@test_object.pid}")
537
+ it "should omit base metadata and RELS-EXT if :model_only==true" do
538
+ @test_object.add_relationship(:has_part, "foo", true)
539
+ solr_doc = @test_object.to_solr(Hash.new, :model_only => true)
540
+ solr_doc["system_create_dt"].should be_nil
541
+ solr_doc["system_modified_dt"].should be_nil
542
+ solr_doc["id"].should be_nil
543
+ solr_doc["has_part_s"].should be_nil
544
+ end
545
+
546
+ it "should add self.class as the :active_fedora_model" do
547
+ stub_get(@this_pid)
548
+ stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
549
+ @test_history = FooHistory.new()
550
+ solr_doc = @test_history.to_solr
551
+ solr_doc["active_fedora_model_s"].should eql("FooHistory")
552
+ end
553
+
554
+ it "should use mappings.yml to decide names of solr fields" do
555
+ cdate = "2008-07-02T05:09:42.015Z"
556
+ mdate = "2009-07-07T23:37:18.991Z"
557
+ @test_object.stubs(:create_date).returns(cdate)
558
+ @test_object.stubs(:modified_date).returns(mdate)
559
+ solr_doc = @test_object.to_solr
560
+ solr_doc["system_create_dt"].should eql(cdate)
561
+ solr_doc["system_modified_dt"].should eql(mdate)
562
+ solr_doc[:id].should eql("#{@test_object.pid}")
563
+ solr_doc["active_fedora_model_s"].should eql(@test_object.class.inspect)
564
+
565
+ ActiveFedora::SolrService.load_mappings(File.join(File.dirname(__FILE__), "..", "..", "config", "solr_mappings_af_0.1.yml"))
566
+ solr_doc = @test_object.to_solr
567
+ [:system_create_dt, :system_modified_dt, :active_fedora_model_s].each do |fn|
568
+ solr_doc[fn].should == nil
569
+ end
570
+ solr_doc["system_create_date"].should eql(cdate)
571
+ solr_doc["system_modified_date"].should eql(mdate)
572
+ solr_doc[:id].should eql("#{@test_object.pid}")
573
+ solr_doc["active_fedora_model_field"].should eql(@test_object.class.inspect)
574
+ end
575
+
576
+ it "should call .to_solr on all MetadataDatastreams and NokogiriDatastreams, passing the resulting document to solr" do
577
+ mock1 = mock("ds1", :to_solr)
578
+ mock1.expects(:solrize_profile)
579
+ mock2 = mock("ds2", :to_solr)
580
+ mock2.expects(:solrize_profile)
581
+ ngds = mock("ngds")
582
+ ngds.expects(:solrize_profile)
583
+ mock1.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(true)
584
+ mock2.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(true)
585
+
586
+ @test_object.expects(:datastreams).returns({:ds1 => mock1, :ds2 => mock2, :ngds => ngds})
587
+ @test_object.expects(:solrize_relationships)
588
+ @test_object.to_solr
589
+ end
590
+ it "should call .to_solr on the relationships rels-ext is dirty" do
591
+ @test_object.add_relationship(:has_collection_member, "info:fedora/foo:member")
592
+ rels_ext = @test_object.rels_ext
593
+ rels_ext.dirty?.should == true
594
+ @test_object.expects(:solrize_relationships)
595
+ @test_object.to_solr
596
+ end
597
+
473
598
  end
474
599
 
475
- it "should omit base metadata and RELS-EXT if :model_only==true" do
476
- @test_object.add_relationship(:has_part, "foo", true)
477
- solr_doc = @test_object.to_solr(Hash.new, :model_only => true)
478
- solr_doc["system_create_dt"].should be_nil
479
- solr_doc["system_modified_dt"].should be_nil
480
- solr_doc["id"].should be_nil
481
- solr_doc["has_part_s"].should be_nil
600
+ describe ".label" do
601
+ it "should return the label of the inner object" do
602
+ @test_object.inner_object.expects(:label).returns("foo label")
603
+ @test_object.label.should == "foo label"
604
+ end
482
605
  end
483
606
 
484
- it "should add self.class as the :active_fedora_model" do
485
- stub_get(@this_pid)
486
- stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
487
- @test_history = FooHistory.new()
488
- solr_doc = @test_history.to_solr
489
- solr_doc["active_fedora_model_s"].should eql("FooHistory")
490
- end
491
-
492
- it "should use mappings.yml to decide names of solr fields" do
493
- cdate = "2008-07-02T05:09:42.015Z"
494
- mdate = "2009-07-07T23:37:18.991Z"
495
- @test_object.stubs(:create_date).returns(cdate)
496
- @test_object.stubs(:modified_date).returns(mdate)
497
- solr_doc = @test_object.to_solr
498
- solr_doc["system_create_dt"].should eql(cdate)
499
- solr_doc["system_modified_dt"].should eql(mdate)
500
- solr_doc[:id].should eql("#{@test_object.pid}")
501
- solr_doc["active_fedora_model_s"].should eql(@test_object.class.inspect)
502
-
503
- ActiveFedora::SolrService.load_mappings(File.join(File.dirname(__FILE__), "..", "..", "config", "solr_mappings_af_0.1.yml"))
504
- solr_doc = @test_object.to_solr
505
- [:system_create_dt, :system_modified_dt, :active_fedora_model_s].each do |fn|
506
- solr_doc[fn].should == nil
607
+ describe ".label=" do
608
+ it "should set the label of the inner object" do
609
+ @test_object.label.should_not == "foo label"
610
+ @test_object.label = "foo label"
611
+ @test_object.label.should == "foo label"
507
612
  end
508
- solr_doc["system_create_date"].should eql(cdate)
509
- solr_doc["system_modified_date"].should eql(mdate)
510
- solr_doc[:id].should eql("#{@test_object.pid}")
511
- solr_doc["active_fedora_model_field"].should eql(@test_object.class.inspect)
512
613
  end
513
614
 
514
- it "should call .to_solr on all MetadataDatastreams and NokogiriDatastreams, passing the resulting document to solr" do
515
- mock1 = mock("ds1", :to_solr)
516
- mock2 = mock("ds2", :to_solr)
517
- ngds = mock("ngds")
518
- mock1.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(true)
519
- mock2.expects(:kind_of?).with(ActiveFedora::MetadataDatastream).returns(true)
520
-
521
- @test_object.expects(:datastreams).returns({:ds1 => mock1, :ds2 => mock2, :ngds => ngds})
522
- @test_object.expects(:solrize_relationships)
523
- @test_object.to_solr
615
+
616
+ describe "get_values_from_datastream" do
617
+ it "should look up the named datastream and call get_values with the given pointer/field_name" do
618
+ mock_ds = mock("Datastream", :get_values=>["value1", "value2"])
619
+ @test_object.stubs(:datastreams).returns({"ds1"=>mock_ds})
620
+ @test_object.get_values_from_datastream("ds1", "--my xpath--").should == ["value1", "value2"]
621
+ end
524
622
  end
525
- it "should call .to_solr on the relationships rels-ext is dirty" do
526
- @test_object.add_relationship(:has_collection_member, "info:fedora/foo:member")
527
- rels_ext = @test_object.rels_ext
528
- rels_ext.dirty?.should == true
529
- @test_object.expects(:solrize_relationships)
530
- @test_object.to_solr
623
+
624
+ describe "update_datastream_attributes" do
625
+ it "should look up any datastreams specified as keys in the given hash and call update_attributes on the datastream" do
626
+ mock_desc_metadata = mock("descMetadata")
627
+ mock_properties = mock("properties")
628
+ mock_ds_hash = {'descMetadata'=>mock_desc_metadata, 'properties'=>mock_properties}
629
+
630
+ ds_values_hash = {
631
+ "descMetadata"=>{ [{:person=>0}, :role]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"} },
632
+ "properties"=>{ "notes"=>"foo" }
633
+ }
634
+ m = FooHistory.new
635
+ m.stubs(:datastreams).returns(mock_ds_hash)
636
+ mock_desc_metadata.expects(:update_indexed_attributes).with( ds_values_hash['descMetadata'] )
637
+ mock_properties.expects(:update_indexed_attributes).with( ds_values_hash['properties'] )
638
+ m.update_datastream_attributes( ds_values_hash )
639
+ end
640
+ it "should not do anything and should return an empty hash if the specified datastream does not exist" do
641
+ ds_values_hash = {
642
+ "nonexistentDatastream"=>{ "notes"=>"foo" }
643
+ }
644
+ m = FooHistory.new
645
+ untouched_xml = m.to_xml
646
+ m.update_datastream_attributes( ds_values_hash ).should == {}
647
+ m.to_xml.should == untouched_xml
648
+ end
531
649
  end
532
650
 
533
- end
534
-
535
- describe ".label" do
536
- it "should return the label of the inner object" do
537
- @test_object.inner_object.expects(:label).returns("foo label")
538
- @test_object.label.should == "foo label"
651
+ describe "update_attributes" do
652
+
653
+ it "should set the attributes and save" do
654
+ m = FooHistory.new
655
+ att= {"fubar"=> '1234', "baz" =>'stuff'}
656
+
657
+ m.expects(:fubar=).with('1234')
658
+ m.expects(:baz=).with('stuff')
659
+ m.expects(:save)
660
+ m.update_attributes(att)
661
+ end
539
662
  end
540
- end
541
-
542
- describe ".label=" do
543
- it "should set the label of the inner object" do
544
- @test_object.label.should_not == "foo label"
545
- @test_object.label = "foo label"
546
- @test_object.label.should == "foo label"
663
+
664
+ describe "update_indexed_attributes" do
665
+ it "should call .update_indexed_attributes on all metadata datastreams & nokogiri datastreams" do
666
+ m = FooHistory.new
667
+ att= {"fubar"=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}
668
+
669
+ m.datastreams['someData'].expects(:update_indexed_attributes)
670
+ m.datastreams["withText"].expects(:update_indexed_attributes)
671
+ m.datastreams['withText2'].expects(:update_indexed_attributes)
672
+ m.update_indexed_attributes(att)
673
+ end
674
+ it "should take a :datastreams argument" do
675
+ att= {"fubar"=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}
676
+ stub_get(@this_pid)
677
+ stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
678
+ m = FooHistory.new()
679
+ m.update_indexed_attributes(att, :datastreams=>"withText")
680
+ m.should_not be_nil
681
+ m.datastreams['someData'].fubar_values.should == []
682
+ m.datastreams["withText"].fubar_values.should == ['mork', 'york', 'mangle']
683
+ m.datastreams['withText2'].fubar_values.should == []
684
+
685
+ att= {"fubar"=>{"-1"=>"tork", "0"=>"work", "1"=>"bork"}}
686
+ m.update_indexed_attributes(att, :datastreams=>["someData", "withText2"])
687
+ m.should_not be_nil
688
+ m.datastreams['someData'].fubar_values.should == ['tork', 'work', 'bork']
689
+ m.datastreams["withText"].fubar_values.should == ['mork', 'york', 'mangle']
690
+ m.datastreams['withText2'].fubar_values.should == ['tork', 'work', 'bork']
691
+ end
547
692
  end
548
- end
549
-
550
-
551
- describe "get_values_from_datastream" do
552
- it "should look up the named datastream and call get_values with the given pointer/field_name" do
553
- mock_ds = mock("Datastream", :get_values=>["value1", "value2"])
554
- @test_object.stubs(:datastreams).returns({"ds1"=>mock_ds})
555
- @test_object.get_values_from_datastream("ds1", "--my xpath--").should == ["value1", "value2"]
693
+
694
+ it "should expose solr for real." do
695
+ sinmock = mock('solr instance')
696
+ conmock = mock("solr conn")
697
+ sinmock.expects(:conn).returns(conmock)
698
+ conmock.expects(:query).with('pid: foobar', {}).returns({:baz=>:bif})
699
+ ActiveFedora::SolrService.expects(:instance).returns(sinmock)
700
+ FooHistory.solr_search("pid: foobar").should == {:baz=>:bif}
556
701
  end
557
- end
558
-
559
- describe "update_datastream_attributes" do
560
- it "should look up any datastreams specified as keys in the given hash and call update_attributes on the datastream" do
561
- mock_desc_metadata = mock("descMetadata")
562
- mock_properties = mock("properties")
563
- mock_ds_hash = {'descMetadata'=>mock_desc_metadata, 'properties'=>mock_properties}
564
-
565
- ds_values_hash = {
566
- "descMetadata"=>{ [{:person=>0}, :role]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"} },
567
- "properties"=>{ "notes"=>"foo" }
568
- }
569
- m = FooHistory.new
570
- m.stubs(:datastreams).returns(mock_ds_hash)
571
- mock_desc_metadata.expects(:update_indexed_attributes).with( ds_values_hash['descMetadata'] )
572
- mock_properties.expects(:update_indexed_attributes).with( ds_values_hash['properties'] )
573
- m.update_datastream_attributes( ds_values_hash )
574
- end
575
- it "should not do anything and should return an empty hash if the specified datastream does not exist" do
576
- ds_values_hash = {
577
- "nonexistentDatastream"=>{ "notes"=>"foo" }
578
- }
579
- m = FooHistory.new
580
- untouched_xml = m.to_xml
581
- m.update_datastream_attributes( ds_values_hash ).should == {}
582
- m.to_xml.should == untouched_xml
702
+ it "should expose solr for real. and pass args through" do
703
+ sinmock = mock('solr instance')
704
+ conmock = mock("solr conn")
705
+ sinmock.expects(:conn).returns(conmock)
706
+ conmock.expects(:query).with('pid: foobar', {:ding => :dang}).returns({:baz=>:bif})
707
+ ActiveFedora::SolrService.expects(:instance).returns(sinmock)
708
+ FooHistory.solr_search("pid: foobar", {:ding=>:dang}).should == {:baz=>:bif}
583
709
  end
584
- end
585
-
586
- describe "update_attributes" do
587
710
 
588
- it "should set the attributes and save" do
589
- m = FooHistory.new
590
- att= {"fubar"=> '1234', "baz" =>'stuff'}
591
-
592
- m.expects(:fubar=).with('1234')
593
- m.expects(:baz=).with('stuff')
594
- m.expects(:save)
595
- m.update_attributes(att)
596
- end
597
- end
598
-
599
- describe "update_indexed_attributes" do
600
- it "should call .update_indexed_attributes on all metadata datastreams & nokogiri datastreams" do
601
- m = FooHistory.new
602
- att= {"fubar"=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}
711
+ describe '#relationships_by_name' do
603
712
 
604
- m.datastreams['someData'].expects(:update_indexed_attributes)
605
- m.datastreams["withText"].expects(:update_indexed_attributes)
606
- m.datastreams['withText2'].expects(:update_indexed_attributes)
607
- m.update_indexed_attributes(att)
608
- end
609
- it "should take a :datastreams argument" do
610
- att= {"fubar"=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}
611
- stub_get(@this_pid)
612
- stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
613
- m = FooHistory.new()
614
- m.update_indexed_attributes(att, :datastreams=>"withText")
615
- m.should_not be_nil
616
- m.datastreams['someData'].fubar_values.should == []
617
- m.datastreams["withText"].fubar_values.should == ['mork', 'york', 'mangle']
618
- m.datastreams['withText2'].fubar_values.should == []
713
+ before do
714
+ class MockNamedRelationships < ActiveFedora::Base
715
+ include ActiveFedora::FileManagement
716
+ has_relationship "testing", :has_part, :type=>ActiveFedora::Base
717
+ has_relationship "testing2", :has_member, :type=>ActiveFedora::Base
718
+ has_relationship "testing_inbound", :has_part, :type=>ActiveFedora::Base, :inbound=>true
719
+ end
720
+ end
619
721
 
620
- att= {"fubar"=>{"-1"=>"tork", "0"=>"work", "1"=>"bork"}}
621
- m.update_indexed_attributes(att, :datastreams=>["someData", "withText2"])
622
- m.should_not be_nil
623
- m.datastreams['someData'].fubar_values.should == ['tork', 'work', 'bork']
624
- m.datastreams["withText"].fubar_values.should == ['mork', 'york', 'mangle']
625
- m.datastreams['withText2'].fubar_values.should == ['tork', 'work', 'bork']
722
+ it 'should return current relationships by name' do
723
+ next_pid = increment_pid.to_s
724
+ ActiveFedora::Base.stubs(:assign_pid).returns(next_pid)
725
+ stub_get(next_pid)
726
+ @test_object2 = MockNamedRelationships.new
727
+ @test_object2.add_relationship(:has_model, MockNamedRelationships.to_class_uri)
728
+ @test_object.add_relationship(:has_model, ActiveFedora::Base.to_class_uri)
729
+ #should return expected named relationships
730
+ @test_object2.relationships_by_name
731
+ @test_object2.relationships_by_name[:self]["testing"].should == []
732
+ @test_object2.relationships_by_name[:self]["testing2"].should == []
733
+ @test_object2.relationships_by_name[:self]["parts_outbound"].should == []
734
+ @test_object2.add_relationship_by_name("testing",@test_object)
735
+ # @test_object2.relationships_by_name.should == {:self=>{"testing"=>[@test_object.internal_uri],"testing2"=>[],"part_of"=>[], "parts_outbound"=>[@test_object.internal_uri], "collection_members"=>[]}}
736
+
737
+ @test_object2.relationships_by_name[:self]["testing"].should == [@test_object.internal_uri]
738
+ @test_object2.relationships_by_name[:self]["testing2"].should == []
739
+ @test_object2.relationships_by_name[:self]["parts_outbound"].should == [@test_object.internal_uri]
740
+ end
626
741
  end
627
- end
628
-
629
- it "should expose solr for real." do
630
- sinmock = mock('solr instance')
631
- conmock = mock("solr conn")
632
- sinmock.expects(:conn).returns(conmock)
633
- conmock.expects(:query).with('pid: foobar', {}).returns({:baz=>:bif})
634
- ActiveFedora::SolrService.expects(:instance).returns(sinmock)
635
- FooHistory.solr_search("pid: foobar").should == {:baz=>:bif}
636
- end
637
- it "should expose solr for real. and pass args through" do
638
- sinmock = mock('solr instance')
639
- conmock = mock("solr conn")
640
- sinmock.expects(:conn).returns(conmock)
641
- conmock.expects(:query).with('pid: foobar', {:ding => :dang}).returns({:baz=>:bif})
642
- ActiveFedora::SolrService.expects(:instance).returns(sinmock)
643
- FooHistory.solr_search("pid: foobar", {:ding=>:dang}).should == {:baz=>:bif}
644
- end
645
742
 
646
- describe '#relationships_by_name' do
647
743
 
648
- before do
649
- ActiveSupport::Deprecation.stubs(:warn)
650
-
651
- class MockNamedRelationships < ActiveFedora::Base
652
- include ActiveFedora::FileManagement
653
- has_relationship "testing", :has_part, :type=>ActiveFedora::Base
654
- has_relationship "testing2", :has_member, :type=>ActiveFedora::Base
655
- has_relationship "testing_inbound", :has_part, :type=>ActiveFedora::Base, :inbound=>true
744
+ describe '#create_relationship_name_methods' do
745
+ before do
746
+ class MockCreateNamedRelationshipMethodsBase < ActiveFedora::Base
747
+ include ActiveFedora::Relationships
748
+ register_relationship_desc :self, "testing", :is_part_of, :type=>ActiveFedora::Base
749
+ create_relationship_name_methods "testing"
750
+ end
656
751
  end
657
- end
658
-
659
- it 'should return current relationships by name' do
660
- next_pid = increment_pid.to_s
661
- ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(next_pid)
662
- stub_get(next_pid)
663
- @test_object2 = MockNamedRelationships.new
664
- @test_object2.add_relationship(:has_model, MockNamedRelationships.to_class_uri)
665
- @test_object.add_relationship(:has_model, ActiveFedora::Base.to_class_uri)
666
- #should return expected named relationships
667
- @test_object2.relationships_by_name
668
- @test_object2.relationships_by_name[:self]["testing"].should == []
669
- @test_object2.relationships_by_name[:self]["testing2"].should == []
670
- @test_object2.relationships_by_name[:self]["parts_outbound"].should == []
671
- @test_object2.add_relationship_by_name("testing",@test_object)
672
- # @test_object2.relationships_by_name.should == {:self=>{"testing"=>[@test_object.internal_uri],"testing2"=>[],"part_of"=>[], "parts_outbound"=>[@test_object.internal_uri], "collection_members"=>[]}}
673
-
674
- @test_object2.relationships_by_name[:self]["testing"].should == [@test_object.internal_uri]
675
- @test_object2.relationships_by_name[:self]["testing2"].should == []
676
- @test_object2.relationships_by_name[:self]["parts_outbound"].should == [@test_object.internal_uri]
677
- end
678
- end
679
-
680
-
681
- describe '#create_relationship_name_methods' do
682
- before do
683
- ActiveSupport::Deprecation.stubs(:warn)
684
- class MockCreateNamedRelationshipMethodsBase < ActiveFedora::Base
685
- register_relationship_desc :self, "testing", :is_part_of, :type=>ActiveFedora::Base
686
- create_relationship_name_methods "testing"
752
+
753
+ it 'should append and remove using helper methods for each outbound relationship' do
754
+ next_pid = increment_pid.to_s
755
+ ActiveFedora::Base.stubs(:assign_pid).returns(next_pid)
756
+ stub_get(next_pid)
757
+ @test_object2 = MockCreateNamedRelationshipMethodsBase.new
758
+ @test_object2.should respond_to(:testing_append)
759
+ @test_object2.should respond_to(:testing_remove)
760
+ #test executing each one to make sure code added is correct
761
+ model_pid =ActiveFedora::Base.to_class_uri
762
+ @test_object.add_relationship(:has_model,model_pid)
763
+ @test_object2.add_relationship(:has_model,model_pid)
764
+ @test_object2.testing_append(@test_object)
765
+ #create relationship to access generate_uri method for an object
766
+ @test_object2.relationships_by_name[:self]["testing"].should == [@test_object.internal_uri]
767
+ @test_object2.testing_remove(@test_object)
768
+ @test_object2.relationships_by_name[:self]["testing"].should == []
687
769
  end
688
770
  end
689
-
690
- it 'should append and remove using helper methods for each outbound relationship' do
691
- next_pid = increment_pid.to_s
692
- ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(next_pid)
693
- stub_get(next_pid)
694
- @test_object2 = MockCreateNamedRelationshipMethodsBase.new
695
- @test_object2.should respond_to(:testing_append)
696
- @test_object2.should respond_to(:testing_remove)
697
- #test executing each one to make sure code added is correct
698
- model_pid =ActiveFedora::Base.to_class_uri
699
- @test_object.add_relationship(:has_model,model_pid)
700
- @test_object2.add_relationship(:has_model,model_pid)
701
- @test_object2.testing_append(@test_object)
702
- #create relationship to access generate_uri method for an object
703
- @test_object2.relationships_by_name[:self]["testing"].should == [@test_object.internal_uri]
704
- @test_object2.testing_remove(@test_object)
705
- @test_object2.relationships_by_name[:self]["testing"].should == []
706
- end
707
- end
708
771
 
709
- describe ".solrize_relationships" do
710
- it "should serialize the relationships into a Hash" do
711
- graph = RDF::Graph.new
712
- subject = RDF::URI.new "info:fedora/test:sample_pid"
713
- graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:is_member_of), RDF::URI.new('info:fedora/demo:10'))
714
- graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:is_part_of), RDF::URI.new('info:fedora/demo:11'))
715
- graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_part), RDF::URI.new('info:fedora/demo:12'))
716
- graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:conforms_to), "AnInterface")
717
-
718
- @test_object.expects(:relationships).returns(graph)
719
- solr_doc = @test_object.solrize_relationships
720
- solr_doc["is_member_of_s"].should == ["info:fedora/demo:10"]
721
- solr_doc["is_part_of_s"].should == ["info:fedora/demo:11"]
722
- solr_doc["has_part_s"].should == ["info:fedora/demo:12"]
723
- solr_doc["conforms_to_s"].should == ["AnInterface"]
772
+ describe ".solrize_relationships" do
773
+ it "should serialize the relationships into a Hash" do
774
+ graph = RDF::Graph.new
775
+ subject = RDF::URI.new "info:fedora/test:sample_pid"
776
+ graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:is_member_of), RDF::URI.new('info:fedora/demo:10'))
777
+ graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:is_part_of), RDF::URI.new('info:fedora/demo:11'))
778
+ graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_part), RDF::URI.new('info:fedora/demo:12'))
779
+ graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:conforms_to), "AnInterface")
780
+
781
+ @test_object.expects(:relationships).returns(graph)
782
+ solr_doc = @test_object.solrize_relationships
783
+ solr_doc["is_member_of_s"].should == ["info:fedora/demo:10"]
784
+ solr_doc["is_part_of_s"].should == ["info:fedora/demo:11"]
785
+ solr_doc["has_part_s"].should == ["info:fedora/demo:12"]
786
+ solr_doc["conforms_to_s"].should == ["AnInterface"]
787
+ end
724
788
  end
725
789
  end
726
790
  end