active-fedora 6.8.0 → 7.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +15 -5
- data/CONTRIBUTING.md +2 -0
- data/Gemfile +0 -2
- data/History.txt +2 -32
- data/README.md +143 -0
- data/Rakefile +5 -7
- data/active-fedora.gemspec +9 -9
- data/gemfiles/rails3.gemfile +11 -0
- data/gemfiles/rails4.gemfile +10 -0
- data/lib/active_fedora.rb +31 -4
- data/lib/active_fedora/association_relation.rb +18 -0
- data/lib/active_fedora/associations.rb +38 -171
- data/lib/active_fedora/associations/association.rb +163 -0
- data/lib/active_fedora/associations/association_scope.rb +39 -0
- data/lib/active_fedora/associations/belongs_to_association.rb +47 -25
- data/lib/active_fedora/associations/builder/association.rb +55 -0
- data/lib/active_fedora/associations/builder/belongs_to.rb +100 -0
- data/lib/active_fedora/associations/builder/collection_association.rb +56 -0
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +30 -0
- data/lib/active_fedora/associations/builder/has_many.rb +63 -0
- data/lib/active_fedora/associations/builder/singular_association.rb +32 -0
- data/lib/active_fedora/associations/{association_collection.rb → collection_association.rb} +203 -53
- data/lib/active_fedora/associations/collection_proxy.rb +862 -0
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +35 -25
- data/lib/active_fedora/associations/has_many_association.rb +36 -11
- data/lib/active_fedora/associations/singular_association.rb +62 -0
- data/lib/active_fedora/attributes.rb +43 -139
- data/lib/active_fedora/autosave_association.rb +317 -0
- data/lib/active_fedora/base.rb +10 -327
- data/lib/active_fedora/callbacks.rb +1 -3
- data/lib/active_fedora/content_model.rb +16 -0
- data/lib/active_fedora/core.rb +151 -0
- data/lib/active_fedora/datastream_attribute.rb +76 -0
- data/lib/active_fedora/datastream_hash.rb +8 -13
- data/lib/active_fedora/datastreams.rb +39 -26
- data/lib/active_fedora/digital_object.rb +2 -2
- data/lib/active_fedora/fedora_attributes.rb +45 -0
- data/lib/active_fedora/fixture_loader.rb +1 -1
- data/lib/active_fedora/indexing.rb +6 -1
- data/lib/active_fedora/model.rb +0 -17
- data/lib/active_fedora/nested_attributes.rb +2 -2
- data/lib/active_fedora/null_relation.rb +7 -0
- data/lib/active_fedora/om_datastream.rb +3 -4
- data/lib/active_fedora/persistence.rb +41 -29
- data/lib/active_fedora/querying.rb +2 -163
- data/lib/active_fedora/rdf.rb +1 -0
- data/lib/active_fedora/rdf/indexing.rb +67 -0
- data/lib/active_fedora/rdf_datastream.rb +2 -50
- data/lib/active_fedora/rdf_node.rb +12 -7
- data/lib/active_fedora/rdf_node/term_proxy.rb +30 -21
- data/lib/active_fedora/rdfxml_rdf_datastream.rb +1 -1
- data/lib/active_fedora/reflection.rb +163 -20
- data/lib/active_fedora/relation.rb +33 -130
- data/lib/active_fedora/relation/calculations.rb +19 -0
- data/lib/active_fedora/relation/delegation.rb +22 -0
- data/lib/active_fedora/relation/finder_methods.rb +247 -0
- data/lib/active_fedora/relation/merger.rb +22 -0
- data/lib/active_fedora/relation/query_methods.rb +58 -0
- data/lib/active_fedora/relation/spawn_methods.rb +46 -0
- data/lib/active_fedora/relationship_graph.rb +0 -2
- data/lib/active_fedora/rels_ext_datastream.rb +1 -4
- data/lib/active_fedora/rubydora_connection.rb +1 -1
- data/lib/active_fedora/scoping.rb +20 -0
- data/lib/active_fedora/scoping/default.rb +38 -0
- data/lib/active_fedora/scoping/named.rb +32 -0
- data/lib/active_fedora/semantic_node.rb +54 -106
- data/lib/active_fedora/serialization.rb +19 -0
- data/lib/active_fedora/sharding.rb +58 -0
- data/lib/active_fedora/solr_digital_object.rb +15 -5
- data/lib/active_fedora/solr_instance_loader.rb +1 -1
- data/lib/active_fedora/solr_service.rb +1 -1
- data/lib/active_fedora/unsaved_digital_object.rb +6 -4
- data/lib/active_fedora/version.rb +1 -1
- data/lib/tasks/active_fedora.rake +3 -0
- data/lib/tasks/active_fedora_dev.rake +6 -5
- data/spec/config_helper.rb +14 -14
- data/spec/integration/associations_spec.rb +168 -455
- data/spec/integration/attributes_spec.rb +12 -11
- data/spec/integration/auditable_spec.rb +11 -11
- data/spec/integration/autosave_association_spec.rb +25 -0
- data/spec/integration/base_spec.rb +163 -163
- data/spec/integration/belongs_to_association_spec.rb +166 -0
- data/spec/integration/bug_spec.rb +7 -7
- data/spec/integration/collection_association_spec.rb +58 -0
- data/spec/integration/complex_rdf_datastream_spec.rb +88 -88
- data/spec/integration/datastream_collections_spec.rb +69 -69
- data/spec/integration/datastream_spec.rb +43 -43
- data/spec/integration/datastreams_spec.rb +63 -63
- data/spec/integration/delete_all_spec.rb +46 -39
- data/spec/integration/fedora_solr_sync_spec.rb +5 -5
- data/spec/integration/field_to_solr_name_spec.rb +34 -0
- data/spec/integration/full_featured_model_spec.rb +100 -101
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +341 -0
- data/spec/integration/has_many_associations_spec.rb +172 -24
- data/spec/integration/json_serialization_spec.rb +31 -0
- data/spec/integration/load_from_solr_spec.rb +48 -0
- data/spec/integration/model_spec.rb +35 -40
- data/spec/integration/nested_attribute_spec.rb +42 -43
- data/spec/integration/ntriples_datastream_spec.rb +131 -113
- data/spec/integration/om_datastream_spec.rb +67 -67
- data/spec/integration/persistence_spec.rb +7 -7
- data/spec/integration/rdf_nested_attributes_spec.rb +56 -56
- data/spec/integration/relation_delegation_spec.rb +26 -25
- data/spec/integration/relation_spec.rb +42 -0
- data/spec/integration/rels_ext_datastream_spec.rb +20 -20
- data/spec/integration/scoped_query_spec.rb +61 -51
- data/spec/integration/solr_instance_loader_spec.rb +5 -5
- data/spec/integration/solr_service_spec.rb +46 -46
- data/spec/samples/hydra-mods_article_datastream.rb +334 -334
- data/spec/samples/hydra-rights_metadata_datastream.rb +57 -57
- data/spec/samples/marpa-dc_datastream.rb +17 -17
- data/spec/samples/models/audio_record.rb +16 -16
- data/spec/samples/models/image.rb +2 -2
- data/spec/samples/models/mods_article.rb +5 -5
- data/spec/samples/models/oral_history.rb +18 -18
- data/spec/samples/models/seminar.rb +24 -24
- data/spec/samples/models/seminar_audio_file.rb +17 -17
- data/spec/samples/oral_history_sample_model.rb +21 -21
- data/spec/samples/special_thing.rb +14 -14
- data/spec/spec_helper.rb +11 -7
- data/spec/support/an_active_model.rb +2 -8
- data/spec/support/freeze_mocks.rb +12 -0
- data/spec/support/mock_fedora.rb +17 -16
- data/spec/unit/active_fedora_spec.rb +58 -60
- data/spec/unit/attributes_spec.rb +314 -0
- data/spec/unit/base_active_model_spec.rb +28 -27
- data/spec/unit/base_cma_spec.rb +5 -5
- data/spec/unit/base_datastream_management_spec.rb +27 -27
- data/spec/unit/base_extra_spec.rb +76 -48
- data/spec/unit/base_spec.rb +277 -348
- data/spec/unit/callback_spec.rb +18 -19
- data/spec/unit/code_configurator_spec.rb +17 -17
- data/spec/unit/config_spec.rb +8 -16
- data/spec/unit/content_model_spec.rb +79 -60
- data/spec/unit/datastream_collections_spec.rb +229 -229
- data/spec/unit/datastream_spec.rb +51 -63
- data/spec/unit/datastreams_spec.rb +87 -87
- data/spec/unit/file_configurator_spec.rb +217 -217
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +44 -25
- data/spec/unit/has_many_collection_spec.rb +26 -8
- data/spec/unit/inheritance_spec.rb +13 -12
- data/spec/unit/model_spec.rb +39 -45
- data/spec/unit/nom_datastream_spec.rb +15 -15
- data/spec/unit/ntriples_datastream_spec.rb +123 -118
- data/spec/unit/om_datastream_spec.rb +227 -233
- data/spec/unit/persistence_spec.rb +34 -15
- data/spec/unit/predicates_spec.rb +73 -73
- data/spec/unit/property_spec.rb +17 -9
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +33 -33
- data/spec/unit/query_spec.rb +222 -198
- data/spec/unit/rdf_datastream_spec.rb +21 -28
- data/spec/unit/rdf_list_nested_attributes_spec.rb +34 -34
- data/spec/unit/rdf_list_spec.rb +65 -64
- data/spec/unit/rdf_node_spec.rb +7 -7
- data/spec/unit/rdf_xml_writer_spec.rb +10 -10
- data/spec/unit/rdfxml_rdf_datastream_spec.rb +27 -27
- data/spec/unit/relationship_graph_spec.rb +51 -51
- data/spec/unit/rels_ext_datastream_spec.rb +68 -74
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +12 -12
- data/spec/unit/rubydora_connection_spec.rb +5 -5
- data/spec/unit/semantic_node_spec.rb +48 -107
- data/spec/unit/serializers_spec.rb +4 -4
- data/spec/unit/service_definitions_spec.rb +26 -26
- data/spec/unit/simple_datastream_spec.rb +17 -17
- data/spec/unit/solr_config_options_spec.rb +29 -28
- data/spec/unit/solr_digital_object_spec.rb +17 -25
- data/spec/unit/solr_service_spec.rb +95 -82
- data/spec/unit/unsaved_digital_object_spec.rb +24 -23
- data/spec/unit/validations_spec.rb +21 -21
- metadata +110 -159
- data/.rspec +0 -1
- data/.rubocop.yml +0 -1
- data/.rubocop_todo.yml +0 -938
- data/CONSOLE_GETTING_STARTED.textile +0 -1
- data/NOKOGIRI_DATASTREAMS.textile +0 -1
- data/README.textile +0 -116
- data/lib/active_fedora/associations/association_proxy.rb +0 -178
- data/lib/active_fedora/delegating.rb +0 -72
- data/lib/active_fedora/nokogiri_datastream.rb +0 -11
- data/spec/integration/delegating_spec.rb +0 -59
- data/spec/rails3_test_app/.gitignore +0 -4
- data/spec/rails3_test_app/.rspec +0 -1
- data/spec/rails3_test_app/Gemfile +0 -40
- data/spec/rails3_test_app/Rakefile +0 -7
- data/spec/rails3_test_app/app/controllers/application_controller.rb +0 -3
- data/spec/rails3_test_app/app/helpers/application_helper.rb +0 -2
- data/spec/rails3_test_app/app/views/layouts/application.html.erb +0 -14
- data/spec/rails3_test_app/config.ru +0 -4
- data/spec/rails3_test_app/config/application.rb +0 -42
- data/spec/rails3_test_app/config/boot.rb +0 -6
- data/spec/rails3_test_app/config/database.yml +0 -22
- data/spec/rails3_test_app/config/environment.rb +0 -5
- data/spec/rails3_test_app/config/environments/development.rb +0 -25
- data/spec/rails3_test_app/config/environments/production.rb +0 -49
- data/spec/rails3_test_app/config/environments/test.rb +0 -35
- data/spec/rails3_test_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails3_test_app/config/initializers/inflections.rb +0 -10
- data/spec/rails3_test_app/config/initializers/mime_types.rb +0 -5
- data/spec/rails3_test_app/config/initializers/secret_token.rb +0 -7
- data/spec/rails3_test_app/config/initializers/session_store.rb +0 -8
- data/spec/rails3_test_app/config/locales/en.yml +0 -5
- data/spec/rails3_test_app/config/routes.rb +0 -58
- data/spec/rails3_test_app/db/seeds.rb +0 -7
- data/spec/rails3_test_app/run_tests +0 -3
- data/spec/rails3_test_app/script/rails +0 -6
- data/spec/rails3_test_app/spec/spec_helper.rb +0 -27
- data/spec/rails3_test_app/spec/unit/rails_3_init.rb +0 -15
- data/spec/unit/association_proxy_spec.rb +0 -12
- data/spec/unit/base_delegate_spec.rb +0 -197
- data/spec/unit/base_delegate_to_spec.rb +0 -73
data/spec/unit/callback_spec.rb
CHANGED
@@ -3,12 +3,11 @@ require 'spec_helper'
|
|
3
3
|
describe ActiveFedora::Base do
|
4
4
|
before :all do
|
5
5
|
class CallbackStub < ActiveFedora::Base
|
6
|
-
has_metadata :type
|
7
|
-
m.field
|
8
|
-
m.field
|
6
|
+
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"someData" do |m|
|
7
|
+
m.field "fubar", :string
|
8
|
+
m.field "swank", :text
|
9
9
|
end
|
10
|
-
|
11
|
-
delegate :swank, :to => 'someData', multiple: true
|
10
|
+
has_attributes :fubar, :swank, datastream: 'someData', multiple: true
|
12
11
|
|
13
12
|
after_initialize :a_init
|
14
13
|
before_save :b_save
|
@@ -30,23 +29,23 @@ describe ActiveFedora::Base do
|
|
30
29
|
Object.send(:remove_const, :CallbackStub)
|
31
30
|
end
|
32
31
|
|
33
|
-
it
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
it "Should have after_initialize, before_save,after_save, before_create, after_create, after_update, before_update, before_destroy" do
|
33
|
+
CallbackStub.any_instance.should_receive(:a_init)
|
34
|
+
CallbackStub.any_instance.should_receive :b_create
|
35
|
+
CallbackStub.any_instance.should_receive :a_create
|
36
|
+
CallbackStub.any_instance.should_receive(:b_save)
|
37
|
+
CallbackStub.any_instance.should_receive(:a_save)
|
39
38
|
cb = CallbackStub.new :pid => 'test:123'
|
40
39
|
cb.save
|
41
40
|
end
|
42
|
-
it
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
it "Should have after_initialize, before_save,after_save, before_create, after_create, after_update, before_update, before_destroy" do
|
42
|
+
CallbackStub.any_instance.should_receive(:a_init)
|
43
|
+
CallbackStub.any_instance.should_receive(:b_save)
|
44
|
+
CallbackStub.any_instance.should_receive(:a_save)
|
45
|
+
CallbackStub.any_instance.should_receive(:a_find)
|
46
|
+
CallbackStub.any_instance.should_receive(:b_update)
|
47
|
+
CallbackStub.any_instance.should_receive(:a_update)
|
48
|
+
CallbackStub.any_instance.should_receive(:do_stuff)
|
50
49
|
|
51
50
|
cb2 = CallbackStub.find('test:123')
|
52
51
|
cb2.save
|
@@ -2,34 +2,34 @@ require 'spec_helper'
|
|
2
2
|
require 'config_helper'
|
3
3
|
|
4
4
|
describe ActiveFedora::FileConfigurator do
|
5
|
-
|
5
|
+
|
6
6
|
before :all do
|
7
7
|
class TestConfigurator
|
8
8
|
attr_reader :fedora_config, :solr_config, :predicate_config
|
9
|
-
|
9
|
+
|
10
10
|
def init(options = {})
|
11
11
|
@fedora_config = options[:fedora_config]
|
12
12
|
@solr_config = options[:solr_config]
|
13
13
|
@predicate_config = options[:predicate_config]
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
@config_params = {
|
18
18
|
:fedora_config => { :url => 'http://codeconfig.example.edu/fedora/', :user => 'fedoraAdmin', :password => 'configurator', :cert_file => '/path/to/cert/file' },
|
19
19
|
:solr_config => { :url => 'http://codeconfig.example.edu/solr/' },
|
20
|
-
:predicate_config => {
|
20
|
+
:predicate_config => {
|
21
21
|
:default_namespace => 'info:fedora/fedora-system:def/relations-external#',
|
22
22
|
:predicate_mapping => {
|
23
|
-
'info:fedora/fedora-system:def/relations-external#' => { :has_part => 'hasPart' }
|
23
|
+
'info:fedora/fedora-system:def/relations-external#' => { :has_part => 'hasPart' }
|
24
24
|
}
|
25
25
|
}
|
26
26
|
}
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
before :each do
|
30
30
|
ActiveFedora.configurator = TestConfigurator.new
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
after :all do
|
34
34
|
unstub_rails
|
35
35
|
# Restore to default fedora configs
|
@@ -37,15 +37,15 @@ describe ActiveFedora::FileConfigurator do
|
|
37
37
|
restore_spec_configuration
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
it "should initialize from code" do
|
41
|
+
YAMLAdaptor.should_receive(:load).never
|
42
|
+
File.should_receive(:exists?).never
|
43
|
+
File.should_receive(:read).never
|
44
|
+
File.should_receive(:open).never
|
45
45
|
ActiveFedora.init(@config_params)
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
ActiveFedora.fedora_config.credentials.should == @config_params[:fedora_config]
|
47
|
+
ActiveFedora.solr_config.should == @config_params[:solr_config]
|
48
|
+
ActiveFedora::Predicates.predicate_mappings['info:fedora/fedora-system:def/relations-external#'].length.should == 1
|
49
49
|
end
|
50
|
-
|
51
|
-
end
|
50
|
+
|
51
|
+
end
|
data/spec/unit/config_spec.rb
CHANGED
@@ -1,27 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::Config do
|
4
|
-
describe
|
4
|
+
describe "with a single fedora instance" do
|
5
5
|
conf = YAMLAdaptor.load(File.read('spec/fixtures/rails_root/config/fedora.yml'))['test']
|
6
6
|
subject { ActiveFedora::Config.new(conf) }
|
7
|
-
|
8
|
-
|
9
|
-
subject { super().credentials }
|
10
|
-
it { is_expected.to eq({:url => 'http://testhost.com:8983/fedora', :user => 'fedoraAdmin', :password => 'fedoraAdmin'})}
|
11
|
-
end
|
12
|
-
it { is_expected.not_to be_sharded }
|
7
|
+
its(:credentials) { should == {:url => 'http://testhost.com:8983/fedora', :user=> 'fedoraAdmin', :password=> 'fedoraAdmin'}}
|
8
|
+
it { should_not be_sharded }
|
13
9
|
end
|
14
|
-
describe
|
10
|
+
describe "with several fedora shards" do
|
15
11
|
conf = YAMLAdaptor.load(File.read('spec/fixtures/sharded_fedora.yml'))['test']
|
16
12
|
subject { ActiveFedora::Config.new(conf) }
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
{:url => 'http://127.0.0.1:8983/fedora2', :user => 'fedoraAdmin', :password => 'fedoraAdmin'},
|
22
|
-
{:url => 'http://127.0.0.1:8983/fedora3', :user => 'fedoraAdmin', :password => 'fedoraAdmin'}])}
|
23
|
-
end
|
24
|
-
it { is_expected.to be_sharded }
|
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 }
|
25
17
|
end
|
26
18
|
|
27
19
|
end
|
@@ -1,99 +1,118 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::ContentModel do
|
4
|
-
|
4
|
+
|
5
5
|
before(:all) do
|
6
6
|
class BaseModel < ActiveFedora::Base
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
class SampleModel < BaseModel
|
10
10
|
end
|
11
11
|
|
12
12
|
class GenericContent < ActiveFedora::Base
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
module Sample
|
16
16
|
class NamespacedModel < ActiveFedora::Base
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
before(:each) do
|
22
22
|
stub_get('__nextid__')
|
23
|
-
|
24
|
-
|
23
|
+
ActiveFedora::Base.stub(:assign_pid).and_return("__nextid__")
|
24
|
+
Rubydora::Repository.any_instance.stub(:client).and_return(@mock_client)
|
25
25
|
@test_cmodel = ActiveFedora::ContentModel.new
|
26
26
|
end
|
27
|
-
|
28
|
-
it
|
29
|
-
|
27
|
+
|
28
|
+
it "should provide #new" do
|
29
|
+
ActiveFedora::ContentModel.should respond_to(:new)
|
30
30
|
end
|
31
|
-
|
32
|
-
describe
|
33
|
-
it
|
34
|
-
|
31
|
+
|
32
|
+
describe "#new" do
|
33
|
+
it "should create a kind of ActiveFedora::Base object" do
|
34
|
+
@test_cmodel.should be_kind_of(ActiveFedora::Base)
|
35
35
|
end
|
36
|
-
it
|
37
|
-
|
38
|
-
boo_model = ActiveFedora::ContentModel.new(:pid_suffix =>
|
39
|
-
|
36
|
+
it "should set pid_suffix to empty string unless overriden in options hash" do
|
37
|
+
@test_cmodel.pid_suffix.should == ""
|
38
|
+
boo_model = ActiveFedora::ContentModel.new(:pid_suffix => "boo")
|
39
|
+
boo_model.pid_suffix.should == "boo"
|
40
40
|
end
|
41
|
-
it
|
42
|
-
|
43
|
-
boo_model = ActiveFedora::ContentModel.new(:namespace =>
|
44
|
-
|
41
|
+
it "should set namespace to cmodel unless overriden in options hash" do
|
42
|
+
@test_cmodel.namespace.should == "afmodel"
|
43
|
+
boo_model = ActiveFedora::ContentModel.new(:namespace => "boo")
|
44
|
+
boo_model.namespace.should == "boo"
|
45
45
|
end
|
46
46
|
end
|
47
|
-
|
48
|
-
it
|
49
|
-
|
50
|
-
|
47
|
+
|
48
|
+
it "should provide @pid_suffix" do
|
49
|
+
@test_cmodel.should respond_to(:pid_suffix)
|
50
|
+
@test_cmodel.should respond_to(:pid_suffix=)
|
51
51
|
end
|
52
|
+
|
53
|
+
describe '.best_model_for' do
|
54
|
+
it 'should be the input model if no relationships' do
|
55
|
+
mock_object = BaseModel.new
|
56
|
+
mock_object.should_receive(:relationships).with(:has_model).and_return([])
|
57
|
+
expect(ActiveFedora::ContentModel.best_model_for(mock_object)).to eq BaseModel
|
58
|
+
end
|
52
59
|
|
60
|
+
it 'should be based on inheritance hierarchy' do
|
61
|
+
mock_object = ActiveFedora::Base.new
|
62
|
+
mock_object.should_receive(:relationships).with(:has_model).and_return(["info:fedora/fedora-system:ServiceDefinition-3.0", 'info:fedora/afmodel:SampleModel', 'info:fedora/afmodel:BaseModel'])
|
63
|
+
expect(ActiveFedora::ContentModel.best_model_for(mock_object)).to eq SampleModel
|
64
|
+
end
|
53
65
|
|
54
|
-
|
55
|
-
|
56
|
-
mock_object
|
57
|
-
expect(
|
58
|
-
|
66
|
+
it 'should find the deepest descendant of the on inheritance hierarchy' do
|
67
|
+
mock_object = BaseModel.new
|
68
|
+
mock_object.should_receive(:relationships).with(:has_model).and_return(["info:fedora/fedora-system:ServiceDefinition-3.0", 'info:fedora/afmodel:SampleModel', 'info:fedora/afmodel:BaseModel'])
|
69
|
+
expect(ActiveFedora::ContentModel.best_model_for(mock_object)).to eq SampleModel
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "models_asserted_by" do
|
74
|
+
it "should return an array of all of the content models asserted by the given object" do
|
75
|
+
mock_object = double("ActiveFedora Object")
|
76
|
+
mock_object.should_receive(:relationships).with(:has_model).and_return(["info:fedora/fedora-system:ServiceDefinition-3.0", "info:fedora/afmodel:SampleModel", "info:fedora/afmodel:NonDefinedModel"])
|
77
|
+
ActiveFedora::ContentModel.models_asserted_by(mock_object).should == ["info:fedora/fedora-system:ServiceDefinition-3.0", "info:fedora/afmodel:SampleModel", "info:fedora/afmodel:NonDefinedModel"]
|
59
78
|
end
|
60
79
|
it "should return an empty array if the object doesn't have a RELS-EXT datastream" do
|
61
|
-
mock_object = double(
|
62
|
-
|
63
|
-
|
80
|
+
mock_object = double("ActiveFedora Object")
|
81
|
+
mock_object.should_receive(:relationships).with(:has_model).and_return([])
|
82
|
+
ActiveFedora::ContentModel.models_asserted_by(mock_object).should == []
|
64
83
|
end
|
65
84
|
end
|
66
|
-
|
67
|
-
describe
|
68
|
-
it
|
69
|
-
mock_object = double(
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
it
|
74
|
-
|
75
|
-
mock_object = double(
|
76
|
-
|
77
|
-
|
78
|
-
end
|
79
|
-
it
|
80
|
-
mock_object = double(
|
81
|
-
|
82
|
-
|
85
|
+
|
86
|
+
describe "known_models_asserted_by" do
|
87
|
+
it "should figure out the applicable models to load" do
|
88
|
+
mock_object = double("ActiveFedora Object")
|
89
|
+
mock_object.should_receive(:relationships).with(:has_model).and_return(["info:fedora/fedora-system:ServiceDefinition-3.0", "info:fedora/afmodel:SampleModel", "info:fedora/afmodel:NonDefinedModel"])
|
90
|
+
ActiveFedora::ContentModel.known_models_for(mock_object).should == [SampleModel]
|
91
|
+
end
|
92
|
+
it "should support namespaced models" do
|
93
|
+
pending "This is harder than it looks."
|
94
|
+
mock_object = double("ActiveFedora Object")
|
95
|
+
mock_object.should_receive(:relationships).with(:has_model).and_return(["info:fedora/afmodel:Sample_NamespacedModel"])
|
96
|
+
ActiveFedora::ContentModel.known_models_for(mock_object).should == [Sample::NamespacedModel]
|
97
|
+
end
|
98
|
+
it "should default to using ActiveFedora::Base as the model" do
|
99
|
+
mock_object = double("ActiveFedora Object")
|
100
|
+
mock_object.should_receive(:relationships).with(:has_model).and_return(["info:fedora/afmodel:NonDefinedModel"])
|
101
|
+
ActiveFedora::ContentModel.known_models_for(mock_object).should == [ActiveFedora::Base]
|
83
102
|
end
|
84
103
|
it "should still work even if the object doesn't have a RELS-EXT datastream" do
|
85
|
-
mock_object = double(
|
86
|
-
|
87
|
-
|
104
|
+
mock_object = double("ActiveFedora Object")
|
105
|
+
mock_object.should_receive(:relationships).with(:has_model).and_return([])
|
106
|
+
ActiveFedora::ContentModel.known_models_for(mock_object).should == [ActiveFedora::Base]
|
88
107
|
end
|
89
108
|
end
|
90
|
-
|
91
|
-
describe
|
92
|
-
it
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
109
|
+
|
110
|
+
describe "uri_to_model_class" do
|
111
|
+
it "should return an ActiveFedora Model class corresponding to the given uri if a valid model can be found" do
|
112
|
+
ActiveFedora::ContentModel.uri_to_model_class("info:fedora/afmodel:SampleModel").should == SampleModel
|
113
|
+
ActiveFedora::ContentModel.uri_to_model_class("info:fedora/afmodel:NonDefinedModel").should == false
|
114
|
+
ActiveFedora::ContentModel.uri_to_model_class("info:fedora/afmodel:String").should == false
|
115
|
+
ActiveFedora::ContentModel.uri_to_model_class("info:fedora/hydra-cModel:genericContent").should == GenericContent
|
97
116
|
end
|
98
117
|
end
|
99
118
|
|
@@ -3,177 +3,177 @@ require 'spec_helper'
|
|
3
3
|
describe ActiveFedora::DatastreamCollections do
|
4
4
|
describe '.has_datastream' do
|
5
5
|
before(:all) do
|
6
|
-
|
6
|
+
|
7
7
|
class MockHasDatastream < ActiveFedora::Base
|
8
8
|
include ActiveFedora::DatastreamCollections
|
9
|
-
has_datastream :name
|
10
|
-
has_datastream :name
|
11
|
-
has_datastream :name
|
9
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
10
|
+
has_datastream :name=>"EAD", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
|
11
|
+
has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
it 'should cache a definition of named datastream and create helper methods to add/remove/access them' do
|
16
16
|
@test_object2 = MockHasDatastream.new
|
17
17
|
#prefix should default to name in caps if not specified in has_datastream call
|
18
|
-
|
19
|
-
:type
|
20
|
-
:controlGroup
|
21
|
-
|
22
|
-
:type
|
23
|
-
:controlGroup
|
24
|
-
|
25
|
-
:type
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
18
|
+
@test_object2.named_datastreams_desc.should == {"thumbnail"=>{:name=>"thumbnail",:prefix => "THUMB",
|
19
|
+
:type=>"ActiveFedora::Datastream", :mimeType=>"image/jpeg",
|
20
|
+
:controlGroup=>'M'},
|
21
|
+
"EAD"=> {:name=>"EAD", :prefix=>"EAD",
|
22
|
+
:type=>"ActiveFedora::Datastream", :mimeType=>"application/xml",
|
23
|
+
:controlGroup=>'M' },
|
24
|
+
"external"=> {:name=>"external", :prefix=>"EXTERNAL",
|
25
|
+
:type=>"ActiveFedora::Datastream", :controlGroup=>'E' }}
|
26
|
+
@test_object2.should respond_to(:thumbnail_append)
|
27
|
+
@test_object2.should respond_to(:thumbnail_file_append)
|
28
|
+
@test_object2.should respond_to(:thumbnail)
|
29
|
+
@test_object2.should respond_to(:thumbnail_ids)
|
30
|
+
@test_object2.should respond_to(:ead_append)
|
31
|
+
@test_object2.should respond_to(:ead_file_append)
|
32
|
+
@test_object2.should respond_to(:EAD)
|
33
|
+
@test_object2.should respond_to(:EAD_ids)
|
34
|
+
@test_object2.should respond_to(:external)
|
35
|
+
@test_object2.should respond_to(:external_ids)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
describe '#datastream_names' do
|
39
39
|
before(:all) do
|
40
40
|
class MockDatastreamNames < ActiveFedora::Base
|
41
41
|
include ActiveFedora::DatastreamCollections
|
42
|
-
has_datastream :name
|
43
|
-
has_datastream :name
|
42
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
43
|
+
has_datastream :name=>"EAD", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
it 'should return a set of datastream names defined by has_datastream' do
|
48
48
|
@test_object2 = MockDatastreamNames.new
|
49
|
-
|
49
|
+
@test_object2.datastream_names.should include("thumbnail","EAD")
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
describe '#add_named_datastream' do
|
54
54
|
before(:all) do
|
55
55
|
class MockAddNamedDatastream < ActiveFedora::Base
|
56
56
|
include ActiveFedora::DatastreamCollections
|
57
|
-
has_datastream :name
|
58
|
-
has_datastream :name
|
59
|
-
has_datastream :name
|
60
|
-
has_datastream :name
|
57
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
58
|
+
has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
59
|
+
has_datastream :name=>"anymime", :type=>ActiveFedora::Datastream, :controlGroup=>'M'
|
60
|
+
has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
|
61
61
|
end
|
62
62
|
end
|
63
63
|
before do
|
64
64
|
|
65
65
|
@test_object2 = MockAddNamedDatastream.new
|
66
|
-
@f = File.new(File.join( File.dirname(__FILE__),
|
67
|
-
@f2 = File.new(File.join( File.dirname(__FILE__),
|
68
|
-
|
69
|
-
|
66
|
+
@f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
|
67
|
+
@f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
|
68
|
+
@f.stub(:content_type).and_return("image/jpeg")
|
69
|
+
@f2.stub(:original_filename).and_return("dino.jpg")
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
it 'cannot add a datastream with name that does not exist' do
|
73
|
-
expect { @test_object2.add_named_datastream(
|
73
|
+
expect { @test_object2.add_named_datastream("thumb",{:content_type=>"image/jpeg",:blob=>f}) }.to raise_error
|
74
74
|
end
|
75
75
|
|
76
|
-
it
|
77
|
-
@test_object2.add_named_datastream(
|
76
|
+
it "should accept a file blob" do
|
77
|
+
@test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:blob=>@f})
|
78
78
|
end
|
79
79
|
|
80
|
-
it
|
81
|
-
@test_object2.add_named_datastream(
|
80
|
+
it "should accept a file handle" do
|
81
|
+
@test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:file=>@f})
|
82
82
|
end
|
83
83
|
|
84
|
-
it
|
85
|
-
@test_object2.add_named_datastream(
|
84
|
+
it "should allow access to file content" do
|
85
|
+
@test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:file=>@f})
|
86
86
|
@test_object2.save!
|
87
87
|
@test_object2.thumbnail[0].content
|
88
88
|
end
|
89
89
|
|
90
|
-
it
|
91
|
-
expect { @test_object2.add_named_datastream(
|
90
|
+
it "should raise an error if neither a blob nor file is set" do
|
91
|
+
expect { @test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg"}) }.to raise_error
|
92
92
|
end
|
93
93
|
|
94
|
-
it
|
95
|
-
@test_object2.add_named_datastream(
|
96
|
-
|
94
|
+
it "should use the given label for the dsLabel" do
|
95
|
+
@test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>@f2, :label=>"my_image"})
|
96
|
+
@test_object2.high.first.dsLabel.should == "my_image"
|
97
97
|
end
|
98
98
|
|
99
|
-
it
|
100
|
-
@test_object2.add_named_datastream(
|
101
|
-
|
102
|
-
end
|
99
|
+
it "should fallback on using the file name" do
|
100
|
+
@test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>@f2})
|
101
|
+
@test_object2.high.first.dsLabel.should == "dino.jpg"
|
102
|
+
end
|
103
103
|
|
104
|
-
it
|
105
|
-
|
106
|
-
@test_object2.add_named_datastream(
|
104
|
+
it "should check the file for a content type" do
|
105
|
+
@f.should_receive(:content_type).and_return("image/jpeg")
|
106
|
+
@test_object2.add_named_datastream("thumbnail",{:file=>@f})
|
107
107
|
end
|
108
108
|
|
109
|
-
it
|
110
|
-
expect { @test_object2.add_named_datastream(
|
109
|
+
it "should raise an error if no content type is avialable" do
|
110
|
+
expect { @test_object2.add_named_datastream("thumbnail",{:file=>@f2}) }.to raise_error
|
111
111
|
end
|
112
112
|
|
113
|
-
it
|
114
|
-
|
115
|
-
expect { @test_object2.add_named_datastream(
|
113
|
+
it "should encsure mimetype and content type match" do
|
114
|
+
@f.stub(:content_type).and_return("image/tiff")
|
115
|
+
expect { @test_object2.add_named_datastream("thumbnail",{:file=>f}) }.to raise_error
|
116
116
|
end
|
117
|
-
|
118
|
-
it
|
117
|
+
|
118
|
+
it "should allow any mime type" do
|
119
119
|
#check for if any mime type allowed
|
120
|
-
@test_object2.add_named_datastream(
|
120
|
+
@test_object2.add_named_datastream("anymime",{:file=>@f})
|
121
121
|
#check datastream created is of type ActiveFedora::Datastream
|
122
|
-
|
122
|
+
@test_object2.anymime.first.class.should == ActiveFedora::Datastream
|
123
123
|
end
|
124
124
|
|
125
|
-
it
|
125
|
+
it "should cgecj that a dsid forms to the prefix" do
|
126
126
|
#if dsid supplied check that conforms to prefix
|
127
|
-
|
128
|
-
expect { @test_object2.add_named_datastream(
|
127
|
+
@f.stub(:content_type).and_return("image/jpeg")
|
128
|
+
expect { @test_object2.add_named_datastream("thumbnail",{:file=>@f,:dsid=>"DS1"}) }.to raise_error
|
129
129
|
end
|
130
130
|
|
131
|
-
it
|
132
|
-
@test_object2.add_named_datastream(
|
131
|
+
it "should have the right properties" do
|
132
|
+
@test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>@f2})
|
133
133
|
#if prefix not set check uses name in CAPS and dsid uses prefix
|
134
134
|
#@test_object2.high.first.attributes[:prefix].should == "HIGH"
|
135
135
|
@test_object2.high.first.dsid.match(/HIGH[0-9]/)
|
136
136
|
#check datastreams added with other right properties
|
137
|
-
|
137
|
+
@test_object2.high.first.controlGroup.should == "M"
|
138
138
|
end
|
139
139
|
|
140
|
-
it
|
141
|
-
|
140
|
+
it "should work with external datastreams" do
|
141
|
+
|
142
142
|
#check external datastream
|
143
|
-
@test_object2.add_named_datastream(
|
143
|
+
@test_object2.add_named_datastream("external",{:dsLocation=>"http://myreasource.com"})
|
144
144
|
#check dslocation goes to dslabel
|
145
|
-
|
145
|
+
@test_object2.external.first.dsLabel.should == "http://myreasource.com"
|
146
146
|
#check datastreams added to fedora (may want to stub this at first)
|
147
147
|
end
|
148
148
|
end
|
149
|
-
|
149
|
+
|
150
150
|
describe '#add_named_file_datastream' do
|
151
151
|
before do
|
152
152
|
class MockAddNamedFileDatastream < ActiveFedora::Base
|
153
153
|
include ActiveFedora::DatastreamCollections
|
154
|
-
has_datastream :name
|
155
|
-
has_datastream :name
|
156
|
-
has_datastream :name
|
154
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
155
|
+
has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
156
|
+
has_datastream :name=>"anymime", :type=>ActiveFedora::Datastream, :controlGroup=>'M'
|
157
157
|
end
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
it 'should add a datastream as controlGroup M with blob set to file' do
|
161
161
|
@test_object2 = MockAddNamedFileDatastream.new
|
162
|
-
f = File.new(File.join( File.dirname(__FILE__),
|
162
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
|
163
163
|
#these normally supplied in multi-part post request
|
164
|
-
|
165
|
-
|
166
|
-
@test_object2.add_named_file_datastream(
|
164
|
+
f.stub(:original_filename).and_return("minivan.jpg")
|
165
|
+
f.stub(:content_type).and_return("image/jpeg")
|
166
|
+
@test_object2.add_named_file_datastream("thumbnail",f)
|
167
167
|
thumb = @test_object2.thumbnail.first
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
168
|
+
thumb.class.should == ActiveFedora::Datastream
|
169
|
+
thumb.mimeType.should == "image/jpeg"
|
170
|
+
thumb.dsid.should == "THUMB1"
|
171
|
+
thumb.controlGroup.should == "M"
|
172
|
+
thumb.dsLabel.should == "minivan.jpg"
|
173
173
|
#thumb.name.should == "thumbnail"
|
174
|
-
# :prefix=>"THUMB", :content_type=>"image/jpeg", :dsid=>"THUMB1", :dsID=>"THUMB1",
|
174
|
+
# :prefix=>"THUMB", :content_type=>"image/jpeg", :dsid=>"THUMB1", :dsID=>"THUMB1",
|
175
175
|
# :pid=>@test_object2.pid, :mimeType=>"image/jpeg", :controlGroup=>"M", :dsLabel=>"minivan.jpg", :name=>"thumbnail"}
|
176
|
-
|
176
|
+
|
177
177
|
end
|
178
178
|
end
|
179
179
|
|
@@ -181,72 +181,72 @@ describe ActiveFedora::DatastreamCollections do
|
|
181
181
|
before do
|
182
182
|
class MockUpdateNamedDatastream < ActiveFedora::Base
|
183
183
|
include ActiveFedora::DatastreamCollections
|
184
|
-
has_datastream :name
|
184
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
185
185
|
end
|
186
186
|
end
|
187
|
-
|
187
|
+
|
188
188
|
it 'should update a datastream and not increment the dsid' do
|
189
189
|
@test_object2 = MockUpdateNamedDatastream.new
|
190
|
-
f = File.new(File.join( File.dirname(__FILE__),
|
191
|
-
f2 = File.new(File.join( File.dirname(__FILE__),
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
190
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
|
191
|
+
f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
|
192
|
+
f.stub(:content_type).and_return("image/jpeg")
|
193
|
+
f.stub(:original_filename).and_return("minivan.jpg")
|
194
|
+
f2.stub(:content_type).and_return("image/jpeg")
|
195
|
+
f2.stub(:original_filename).and_return("dino.jpg")
|
196
196
|
#check raise exception if dsid not supplied
|
197
|
-
@test_object2.add_named_datastream(
|
197
|
+
@test_object2.add_named_datastream("thumbnail",{:file=>f})
|
198
198
|
had_exception = false
|
199
199
|
begin
|
200
|
-
@test_object2.update_named_datastream(
|
200
|
+
@test_object2.update_named_datastream("thumbnail",{:file=>f})
|
201
201
|
rescue
|
202
202
|
had_exception = true
|
203
203
|
end
|
204
|
-
raise
|
204
|
+
raise "Failed to raise exception if dsid not supplied" unless had_exception
|
205
205
|
#raise exception if dsid does not exist
|
206
206
|
had_exception = false
|
207
207
|
begin
|
208
|
-
@test_object2.update_named_datastream(
|
208
|
+
@test_object2.update_named_datastream("thumbnail",{:file=>f,:dsid=>"THUMB100"})
|
209
209
|
rescue
|
210
210
|
had_exception = true
|
211
211
|
end
|
212
|
-
raise
|
213
|
-
#check datastream is updated in place without new dsid
|
214
|
-
|
215
|
-
@test_object2.thumbnail_ids == [
|
212
|
+
raise "Failed to raise exception if dsid does not exist" unless had_exception
|
213
|
+
#check datastream is updated in place without new dsid
|
214
|
+
@test_object2.thumbnail.size.should == 1
|
215
|
+
@test_object2.thumbnail_ids == ["THUMB1"]
|
216
216
|
thumb1 = @test_object2.thumbnail.first
|
217
|
-
|
218
|
-
|
219
|
-
|
217
|
+
thumb1.dsid.should == 'THUMB1'
|
218
|
+
thumb1.pid.should == @test_object2.pid
|
219
|
+
thumb1.dsLabel.should == 'minivan.jpg'
|
220
220
|
f.rewind
|
221
|
-
@test_object2.update_named_datastream(
|
222
|
-
|
223
|
-
@test_object2.thumbnail_ids == [
|
221
|
+
@test_object2.update_named_datastream("thumbnail",{:file=>f2,:dsid=>"THUMB1"})
|
222
|
+
@test_object2.thumbnail.size.should == 1
|
223
|
+
@test_object2.thumbnail_ids == ["THUMB1"]
|
224
224
|
# @test_object2.thumbnail.first.attributes.should == {:type=>"ActiveFedora::Datastream",
|
225
|
-
# :content_type=>"image/jpeg",
|
226
|
-
# :prefix=>"THUMB", :mimeType=>"image/jpeg",
|
227
|
-
# :controlGroup=>"M", :dsid=>"THUMB1",
|
228
|
-
# :pid=>@test_object2.pid, :dsID=>"THUMB1",
|
225
|
+
# :content_type=>"image/jpeg",
|
226
|
+
# :prefix=>"THUMB", :mimeType=>"image/jpeg",
|
227
|
+
# :controlGroup=>"M", :dsid=>"THUMB1",
|
228
|
+
# :pid=>@test_object2.pid, :dsID=>"THUMB1",
|
229
229
|
# :name=>"thumbnail", :dsLabel=>"dino.jpg"}
|
230
230
|
thumb1 = @test_object2.thumbnail.first
|
231
|
-
|
232
|
-
|
233
|
-
|
231
|
+
thumb1.dsid.should == 'THUMB1'
|
232
|
+
thumb1.pid.should == @test_object2.pid
|
233
|
+
thumb1.dsLabel.should == 'dino.jpg'
|
234
234
|
end
|
235
235
|
end
|
236
236
|
describe '#named_datastreams_desc' do
|
237
|
-
|
237
|
+
|
238
238
|
before do
|
239
239
|
class MockNamedDatastreamsDesc < ActiveFedora::Base
|
240
240
|
include ActiveFedora::DatastreamCollections
|
241
|
-
has_datastream :name
|
241
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
242
242
|
end
|
243
243
|
end
|
244
|
-
|
244
|
+
|
245
245
|
it 'should intialize a value to an empty hash and then not modify afterward' do
|
246
246
|
@test_object2 = MockNamedDatastreamsDesc.new
|
247
|
-
|
248
|
-
:type
|
249
|
-
:controlGroup
|
247
|
+
@test_object2.named_datastreams_desc.should == {"thumbnail"=>{:name=>"thumbnail",:prefix => "THUMB",
|
248
|
+
:type=>"ActiveFedora::Datastream", :mimeType=>"image/jpeg",
|
249
|
+
:controlGroup=>'M'}}
|
250
250
|
end
|
251
251
|
end
|
252
252
|
|
@@ -254,166 +254,166 @@ describe ActiveFedora::DatastreamCollections do
|
|
254
254
|
before do
|
255
255
|
class MockIsNamedDatastream < ActiveFedora::Base
|
256
256
|
include ActiveFedora::DatastreamCollections
|
257
|
-
has_datastream :name
|
257
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
258
258
|
end
|
259
259
|
end
|
260
|
-
|
260
|
+
|
261
261
|
it 'should return true if a named datastream exists in model' do
|
262
262
|
@test_object2 = MockIsNamedDatastream.new
|
263
|
-
|
264
|
-
|
263
|
+
@test_object2.is_named_datastream?("thumbnail").should == true
|
264
|
+
@test_object2.is_named_datastream?("thumb").should == false
|
265
265
|
end
|
266
266
|
end
|
267
|
-
|
268
|
-
|
267
|
+
|
268
|
+
|
269
269
|
describe '#named_datastreams' do
|
270
270
|
before do
|
271
271
|
class MockNamedDatastreams < ActiveFedora::Base
|
272
272
|
include ActiveFedora::DatastreamCollections
|
273
|
-
has_datastream :name
|
274
|
-
has_datastream :name
|
275
|
-
has_datastream :name
|
273
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
274
|
+
has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
275
|
+
has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
|
276
276
|
end
|
277
277
|
end
|
278
|
-
|
278
|
+
|
279
279
|
it 'should return a hash of datastream names to arrays of datastreams' do
|
280
280
|
@test_object2 = MockNamedDatastreams.new
|
281
|
-
f = File.new(File.join( File.dirname(__FILE__),
|
282
|
-
|
283
|
-
|
284
|
-
f2 = File.new(File.join( File.dirname(__FILE__),
|
285
|
-
|
286
|
-
|
281
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg" ))
|
282
|
+
f.stub(:content_type).and_return("image/jpeg")
|
283
|
+
f.stub(:original_filename).and_return("minivan.jpg")
|
284
|
+
f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
|
285
|
+
f2.stub(:content_type).and_return("image/jpeg")
|
286
|
+
f2.stub(:original_filename).and_return("dino.jpg")
|
287
287
|
@test_object2.thumbnail_file_append(f)
|
288
288
|
@test_object2.high_file_append(f2)
|
289
|
-
@test_object2.external_append({:dsLocation
|
289
|
+
@test_object2.external_append({:dsLocation=>"http://myresource.com"})
|
290
290
|
datastreams = @test_object2.named_datastreams
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
291
|
+
datastreams.keys.include?("thumbnail").should == true
|
292
|
+
datastreams.keys.include?("external").should == true
|
293
|
+
datastreams.keys.include?("high").should == true
|
294
|
+
datastreams.keys.size.should == 3
|
295
|
+
datastreams["thumbnail"].size.should == 1
|
296
|
+
datastreams["thumbnail"].first.dsid.should == 'THUMB1'
|
297
|
+
datastreams["thumbnail"].first.dsLabel.should == 'minivan.jpg'
|
298
|
+
datastreams["thumbnail"].first.controlGroup.should == "M"
|
299
|
+
|
300
|
+
datastreams["external"].size.should == 1
|
301
|
+
datastreams["external"].first.dsid.should == "EXTERNAL1"
|
302
|
+
datastreams["external"].first.dsLocation.should == "http://myresource.com"
|
303
|
+
datastreams["external"].first.controlGroup.should == "E"
|
304
|
+
datastreams["external"].first.content.should == ""
|
305
|
+
|
306
|
+
datastreams["high"].size.should == 1
|
307
|
+
datastreams["high"].first.dsLabel.should == 'dino.jpg'
|
308
|
+
datastreams["high"].first.controlGroup.should == "M"
|
309
|
+
datastreams["high"].first.dsid.should == "HIGH1"
|
310
310
|
end
|
311
311
|
end
|
312
|
-
|
313
|
-
|
314
|
-
|
312
|
+
|
313
|
+
|
314
|
+
|
315
315
|
describe '#named_datastreams_ids' do
|
316
316
|
before do
|
317
317
|
class MockNamedDatastreamsIds < ActiveFedora::Base
|
318
318
|
include ActiveFedora::DatastreamCollections
|
319
|
-
has_datastream :name
|
320
|
-
has_datastream :name
|
321
|
-
has_datastream :name
|
319
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
320
|
+
has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
321
|
+
has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
|
322
322
|
end
|
323
323
|
end
|
324
|
-
|
324
|
+
|
325
325
|
it 'should provide a hash of datastreams names to array of datastream ids' do
|
326
326
|
@test_object2 = MockNamedDatastreamsIds.new
|
327
|
-
f = File.new(File.join( File.dirname(__FILE__),
|
328
|
-
|
329
|
-
|
330
|
-
f2 = File.new(File.join( File.dirname(__FILE__),
|
331
|
-
|
332
|
-
|
327
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg" ))
|
328
|
+
f.stub(:content_type).and_return("image/jpeg")
|
329
|
+
f.stub(:original_filename).and_return("minivan.jpg")
|
330
|
+
f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
|
331
|
+
f2.stub(:content_type).and_return("image/jpeg")
|
332
|
+
f2.stub(:original_filename).and_return("dino.jpg")
|
333
333
|
@test_object2.thumbnail_file_append(f)
|
334
334
|
@test_object2.high_file_append(f2)
|
335
|
-
@test_object2.external_append({:dsLocation
|
336
|
-
|
335
|
+
@test_object2.external_append({:dsLocation=>"http://myresource.com"})
|
336
|
+
@test_object2.named_datastreams_ids.should == {"thumbnail"=>["THUMB1"],"high"=>["HIGH1"],"external"=>["EXTERNAL1"]}
|
337
337
|
end
|
338
338
|
end
|
339
|
-
|
340
|
-
|
339
|
+
|
340
|
+
|
341
341
|
describe '#create_named_datastream_finders' do
|
342
342
|
before do
|
343
343
|
class MockCreateNamedDatastreamFinder < ActiveFedora::Base
|
344
344
|
include ActiveFedora::DatastreamCollections
|
345
|
-
has_datastream :name
|
346
|
-
has_datastream :name
|
345
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
346
|
+
has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
347
347
|
end
|
348
348
|
end
|
349
|
-
|
349
|
+
|
350
350
|
it 'should create helper methods to get named datastreams or dsids' do
|
351
351
|
@test_object2 = MockCreateNamedDatastreamFinder.new
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
f = File.new(File.join( File.dirname(__FILE__),
|
357
|
-
f2 = File.new(File.join( File.dirname(__FILE__),
|
358
|
-
|
359
|
-
|
360
|
-
@test_object2.add_named_datastream(
|
361
|
-
@test_object2.add_named_datastream(
|
362
|
-
@test_object2.add_named_datastream(
|
352
|
+
@test_object2.should respond_to(:thumbnail)
|
353
|
+
@test_object2.should respond_to(:thumbnail_ids)
|
354
|
+
@test_object2.should respond_to(:high)
|
355
|
+
@test_object2.should respond_to(:high_ids)
|
356
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
|
357
|
+
f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
|
358
|
+
f2.stub(:original_filename).and_return("dino.jpg")
|
359
|
+
f.stub(:content_type).and_return("image/jpeg")
|
360
|
+
@test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:blob=>f, :label=>"testDS"})
|
361
|
+
@test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>f2})
|
362
|
+
@test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>f2})
|
363
363
|
t2_thumb1 = @test_object2.thumbnail.first
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
# :type=>"ActiveFedora::Datastream",
|
370
|
-
# :prefix=>"THUMB", :content_type=>"image/jpeg", :dsid=>"THUMB1", :dsID=>"THUMB1",
|
364
|
+
t2_thumb1.mimeType.should == "image/jpeg"
|
365
|
+
t2_thumb1.controlGroup.should == "M"
|
366
|
+
t2_thumb1.dsLabel.should == "testDS"
|
367
|
+
t2_thumb1.pid.should == @test_object2.pid
|
368
|
+
t2_thumb1.dsid.should == "THUMB1"
|
369
|
+
# :type=>"ActiveFedora::Datastream",
|
370
|
+
# :prefix=>"THUMB", :content_type=>"image/jpeg", :dsid=>"THUMB1", :dsID=>"THUMB1",
|
371
371
|
# :pid=>@test_object2.pid, :mimeType=>"image/jpeg", :controlGroup=>"M", :dsLabel=>"testDS", :name=>"thumbnail", :label=>"testDS"}
|
372
|
-
|
373
|
-
@test_object2.high_ids.include?(
|
374
|
-
@test_object2.high_ids.include?(
|
375
|
-
|
372
|
+
@test_object2.thumbnail_ids.should == ["THUMB1"]
|
373
|
+
@test_object2.high_ids.include?("HIGH1") == true
|
374
|
+
@test_object2.high_ids.include?("HIGH2") == true
|
375
|
+
@test_object2.high_ids.size.should == 2
|
376
376
|
#just check returning datastream object at this point
|
377
|
-
|
377
|
+
@test_object2.high.first.class.should == ActiveFedora::Datastream
|
378
378
|
end
|
379
379
|
end
|
380
|
-
|
380
|
+
|
381
381
|
describe '#create_named_datastream_update_methods' do
|
382
382
|
before do
|
383
383
|
class MockCreateNamedDatastreamUpdateMethods < ActiveFedora::Base
|
384
384
|
include ActiveFedora::DatastreamCollections
|
385
|
-
has_datastream :name
|
386
|
-
has_datastream :name
|
387
|
-
has_datastream :name
|
385
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
386
|
+
has_datastream :name=>"EAD", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
|
387
|
+
has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
|
388
388
|
end
|
389
389
|
end
|
390
|
-
|
390
|
+
|
391
391
|
it 'should create append method for each has_datastream entry' do
|
392
392
|
@test_object2 = MockCreateNamedDatastreamUpdateMethods.new
|
393
393
|
@test_object3 = MockCreateNamedDatastreamUpdateMethods.new
|
394
|
-
|
395
|
-
|
396
|
-
f = File.new(File.join( File.dirname(__FILE__),
|
397
|
-
|
398
|
-
|
394
|
+
@test_object2.should respond_to(:thumbnail_append)
|
395
|
+
@test_object2.should respond_to(:ead_append)
|
396
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
|
397
|
+
f.stub(:content_type).and_return("image/jpeg")
|
398
|
+
f.stub(:original_filename).and_return("minivan.jpg")
|
399
399
|
@test_object2.thumbnail_file_append(f)
|
400
400
|
t2_thumb1 = @test_object2.thumbnail.first
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
@test_object3.thumbnail_append({:file
|
401
|
+
t2_thumb1.mimeType.should == "image/jpeg"
|
402
|
+
t2_thumb1.dsLabel.should == "minivan.jpg"
|
403
|
+
t2_thumb1.pid.should == @test_object2.pid
|
404
|
+
t2_thumb1.dsid.should == "THUMB1"
|
405
|
+
@test_object3.thumbnail_append({:file=>f})
|
406
406
|
t3_thumb1 = @test_object3.thumbnail.first
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
@test_object3.external_append({:dsLocation
|
407
|
+
t3_thumb1.mimeType.should == "image/jpeg"
|
408
|
+
t3_thumb1.dsLabel.should == "minivan.jpg"
|
409
|
+
t3_thumb1.pid.should == @test_object3.pid
|
410
|
+
t3_thumb1.dsid.should == "THUMB1"
|
411
|
+
@test_object3.external_append({:dsLocation=>"http://myresource.com"})
|
412
412
|
t3_external1 = @test_object3.external.first
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
413
|
+
t3_external1.dsLabel.should == "http://myresource.com"
|
414
|
+
t3_external1.dsLocation.should == "http://myresource.com"
|
415
|
+
t3_external1.pid.should == @test_object3.pid
|
416
|
+
t3_external1.dsid.should == "EXTERNAL1"
|
417
417
|
t3_external1.controlGroup == 'E'
|
418
418
|
end
|
419
419
|
end
|