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
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::Config do
4
+ describe "with a single fedora instance" do
5
+ subject { ActiveFedora::Config.new('spec/fixtures/rails_root/config/fedora.yml', 'test') }
6
+ its(:path) { should == 'spec/fixtures/rails_root/config/fedora.yml'}
7
+ its(:credentials) { should == {:url => 'http://testhost.com:8983/fedora', :user=> 'fedoraAdmin', :password=> 'fedoraAdmin'}}
8
+ it { should_not be_sharded }
9
+ end
10
+ describe "with several fedora shards" do
11
+ subject { ActiveFedora::Config.new('spec/fixtures/sharded_fedora.yml', 'test') }
12
+ its(:path) { should == 'spec/fixtures/sharded_fedora.yml'}
13
+ its(:credentials) { should == [{:url => 'http://127.0.0.1:8983/fedora1', :user=> 'fedoraAdmin', :password=> 'fedoraAdmin'},
14
+ {:url => 'http://127.0.0.1:8983/fedora2', :user=> 'fedoraAdmin', :password=> 'fedoraAdmin'},
15
+ {:url => 'http://127.0.0.1:8983/fedora3', :user=> 'fedoraAdmin', :password=> 'fedoraAdmin'}]}
16
+ it { should be_sharded }
17
+ end
18
+
19
+ end
@@ -1,9 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- require 'active_fedora'
4
- require 'mocha'
5
-
6
-
7
3
  describe ActiveFedora::ContentModel do
8
4
 
9
5
  before(:all) do
@@ -24,7 +20,7 @@ describe ActiveFedora::ContentModel do
24
20
 
25
21
  before(:each) do
26
22
  stub_get('__nextid__')
27
- ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns("__nextid__")
23
+ ActiveFedora::Base.stubs(:assign_pid).returns("__nextid__")
28
24
  Rubydora::Repository.any_instance.stubs(:client).returns(@mock_client)
29
25
  @test_cmodel = ActiveFedora::ContentModel.new
30
26
  end
@@ -55,25 +51,6 @@ describe ActiveFedora::ContentModel do
55
51
  end
56
52
 
57
53
 
58
- describe "#pid_from_ruby_class" do
59
- before do
60
- ActiveSupport::Deprecation.stubs(:warn)
61
- end
62
-
63
- it "should construct pids" do
64
- ActiveFedora::ContentModel.pid_from_ruby_class(@test_cmodel.class).should == "info:fedora/afmodel:ActiveFedora_ContentModel"
65
- ActiveFedora::ContentModel.pid_from_ruby_class(@test_cmodel.class, :namespace => "foo", :pid_suffix => "BarBar").should == "info:fedora/foo:ActiveFedora_ContentModelBarBar"
66
- end
67
- it "should construct pids with the namespace declared in the model" do
68
- ActiveFedora::ContentModel.stubs(:pid_namespace).returns("test-cModel")
69
- ActiveFedora::ContentModel.pid_from_ruby_class(@test_cmodel.class).should == "info:fedora/test-cModel:ActiveFedora_ContentModel"
70
- end
71
- it "should construct pids with the suffix declared in the model" do
72
- ActiveFedora::ContentModel.stubs(:pid_suffix).returns("-TEST-SUFFIX")
73
- ActiveFedora::ContentModel.pid_from_ruby_class(@test_cmodel.class).should == 'info:fedora/afmodel:ActiveFedora_ContentModel-TEST-SUFFIX'
74
- end
75
- end
76
-
77
54
  describe "models_asserted_by" do
78
55
  it "should return an array of all of the content models asserted by the given object" do
79
56
  mock_object = mock("ActiveFedora Object")
@@ -1,14 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
-
4
- DEPRECATION_MSG = "Deprecation: DatastreamCollections will not be included by default in the next version. To use has_datastream add 'include ActiveFedora::DatastreamCollections' to your model"
5
-
6
3
  describe ActiveFedora::DatastreamCollections do
7
4
  describe '.has_datastream' do
8
5
  before(:all) do
9
- ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
10
6
 
11
7
  class MockHasDatastream < ActiveFedora::Base
8
+ include ActiveFedora::DatastreamCollections
12
9
  has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
13
10
  has_datastream :name=>"EAD", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
14
11
  has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
@@ -40,8 +37,8 @@ describe ActiveFedora::DatastreamCollections do
40
37
  end
41
38
  describe '#datastream_names' do
42
39
  before(:all) do
43
- ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
44
40
  class MockDatastreamNames < ActiveFedora::Base
41
+ include ActiveFedora::DatastreamCollections
45
42
  has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
