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.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/.rubocop.yml +1 -0
  4. data/.rubocop_todo.yml +938 -0
  5. data/.travis.yml +5 -6
  6. data/Gemfile +3 -1
  7. data/Rakefile +7 -5
  8. data/active-fedora.gemspec +7 -8
  9. data/lib/active_fedora/om_datastream.rb +1 -0
  10. data/lib/active_fedora/rdf_xml_writer.rb +31 -62
  11. data/lib/active_fedora/version.rb +1 -1
  12. data/spec/config_helper.rb +14 -14
  13. data/spec/integration/associations_spec.rb +232 -232
  14. data/spec/integration/attributes_spec.rb +11 -12
  15. data/spec/integration/auditable_spec.rb +10 -10
  16. data/spec/integration/base_spec.rb +163 -163
  17. data/spec/integration/bug_spec.rb +7 -7
  18. data/spec/integration/complex_rdf_datastream_spec.rb +88 -88
  19. data/spec/integration/datastream_collections_spec.rb +69 -69
  20. data/spec/integration/datastream_spec.rb +43 -43
  21. data/spec/integration/datastreams_spec.rb +63 -63
  22. data/spec/integration/delegating_spec.rb +14 -14
  23. data/spec/integration/delete_all_spec.rb +38 -42
  24. data/spec/integration/fedora_solr_sync_spec.rb +5 -5
  25. data/spec/integration/full_featured_model_spec.rb +101 -101
  26. data/spec/integration/has_many_associations_spec.rb +24 -24
  27. data/spec/integration/model_spec.rb +30 -30
  28. data/spec/integration/nested_attribute_spec.rb +41 -41
  29. data/spec/integration/ntriples_datastream_spec.rb +107 -107
  30. data/spec/integration/om_datastream_spec.rb +67 -67
  31. data/spec/integration/persistence_spec.rb +6 -6
  32. data/spec/integration/rdf_nested_attributes_spec.rb +56 -56
  33. data/spec/integration/relation_delegation_spec.rb +24 -26
  34. data/spec/integration/rels_ext_datastream_spec.rb +20 -20
  35. data/spec/integration/scoped_query_spec.rb +40 -41
  36. data/spec/integration/solr_instance_loader_spec.rb +4 -4
  37. data/spec/integration/solr_service_spec.rb +46 -46
  38. data/spec/rails3_test_app/config/application.rb +1 -1
  39. data/spec/rails3_test_app/config/environments/development.rb +0 -1
  40. data/spec/rails3_test_app/config/environments/production.rb +1 -1
  41. data/spec/rails3_test_app/spec/spec_helper.rb +3 -3
  42. data/spec/rails3_test_app/spec/unit/rails_3_init.rb +4 -4
  43. data/spec/samples/hydra-mods_article_datastream.rb +334 -334
  44. data/spec/samples/hydra-rights_metadata_datastream.rb +57 -57
  45. data/spec/samples/marpa-dc_datastream.rb +17 -17
  46. data/spec/samples/models/audio_record.rb +16 -16
  47. data/spec/samples/models/image.rb +2 -2
  48. data/spec/samples/models/mods_article.rb +5 -5
  49. data/spec/samples/models/oral_history.rb +18 -18
  50. data/spec/samples/models/seminar.rb +24 -24
  51. data/spec/samples/models/seminar_audio_file.rb +17 -17
  52. data/spec/samples/oral_history_sample_model.rb +21 -21
  53. data/spec/samples/special_thing.rb +14 -14
  54. data/spec/spec_helper.rb +7 -11
  55. data/spec/support/an_active_model.rb +2 -2
  56. data/spec/support/mock_fedora.rb +16 -17
  57. data/spec/unit/active_fedora_spec.rb +58 -58
  58. data/spec/unit/association_proxy_spec.rb +5 -7
  59. data/spec/unit/base_active_model_spec.rb +25 -26
  60. data/spec/unit/base_cma_spec.rb +5 -5
  61. data/spec/unit/base_datastream_management_spec.rb +27 -27
  62. data/spec/unit/base_delegate_spec.rb +80 -82
  63. data/spec/unit/base_delegate_to_spec.rb +37 -39
  64. data/spec/unit/base_extra_spec.rb +48 -48
  65. data/spec/unit/base_spec.rb +300 -300
  66. data/spec/unit/callback_spec.rb +19 -19
  67. data/spec/unit/code_configurator_spec.rb +17 -17
  68. data/spec/unit/config_spec.rb +16 -8
  69. data/spec/unit/content_model_spec.rb +60 -60
  70. data/spec/unit/datastream_collections_spec.rb +229 -229
  71. data/spec/unit/datastream_spec.rb +57 -54
  72. data/spec/unit/datastreams_spec.rb +77 -77
  73. data/spec/unit/file_configurator_spec.rb +217 -217
  74. data/spec/unit/has_and_belongs_to_many_collection_spec.rb +26 -26
  75. data/spec/unit/has_many_collection_spec.rb +9 -9
  76. data/spec/unit/inheritance_spec.rb +12 -13
  77. data/spec/unit/model_spec.rb +41 -51
  78. data/spec/unit/nom_datastream_spec.rb +15 -15
  79. data/spec/unit/ntriples_datastream_spec.rb +112 -112
  80. data/spec/unit/om_datastream_spec.rb +233 -227
  81. data/spec/unit/persistence_spec.rb +6 -6
  82. data/spec/unit/predicates_spec.rb +73 -73
  83. data/spec/unit/property_spec.rb +9 -17
  84. data/spec/unit/qualified_dublin_core_datastream_spec.rb +33 -33
  85. data/spec/unit/query_spec.rb +188 -217
  86. data/spec/unit/rdf_datastream_spec.rb +28 -21
  87. data/spec/unit/rdf_list_nested_attributes_spec.rb +34 -34
  88. data/spec/unit/rdf_list_spec.rb +80 -104
  89. data/spec/unit/rdf_node_spec.rb +7 -7
  90. data/spec/unit/rdf_xml_writer_spec.rb +10 -10
  91. data/spec/unit/rdfxml_rdf_datastream_spec.rb +27 -27
  92. data/spec/unit/relationship_graph_spec.rb +51 -51
  93. data/spec/unit/rels_ext_datastream_spec.rb +75 -69
  94. data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +15 -15
  95. data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +15 -15
  96. data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +15 -15
  97. data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +12 -12
  98. data/spec/unit/rubydora_connection_spec.rb +5 -5
  99. data/spec/unit/semantic_node_spec.rb +59 -59
  100. data/spec/unit/serializers_spec.rb +4 -4
  101. data/spec/unit/service_definitions_spec.rb +26 -26
  102. data/spec/unit/simple_datastream_spec.rb +17 -17
  103. data/spec/unit/solr_config_options_spec.rb +27 -28
  104. data/spec/unit/solr_digital_object_spec.rb +21 -21
  105. data/spec/unit/solr_service_spec.rb +81 -81
  106. data/spec/unit/unsaved_digital_object_spec.rb +20 -20
  107. data/spec/unit/validations_spec.rb +21 -21
  108. metadata +70 -58
  109. data/gemfiles/gemfile.rails3 +0 -11
  110. data/gemfiles/gemfile.rails4 +0 -10
