active-fedora 6.7.8 → 6.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +938 -0
- data/.travis.yml +5 -6
- data/Gemfile +3 -1
- data/Rakefile +7 -5
- data/active-fedora.gemspec +7 -8
- data/lib/active_fedora/om_datastream.rb +1 -0
- data/lib/active_fedora/rdf_xml_writer.rb +31 -62
- data/lib/active_fedora/version.rb +1 -1
- data/spec/config_helper.rb +14 -14
- data/spec/integration/associations_spec.rb +232 -232
- data/spec/integration/attributes_spec.rb +11 -12
- data/spec/integration/auditable_spec.rb +10 -10
- data/spec/integration/base_spec.rb +163 -163
- data/spec/integration/bug_spec.rb +7 -7
- 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/delegating_spec.rb +14 -14
- data/spec/integration/delete_all_spec.rb +38 -42
- data/spec/integration/fedora_solr_sync_spec.rb +5 -5
- data/spec/integration/full_featured_model_spec.rb +101 -101
- data/spec/integration/has_many_associations_spec.rb +24 -24
- data/spec/integration/model_spec.rb +30 -30
- data/spec/integration/nested_attribute_spec.rb +41 -41
- data/spec/integration/ntriples_datastream_spec.rb +107 -107
- data/spec/integration/om_datastream_spec.rb +67 -67
- data/spec/integration/persistence_spec.rb +6 -6
- data/spec/integration/rdf_nested_attributes_spec.rb +56 -56
- data/spec/integration/relation_delegation_spec.rb +24 -26
- data/spec/integration/rels_ext_datastream_spec.rb +20 -20
- data/spec/integration/scoped_query_spec.rb +40 -41
- data/spec/integration/solr_instance_loader_spec.rb +4 -4
- data/spec/integration/solr_service_spec.rb +46 -46
- data/spec/rails3_test_app/config/application.rb +1 -1
- data/spec/rails3_test_app/config/environments/development.rb +0 -1
- data/spec/rails3_test_app/config/environments/production.rb +1 -1
- data/spec/rails3_test_app/spec/spec_helper.rb +3 -3
- data/spec/rails3_test_app/spec/unit/rails_3_init.rb +4 -4
- 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 +7 -11
- data/spec/support/an_active_model.rb +2 -2
- data/spec/support/mock_fedora.rb +16 -17
- data/spec/unit/active_fedora_spec.rb +58 -58
- data/spec/unit/association_proxy_spec.rb +5 -7
- data/spec/unit/base_active_model_spec.rb +25 -26
- data/spec/unit/base_cma_spec.rb +5 -5
- data/spec/unit/base_datastream_management_spec.rb +27 -27
- data/spec/unit/base_delegate_spec.rb +80 -82
- data/spec/unit/base_delegate_to_spec.rb +37 -39
- data/spec/unit/base_extra_spec.rb +48 -48
- data/spec/unit/base_spec.rb +300 -300
- data/spec/unit/callback_spec.rb +19 -19
- data/spec/unit/code_configurator_spec.rb +17 -17
- data/spec/unit/config_spec.rb +16 -8
- data/spec/unit/content_model_spec.rb +60 -60
- data/spec/unit/datastream_collections_spec.rb +229 -229
- data/spec/unit/datastream_spec.rb +57 -54
- data/spec/unit/datastreams_spec.rb +77 -77
- data/spec/unit/file_configurator_spec.rb +217 -217
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +26 -26
- data/spec/unit/has_many_collection_spec.rb +9 -9
- data/spec/unit/inheritance_spec.rb +12 -13
- data/spec/unit/model_spec.rb +41 -51
- data/spec/unit/nom_datastream_spec.rb +15 -15
- data/spec/unit/ntriples_datastream_spec.rb +112 -112
- data/spec/unit/om_datastream_spec.rb +233 -227
- data/spec/unit/persistence_spec.rb +6 -6
- data/spec/unit/predicates_spec.rb +73 -73
- data/spec/unit/property_spec.rb +9 -17
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +33 -33
- data/spec/unit/query_spec.rb +188 -217
- data/spec/unit/rdf_datastream_spec.rb +28 -21
- data/spec/unit/rdf_list_nested_attributes_spec.rb +34 -34
- data/spec/unit/rdf_list_spec.rb +80 -104
- 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 +75 -69
- 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 +59 -59
- 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 +27 -28
- data/spec/unit/solr_digital_object_spec.rb +21 -21
- data/spec/unit/solr_service_spec.rb +81 -81
- data/spec/unit/unsaved_digital_object_spec.rb +20 -20
- data/spec/unit/validations_spec.rb +21 -21
- metadata +70 -58
- data/gemfiles/gemfile.rails3 +0 -11
- data/gemfiles/gemfile.rails4 +0 -10
data/spec/unit/callback_spec.rb
CHANGED
@@ -3,12 +3,12 @@ require 'spec_helper'
|
|
3
3
|
describe ActiveFedora::Base do
|
4
4
|
before :all do
|
5
5
|
class CallbackStub < ActiveFedora::Base
|
6
|
-
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>
|
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
|
-
delegate :fubar, :to=>'someData', multiple: true
|
11
|
-
delegate :swank, :to=>'someData', multiple: true
|
10
|
+
delegate :fubar, :to => 'someData', multiple: true
|
11
|
+
delegate :swank, :to => 'someData', multiple: true
|
12
12
|
|
13
13
|
after_initialize :a_init
|
14
14
|
before_save :b_save
|
@@ -30,23 +30,23 @@ describe ActiveFedora::Base do
|
|
30
30
|
Object.send(:remove_const, :CallbackStub)
|
31
31
|
end
|
32
32
|
|
33
|
-
it
|
34
|
-
CallbackStub.
|
35
|
-
CallbackStub.
|
36
|
-
CallbackStub.
|
37
|
-
CallbackStub.
|
38
|
-
CallbackStub.
|
33
|
+
it 'Should have after_initialize, before_save,after_save, before_create, after_create, after_update, before_update, before_destroy' do
|
34
|
+
expect_any_instance_of(CallbackStub).to receive(:a_init)
|
35
|
+
expect_any_instance_of(CallbackStub).to receive :b_create
|
36
|
+
expect_any_instance_of(CallbackStub).to receive :a_create
|
37
|
+
expect_any_instance_of(CallbackStub).to receive(:b_save)
|
38
|
+
expect_any_instance_of(CallbackStub).to receive(:a_save)
|
39
39
|
cb = CallbackStub.new :pid => 'test:123'
|
40
40
|
cb.save
|
41
41
|
end
|
42
|
-
it
|
43
|
-
CallbackStub.
|
44
|
-
CallbackStub.
|
45
|
-
CallbackStub.
|
46
|
-
CallbackStub.
|
47
|
-
CallbackStub.
|
48
|
-
CallbackStub.
|
49
|
-
CallbackStub.
|
42
|
+
it 'Should have after_initialize, before_save,after_save, before_create, after_create, after_update, before_update, before_destroy' do
|
43
|
+
expect_any_instance_of(CallbackStub).to receive(:a_init)
|
44
|
+
expect_any_instance_of(CallbackStub).to receive(:b_save)
|
45
|
+
expect_any_instance_of(CallbackStub).to receive(:a_save)
|
46
|
+
expect_any_instance_of(CallbackStub).to receive(:a_find)
|
47
|
+
expect_any_instance_of(CallbackStub).to receive(:b_update)
|
48
|
+
expect_any_instance_of(CallbackStub).to receive(:a_update)
|
49
|
+
expect_any_instance_of(CallbackStub).to receive(:do_stuff)
|
50
50
|
|
51
51
|
cb2 = CallbackStub.find('test:123')
|
52
52
|
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
|
-
YAMLAdaptor.
|
42
|
-
File.
|
43
|
-
File.
|
44
|
-
File.
|
40
|
+
it 'should initialize from code' do
|
41
|
+
expect(YAMLAdaptor).to receive(:load).never
|
42
|
+
expect(File).to receive(:exists?).never
|
43
|
+
expect(File).to receive(:read).never
|
44
|
+
expect(File).to receive(:open).never
|
45
45
|
ActiveFedora.init(@config_params)
|
46
|
-
ActiveFedora.fedora_config.credentials.
|
47
|
-
ActiveFedora.solr_config.
|
48
|
-
ActiveFedora::Predicates.predicate_mappings['info:fedora/fedora-system:def/relations-external#'].length.
|
46
|
+
expect(ActiveFedora.fedora_config.credentials).to eq(@config_params[:fedora_config])
|
47
|
+
expect(ActiveFedora.solr_config).to eq(@config_params[:solr_config])
|
48
|
+
expect(ActiveFedora::Predicates.predicate_mappings['info:fedora/fedora-system:def/relations-external#'].length).to eq(1)
|
49
49
|
end
|
50
|
-
|
51
|
-
end
|
50
|
+
|
51
|
+
end
|
data/spec/unit/config_spec.rb
CHANGED
@@ -1,19 +1,27 @@
|
|
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
|
-
|
7
|
+
|
8
|
+
describe '#credentials' do
|
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 }
|
9
13
|
end
|
10
|
-
describe
|
14
|
+
describe 'with several fedora shards' do
|
11
15
|
conf = YAMLAdaptor.load(File.read('spec/fixtures/sharded_fedora.yml'))['test']
|
12
16
|
subject { ActiveFedora::Config.new(conf) }
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
|
18
|
+
describe '#credentials' do
|
19
|
+
subject { super().credentials }
|
20
|
+
it { is_expected.to eq([{:url => 'http://127.0.0.1:8983/fedora1', :user => 'fedoraAdmin', :password => 'fedoraAdmin'},
|
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 }
|
17
25
|
end
|
18
26
|
|
19
27
|
end
|
@@ -1,99 +1,99 @@
|
|
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
|
-
ActiveFedora::Base.
|
24
|
-
Rubydora::Repository.
|
23
|
+
allow(ActiveFedora::Base).to receive(:assign_pid).and_return('__nextid__')
|
24
|
+
allow_any_instance_of(Rubydora::Repository).to receive(:client).and_return(@mock_client)
|
25
25
|
@test_cmodel = ActiveFedora::ContentModel.new
|
26
26
|
end
|
27
|
-
|
28
|
-
it
|
29
|
-
ActiveFedora::ContentModel.
|
27
|
+
|
28
|
+
it 'should provide #new' do
|
29
|
+
expect(ActiveFedora::ContentModel).to respond_to(:new)
|
30
30
|
end
|
31
|
-
|
32
|
-
describe
|
33
|
-
it
|
34
|
-
@test_cmodel.
|
31
|
+
|
32
|
+
describe '#new' do
|
33
|
+
it 'should create a kind of ActiveFedora::Base object' do
|
34
|
+
expect(@test_cmodel).to be_kind_of(ActiveFedora::Base)
|
35
35
|
end
|
36
|
-
it
|
37
|
-
@test_cmodel.pid_suffix.
|
38
|
-
boo_model = ActiveFedora::ContentModel.new(:pid_suffix =>
|
39
|
-
boo_model.pid_suffix.
|
36
|
+
it 'should set pid_suffix to empty string unless overriden in options hash' do
|
37
|
+
expect(@test_cmodel.pid_suffix).to eq('')
|
38
|
+
boo_model = ActiveFedora::ContentModel.new(:pid_suffix => 'boo')
|
39
|
+
expect(boo_model.pid_suffix).to eq('boo')
|
40
40
|
end
|
41
|
-
it
|
42
|
-
@test_cmodel.namespace.
|
43
|
-
boo_model = ActiveFedora::ContentModel.new(:namespace =>
|
44
|
-
boo_model.namespace.
|
41
|
+
it 'should set namespace to cmodel unless overriden in options hash' do
|
42
|
+
expect(@test_cmodel.namespace).to eq('afmodel')
|
43
|
+
boo_model = ActiveFedora::ContentModel.new(:namespace => 'boo')
|
44
|
+
expect(boo_model.namespace).to eq('boo')
|
45
45
|
end
|
46
46
|
end
|
47
|
-
|
48
|
-
it
|
49
|
-
@test_cmodel.
|
50
|
-
@test_cmodel.
|
47
|
+
|
48
|
+
it 'should provide @pid_suffix' do
|
49
|
+
expect(@test_cmodel).to respond_to(:pid_suffix)
|
50
|
+
expect(@test_cmodel).to respond_to(:pid_suffix=)
|
51
51
|
end
|
52
|
-
|
53
|
-
|
54
|
-
describe
|
55
|
-
it
|
56
|
-
mock_object = double(
|
57
|
-
mock_object.
|
58
|
-
ActiveFedora::ContentModel.models_asserted_by(mock_object).
|
52
|
+
|
53
|
+
|
54
|
+
describe 'models_asserted_by' do
|
55
|
+
it 'should return an array of all of the content models asserted by the given object' do
|
56
|
+
mock_object = double('ActiveFedora Object')
|
57
|
+
expect(mock_object).to receive(:relationships).with(:has_model).and_return(['info:fedora/fedora-system:ServiceDefinition-3.0', 'info:fedora/afmodel:SampleModel', 'info:fedora/afmodel:NonDefinedModel'])
|
58
|
+
expect(ActiveFedora::ContentModel.models_asserted_by(mock_object)).to eq(['info:fedora/fedora-system:ServiceDefinition-3.0', 'info:fedora/afmodel:SampleModel', 'info:fedora/afmodel:NonDefinedModel'])
|
59
59
|
end
|
60
60
|
it "should return an empty array if the object doesn't have a RELS-EXT datastream" do
|
61
|
-
mock_object = double(
|
62
|
-
mock_object.
|
63
|
-
ActiveFedora::ContentModel.models_asserted_by(mock_object).
|
61
|
+
mock_object = double('ActiveFedora Object')
|
62
|
+
expect(mock_object).to receive(:relationships).with(:has_model).and_return([])
|
63
|
+
expect(ActiveFedora::ContentModel.models_asserted_by(mock_object)).to eq([])
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
67
|
-
describe
|
68
|
-
it
|
69
|
-
mock_object = double(
|
70
|
-
mock_object.
|
71
|
-
ActiveFedora::ContentModel.known_models_for(mock_object).
|
66
|
+
|
67
|
+
describe 'known_models_asserted_by' do
|
68
|
+
it 'should figure out the applicable models to load' do
|
69
|
+
mock_object = double('ActiveFedora Object')
|
70
|
+
expect(mock_object).to receive(:relationships).with(:has_model).and_return(['info:fedora/fedora-system:ServiceDefinition-3.0', 'info:fedora/afmodel:SampleModel', 'info:fedora/afmodel:NonDefinedModel'])
|
71
|
+
expect(ActiveFedora::ContentModel.known_models_for(mock_object)).to eq([SampleModel])
|
72
72
|
end
|
73
|
-
it
|
74
|
-
|
75
|
-
mock_object = double(
|
76
|
-
mock_object.
|
77
|
-
ActiveFedora::ContentModel.known_models_for(mock_object).
|
73
|
+
it 'should support namespaced models' do
|
74
|
+
skip 'This is harder than it looks.'
|
75
|
+
mock_object = double('ActiveFedora Object')
|
76
|
+
expect(mock_object).to receive(:relationships).with(:has_model).and_return(['info:fedora/afmodel:Sample_NamespacedModel'])
|
77
|
+
expect(ActiveFedora::ContentModel.known_models_for(mock_object)).to eq([Sample::NamespacedModel])
|
78
78
|
end
|
79
|
-
it
|
80
|
-
mock_object = double(
|
81
|
-
mock_object.
|
82
|
-
ActiveFedora::ContentModel.known_models_for(mock_object).
|
79
|
+
it 'should default to using ActiveFedora::Base as the model' do
|
80
|
+
mock_object = double('ActiveFedora Object')
|
81
|
+
expect(mock_object).to receive(:relationships).with(:has_model).and_return(['info:fedora/afmodel:NonDefinedModel'])
|
82
|
+
expect(ActiveFedora::ContentModel.known_models_for(mock_object)).to eq([ActiveFedora::Base])
|
83
83
|
end
|
84
84
|
it "should still work even if the object doesn't have a RELS-EXT datastream" do
|
85
|
-
mock_object = double(
|
86
|
-
mock_object.
|
87
|
-
ActiveFedora::ContentModel.known_models_for(mock_object).
|
85
|
+
mock_object = double('ActiveFedora Object')
|
86
|
+
expect(mock_object).to receive(:relationships).with(:has_model).and_return([])
|
87
|
+
expect(ActiveFedora::ContentModel.known_models_for(mock_object)).to eq([ActiveFedora::Base])
|
88
88
|
end
|
89
89
|
end
|
90
|
-
|
91
|
-
describe
|
92
|
-
it
|
93
|
-
ActiveFedora::ContentModel.uri_to_model_class(
|
94
|
-
ActiveFedora::ContentModel.uri_to_model_class(
|
95
|
-
ActiveFedora::ContentModel.uri_to_model_class(
|
96
|
-
ActiveFedora::ContentModel.uri_to_model_class(
|
90
|
+
|
91
|
+
describe 'uri_to_model_class' do
|
92
|
+
it 'should return an ActiveFedora Model class corresponding to the given uri if a valid model can be found' do
|
93
|
+
expect(ActiveFedora::ContentModel.uri_to_model_class('info:fedora/afmodel:SampleModel')).to eq(SampleModel)
|
94
|
+
expect(ActiveFedora::ContentModel.uri_to_model_class('info:fedora/afmodel:NonDefinedModel')).to eq(false)
|
95
|
+
expect(ActiveFedora::ContentModel.uri_to_model_class('info:fedora/afmodel:String')).to eq(false)
|
96
|
+
expect(ActiveFedora::ContentModel.uri_to_model_class('info:fedora/hydra-cModel:genericContent')).to eq(GenericContent)
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
@@ -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
|
-
@test_object2.named_datastreams_desc.
|
19
|
-
:type=>
|
20
|
-
:controlGroup=>'M'},
|
21
|
-
|
22
|
-
:type=>
|
23
|
-
:controlGroup=>'M' },
|
24
|
-
|
25
|
-
:type=>
|
26
|
-
@test_object2.
|
27
|
-
@test_object2.
|
28
|
-
@test_object2.
|
29
|
-
@test_object2.
|
30
|
-
@test_object2.
|
31
|
-
@test_object2.
|
32
|
-
@test_object2.
|
33
|
-
@test_object2.
|
34
|
-
@test_object2.
|
35
|
-
@test_object2.
|
18
|
+
expect(@test_object2.named_datastreams_desc).to eq({'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
|
+
expect(@test_object2).to respond_to(:thumbnail_append)
|
27
|
+
expect(@test_object2).to respond_to(:thumbnail_file_append)
|
28
|
+
expect(@test_object2).to respond_to(:thumbnail)
|
29
|
+
expect(@test_object2).to respond_to(:thumbnail_ids)
|
30
|
+
expect(@test_object2).to respond_to(:ead_append)
|
31
|
+
expect(@test_object2).to respond_to(:ead_file_append)
|
32
|
+
expect(@test_object2).to respond_to(:EAD)
|
33
|
+
expect(@test_object2).to respond_to(:EAD_ids)
|
34
|
+
expect(@test_object2).to respond_to(:external)
|
35
|
+
expect(@test_object2).to 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
|
-
@test_object2.datastream_names.
|
49
|
+
expect(@test_object2.datastream_names).to 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
|
-
@f.
|
69
|
-
@f2.
|
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
|
+
allow(@f).to receive(:content_type).and_return('image/jpeg')
|
69
|
+
allow(@f2).to receive(: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
|
-
@test_object2.high.first.dsLabel.
|
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
|
+
expect(@test_object2.high.first.dsLabel).to eq('my_image')
|
97
97
|
end
|
98
98
|
|
99
|
-
it
|
100
|
-
@test_object2.add_named_datastream(
|
101
|
-
@test_object2.high.first.dsLabel.
|
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
|
+
expect(@test_object2.high.first.dsLabel).to eq('dino.jpg')
|
102
|
+
end
|
103
103
|
|
104
|
-
it
|
105
|
-
@f.
|
106
|
-
@test_object2.add_named_datastream(
|
104
|
+
it 'should check the file for a content type' do
|
105
|
+
expect(@f).to 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
|
-
@f.
|
115
|
-
expect { @test_object2.add_named_datastream(
|
113
|
+
it 'should encsure mimetype and content type match' do
|
114
|
+
allow(@f).to receive(: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
|
-
@test_object2.anymime.first.class.
|
122
|
+
expect(@test_object2.anymime.first.class).to eq(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
|
-
@f.
|
128
|
-
expect { @test_object2.add_named_datastream(
|
127
|
+
allow(@f).to receive(: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
|
-
@test_object2.high.first.controlGroup.
|
137
|
+
expect(@test_object2.high.first.controlGroup).to eq('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
|
-
@test_object2.external.first.dsLabel.
|
145
|
+
expect(@test_object2.external.first.dsLabel).to eq('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
|
-
f.
|
165
|
-
f.
|
166
|
-
@test_object2.add_named_file_datastream(
|
164
|
+
allow(f).to receive(:original_filename).and_return('minivan.jpg')
|
165
|
+
allow(f).to receive(:content_type).and_return('image/jpeg')
|
166
|
+
@test_object2.add_named_file_datastream('thumbnail', f)
|
167
167
|
thumb = @test_object2.thumbnail.first
|
168
|
-
thumb.class.
|
169
|
-
thumb.mimeType.
|
170
|
-
thumb.dsid.
|
171
|
-
thumb.controlGroup.
|
172
|
-
thumb.dsLabel.
|
168
|
+
expect(thumb.class).to eq(ActiveFedora::Datastream)
|
169
|
+
expect(thumb.mimeType).to eq('image/jpeg')
|
170
|
+
expect(thumb.dsid).to eq('THUMB1')
|
171
|
+
expect(thumb.controlGroup).to eq('M')
|
172
|
+
expect(thumb.dsLabel).to eq('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
|
-
f.
|
193
|
-
f.
|
194
|
-
f2.
|
195
|
-
f2.
|
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
|
+
allow(f).to receive(:content_type).and_return('image/jpeg')
|
193
|
+
allow(f).to receive(:original_filename).and_return('minivan.jpg')
|
194
|
+
allow(f2).to receive(:content_type).and_return('image/jpeg')
|
195
|
+
allow(f2).to receive(: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
|
-
@test_object2.thumbnail.size.
|
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
|
+
expect(@test_object2.thumbnail.size).to eq(1)
|
215
|
+
@test_object2.thumbnail_ids == ['THUMB1']
|
216
216
|
thumb1 = @test_object2.thumbnail.first
|
217
|
-
thumb1.dsid.
|
218
|
-
thumb1.pid.
|
219
|
-
thumb1.dsLabel.
|
217
|
+
expect(thumb1.dsid).to eq('THUMB1')
|
218
|
+
expect(thumb1.pid).to eq(@test_object2.pid)
|
219
|
+
expect(thumb1.dsLabel).to eq('minivan.jpg')
|
220
220
|
f.rewind
|
221
|
-
@test_object2.update_named_datastream(
|
222
|
-
@test_object2.thumbnail.size.
|
223
|
-
@test_object2.thumbnail_ids == [
|
221
|
+
@test_object2.update_named_datastream('thumbnail', {:file => f2, :dsid => 'THUMB1'})
|
222
|
+
expect(@test_object2.thumbnail.size).to eq(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
|
-
thumb1.dsid.
|
232
|
-
thumb1.pid.
|
233
|
-
thumb1.dsLabel.
|
231
|
+
expect(thumb1.dsid).to eq('THUMB1')
|
232
|
+
expect(thumb1.pid).to eq(@test_object2.pid)
|
233
|
+
expect(thumb1.dsLabel).to eq('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
|
-
@test_object2.named_datastreams_desc.
|
248
|
-
:type=>
|
249
|
-
:controlGroup=>'M'}}
|
247
|
+
expect(@test_object2.named_datastreams_desc).to eq({'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
|
-
@test_object2.is_named_datastream?(
|
264
|
-
@test_object2.is_named_datastream?(
|
263
|
+
expect(@test_object2.is_named_datastream?('thumbnail')).to eq(true)
|
264
|
+
expect(@test_object2.is_named_datastream?('thumb')).to eq(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
|
-
f.
|
283
|
-
f.
|
284
|
-
f2 = File.new(File.join( File.dirname(__FILE__),
|
285
|
-
f2.
|
286
|
-
f2.
|
281
|
+
f = File.new(File.join( File.dirname(__FILE__), '../fixtures/minivan.jpg' ))
|
282
|
+
allow(f).to receive(:content_type).and_return('image/jpeg')
|
283
|
+
allow(f).to receive(:original_filename).and_return('minivan.jpg')
|
284
|
+
f2 = File.new(File.join( File.dirname(__FILE__), '../fixtures/dino.jpg' ))
|
285
|
+
allow(f2).to receive(:content_type).and_return('image/jpeg')
|
286
|
+
allow(f2).to receive(: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
|
-
datastreams.keys.include?(
|
292
|
-
datastreams.keys.include?(
|
293
|
-
datastreams.keys.include?(
|
294
|
-
datastreams.keys.size.
|
295
|
-
datastreams[
|
296
|
-
datastreams[
|
297
|
-
datastreams[
|
298
|
-
datastreams[
|
299
|
-
|
300
|
-
datastreams[
|
301
|
-
datastreams[
|
302
|
-
datastreams[
|
303
|
-
datastreams[
|
304
|
-
datastreams[
|
305
|
-
|
306
|
-
datastreams[
|
307
|
-
datastreams[
|
308
|
-
datastreams[
|
309
|
-
datastreams[
|
291
|
+
expect(datastreams.keys.include?('thumbnail')).to eq(true)
|
292
|
+
expect(datastreams.keys.include?('external')).to eq(true)
|
293
|
+
expect(datastreams.keys.include?('high')).to eq(true)
|
294
|
+
expect(datastreams.keys.size).to eq(3)
|
295
|
+
expect(datastreams['thumbnail'].size).to eq(1)
|
296
|
+
expect(datastreams['thumbnail'].first.dsid).to eq('THUMB1')
|
297
|
+
expect(datastreams['thumbnail'].first.dsLabel).to eq('minivan.jpg')
|
298
|
+
expect(datastreams['thumbnail'].first.controlGroup).to eq('M')
|
299
|
+
|
300
|
+
expect(datastreams['external'].size).to eq(1)
|
301
|
+
expect(datastreams['external'].first.dsid).to eq('EXTERNAL1')
|
302
|
+
expect(datastreams['external'].first.dsLocation).to eq('http://myresource.com')
|
303
|
+
expect(datastreams['external'].first.controlGroup).to eq('E')
|
304
|
+
expect(datastreams['external'].first.content).to eq('')
|
305
|
+
|
306
|
+
expect(datastreams['high'].size).to eq(1)
|
307
|
+
expect(datastreams['high'].first.dsLabel).to eq('dino.jpg')
|
308
|
+
expect(datastreams['high'].first.controlGroup).to eq('M')
|
309
|
+
expect(datastreams['high'].first.dsid).to eq('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
|
-
f.
|
329
|
-
f.
|
330
|
-
f2 = File.new(File.join( File.dirname(__FILE__),
|
331
|
-
f2.
|
332
|
-
f2.
|
327
|
+
f = File.new(File.join( File.dirname(__FILE__), '../fixtures/minivan.jpg' ))
|
328
|
+
allow(f).to receive(:content_type).and_return('image/jpeg')
|
329
|
+
allow(f).to receive(:original_filename).and_return('minivan.jpg')
|
330
|
+
f2 = File.new(File.join( File.dirname(__FILE__), '../fixtures/dino.jpg' ))
|
331
|
+
allow(f2).to receive(:content_type).and_return('image/jpeg')
|
332
|
+
allow(f2).to receive(: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
|
-
@test_object2.named_datastreams_ids.
|
335
|
+
@test_object2.external_append({:dsLocation => 'http://myresource.com'})
|
336
|
+
expect(@test_object2.named_datastreams_ids).to eq({'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
|
-
@test_object2.
|
353
|
-
@test_object2.
|
354
|
-
@test_object2.
|
355
|
-
@test_object2.
|
356
|
-
f = File.new(File.join( File.dirname(__FILE__),
|
357
|
-
f2 = File.new(File.join( File.dirname(__FILE__),
|
358
|
-
f2.
|
359
|
-
f.
|
360
|
-
@test_object2.add_named_datastream(
|
361
|
-
@test_object2.add_named_datastream(
|
362
|
-
@test_object2.add_named_datastream(
|
352
|
+
expect(@test_object2).to respond_to(:thumbnail)
|
353
|
+
expect(@test_object2).to respond_to(:thumbnail_ids)
|
354
|
+
expect(@test_object2).to respond_to(:high)
|
355
|
+
expect(@test_object2).to 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
|
+
allow(f2).to receive(:original_filename).and_return('dino.jpg')
|
359
|
+
allow(f).to receive(: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
|
-
t2_thumb1.mimeType.
|
365
|
-
t2_thumb1.controlGroup.
|
366
|
-
t2_thumb1.dsLabel.
|
367
|
-
t2_thumb1.pid.
|
368
|
-
t2_thumb1.dsid.
|
369
|
-
# :type=>"ActiveFedora::Datastream",
|
370
|
-
# :prefix=>"THUMB", :content_type=>"image/jpeg", :dsid=>"THUMB1", :dsID=>"THUMB1",
|
364
|
+
expect(t2_thumb1.mimeType).to eq('image/jpeg')
|
365
|
+
expect(t2_thumb1.controlGroup).to eq('M')
|
366
|
+
expect(t2_thumb1.dsLabel).to eq('testDS')
|
367
|
+
expect(t2_thumb1.pid).to eq(@test_object2.pid)
|
368
|
+
expect(t2_thumb1.dsid).to eq('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
|
-
@test_object2.thumbnail_ids.
|
373
|
-
@test_object2.high_ids.include?(
|
374
|
-
@test_object2.high_ids.include?(
|
375
|
-
@test_object2.high_ids.size.
|
372
|
+
expect(@test_object2.thumbnail_ids).to eq(['THUMB1'])
|
373
|
+
@test_object2.high_ids.include?('HIGH1') == true
|
374
|
+
@test_object2.high_ids.include?('HIGH2') == true
|
375
|
+
expect(@test_object2.high_ids.size).to eq(2)
|
376
376
|
#just check returning datastream object at this point
|
377
|
-
@test_object2.high.first.class.
|
377
|
+
expect(@test_object2.high.first.class).to eq(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
|
-
@test_object2.
|
395
|
-
@test_object2.
|
396
|
-
f = File.new(File.join( File.dirname(__FILE__),
|
397
|
-
f.
|
398
|
-
f.
|
394
|
+
expect(@test_object2).to respond_to(:thumbnail_append)
|
395
|
+
expect(@test_object2).to respond_to(:ead_append)
|
396
|
+
f = File.new(File.join( File.dirname(__FILE__), '../fixtures/minivan.jpg'))
|
397
|
+
allow(f).to receive(:content_type).and_return('image/jpeg')
|
398
|
+
allow(f).to receive(:original_filename).and_return('minivan.jpg')
|
399
399
|
@test_object2.thumbnail_file_append(f)
|
400
400
|
t2_thumb1 = @test_object2.thumbnail.first
|
401
|
-
t2_thumb1.mimeType.
|
402
|
-
t2_thumb1.dsLabel.
|
403
|
-
t2_thumb1.pid.
|
404
|
-
t2_thumb1.dsid.
|
405
|
-
@test_object3.thumbnail_append({:file=>f})
|
401
|
+
expect(t2_thumb1.mimeType).to eq('image/jpeg')
|
402
|
+
expect(t2_thumb1.dsLabel).to eq('minivan.jpg')
|
403
|
+
expect(t2_thumb1.pid).to eq(@test_object2.pid)
|
404
|
+
expect(t2_thumb1.dsid).to eq('THUMB1')
|
405
|
+
@test_object3.thumbnail_append({:file => f})
|
406
406
|
t3_thumb1 = @test_object3.thumbnail.first
|
407
|
-
t3_thumb1.mimeType.
|
408
|
-
t3_thumb1.dsLabel.
|
409
|
-
t3_thumb1.pid.
|
410
|
-
t3_thumb1.dsid.
|
411
|
-
@test_object3.external_append({:dsLocation=>
|
407
|
+
expect(t3_thumb1.mimeType).to eq('image/jpeg')
|
408
|
+
expect(t3_thumb1.dsLabel).to eq('minivan.jpg')
|
409
|
+
expect(t3_thumb1.pid).to eq(@test_object3.pid)
|
410
|
+
expect(t3_thumb1.dsid).to eq('THUMB1')
|
411
|
+
@test_object3.external_append({:dsLocation => 'http://myresource.com'})
|
412
412
|
t3_external1 = @test_object3.external.first
|
413
|
-
t3_external1.dsLabel.
|
414
|
-
t3_external1.dsLocation.
|
415
|
-
t3_external1.pid.
|
416
|
-
t3_external1.dsid.
|
413
|
+
expect(t3_external1.dsLabel).to eq('http://myresource.com')
|
414
|
+
expect(t3_external1.dsLocation).to eq('http://myresource.com')
|
415
|
+
expect(t3_external1.pid).to eq(@test_object3.pid)
|
416
|
+
expect(t3_external1.dsid).to eq('EXTERNAL1')
|
417
417
|
t3_external1.controlGroup == 'E'
|
418
418
|
end
|
419
419
|
end
|