46
43
  has_datastream :name=>"EAD", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
47
44
  end
@@ -55,8 +52,8 @@ describe ActiveFedora::DatastreamCollections do
55
52
 
56
53
  describe '#add_named_datastream' do
57
54
  before(:all) do
58
- ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
59
55
  class MockAddNamedDatastream < ActiveFedora::Base
56
+ include ActiveFedora::DatastreamCollections
60
57
  has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
61
58
  has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
62
59
  has_datastream :name=>"anymime", :type=>ActiveFedora::Datastream, :controlGroup=>'M'
@@ -146,8 +143,8 @@ describe ActiveFedora::DatastreamCollections do
146
143
 
147
144
  describe '#add_named_file_datastream' do
148
145
  before do
149
- ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
150
146
  class MockAddNamedFileDatastream < ActiveFedora::Base
147
+ include ActiveFedora::DatastreamCollections
151
148
  has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
152
149
  has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
153
150
  has_datastream :name=>"anymime", :type=>ActiveFedora::Datastream, :controlGroup=>'M'
@@ -176,8 +173,8 @@ describe ActiveFedora::DatastreamCollections do
176
173
 
177
174
  describe '#update_named_datastream' do
178
175
  before do
179
- ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
180
176
  class MockUpdateNamedDatastream < ActiveFedora::Base
177
+ include ActiveFedora::DatastreamCollections
181
178
  has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
182
179
  end
183
180
  end
@@ -236,8 +233,8 @@ describe ActiveFedora::DatastreamCollections do
236
233
  describe '#named_datastreams_desc' do
237
234
 
238
235
  before do
239
- ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
240
236
  class MockNamedDatastreamsDesc < ActiveFedora::Base
237
+ include ActiveFedora::DatastreamCollections
241
238
  has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
242
239
  end
243
240
  end
@@ -252,8 +249,8 @@ describe ActiveFedora::DatastreamCollections do
252
249
 
253
250
  describe '#is_named_datastream?' do
254
251
  before do
255
- ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
256
252
  class MockIsNamedDatastream < ActiveFedora::Base
253
+ include ActiveFedora::DatastreamCollections
257
254
  has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
258
255
  end
259
256
  end
@@ -268,8 +265,8 @@ describe ActiveFedora::DatastreamCollections do
268
265
 
269
266
  describe '#named_datastreams' do
270
267
  before do
271
- ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
272
268
  class MockNamedDatastreams < ActiveFedora::Base
269
+ include ActiveFedora::DatastreamCollections
273
270
  has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
274
271
  has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
275
272
  has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
@@ -318,8 +315,8 @@ describe ActiveFedora::DatastreamCollections do
318
315
 
319
316
  describe '#named_datastreams_ids' do
320
317
  before do
321
- ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
322
318
  class MockNamedDatastreamsIds < ActiveFedora::Base
319
+ include ActiveFedora::DatastreamCollections
323
320
  has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
324
321
  has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
325
322
  has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
@@ -344,8 +341,8 @@ describe ActiveFedora::DatastreamCollections do
344
341
 
345
342
  describe '#create_named_datastream_finders' do
346
343
  before do
347
- ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
348
344
  class MockCreateNamedDatastreamFinder < ActiveFedora::Base
345
+ include ActiveFedora::DatastreamCollections
349
346
  has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
350
347
  has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
351
348
  end
@@ -384,8 +381,8 @@ describe ActiveFedora::DatastreamCollections do
384
381
 
385
382
  describe '#create_named_datastream_update_methods' do
386
383
  before do
387
- ActiveSupport::Deprecation.expects(:warn).with(DEPRECATION_MSG)
388
384
  class MockCreateNamedDatastreamUpdateMethods < ActiveFedora::Base
385
+ include ActiveFedora::DatastreamCollections
389
386
  has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
390
387
  has_datastream :name=>"EAD", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
391
388
  has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
@@ -29,7 +29,8 @@ describe ActiveFedora::Datastreams do
29
29
  @this_pid = increment_pid.to_s
30
30
  stub_get(@this_pid)
31
31
  Rubydora::Repository.any_instance.stubs(:client).returns(@mock_client)
32
- ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(@this_pid)
32
+ ActiveFedora::Base.stubs(:assign_pid).returns(@this_pid)
33
+ #ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(@this_pid)
33
34
  end
34
35
 
35
36
  describe "creates datastreams" do
@@ -52,6 +53,7 @@ describe ActiveFedora::Datastreams do
52
53
  stub_add_ds(@this_pid, ['RELS-EXT', 'someData', 'withText', 'withText2'])