@@ -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=>"someData" do |m|
7
- m.field "fubar", :string
8
- m.field "swank", :text
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 "Should have after_initialize, before_save,after_save, before_create, after_create, after_update, before_update, before_destroy" do
34
- CallbackStub.any_instance.should_receive(:a_init)
35
- CallbackStub.any_instance.should_receive :b_create
36
- CallbackStub.any_instance.should_receive :a_create
37
- CallbackStub.any_instance.should_receive(:b_save)
38
- CallbackStub.any_instance.should_receive(:a_save)
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 "Should have after_initialize, before_save,after_save, before_create, after_create, after_update, before_update, before_destroy" do
43
- CallbackStub.any_instance.should_receive(:a_init)
44
- CallbackStub.any_instance.should_receive(:b_save)
45
- CallbackStub.any_instance.should_receive(:a_save)
46
- CallbackStub.any_instance.should_receive(:a_find)
47
- CallbackStub.any_instance.should_receive(:b_update)
48
- CallbackStub.any_instance.should_receive(:a_update)
49
- CallbackStub.any_instance.should_receive(:do_stuff)
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 "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
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.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
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
@@ -1,19 +1,27 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::Config do
4
- describe "with a single fedora instance" do
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
- its(:credentials) { should == {:url => 'http://testhost.com:8983/fedora', :user=> 'fedoraAdmin', :password=> 'fedoraAdmin'}}
8
- it { should_not be_sharded }
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 "with several fedora shards" do
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
- its(:credentials) { should == [{:url => 'http://127.0.0.1:8983/fedora1', :user=> 'fedoraAdmin', :password=> 'fedoraAdmin'},
14
- {:url => 'http://127.0.0.1:8983/fedora2', :user=> 'fedoraAdmin', :password=> 'fedoraAdmin'},
15
- {:url => 'http://127.0.0.1:8983/fedora3', :user=> 'fedoraAdmin', :password=> 'fedoraAdmin'}]}
16
- it { should be_sharded }
17
+
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.stub(:assign_pid).and_return("__nextid__")
24
- Rubydora::Repository.any_instance.stub(:client).and_return(@mock_client)
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 "should provide #new" do
29
- ActiveFedora::ContentModel.should respond_to(:new)
27
+
28
+ it 'should provide #new' do
29
+ expect(ActiveFedora::ContentModel).to respond_to(:new)
30
30
  end
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)
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 "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"
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 "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"
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 "should provide @pid_suffix" do
49
- @test_cmodel.should respond_to(:pid_suffix)
50
- @test_cmodel.should respond_to(:pid_suffix=)
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 "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
- 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"])
58
- ActiveFedora::ContentModel.models_asserted_by(mock_object).should == ["info:fedora/fedora-system:ServiceDefinition-3.0", "info:fedora/afmodel:SampleModel", "info:fedora/afmodel:NonDefinedModel"]
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("ActiveFedora Object")
62
- mock_object.should_receive(:relationships).with(:has_model).and_return([])
63
- ActiveFedora::ContentModel.models_asserted_by(mock_object).should == []
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 "known_models_asserted_by" do
68
- it "should figure out the applicable models to load" do
69
- mock_object = double("ActiveFedora Object")
70
- 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"])
71
- ActiveFedora::ContentModel.known_models_for(mock_object).should == [SampleModel]
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 "should support namespaced models" do
74
- pending "This is harder than it looks."
75
- mock_object = double("ActiveFedora Object")
76
- mock_object.should_receive(:relationships).with(:has_model).and_return(["info:fedora/afmodel:Sample_NamespacedModel"])
77
- ActiveFedora::ContentModel.known_models_for(mock_object).should == [Sample::NamespacedModel]
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 "should default to using ActiveFedora::Base as the model" do
80
- mock_object = double("ActiveFedora Object")
81
- mock_object.should_receive(:relationships).with(:has_model).and_return(["info:fedora/afmodel:NonDefinedModel"])
82
- ActiveFedora::ContentModel.known_models_for(mock_object).should == [ActiveFedora::Base]
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("ActiveFedora Object")
86
- mock_object.should_receive(:relationships).with(:has_model).and_return([])
87
- ActiveFedora::ContentModel.known_models_for(mock_object).should == [ActiveFedora::Base]
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 "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
- ActiveFedora::ContentModel.uri_to_model_class("info:fedora/afmodel:SampleModel").should == SampleModel
94
- ActiveFedora::ContentModel.uri_to_model_class("info:fedora/afmodel:NonDefinedModel").should == false
95
- ActiveFedora::ContentModel.uri_to_model_class("info:fedora/afmodel:String").should == false
96
- ActiveFedora::ContentModel.uri_to_model_class("info:fedora/hydra-cModel:genericContent").should == GenericContent
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=>"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'
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.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)
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=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
43
- has_datastream :name=>"EAD", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
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.should include("thumbnail","EAD")
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=>"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'
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__), "../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")
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("thumb",{:content_type=>"image/jpeg",:blob=>f}) }.to raise_error
73
+ expect { @test_object2.add_named_datastream('thumb', {:content_type => 'image/jpeg', :blob => f}) }.to raise_error
74
74
  end
