ddr-models 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +12 -0
  3. data/README.md +5 -0
  4. data/Rakefile +37 -0
  5. data/app/models/attachment.rb +7 -0
  6. data/app/models/collection.rb +54 -0
  7. data/app/models/component.rb +15 -0
  8. data/app/models/item.rb +19 -0
  9. data/app/models/solr_document.rb +36 -0
  10. data/app/models/target.rb +8 -0
  11. data/config/initializers/active_fedora_base.rb +77 -0
  12. data/config/initializers/active_fedora_datastream.rb +5 -0
  13. data/config/initializers/ddr.rb +8 -0
  14. data/config/initializers/devise.rb +245 -0
  15. data/config/initializers/devise.rb~ +245 -0
  16. data/config/initializers/subscriptions.rb +15 -0
  17. data/config/routes.rb +2 -0
  18. data/db/migrate/20141021233359_create_events.rb +28 -0
  19. data/db/migrate/20141021234156_create_minted_ids.rb +19 -0
  20. data/db/migrate/20141103192146_create_workflow_state.rb +13 -0
  21. data/db/migrate/20141104181418_create_users.rb +34 -0
  22. data/db/migrate/20141104181418_create_users.rb~ +6 -0
  23. data/lib/ddr-models.rb +1 -0
  24. data/lib/ddr/actions.rb +8 -0
  25. data/lib/ddr/actions/fixity_check.rb +35 -0
  26. data/lib/ddr/auth.rb +45 -0
  27. data/lib/ddr/auth.rb~ +47 -0
  28. data/lib/ddr/auth/ability.rb +204 -0
  29. data/lib/ddr/auth/ability.rb~ +204 -0
  30. data/lib/ddr/auth/group_service.rb +53 -0
  31. data/lib/ddr/auth/group_service.rb~ +53 -0
  32. data/lib/ddr/auth/grouper_service.rb +76 -0
  33. data/lib/ddr/auth/grouper_service.rb~ +77 -0
  34. data/lib/ddr/auth/remote_group_service.rb +35 -0
  35. data/lib/ddr/auth/remote_group_service.rb~ +35 -0
  36. data/lib/ddr/auth/superuser.rb +13 -0
  37. data/lib/ddr/auth/superuser.rb~ +9 -0
  38. data/lib/ddr/auth/user.rb +71 -0
  39. data/lib/ddr/auth/user.rb~ +65 -0
  40. data/lib/ddr/configurable.rb +34 -0
  41. data/lib/ddr/datastreams.rb +32 -0
  42. data/lib/ddr/datastreams/content_metadata_datastream.rb +147 -0
  43. data/lib/ddr/datastreams/datastream_behavior.rb +95 -0
  44. data/lib/ddr/datastreams/descriptive_metadata_datastream.rb +84 -0
  45. data/lib/ddr/datastreams/properties_datastream.rb +25 -0
  46. data/lib/ddr/datastreams/role_assignments_datastream.rb +19 -0
  47. data/lib/ddr/events.rb +17 -0
  48. data/lib/ddr/events/creation_event.rb +12 -0
  49. data/lib/ddr/events/event.rb +163 -0
  50. data/lib/ddr/events/fixity_check_event.rb +43 -0
  51. data/lib/ddr/events/ingestion_event.rb +12 -0
  52. data/lib/ddr/events/preservation_event_behavior.rb +37 -0
  53. data/lib/ddr/events/preservation_event_type.rb +24 -0
  54. data/lib/ddr/events/reindex_object_after_save.rb +18 -0
  55. data/lib/ddr/events/update_event.rb +9 -0
  56. data/lib/ddr/events/validation_event.rb +11 -0
  57. data/lib/ddr/events/virus_check_event.rb +30 -0
  58. data/lib/ddr/index_fields.rb +39 -0
  59. data/lib/ddr/metadata.rb +22 -0
  60. data/lib/ddr/metadata/duke_terms.rb +15 -0
  61. data/lib/ddr/metadata/premis_event.rb +59 -0
  62. data/lib/ddr/metadata/rdf_vocabulary_parser.rb +45 -0
  63. data/lib/ddr/metadata/roles_vocabulary.rb +10 -0
  64. data/lib/ddr/metadata/sources/duketerms.rdf.xml +856 -0
  65. data/lib/ddr/metadata/vocabulary.rb +37 -0
  66. data/lib/ddr/models.rb +60 -0
  67. data/lib/ddr/models/access_controllable.rb +23 -0
  68. data/lib/ddr/models/base.rb +37 -0
  69. data/lib/ddr/models/describable.rb +81 -0
  70. data/lib/ddr/models/engine.rb +58 -0
  71. data/lib/ddr/models/error.rb +12 -0
  72. data/lib/ddr/models/event_loggable.rb +36 -0
  73. data/lib/ddr/models/file_management.rb +183 -0
  74. data/lib/ddr/models/fixity_checkable.rb +20 -0
  75. data/lib/ddr/models/governable.rb +48 -0
  76. data/lib/ddr/models/has_attachments.rb +12 -0
  77. data/lib/ddr/models/has_children.rb +21 -0
  78. data/lib/ddr/models/has_content.rb +114 -0
  79. data/lib/ddr/models/has_content_metadata.rb +16 -0
  80. data/lib/ddr/models/has_properties.rb +15 -0
  81. data/lib/ddr/models/has_role_assignments.rb +17 -0
  82. data/lib/ddr/models/has_thumbnail.rb +27 -0
  83. data/lib/ddr/models/has_workflow.rb +29 -0
  84. data/lib/ddr/models/indexing.rb +53 -0
  85. data/lib/ddr/models/licensable.rb +28 -0
  86. data/lib/ddr/models/minted_id.rb +10 -0
  87. data/lib/ddr/models/permanent_identification.rb +48 -0
  88. data/lib/ddr/models/solr_document.rb +193 -0
  89. data/lib/ddr/models/version.rb +5 -0
  90. data/lib/ddr/notifications.rb +15 -0
  91. data/lib/ddr/services.rb +8 -0
  92. data/lib/ddr/services/id_service.rb +48 -0
  93. data/lib/ddr/utils.rb +153 -0
  94. data/lib/ddr/workflow.rb +8 -0
  95. data/lib/ddr/workflow/workflow_state.rb +39 -0
  96. data/spec/dummy/README.rdoc +28 -0
  97. data/spec/dummy/Rakefile +6 -0
  98. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  99. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  100. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  101. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  102. data/spec/dummy/app/models/user.rb +5 -0
  103. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  104. data/spec/dummy/bin/bundle +3 -0
  105. data/spec/dummy/bin/rails +4 -0
  106. data/spec/dummy/bin/rake +4 -0
  107. data/spec/dummy/config.ru +4 -0
  108. data/spec/dummy/config/application.rb +29 -0
  109. data/spec/dummy/config/boot.rb +5 -0
  110. data/spec/dummy/config/database.yml +25 -0
  111. data/spec/dummy/config/environment.rb +5 -0
  112. data/spec/dummy/config/environments/development.rb +37 -0
  113. data/spec/dummy/config/environments/production.rb +78 -0
  114. data/spec/dummy/config/environments/test.rb +39 -0
  115. data/spec/dummy/config/initializers/assets.rb +8 -0
  116. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  117. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  118. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  119. data/spec/dummy/config/initializers/inflections.rb +16 -0
  120. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  121. data/spec/dummy/config/initializers/session_store.rb +3 -0
  122. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  123. data/spec/dummy/config/locales/en.yml +23 -0
  124. data/spec/dummy/config/routes.rb +56 -0
  125. data/spec/dummy/config/secrets.yml +22 -0
  126. data/spec/dummy/db/development.sqlite3 +0 -0
  127. data/spec/dummy/db/schema.rb +80 -0
  128. data/spec/dummy/db/test.sqlite3 +0 -0
  129. data/spec/dummy/log/development.log +4974 -0
  130. data/spec/dummy/log/test.log +55627 -0
  131. data/spec/dummy/public/404.html +67 -0
  132. data/spec/dummy/public/422.html +67 -0
  133. data/spec/dummy/public/500.html +66 -0
  134. data/spec/dummy/public/favicon.ico +0 -0
  135. data/spec/factories/attachment_factories.rb +15 -0
  136. data/spec/factories/collection_factories.rb +16 -0
  137. data/spec/factories/component_factories.rb +15 -0
  138. data/spec/factories/event_factories.rb +7 -0
  139. data/spec/factories/item_factories.rb +16 -0
  140. data/spec/factories/target_factories.rb +11 -0
  141. data/spec/factories/test_model_factories.rb +133 -0
  142. data/spec/factories/user_factories.rb +7 -0
  143. data/spec/factories/user_factories.rb~ +7 -0
  144. data/spec/features/grouper_integration_spec.rb~ +21 -0
  145. data/spec/fixtures/contentMetadata.xml +37 -0
  146. data/spec/fixtures/image1.tiff +0 -0
  147. data/spec/fixtures/image2.tiff +0 -0
  148. data/spec/fixtures/image3.tiff +0 -0
  149. data/spec/fixtures/library-devil.tiff +0 -0
  150. data/spec/fixtures/sample.docx +0 -0
  151. data/spec/fixtures/sample.pdf +0 -0
  152. data/spec/fixtures/target.png +0 -0
  153. data/spec/models/ability_spec.rb +248 -0
  154. data/spec/models/ability_spec.rb~ +245 -0
  155. data/spec/models/active_fedora_base_spec.rb +107 -0
  156. data/spec/models/active_fedora_datastream_spec.rb +121 -0
  157. data/spec/models/attachment_spec.rb +13 -0
  158. data/spec/models/collection_spec.rb +33 -0
  159. data/spec/models/component_spec.rb +8 -0
  160. data/spec/models/descriptive_metadata_datastream_spec.rb +102 -0
  161. data/spec/models/events_spec.rb +64 -0
  162. data/spec/models/file_management_spec.rb +179 -0
  163. data/spec/models/has_role_assignments_spec.rb +29 -0
  164. data/spec/models/has_workflow_spec.rb +54 -0
  165. data/spec/models/item_spec.rb +8 -0
  166. data/spec/models/permanent_identification_spec.rb +65 -0
  167. data/spec/models/role_assignments_datastream_spec.rb +25 -0
  168. data/spec/models/superuser_spec.rb +13 -0
  169. data/spec/models/superuser_spec.rb~ +13 -0
  170. data/spec/models/target_spec.rb +8 -0
  171. data/spec/models/user_spec.rb +60 -0
  172. data/spec/models/user_spec.rb~ +56 -0
  173. data/spec/services/group_service_spec.rb +75 -0
  174. data/spec/services/group_service_spec.rb~ +71 -0
  175. data/spec/services/id_service_spec.rb +33 -0
  176. data/spec/spec_helper.rb +125 -0
  177. data/spec/support/shared_examples_for_access_controllables.rb +6 -0
  178. data/spec/support/shared_examples_for_associations.rb +8 -0
  179. data/spec/support/shared_examples_for_ddr_models.rb +7 -0
  180. data/spec/support/shared_examples_for_describables.rb +63 -0
  181. data/spec/support/shared_examples_for_event_loggables.rb +3 -0
  182. data/spec/support/shared_examples_for_events.rb +179 -0
  183. data/spec/support/shared_examples_for_governables.rb +17 -0
  184. data/spec/support/shared_examples_for_has_content.rb +136 -0
  185. data/spec/support/shared_examples_for_has_content_metadata.rb +74 -0
  186. data/spec/support/shared_examples_for_has_properties.rb +5 -0
  187. data/spec/support/shared_examples_for_indexing.rb +36 -0
  188. metadata +562 -0
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe User, :type => :model do
4
+
5
+ subject { FactoryGirl.build(:user) }
6
+
7
+ describe "#member_of?" do
8
+ it "should return true if the user is a member of the group" do
9
+ allow(subject).to receive(:groups).and_return(["foo", "bar"])
10
+ expect(subject).to be_member_of("foo")
11
+ end
12
+ it "should return false if the user is not a member of the group" do
13
+ allow(subject).to receive(:groups).and_return(["foo", "bar"])
14
+ expect(subject).not_to be_member_of("baz")
15
+ end
16
+ end
17
+
18
+ describe "#authorized_to_act_as_superuser?" do
19
+ it "should return false if the superuser group is not defined (nil)" do
20
+ DulHydra.superuser_group = nil
21
+ expect(subject).not_to be_authorized_to_act_as_superuser
22
+ end
23
+ it "should return false if the user is not a member of the superuser group" do
24
+ DulHydra.superuser_group = "superusers"
25
+ allow(subject).to receive(:groups).and_return(["normal"])
26
+ expect(subject).not_to be_authorized_to_act_as_superuser
27
+ end
28
+ it "should return true if the user is a member of the superuser group" do
29
+ DulHydra.superuser_group = "superusers"
30
+ allow(subject).to receive(:groups).and_return(["superusers"])
31
+ expect(subject).to be_authorized_to_act_as_superuser
32
+ end
33
+ end
34
+
35
+ describe "#principal_name" do
36
+ it "should return the principal name for the user" do
37
+ expect(subject.principal_name).to eq subject.user_key
38
+ end
39
+ end
40
+
41
+ describe "#principals" do
42
+ it "should be a list of the user's groups + the user's principal_name" do
43
+ allow(subject).to receive(:groups) { ["foo", "bar"] }
44
+ expect(subject.principals).to match_array ["foo", "bar", subject.principal_name]
45
+ end
46
+ end
47
+
48
+ describe "#has_role?" do
49
+ let(:obj) { double }
50
+ it "should send :principal_has_role? to the object with the user's principals" do
51
+ expect(obj).to receive(:principal_has_role?).with(subject.principals, :administrator)
52
+ subject.has_role?(obj, :administrator)
53
+ end
54
+ end
55
+
56
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ module Ddr
4
+ module Auth
5
+ RSpec.describe GroupService do
6
+ subject { described_class.new }
7
+
8
+ describe "#groups" do
9
+ describe "at minimum" do
10
+ it "should include the 'public' and 'registered' groups" do
11
+ expect(subject.groups).to include("public", "registered")
12
+ end
13
+ end
14
+ describe "using #append_groups hook" do
15
+ before { allow(subject).to receive(:append_groups).and_return(["spam:eggs", "fish:water"]) }
16
+ it "should add the groups to the list" do
17
+ expect(subject.groups).to include("spam:eggs", "fish:water")
18
+ end
19
+ end
20
+ describe "when RoleMapper config file is present and not empty" do
21
+ before do
22
+ allow(described_class).to receive(:include_role_mapper_groups).and_return(true)
23
+ allow(RoleMapper).to receive(:role_names).and_return(["foo", "bar"])
24
+ end
25
+ it "should include the role mapper groups" do
26
+ expect(subject.groups).to include("foo", "bar")
27
+ end
28
+ end
29
+ describe "when RoleMapper config file is missing or empty" do
30
+ before { allow(described_class).to receive(:include_role_mapper_groups).and_return(false) }
31
+ it "should only include the default minimum groups" do
32
+ expect(subject.groups).to match_array(["public", "registered"])
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "#user_groups(user)" do
38
+ describe "when user is not persisted" do
39
+ let(:user) { FactoryGirl.build(:user) }
40
+ it "should return only 'public' group" do
41
+ expect(subject.user_groups(user)).to eq(["public"])
42
+ end
43
+ end
44
+ describe "when the user is persisted" do
45
+ let(:user) { FactoryGirl.create(:user) }
46
+ it "should include the 'public' and 'registered' groups" do
47
+ expect(subject.user_groups(user)).to include("public", "registered")
48
+ end
49
+ describe "using #append_user_groups(user) hook" do
50
+ before { allow(subject).to receive(:append_user_groups).with(user).and_return(["spam:eggs", "fish:water"]) }
51
+ it "should add the groups to the list" do
52
+ expect(subject.user_groups(user)).to include("spam:eggs", "fish:water")
53
+ end
54
+ end
55
+ describe "when the RoleMapper config file is present and not empty" do
56
+ before do
57
+ allow(described_class).to receive(:include_role_mapper_groups).and_return(true)
58
+ allow(RoleMapper).to receive(:roles).with(user).and_return(["foo", "bar"])
59
+ end
60
+ it "should add the user's roles to the list" do
61
+ expect(subject.user_groups(user)).to include("foo", "bar")
62
+ end
63
+ end
64
+ describe "when RoleMapper config file is missing or empty" do
65
+ before { allow(described_class).to receive(:include_role_mapper_groups).and_return(false) }
66
+ it "should only include the default minimum groups" do
67
+ expect(subject.groups).to match_array(["public", "registered"])
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe DulHydra::Services::GroupService do
4
+ subject { described_class.new }
5
+
6
+ describe "#groups" do
7
+ describe "at minimum" do
8
+ it "should include the 'public' and 'registered' groups" do
9
+ expect(subject.groups).to include("public", "registered")
10
+ end
11
+ end
12
+ describe "using #append_groups hook" do
13
+ before { allow(subject).to receive(:append_groups).and_return(["spam:eggs", "fish:water"]) }
14
+ it "should add the groups to the list" do
15
+ expect(subject.groups).to include("spam:eggs", "fish:water")
16
+ end
17
+ end
18
+ describe "when RoleMapper config file is present and not empty" do
19
+ before do
20
+ allow(described_class).to receive(:include_role_mapper_groups).and_return(true)
21
+ allow(RoleMapper).to receive(:role_names).and_return(["foo", "bar"])
22
+ end
23
+ it "should include the role mapper groups" do
24
+ expect(subject.groups).to include("foo", "bar")
25
+ end
26
+ end
27
+ describe "when RoleMapper config file is missing or empty" do
28
+ before { allow(described_class).to receive(:include_role_mapper_groups).and_return(false) }
29
+ it "should only include the default minimum groups" do
30
+ expect(subject.groups).to match_array(["public", "registered"])
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "#user_groups(user)" do
36
+ describe "when user is not persisted" do
37
+ let(:user) { FactoryGirl.build(:user) }
38
+ it "should return only 'public' group" do
39
+ expect(subject.user_groups(user)).to eq(["public"])
40
+ end
41
+ end
42
+ describe "when the user is persisted" do
43
+ let(:user) { FactoryGirl.create(:user) }
44
+ it "should include the 'public' and 'registered' groups" do
45
+ expect(subject.user_groups(user)).to include("public", "registered")
46
+ end
47
+ describe "using #append_user_groups(user) hook" do
48
+ before { allow(subject).to receive(:append_user_groups).with(user).and_return(["spam:eggs", "fish:water"]) }
49
+ it "should add the groups to the list" do
50
+ expect(subject.user_groups(user)).to include("spam:eggs", "fish:water")
51
+ end
52
+ end
53
+ describe "when the RoleMapper config file is present and not empty" do
54
+ before do
55
+ allow(described_class).to receive(:include_role_mapper_groups).and_return(true)
56
+ allow(RoleMapper).to receive(:roles).with(user).and_return(["foo", "bar"])
57
+ end
58
+ it "should add the user's roles to the list" do
59
+ expect(subject.user_groups(user)).to include("foo", "bar")
60
+ end
61
+ end
62
+ describe "when RoleMapper config file is missing or empty" do
63
+ before { allow(described_class).to receive(:include_role_mapper_groups).and_return(false) }
64
+ it "should only include the default minimum groups" do
65
+ expect(subject.groups).to match_array(["public", "registered"])
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Ddr::Services::IdService do
4
+
5
+ before { FileUtils.rm(Ddr::Models.minter_statefile) if File.exists?(Ddr::Models.minter_statefile)}
6
+ after { FileUtils.rm(Ddr::Models.minter_statefile) }
7
+
8
+ context "identifier format" do
9
+ before { allow(Ddr::Services::IdService).to receive(:noid_template).and_return("x.rddeeddeek") }
10
+ it "should mint identifiers of the appropriate format" do
11
+ expect(Ddr::Services::IdService.mint).to match(/x\d\d\w\w\d\d\w\w\w/)
12
+ end
13
+ end
14
+
15
+ context "duplicate identifiers" do
16
+ before do
17
+ allow(Ddr::Services::IdService).to receive(:noid_template).and_return(".rd")
18
+ Ddr::Models::MintedId.create(minted_id: '0')
19
+ Ddr::Models::MintedId.create(minted_id: '1')
20
+ Ddr::Models::MintedId.create(minted_id: '2')
21
+ Ddr::Models::MintedId.create(minted_id: '3')
22
+ Ddr::Models::MintedId.create(minted_id: '4')
23
+ Ddr::Models::MintedId.create(minted_id: '6')
24
+ Ddr::Models::MintedId.create(minted_id: '7')
25
+ Ddr::Models::MintedId.create(minted_id: '8')
26
+ Ddr::Models::MintedId.create(minted_id: '9')
27
+ end
28
+ it "should not mint an already existing identifier" do
29
+ expect(Ddr::Services::IdService.mint).to eq('5')
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,125 @@
1
+ ENV['RAILS_ENV'] ||= "test"
2
+
3
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
+
5
+ require "ddr-models"
6
+ require "rails"
7
+ require "rspec/rails"
8
+ require "factory_girl_rails"
9
+ require "database_cleaner"
10
+
11
+ Dir[File.join(File.dirname(__FILE__), "support", "*.rb")].each { |f| require f }
12
+
13
+ DatabaseCleaner.strategy = :truncation
14
+
15
+ require "ddr-antivirus"
16
+ Ddr::Antivirus.scanner_adapter = :null
17
+
18
+ require "logger"
19
+ Ddr::Antivirus.logger = Logger.new(File::NULL)
20
+
21
+ # This file was generated by the `rspec --init` command. Conventionally, all
22
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
23
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
24
+ # file to always be loaded, without a need to explicitly require it in any files.
25
+ #
26
+ # Given that it is always loaded, you are encouraged to keep this file as
27
+ # light-weight as possible. Requiring heavyweight dependencies from this file
28
+ # will add to the boot time of your test suite on EVERY test run, even for an
29
+ # individual file that may not need all of that loaded. Instead, consider making
30
+ # a separate helper file that requires the additional dependencies and performs
31
+ # the additional setup, and require it from the spec files that actually need it.
32
+ #
33
+ # The `.rspec` file also contains a few flags that are not defaults but that
34
+ # users commonly want.
35
+ #
36
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
37
+ RSpec.configure do |config|
38
+
39
+ config.include ActionDispatch::TestProcess
40
+ config.fixture_path = File.join(Ddr::Models::Engine.root, "spec", "fixtures")
41
+ config.use_transactional_fixtures = true
42
+
43
+ # rspec-expectations config goes here. You can use an alternate
44
+ # assertion/expectation library such as wrong or the stdlib/minitest
45
+ # assertions if you prefer.
46
+ config.expect_with :rspec do |expectations|
47
+ # This option will default to `true` in RSpec 4. It makes the `description`
48
+ # and `failure_message` of custom matchers include text for helper methods
49
+ # defined using `chain`, e.g.:
50
+ # be_bigger_than(2).and_smaller_than(4).description
51
+ # # => "be bigger than 2 and smaller than 4"
52
+ # ...rather than:
53
+ # # => "be bigger than 2"
54
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
55
+ end
56
+
57
+ # rspec-mocks config goes here. You can use an alternate test double
58
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
59
+ config.mock_with :rspec do |mocks|
60
+ # Prevents you from mocking or stubbing a method that does not exist on
61
+ # a real object. This is generally recommended, and will default to
62
+ # `true` in RSpec 4.
63
+ mocks.verify_partial_doubles = true
64
+ end
65
+
66
+ # These two settings work together to allow you to limit a spec run
67
+ # to individual examples or groups you care about by tagging them with
68
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
69
+ # get run.
70
+ config.filter_run :focus
71
+ config.run_all_when_everything_filtered = true
72
+
73
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
74
+ # For more details, see:
75
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
76
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
77
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
78
+ config.disable_monkey_patching!
79
+
80
+ # This setting enables warnings. It's recommended, but in some cases may
81
+ # be too noisy due to issues in dependencies.
82
+ #config.warnings = true
83
+
84
+ # Many RSpec users commonly either run the entire suite or an individual
85
+ # file, and it's useful to allow more verbose output when running an
86
+ # individual spec file.
87
+ if config.files_to_run.one?
88
+ # Use the documentation formatter for detailed output,
89
+ # unless a formatter has already been configured
90
+ # (e.g. via a command-line flag).
91
+ config.default_formatter = 'doc'
92
+ end
93
+
94
+ # Print the 10 slowest examples and example groups at the
95
+ # end of the spec run, to help surface which specs are running
96
+ # particularly slow.
97
+ #config.profile_examples = 10
98
+
99
+ # Run specs in random order to surface order dependencies. If you find an
100
+ # order dependency and want to debug it, you can fix the order by providing
101
+ # the seed, which is printed after each run.
102
+ # --seed 1234
103
+ config.order = :random
104
+
105
+ # Seed global randomization in this process using the `--seed` CLI option.
106
+ # Setting this allows you to use `--seed` to deterministically reproduce
107
+ # test failures related to randomization by passing the same `--seed` value
108
+ # as the one that triggered the failure.
109
+ Kernel.srand config.seed
110
+
111
+ config.before(:suite) do
112
+ DatabaseCleaner.clean
113
+ ActiveFedora::Base.destroy_all
114
+ Ddr::Models.external_file_store = Dir.mktmpdir
115
+ end
116
+
117
+ config.after(:suite) do
118
+ FileUtils.remove_entry_secure Ddr::Models.external_file_store
119
+ end
120
+
121
+ config.after(:each) do
122
+ ActiveFedora::Base.destroy_all
123
+ end
124
+
125
+ end
@@ -0,0 +1,6 @@
1
+ RSpec.shared_examples "an access controllable object" do
2
+ it "should have a rightsMetadata datastream" do
3
+ expect(subject.datastreams.keys).to include("rightsMetadata")
4
+ expect(subject.datastreams["rightsMetadata"]).to be_kind_of(Hydra::Datastream::RightsMetadata)
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ RSpec.shared_examples "it has an association" do |macro, association, property, class_name|
2
+ it "via a certain property" do
3
+ expect(described_class.reflect_on_association(association).options[:property]).to eq property
4
+ end
5
+ it "targeting a certain class name" do
6
+ expect(described_class.reflect_on_association(association).options[:class_name]).to eq class_name
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ RSpec.shared_examples "a DDR model" do
2
+ it_behaves_like "a describable object"
3
+ it_behaves_like "a governable object"
4
+ it_behaves_like "an access controllable object"
5
+ it_behaves_like "an object that has properties"
6
+ it_behaves_like "an object that has a display title"
7
+ end
@@ -0,0 +1,63 @@
1
+ RSpec.shared_examples "a describable object" do
2
+ let(:object) { described_class.new }
3
+ context "having an identifier" do
4
+ before do
5
+ object.identifier = ["id001"]
6
+ object.save(validate: false)
7
+ end
8
+ it "should be findable by identifier" do
9
+ expect(described_class.find_by_identifier('id001')).to include object
10
+ end
11
+ end
12
+ describe "#desc_metadata_terms" do
13
+ it "should have a default value" do
14
+ expect(object.desc_metadata_terms).to eq Ddr::Datastreams::DescriptiveMetadataDatastream.term_names
15
+ end
16
+ describe "arguments" do
17
+ it "with fixed results" do
18
+ expect(object.desc_metadata_terms(:dcterms)).to eq(Ddr::Metadata::Vocabulary.term_names(RDF::DC11) + (Ddr::Metadata::Vocabulary.term_names(RDF::DC) - Ddr::Metadata::Vocabulary.term_names(RDF::DC11)))
19
+ expect(object.desc_metadata_terms(:dcterms)).to match_array Ddr::Metadata::Vocabulary.term_names(RDF::DC)
20
+ expect(object.desc_metadata_terms(:duke)).to eq Ddr::Metadata::Vocabulary.term_names(Ddr::Metadata::DukeTerms)
21
+ expect(object.desc_metadata_terms(:dcterms_elements11)).to eq Ddr::Metadata::Vocabulary.term_names(RDF::DC11)
22
+ expect(object.desc_metadata_terms(:defined_attributes)).to match_array Ddr::Metadata::Vocabulary.term_names(RDF::DC11)
23
+ end
24
+ context "with variable results" do
25
+ before do
26
+ object.descMetadata.title = ["Object Title"]
27
+ object.descMetadata.creator = ["Duke University Libraries"]
28
+ object.descMetadata.identifier = ["id001"]
29
+ object.save
30
+ end
31
+ it "should accept an :empty argument" do
32
+ expect(object.desc_metadata_terms(:empty)).to eq(object.desc_metadata_terms - [:title, :creator, :identifier])
33
+ end
34
+ it "should accept a :present argument" do
35
+ expect(object.desc_metadata_terms(:present)).to match_array [:title, :creator, :identifier]
36
+ end
37
+ end
38
+ end
39
+ end
40
+ describe "#set_desc_metadata" do
41
+ let(:term_values_hash) { object.desc_metadata_terms.each_with_object({}) {|t, memo| memo[t] = ["Value"]} }
42
+ it "should set the descMetadata terms to the values of the matching keys in the hash" do
43
+ object.desc_metadata_terms.each do |t|
44
+ expect(object).to receive(:set_desc_metadata_values).with(t, ["Value"])
45
+ end
46
+ object.set_desc_metadata(term_values_hash)
47
+ end
48
+ end
49
+ describe "#set_desc_metadata_values" do
50
+ context "when values == nil" do
51
+ it "should set the term to an empty value" do
52
+ object.set_desc_metadata_values(:title, nil)
53
+ expect(object.descMetadata.title).to be_empty
54
+ end
55
+ end
56
+ context "when values is an array" do
57
+ it "should reject empty values from the array" do
58
+ object.set_desc_metadata_values(:title, ["Object Title", nil, "Alternative Title", ""])
59
+ expect(object.descMetadata.title).to eq ["Object Title", "Alternative Title"]
60
+ end
61
+ end
62
+ end
63
+ end