53
54
 
54
55
  @n = FooHistory.new()
56
+ FooHistory.stubs(:assign_pid).returns(@this_pid)
55
57
  @n.datastreams['RELS-EXT'].expects(:changed?).returns(true).at_least_once
56
58
  @n.expects(:update_index)
57
59
  @n.save
@@ -71,7 +73,7 @@ describe ActiveFedora::Datastreams do
71
73
 
72
74
 
73
75
  it "should create specified datastreams with appropriate control group" do
74
- ActiveFedora.fedora_config.stubs(:[]).returns({:url=>'sub_url'})
76
+ ActiveFedora.stubs(:config_for_environment).returns(:url=>'sub_url')
75
77
  stub_ingest(@this_pid)
76
78
  stub_add_ds(@this_pid, ['RELS-EXT', 'DC', 'rightsMetadata', 'properties', 'descMetadata', 'UKETD_DC'])
77
79
  stub_get(@this_pid, ['RELS-EXT', 'DC', 'rightsMetadata', 'properties', 'descMetadata', 'UKETD_DC'])
@@ -94,6 +96,7 @@ describe ActiveFedora::Datastreams do
94
96
 
95
97
  end
96
98
  @n = UketdObject.new()
99
+ UketdObject.stubs(:assign_pid).returns(@this_pid)
97
100
  @n.save
98
101
  @n.datastreams["DC"].controlGroup.should eql("X")
99
102
  @n.datastreams["rightsMetadata"].controlGroup.should eql("X")
@@ -120,39 +123,35 @@ describe ActiveFedora::Datastreams do
120
123
  end
121
124
  stub_ingest(@this_pid)
122
125
  @n = MoreFooHistory.new
126
+ MoreFooHistory.stubs(:assign_pid).returns(@this_pid)
123
127
  @n.save
124
128
  @n.datastreams['externalDisseminator'].dsLocation.should == "http://exampl.com/mypic.jpg"
125
129
  end
126
130
 
127
- it "should allow :control_group => 'E' without a :url option" do
128
- class MoreFooHistory < ActiveFedora::Base
129
- has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "E"
131
+ describe "control_group E without a url" do
132
+ before do
133
+ class MoreFooHistory < ActiveFedora::Base
134
+ has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "E"
135
+ end
136
+ stub_ingest(@this_pid)
137
+ @n = MoreFooHistory.new
138
+ MoreFooHistory.stubs(:assign_pid).returns(@this_pid)
130
139
  end
131
- stub_ingest(@this_pid)
132
- @n = MoreFooHistory.new
133
- @n.datastreams['externalDisseminator'].dsLocation.present?.should == false
134
- @n.save
135
- end
136
-
137
- it "should fail validation if a :url is not added before save" do
138
- class MoreFooHistory < ActiveFedora::Base
139
- has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "E"
140
+ it "should allow :control_group => 'E' without a :url option" do
141
+ @n.datastreams['externalDisseminator'].dsLocation.present?.should == false
142
+ @n.save
140
143
  end
141
- stub_ingest(@this_pid)
142
- @n = MoreFooHistory.new
143
- @n.datastreams['externalDisseminator'].validate_content_present.should == false
144
- @n.save
145
- end
146
-
147
- it "should pass validation if a :url is added before save" do
148
- class MoreFooHistory < ActiveFedora::Base
149
- has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "E"
144
+
145
+ it "should fail validation if a :url is not added before save" do
146
+ @n.datastreams['externalDisseminator'].validate_content_present.should == false
147
+ @n.save
148
+ end
149
+
150
+ it "should pass validation if a :url is added before save" do
151
+ @n.datastreams['externalDisseminator'].dsLocation = "http://exampl.com/mypic.jpg"
152
+ @n.datastreams['externalDisseminator'].validate_content_present.should == true
153
+ @n.save
150
154
  end
151
- stub_ingest(@this_pid)
152
- @n = MoreFooHistory.new
153
- @n.datastreams['externalDisseminator'].dsLocation = "http://exampl.com/mypic.jpg"
154
- @n.datastreams['externalDisseminator'].validate_content_present.should == true
155
- @n.save
156
155
  end
157
156
  end
158
157
 
@@ -172,38 +171,34 @@ describe ActiveFedora::Datastreams do
172
171
  has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "R", :url => "http://exampl.com/mypic.jpg"
173
172
  end
174
173
  @n = MoreFooHistory.new
174
+ MoreFooHistory.stubs(:assign_pid).returns(@this_pid)
175
175
  @n.save
176
176
  end
177
177
 