75
75
 
76
- it "should accept a file blob" do
77
- @test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:blob=>@f})
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 "should accept a file handle" do
81
- @test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:file=>@f})
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 "should allow access to file content" do
85
- @test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:file=>@f})
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 "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
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 "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"
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 "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
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 "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})
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 "should raise an error if no content type is avialable" do
110
- expect { @test_object2.add_named_datastream("thumbnail",{:file=>@f2}) }.to raise_error
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 "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
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 "should allow any mime type" do
117
+
118
+ it 'should allow any mime type' do
119
119
  #check for if any mime type allowed
120
- @test_object2.add_named_datastream("anymime",{:file=>@f})
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.should == ActiveFedora::Datastream
122
+ expect(@test_object2.anymime.first.class).to eq(ActiveFedora::Datastream)
123
123
  end
124
124
 
125
- it "should cgecj that a dsid forms to the prefix" do
125
+ it 'should cgecj that a dsid forms to the prefix' do
126
126
  #if dsid supplied check that conforms to prefix
127
- @f.stub(:content_type).and_return("image/jpeg")
128
- expect { @test_object2.add_named_datastream("thumbnail",{:file=>@f,:dsid=>"DS1"}) }.to raise_error
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 "should have the right properties" do
132
- @test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>@f2})
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.should == "M"
137
+ expect(@test_object2.high.first.controlGroup).to eq('M')
138
138
  end