178
- it "should allow :control_group => 'R' without a :url option" do
179
- class MoreFooHistory < ActiveFedora::Base
180
- has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "R"
178
+ describe "control_group R without url" do
179
+ before do
180
+ class MoreFooHistory < ActiveFedora::Base
181
+ has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "R"
182
+ end
183
+ MoreFooHistory.stubs(:assign_pid).returns(@this_pid)
184
+ stub_ingest(@this_pid)
185
+ @n = MoreFooHistory.new
181
186
  end
182
- stub_ingest(@this_pid)
183
- @n = MoreFooHistory.new
184
- @n.datastreams['externalDisseminator'].dsLocation.present?.should == false
185
- @n.save
186
- end
187
-
188
- it "should fail validation if a :url is not added before save" do
189
- class MoreFooHistory < ActiveFedora::Base
190
- has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "R"
187
+ it "should allow :control_group => 'R' without a :url option" do
188
+ @n.datastreams['externalDisseminator'].dsLocation.present?.should == false
189
+ @n.save
191
190
  end
192
- stub_ingest(@this_pid)
193
- @n = MoreFooHistory.new
194
- @n.datastreams['externalDisseminator'].validate_content_present.should == false
195
- @n.save
196
- end
197
-
198
- it "should pass validation if a :url is added before save" do
199
- class MoreFooHistory < ActiveFedora::Base
200
- has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "R"
191
+
192
+ it "should fail validation if a :url is not added before save" do
193
+ @n.datastreams['externalDisseminator'].validate_content_present.should == false
194
+ @n.save
195
+ end
196
+
197
+ it "should pass validation if a :url is added before save" do
198
+ @n.datastreams['externalDisseminator'].dsLocation = "http://exampl.com/mypic.jpg"
199
+ @n.datastreams['externalDisseminator'].validate_content_present.should == true
200
+ @n.save
201
201
  end
202
- stub_ingest(@this_pid)
203
- @n = MoreFooHistory.new
204
- @n.datastreams['externalDisseminator'].dsLocation = "http://exampl.com/mypic.jpg"
205
- @n.datastreams['externalDisseminator'].validate_content_present.should == true
206
- @n.save
207
202
  end
208
203
  end
209
204
  end
@@ -1,11 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- require 'active_fedora'
4
- require 'active_fedora/model'
5
- require "rexml/document"
6
- require 'mocha'
7
-
8
-
9
3
  describe ActiveFedora::Model do
10
4
 
11
5
  before(:all) do
@@ -18,7 +12,7 @@ describe ActiveFedora::Model do
18
12
  end
19
13
 
20
14
  before(:each) do
21
- ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns('_nextid_')
15
+ ActiveFedora::Base.stubs(:assign_pid).returns('_nextid_')
22
16
  @test_instance = SpecModel::Basic.new
23
17
  @property = stub("myproperty", :name => "mock_prop", :instance_variable_name => "@mock_prop")
24
18
  SpecModel::Basic.extend(ActiveFedora::Model)
@@ -27,7 +21,7 @@ describe ActiveFedora::Model do
27
21
  end
28
22
 
29
23
  after(:all) do
30
- #Object.send(:remove_const, :SpecModel)
24
+ Object.send(:remove_const, :SpecModel)
31
25
  end
32
26
 
33
27
  it 'should provide #attribute_set and #attribute_get' do
@@ -35,24 +29,6 @@ describe ActiveFedora::Model do
35
29
  SpecModel::Basic.should respond_to(:attribute_get)
36
30
  end
37
31
 
38
- describe "#attribute_set" do
39
- it "should look up the property's ivar name from properties hash" do
40
- pending
41
- SpecModel::Basic.expects(:properties).with(@test_property.name)
42
- SpecModel::Basic.expects(:set_instance_variable).with(@test_property.instance_variable_name, "new value")
43
- SpecModel::Basic.attribute_set(@test_property.name, "new value")
44
- end
45
- end
46
-
47
- describe "#attribute_get" do
48
- it "should look up the property's ivar name from properties hash" do
49
- pending
50
- SpecModel::Basic.expects(:properties).with(@test_property.name)
51
- SpecModel::Basic.expects(:get_instance_variable).with(@test_property.instance_variable_name)
52
- SpecModel::Basic.attribute_get(@test_property.name, "new value")
53
- end
54
- end
55
-
56
32
  it 'should provide #create_property_getter' do
57
33
  SpecModel::Basic.should respond_to(:create_property_getter)
58
34
  end
@@ -104,33 +80,15 @@ describe ActiveFedora::Model do
104
80
  mock_result.expects(:hits).returns([{"id" => "changeme:30"}, {"id" => "changeme:22"}])
105
81
  mock_solr.expects(:query).with('has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic', :rows=>1001).returns(mock_result)
106
82
  ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
107
- ActiveFedora::RubydoraConnection.instance.expects(:find_model).with("changeme:30", SpecModel::Basic).returns("Fake Object1")
108
- ActiveFedora::RubydoraConnection.instance.expects(:find_model).with("changeme:22", SpecModel::Basic).returns("Fake Object2")
83
+ SpecModel::Basic.expects(:load_instance).with("changeme:30").returns("Fake Object1")
84
+ SpecModel::Basic.expects(:load_instance).with("changeme:22").returns("Fake Object2")
109
85
  SpecModel::Basic.find(:all, :rows=>1001).should == ["Fake Object1", "Fake Object2"]
110
86
  end
111
87
 
112
88
  it "(String) should query solr for an object with the given id and return that object" do
113
- ActiveFedora::RubydoraConnection.instance.expects(:find_model).with("changeme:30", SpecModel::Basic).returns("Fake Object")
114
-
89
+ SpecModel::Basic.expects(:load_instance).with("changeme:30").returns("Fake Object")
115
90
  SpecModel::Basic.find("changeme:30").should == "Fake Object"
116
91
  end
117
-
118
- describe"(:pid => xxx)" do
119
- it "should pull the inner object from fedora if it already exists in fedora" do
120
- pending
121
- ActiveFedora::RubydoraConnection.instance.expects(:save).never
122
- mock_obj = mock("Fedora Object")
123
- ActiveFedora::RubydoraConnection.instance.expects(:find_objects).returns([mock_obj])
124
- ActiveFedora::Base.new(:pid=>"test:1").inner_object.should equal(mock_obj)
125
- end
126
- it "should save the inner_object to fedora if it does not already exist" do
127
- pending
128
- ActiveFedora::RubydoraConnection.instance.expects(:save)
129
- ActiveFedora::RubydoraConnection.instance.expects(:find_objects).returns([])
130
- ActiveFedora::Base.new(:pid=>"test:1")
131
- end
132
- end
133
-
134
92
  end
135
93
 
136
94
  describe '#count' do
@@ -178,10 +136,9 @@ describe ActiveFedora::Model do
178
136
  end
179
137
 
180
138
  describe "load_instance" do
181
- it "should use Repository.find_model to instantiate an object" do
182
- mock_repo = mock("repo")
183
- mock_repo.expects(:find_model).with("_PID_", SpecModel::Basic)
184
- ActiveFedora::RubydoraConnection.expects(:instance).returns(mock_repo)
139
+ it "should use SpecModel::Basic.allocate.init_with to instantiate an object" do
140
+ SpecModel::Basic.any_instance.expects(:init_with)
141
+ SpecModel::Basic.expects(:connection_for_pid).with("_PID_")
185
142
  SpecModel::Basic.load_instance("_PID_")
186
143
  end
187
144
  end
@@ -193,15 +150,29 @@ describe ActiveFedora::Model do
193
150
  include ActiveFedora::Model
194
151
  end
195
152
  end
153
+
196
154
  end
197
155
 
198
156
  after :all do
199
157
  SpecModel.send(:remove_const, :CamelCased)
200
158
  end
159
+ subject {SpecModel::CamelCased}
201
160
 
202
- it "should turn a Model class name into an afmodel URI" do
203
- SpecModel::CamelCased.to_class_uri.should == 'info:fedora/afmodel:SpecModel_CamelCased'
161
+ its(:to_class_uri) {should == 'info:fedora/afmodel:SpecModel_CamelCased' }
162
+
163
+ context "with the namespace declared in the model" do
164
+ before do
165
+ subject.stubs(:pid_namespace).returns("test-cModel")
166
+ end
167
+ its(:to_class_uri) {should == 'info:fedora/test-cModel:SpecModel_CamelCased' }
204
168
  end
169
+ context "with the suffix declared in the model" do
170
+ before do
171
+ subject.stubs(:pid_suffix).returns("-TEST-SUFFIX")
172
+ end
173
+ its(:to_class_uri) {should == 'info:fedora/afmodel:SpecModel_CamelCased-TEST-SUFFIX' }
174
+ end
175
+
205
176
 
206
177
  it "should turn an afmodel URI into a Model class name" do
207
178
  ActiveFedora::Model.classname_from_uri('info:fedora/afmodel:SpecModel_CamelCased').should == ['SpecModel::CamelCased', 'afmodel']