139
139
 
140
- it "should work with external datastreams" do
141
-
140
+ it 'should work with external datastreams' do
141
+
142
142
  #check external datastream
143
- @test_object2.add_named_datastream("external",{:dsLocation=>"http://myreasource.com"})
143
+ @test_object2.add_named_datastream('external', {:dsLocation => 'http://myreasource.com'})
144
144
  #check dslocation goes to dslabel
145
- @test_object2.external.first.dsLabel.should == "http://myreasource.com"
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=>"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'
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__), "../fixtures/minivan.jpg"))
162
+ f = File.new(File.join( File.dirname(__FILE__), '../fixtures/minivan.jpg'))
163
163
  #these normally supplied in multi-part post request
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)
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.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"
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=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
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__), "../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")
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("thumbnail",{:file=>f})
197
+ @test_object2.add_named_datastream('thumbnail', {:file => f})
198
198
  had_exception = false
199
199
  begin
200
- @test_object2.update_named_datastream("thumbnail",{:file=>f})
200
+ @test_object2.update_named_datastream('thumbnail', {:file => f})
201
201
  rescue
202
202
  had_exception = true
203
203
  end
204
- raise "Failed to raise exception if dsid not supplied" unless had_exception
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("thumbnail",{:file=>f,:dsid=>"THUMB100"})
208
+ @test_object2.update_named_datastream('thumbnail', {:file => f, :dsid => 'THUMB100'})
209
209
  rescue
210
210
  had_exception = true
211
211
  end
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"]
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.should == 'THUMB1'
218
- thumb1.pid.should == @test_object2.pid
219
- thumb1.dsLabel.should == 'minivan.jpg'
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("thumbnail",{:file=>f2,:dsid=>"THUMB1"})
222
- @test_object2.thumbnail.size.should == 1
223
- @test_object2.thumbnail_ids == ["THUMB1"]
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.should == 'THUMB1'
232
- thumb1.pid.should == @test_object2.pid
233
- thumb1.dsLabel.should == 'dino.jpg'
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=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
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.should == {"thumbnail"=>{:name=>"thumbnail",:prefix => "THUMB",
248
- :type=>"ActiveFedora::Datastream", :mimeType=>"image/jpeg",
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=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
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?("thumbnail").should == true
264
- @test_object2.is_named_datastream?("thumb").should == false
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=>"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'
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__), "../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")
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=>"http://myresource.com"})
289
+ @test_object2.external_append({:dsLocation => 'http://myresource.com'})
290
290
  datastreams = @test_object2.named_datastreams
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"
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=>"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'
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__), "../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")
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=>"http://myresource.com"})
336
- @test_object2.named_datastreams_ids.should == {"thumbnail"=>["THUMB1"],"high"=>["HIGH1"],"external"=>["EXTERNAL1"]}
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=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
346
- has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
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.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})
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.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",
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.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
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.should == ActiveFedora::Datastream
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=>"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'
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.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")
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.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})
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.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"})
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.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"
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