active-fedora 10.3.0 → 11.0.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 (164) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +6 -7
  4. data/.rubocop_todo.yml +55 -0
  5. data/active-fedora.gemspec +6 -10
  6. data/lib/active_fedora/aggregation/list_source.rb +2 -0
  7. data/lib/active_fedora/associations/association_scope.rb +1 -1
  8. data/lib/active_fedora/associations/builder/aggregation.rb +1 -1
  9. data/lib/active_fedora/associations/builder/association.rb +1 -1
  10. data/lib/active_fedora/associations/builder/orders.rb +11 -3
  11. data/lib/active_fedora/associations/collection_association.rb +3 -3
  12. data/lib/active_fedora/associations/contained_finder.rb +2 -2
  13. data/lib/active_fedora/associations/has_many_association.rb +1 -1
  14. data/lib/active_fedora/associations/orders_association.rb +4 -0
  15. data/lib/active_fedora/associations/rdf.rb +2 -0
  16. data/lib/active_fedora/attribute_assignment.rb +0 -1
  17. data/lib/active_fedora/attribute_methods/dirty.rb +1 -1
  18. data/lib/active_fedora/attributes.rb +1 -1
  19. data/lib/active_fedora/base.rb +4 -8
  20. data/lib/active_fedora/change_set.rb +6 -2
  21. data/lib/active_fedora/core.rb +22 -27
  22. data/lib/active_fedora/fedora.rb +2 -6
  23. data/lib/active_fedora/fedora_attributes.rb +1 -1
  24. data/lib/active_fedora/file/streaming.rb +1 -1
  25. data/lib/active_fedora/indexing.rb +1 -18
  26. data/lib/active_fedora/indexing_service.rb +0 -9
  27. data/lib/active_fedora/loadable_from_json.rb +12 -1
  28. data/lib/active_fedora/nested_attributes.rb +2 -2
  29. data/lib/active_fedora/orders/list_node.rb +2 -2
  30. data/lib/active_fedora/orders/ordered_list.rb +7 -3
  31. data/lib/active_fedora/orders/target_proxy.rb +4 -0
  32. data/lib/active_fedora/querying.rb +1 -1
  33. data/lib/active_fedora/railtie.rb +2 -2
  34. data/lib/active_fedora/rdf/persistence.rb +1 -0
  35. data/lib/active_fedora/rdf.rb +0 -1
  36. data/lib/active_fedora/relation/delegation.rb +4 -0
  37. data/lib/active_fedora/solr_hit.rb +0 -13
  38. data/lib/active_fedora/solr_query_builder.rb +17 -13
  39. data/lib/active_fedora/version.rb +1 -1
  40. data/lib/active_fedora.rb +0 -12
  41. data/lib/generators/active_fedora/model/model_generator.rb +1 -1
  42. data/lib/generators/active_fedora/model/templates/model.rb.erb +4 -4
  43. data/lib/tasks/active_fedora_dev.rake +1 -1
  44. data/spec/config_helper.rb +1 -1
  45. data/spec/integration/associations_spec.rb +23 -24
  46. data/spec/integration/attached_files_spec.rb +18 -8
  47. data/spec/integration/attributes_spec.rb +12 -16
  48. data/spec/integration/autosave_association_spec.rb +6 -6
  49. data/spec/integration/base_spec.rb +3 -3
  50. data/spec/integration/basic_contains_association_spec.rb +1 -1
  51. data/spec/integration/clean_connection_spec.rb +1 -1
  52. data/spec/integration/collection_association_spec.rb +2 -5
  53. data/spec/integration/date_time_properties_spec.rb +1 -17
  54. data/spec/integration/direct_container_spec.rb +12 -12
  55. data/spec/integration/directly_contains_one_association_spec.rb +11 -13
  56. data/spec/integration/fedora_solr_sync_spec.rb +2 -2
  57. data/spec/integration/file_fixity_spec.rb +6 -8
  58. data/spec/integration/file_spec.rb +32 -34
  59. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +5 -5
  60. data/spec/integration/has_many_associations_spec.rb +9 -11
  61. data/spec/integration/indexing_spec.rb +2 -2
  62. data/spec/integration/indirect_container_spec.rb +11 -12
  63. data/spec/integration/json_serialization_spec.rb +4 -4
  64. data/spec/integration/query_result_builder_spec.rb +9 -21
  65. data/spec/integration/rdf_nested_attributes_spec.rb +7 -7
  66. data/spec/integration/relation_delegation_spec.rb +8 -10
  67. data/spec/integration/relation_spec.rb +13 -16
  68. data/spec/integration/scoped_query_spec.rb +3 -3
  69. data/spec/integration/solr_hit_spec.rb +4 -15
  70. data/spec/integration/versionable_spec.rb +73 -327
  71. data/spec/integration/with_metadata_spec.rb +1 -1
  72. data/spec/spec_helper.rb +52 -10
  73. data/spec/unit/active_fedora_spec.rb +1 -1
  74. data/spec/unit/aggregation/list_source_spec.rb +37 -37
  75. data/spec/unit/aggregation/ordered_reader_spec.rb +4 -4
  76. data/spec/unit/association_hash_spec.rb +17 -31
  77. data/spec/unit/attached_files_spec.rb +35 -32
  78. data/spec/unit/attributes_spec.rb +25 -25
  79. data/spec/unit/base_active_model_spec.rb +8 -8
  80. data/spec/unit/base_cma_spec.rb +1 -1
  81. data/spec/unit/base_extra_spec.rb +7 -22
  82. data/spec/unit/base_spec.rb +17 -24
  83. data/spec/unit/callback_spec.rb +2 -2
  84. data/spec/unit/change_set_spec.rb +5 -5
  85. data/spec/unit/checksum_spec.rb +2 -2
  86. data/spec/unit/code_configurator_spec.rb +1 -1
  87. data/spec/unit/core/fedora_id_translator_spec.rb +2 -2
  88. data/spec/unit/core/fedora_uri_translator_spec.rb +2 -2
  89. data/spec/unit/core_spec.rb +65 -29
  90. data/spec/unit/default_model_mapper_spec.rb +6 -6
  91. data/spec/unit/fedora_spec.rb +3 -4
  92. data/spec/unit/file_configurator_spec.rb +96 -96
  93. data/spec/unit/file_path_builder_spec.rb +1 -1
  94. data/spec/unit/file_spec.rb +61 -61
  95. data/spec/unit/files_hash_spec.rb +9 -9
  96. data/spec/unit/filter_spec.rb +3 -3
  97. data/spec/unit/finder_methods_spec.rb +3 -3
  98. data/spec/unit/forbidden_attributes_protection_spec.rb +2 -2
  99. data/spec/unit/has_and_belongs_to_many_association_spec.rb +14 -15
  100. data/spec/unit/has_many_association_spec.rb +5 -5
  101. data/spec/unit/indexers/global_indexer_spec.rb +6 -6
  102. data/spec/unit/indexing_service_spec.rb +5 -5
  103. data/spec/unit/indexing_spec.rb +6 -6
  104. data/spec/unit/inheritance_spec.rb +11 -7
  105. data/spec/unit/loadable_from_json_spec.rb +4 -4
  106. data/spec/unit/logger_spec.rb +1 -1
  107. data/spec/unit/model_classifier_spec.rb +5 -5
  108. data/spec/unit/ordered_spec.rb +144 -147
  109. data/spec/unit/orders/list_node_spec.rb +21 -21
  110. data/spec/unit/orders/ordered_list_spec.rb +96 -96
  111. data/spec/unit/orders/reflection_spec.rb +4 -4
  112. data/spec/unit/pathing_spec.rb +4 -4
  113. data/spec/unit/persistence_spec.rb +28 -28
  114. data/spec/unit/property_spec.rb +2 -2
  115. data/spec/unit/query_spec.rb +6 -6
  116. data/spec/unit/rdf/indexing_service_spec.rb +29 -29
  117. data/spec/unit/readonly_spec.rb +5 -4
  118. data/spec/unit/reflection_spec.rb +3 -3
  119. data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +9 -9
  120. data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +9 -9
  121. data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +9 -9
  122. data/spec/unit/schema_indexing_strategy_spec.rb +5 -5
  123. data/spec/unit/serializers_spec.rb +3 -4
  124. data/spec/unit/solr_config_options_spec.rb +13 -16
  125. data/spec/unit/solr_hit_spec.rb +9 -9
  126. data/spec/unit/solr_service_spec.rb +4 -10
  127. data/spec/unit/sparql_insert_spec.rb +2 -2
  128. data/spec/unit/validations_spec.rb +9 -9
  129. data/spec/unit/with_metadata/default_metadata_class_factory_spec.rb +3 -2
  130. data/spec/unit/with_metadata/metadata_node_spec.rb +3 -2
  131. metadata +18 -92
  132. data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +0 -119
  133. data/lib/active_fedora/datastreams.rb +0 -6
  134. data/lib/active_fedora/nom_datastream.rb +0 -73
  135. data/lib/active_fedora/om_datastream.rb +0 -118
  136. data/lib/active_fedora/profile_indexing_service.rb +0 -11
  137. data/lib/active_fedora/qualified_dublin_core_datastream.rb +0 -158
  138. data/lib/active_fedora/rdf/datastream_indexing.rb +0 -49
  139. data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +0 -13
  140. data/lib/active_fedora/rdf/rdf_datastream.rb +0 -167
  141. data/lib/active_fedora/rdf/rdfxml_datastream.rb +0 -13
  142. data/lib/active_fedora/solr_instance_loader.rb +0 -47
  143. data/spec/fixtures/damsObjectModel.xml +0 -38
  144. data/spec/fixtures/dublin_core_rdf_descMetadata.nt +0 -13
  145. data/spec/fixtures/mixed_rdf_descMetadata.nt +0 -7
  146. data/spec/fixtures/mods_articles/mods_article1.xml +0 -98
  147. data/spec/fixtures/solr_rdf_descMetadata.nt +0 -7
  148. data/spec/integration/complex_rdf_datastream_spec.rb +0 -228
  149. data/spec/integration/datastream_rdf_nested_attributes_spec.rb +0 -179
  150. data/spec/integration/ntriples_datastream_spec.rb +0 -203
  151. data/spec/integration/om_datastream_spec.rb +0 -78
  152. data/spec/integration/solr_instance_loader_spec.rb +0 -156
  153. data/spec/samples/hydra-mods_article_datastream.rb +0 -517
  154. data/spec/samples/models/mods_article.rb +0 -9
  155. data/spec/samples/oral_history_sample.xml +0 -38
  156. data/spec/samples/oral_history_xml.xml +0 -35
  157. data/spec/samples/samples.rb +0 -2
  158. data/spec/unit/nom_datastream_spec.rb +0 -60
  159. data/spec/unit/ntriples_datastream_spec.rb +0 -170
  160. data/spec/unit/om_datastream_spec.rb +0 -294
  161. data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -119
  162. data/spec/unit/rdf_datastream_spec.rb +0 -84
  163. data/spec/unit/rdf_resource_datastream_spec.rb +0 -204
  164. data/spec/unit/rdfxml_datastream_spec.rb +0 -106
@@ -159,7 +159,7 @@ module ActiveFedora
159
159
 
160
160
  # Attribute hash keys that should not be assigned as normal attributes.
161
161
  # These hash keys are nested attributes implementation details.
162
- UNASSIGNABLE_KEYS = %w( id _destroy ).freeze
162
+ UNASSIGNABLE_KEYS = %w(id _destroy).freeze
163
163
 
164
164
  # Assigns the given attributes to the association.
165
165
  #
@@ -308,7 +308,7 @@ module ActiveFedora
308
308
  opts = nested_attributes_options[association_name]
309
309
  case callback = opts[:reject_if]
310
310
  when Symbol
311
- method(callback).arity == 0 ? send(callback) : send(callback, attributes)
311
+ method(callback).arity.zero? ? send(callback) : send(callback, attributes)
312
312
  when Proc
313
313
  callback.call(attributes)
314
314
  end
@@ -4,7 +4,7 @@ module ActiveFedora::Orders
4
4
  attr_accessor :prev, :next, :target
5
5
  attr_writer :next_uri, :prev_uri
6
6
  attr_accessor :proxy_in, :proxy_for
7
- def initialize(node_cache, rdf_subject, graph = RDF::Graph.new)
7
+ def initialize(node_cache, rdf_subject, graph = RDF::Repository.new)
8
8
  @rdf_subject = rdf_subject
9
9
  @graph = graph
10
10
  @node_cache = node_cache
@@ -144,7 +144,7 @@ module ActiveFedora::Orders
144
144
  private
145
145
 
146
146
  def resource
147
- @resource ||= Resource.new(uri, graph)
147
+ @resource ||= Resource.new(uri, data: graph)
148
148
  end
149
149
  end
150
150
 
@@ -13,7 +13,11 @@ module ActiveFedora
13
13
  # @param [::RDF::URI] head_subject URI of head node in list.
14
14
  # @param [::RDF::URI] tail_subject URI of tail node in list.
15
15
  def initialize(graph, head_subject, tail_subject)
16
- @graph = graph
16
+ @graph = if graph.respond_to?(:graph)
17
+ graph.graph.data
18
+ else
19
+ graph
20
+ end
17
21
  @head_subject = head_subject
18
22
  @tail_subject = tail_subject
19
23
  @node_cache ||= NodeCache.new
@@ -86,7 +90,7 @@ module ActiveFedora
86
90
  node = build_node(new_node_subject)
87
91
  node.target = target
88
92
  node.proxy_in = proxy_in
89
- if loc == 0
93
+ if loc.zero?
90
94
  append_to(node, head)
91
95
  else
92
96
  append_to(node, ordered_reader.take(loc).last)
@@ -99,7 +103,7 @@ module ActiveFedora
99
103
  node = build_node(new_node_subject)
100
104
  node.proxy_for = proxy_for
101
105
  node.proxy_in = proxy_in
102
- if loc == 0
106
+ if loc.zero?
103
107
  append_to(node, head)
104
108
  else
105
109
  append_to(node, ordered_reader.take(loc).last)
@@ -24,6 +24,10 @@ module ActiveFedora
24
24
  self
25
25
  end
26
26
 
27
+ def ids
28
+ association.reader.map(&:target_id)
29
+ end
30
+
27
31
  # Deletes the element at the specified index, returning that element, or nil if
28
32
  # the index is out of range.
29
33
  def delete_at(loc)
@@ -1,7 +1,7 @@
1
1
  module ActiveFedora
2
2
  module Querying
3
3
  delegate :find, :first, :exists?, :where, :limit, :offset, :order, :delete_all,
4
- :destroy_all, :count, :last, :find_with_conditions, :find_in_batches, :search_with_conditions, :search_in_batches, :search_by_id, :find_each, to: :all
4
+ :destroy_all, :count, :last, :search_with_conditions, :search_in_batches, :search_by_id, :find_each, to: :all
5
5
 
6
6
  def self.extended(base)
7
7
  base.class_attribute :solr_query_handler
@@ -1,7 +1,7 @@
1
1
  module ActiveFedora
2
2
  class Railtie < Rails::Railtie
3
- config.app_middleware.insert_after "::ActionDispatch::Callbacks",
4
- "ActiveFedora::LdpCache"
3
+ config.app_middleware.insert_after ::ActionDispatch::Callbacks,
4
+ ActiveFedora::LdpCache
5
5
 
6
6
  initializer 'active_fedora.autoload', before: :set_autoload_paths do |app|
7
7
  app.config.autoload_paths << 'app/models/datastreams'
@@ -25,6 +25,7 @@ module ActiveFedora
25
25
 
26
26
  # Overrides ActiveTriples::Resource
27
27
  def persisted?
28
+ return true if frozen? && !datastream.new_record?
28
29
  @persisted ||= !datastream.new_record?
29
30
  end
30
31
  end
@@ -1,7 +1,6 @@
1
1
  module ActiveFedora
2
2
  module RDF
3
3
  extend ActiveSupport::Autoload
4
- autoload :DatastreamIndexing
5
4
  autoload :Fcrepo
6
5
  autoload :IndexingService
7
6
  autoload :Persistence
@@ -29,5 +29,9 @@ module ActiveFedora
29
29
  super
30
30
  end
31
31
  end
32
+
33
+ def respond_to_missing?(method, *args)
34
+ array_delegable?(method) || super
35
+ end
32
36
  end
33
37
  end
@@ -46,15 +46,6 @@ module ActiveFedora
46
46
  end
47
47
  end
48
48
 
49
- def instantiate_with_json
50
- model.allocate.init_with_json(profile_json) do |allocated_object|
51
- create_key = allocated_object.indexing_service.class.create_time_solr_name
52
- modified_key = allocated_object.indexing_service.class.modified_time_solr_name
53
- allocated_object.resource.set_value(:create_date, DateTime.parse(document[create_key])) if document[create_key]
54
- allocated_object.resource.set_value(:modified_date, DateTime.parse(document[modified_key])) if document[modified_key]
55
- end
56
- end
57
-
58
49
  def reify(opts = {})
59
50
  model(opts).find(id, cast: true)
60
51
  end
@@ -64,9 +55,5 @@ module ActiveFedora
64
55
  def classifier
65
56
  ActiveFedora.model_mapper.classifier(document)
66
57
  end
67
-
68
- def profile_json
69
- Array(document[ActiveFedora::IndexingService.profile_solr_name]).first
70
- end
71
58
  end
72
59
  end
@@ -11,29 +11,30 @@ module ActiveFedora
11
11
  "{!terms f=#{ActiveFedora.id_field}}#{ids.join(',')}"
12
12
  end
13
13
 
14
- # Create a query with a clause for each key, value
14
+ # Create a raw query with a clause for each key, value
15
15
  # @param [Hash, Array<Array<String>>] field_pairs key is the predicate, value is the target_uri
16
16
  # @param [String] join_with ('AND') the value we're joining the clauses with
17
17
  # @example
18
- # construct_query_for_rel [[:has_model, "info:fedora/afmodel:ComplexCollection"], [:has_model, "info:fedora/afmodel:ActiveFedora_Base"]], 'OR'
19
- # # => _query_:"{!field f=has_model_ssim}info:fedora/afmodel:ComplexCollection" OR _query_:"{!field f=has_model_ssim}info:fedora/afmodel:ActiveFedora_Base"
18
+ # construct_query_for_rel [[:has_model, "ComplexCollection"], [:has_model, "ActiveFedora_Base"]], 'OR'
19
+ # # => _query_:"{!raw f=has_model_ssim}ComplexCollection" OR _query_:"{!raw f=has_model_ssim}ActiveFedora_Base"
20
20
  #
21
21
  # construct_query_for_rel [[Book._reflect_on_association(:library), "foo/bar/baz"]]
22
22
  def construct_query_for_rel(field_pairs, join_with = default_join_with)
23
23
  field_pairs = field_pairs.to_a if field_pairs.is_a? Hash
24
- construct_query(property_values_to_solr(field_pairs), join_with)
24
+ construct_query(property_values_to_solr(field_pairs), join_with, 'raw'.freeze)
25
25
  end
26
26
 
27
27
  # Construct a solr query from a list of pairs (e.g. [field name, values])
28
28
  # @param [Array<Array>] field_pairs a list of pairs of property name and values
29
29
  # @param [String] join_with ('AND') the value we're joining the clauses with
30
+ # @param [String] type ('field') The type of query to run. Either 'raw' or 'field'
30
31
  # @return [String] a solr query
31
32
  # @example
32
33
  # construct_query([['library_id_ssim', '123'], ['owner_ssim', 'Fred']])
33
34
  # # => "_query_:\"{!field f=library_id_ssim}123\" AND _query_:\"{!field f=owner_ssim}Fred\""
34
- def construct_query(field_pairs, join_with = default_join_with)
35
- clauses = pairs_to_clauses(field_pairs)
36
- return "" if clauses.count == 0
35
+ def construct_query(field_pairs, join_with = default_join_with, type = 'field'.freeze)
36
+ clauses = pairs_to_clauses(field_pairs, type)
37
+ return "" if clauses.count.zero?
37
38
  return clauses.first if clauses.count == 1
38
39
  "(#{clauses.join(join_with)})"
39
40
  end
@@ -45,22 +46,24 @@ module ActiveFedora
45
46
  private
46
47
 
47
48
  # @param [Array<Array>] pairs a list of (key, value) pairs. The value itself may
49
+ # @param [String] type The type of query to run. Either 'raw' or 'field'
48
50
  # @return [Array] a list of solr clauses
49
- def pairs_to_clauses(pairs)
51
+ def pairs_to_clauses(pairs, type)
50
52
  pairs.flat_map do |field, value|
51
- condition_to_clauses(field, value)
53
+ condition_to_clauses(field, value, type)
52
54
  end
53
55
  end
54
56
 
55
57
  # @param [String] field
56
58
  # @param [String, Array<String>] values
59
+ # @param [String] type The type of query to run. Either 'raw' or 'field'
57
60
  # @return [Array<String>]
58
- def condition_to_clauses(field, values)
61
+ def condition_to_clauses(field, values, type)
59
62
  values = Array(values)
60
63
  values << nil if values.empty?
61
64
  values.map do |value|
62
65
  if value.present?
63
- field_query(field, value)
66
+ query_clause(type, field, value)
64
67
  else
65
68
  # Check that the field is not present. In SQL: "WHERE field IS NULL"
66
69
  "-#{field}:[* TO *]"
@@ -93,10 +96,11 @@ module ActiveFedora
93
96
  end
94
97
 
95
98
  # Create a raw query clause suitable for sending to solr as an fq element
99
+ # @param [String] type The type of query to run. Either 'raw' or 'field'
96
100
  # @param [String] key
97
101
  # @param [String] value
98
- def field_query(key, value)
99
- "_query_:\"{!field f=#{key}}#{value.gsub('"', '\"')}\""
102
+ def query_clause(type, key, value)
103
+ "_query_:\"{!#{type} f=#{key}}#{value.gsub('"', '\"')}\""
100
104
  end
101
105
  end
102
106
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "10.3.0".freeze
2
+ VERSION = "11.0.0".freeze
3
3
  end
data/lib/active_fedora.rb CHANGED
@@ -59,7 +59,6 @@ module ActiveFedora #:nodoc:
59
59
  autoload :DirectContainer
60
60
  autoload :IndirectContainer
61
61
  end
62
- autoload :Datastreams
63
62
  autoload :DelegatedAttribute
64
63
  autoload_under 'attributes' do
65
64
  autoload :ActiveTripleAttribute
@@ -89,24 +88,14 @@ module ActiveFedora #:nodoc:
89
88
  autoload :LoadableFromJson
90
89
  autoload :ModelClassifier
91
90
  autoload :NestedAttributes
92
- autoload :NomDatastream
93
91
  autoload :NullRelation
94
- autoload :OmDatastream
95
92
  autoload :Orders
96
93
  autoload :Pathing
97
94
  autoload :Persistence
98
- autoload :ProfileIndexingService
99
95
  autoload :Property
100
- autoload :QualifiedDublinCoreDatastream
101
96
  autoload :Querying
102
97
  autoload :QueryResultBuilder
103
98
  autoload :RDF
104
- autoload_under 'rdf' do
105
- autoload :RDFDatastream
106
- autoload :RDFXMLDatastream
107
- autoload :NtriplesRDFDatastream
108
- autoload :FedoraRdfResource
109
- end
110
99
  autoload :Reflection
111
100
  autoload :Relation
112
101
 
@@ -124,7 +113,6 @@ module ActiveFedora #:nodoc:
124
113
  autoload :Serialization
125
114
  autoload :SchemaIndexingStrategy
126
115
  autoload :SolrHit
127
- autoload :SolrInstanceLoader
128
116
  autoload :SolrQueryBuilder
129
117
  autoload :SolrService
130
118
  autoload :SparqlInsert
@@ -7,7 +7,7 @@ module ActiveFedora
7
7
 
8
8
  class_option :directory, type: :string, default: 'models', desc: "Which directory to generate? (i.e. app/DIRECTORY)"
9
9
  class_option :datastream_directory, type: :string, default: 'models/datastreams', desc: "Which datastream directory to generate? (i.e. models/datastreams)"
10
- class_option :contains, type: :string, default: nil, desc: "Name a file to attach"
10
+ class_option :has_subresource, type: :string, default: nil, desc: "Name a file to attach"
11
11
  class_option :datastream, type: :string, default: nil, desc: "Name a metadata datastream to create"
12
12
 
13
13
  def install
@@ -2,7 +2,7 @@
2
2
  # `rails generate active_fedora:model <%= class_name %>`
3
3
  class <%= class_name %> < ActiveFedora::Base
4
4
  <% if options['datastream'] %>
5
- contains :descMetadata, class_name: "<%= options['datastream'] %>"
5
+ has_subresource :descMetadata, class_name: "<%= options['datastream'] %>"
6
6
  <% else %>
7
7
  # Define some properties to store:
8
8
  #
@@ -19,12 +19,12 @@ class <%= class_name %> < ActiveFedora::Base
19
19
  index.as :stored_searchable
20
20
  end
21
21
  <%- end -%>
22
- <% if options['contains'] %>
23
- contains :<%= options['contains'] %>"
22
+ <% if options['has_subresource'] %>
23
+ has_subresource :<%= options['has_subresource'] %>"
24
24
  <% else %>
25
25
  # Uncomment the following lines to add an #attachment method that is a file
26
26
  #
27
- # contains "attachment"
27
+ # has_subresource "attachment"
28
28
  <% end %>
29
29
  #
30
30
  # If you need to add additional attributes to the SOLR document, extend the default indexer:
@@ -43,9 +43,9 @@ namespace :active_fedora do
43
43
 
44
44
  desc "CI build"
45
45
  task :ci do
46
+ Rake::Task['active_fedora:rubocop'].invoke unless ENV['NO_RUBOCOP']
46
47
  ENV['environment'] = "test"
47
48
  with_test_server do
48
- Rake::Task['active_fedora:rubocop'].invoke unless ENV['NO_RUBOCOP']
49
49
  Rake::Task['active_fedora:coverage'].invoke
50
50
  end
51
51
  end
@@ -1,5 +1,5 @@
1
1
  def mock_yaml(hash, path)
2
- mock_file = double(path.split("/")[-1])
2
+ mock_file = instance_double(File, path.split("/")[-1])
3
3
  allow(File).to receive(:exist?).with(path).and_return(true)
4
4
  allow(File).to receive(:open).with(path).and_return(mock_file)
5
5
  allow(Psych).to receive(:load).and_return(hash)
@@ -17,7 +17,7 @@ describe ActiveFedora::Base do
17
17
  end
18
18
 
19
19
  let(:person) { Person.create }
20
- let(:book) { Book.new(author: person) }
20
+ subject(:book) { Book.new(author: person) }
21
21
 
22
22
  it "goes" do
23
23
  book.save
@@ -197,7 +197,7 @@ describe ActiveFedora::Base do
197
197
 
198
198
  it "lets you set an array of objects" do
199
199
  @library.books = [@book, @book2]
200
- expect(@library.books).to eq [@book, @book2]
200
+ expect(@library.books).to contain_exactly @book, @book2
201
201
  @library.save
202
202
 
203
203
  @library.books = [@book]
@@ -205,7 +205,7 @@ describe ActiveFedora::Base do
205
205
  end
206
206
  it "lets you set an array of object ids" do
207
207
  @library.book_ids = [@book.id, @book2.id]
208
- expect(@library.books).to eq [@book, @book2]
208
+ expect(@library.books).to contain_exactly @book, @book2
209
209
  end
210
210
 
211
211
  it "setter should wipe out previously saved relations" do
@@ -219,7 +219,7 @@ describe ActiveFedora::Base do
219
219
  @library.books = [@book, @book2]
220
220
  @library.save
221
221
  @library = Library.find(@library.id)
222
- expect(@library.books).to eq [@book, @book2]
222
+ expect(@library.books).to contain_exactly @book, @book2
223
223
  end
224
224
 
225
225
  it "lets you lookup an array of objects with solr" do
@@ -230,7 +230,7 @@ describe ActiveFedora::Base do
230
230
  @book2.save
231
231
 
232
232
  @library = Library.find(@library.id)
233
- expect(@library.books).to eq [@book, @book2]
233
+ expect(@library.books).to contain_exactly @book, @book2
234
234
 
235
235
  solr_resp = @library.books(response_format: :solr)
236
236
  expect(solr_resp.size).to eq 2
@@ -462,7 +462,7 @@ describe ActiveFedora::Base do
462
462
 
463
463
  it "loads the association stored in the parent" do
464
464
  @reloaded_course = Course.find(@course.id)
465
- expect(@reloaded_course.textbooks).to eq [@t1, @t2]
465
+ expect(@reloaded_course.textbooks).to contain_exactly @t1, @t2
466
466
  end
467
467
 
468
468
  it "allows a parent to be deleted from the has_many association" do
@@ -480,7 +480,7 @@ describe ActiveFedora::Base do
480
480
  @course.textbooks = [@t3, @t4]
481
481
  @course.save
482
482
 
483
- expect(@course.reload.textbooks).to eq [@t3, @t4]
483
+ expect(@course.reload.textbooks).to contain_exactly @t3, @t4
484
484
  end
485
485
 
486
486
  it "allows a child to be deleted from the has_and_belongs_to_many association" do
@@ -524,18 +524,19 @@ describe ActiveFedora::Base do
524
524
  end
525
525
 
526
526
  describe "removing association" do
527
- subject { LibraryBook.create }
528
- before do
529
- @p1 = Page.create
530
- @p2 = Page.create
531
- subject.pages << @p1 << @p2
532
- subject.save!
527
+ let(:p1) { Page.create }
528
+ let(:p2) { Page.create }
529
+ subject(:book) do
530
+ book = LibraryBook.create
531
+ book.pages << p1 << p2
532
+ book.save!
533
+ book
533
534
  end
534
535
  it "saves between the before and after hooks" do
535
- expect(subject).to receive(:before_count).with(1)
536
- expect(subject).to receive(:after_count).with(0)
537
- expect(subject).to receive(:say_hi).with(@p2).twice
538
- subject.pages.delete(@p2)
536
+ expect(book).to receive(:before_count).with(1)
537
+ expect(book).to receive(:after_count).with(0)
538
+ expect(book).to receive(:say_hi).with(p2).twice
539
+ book.pages.delete(p2)
539
540
  end
540
541
  end
541
542
  end
@@ -555,14 +556,12 @@ describe ActiveFedora::Base do
555
556
  end
556
557
 
557
558
  describe "removing association" do
558
- subject { LibraryBook.new }
559
- before do
560
- @p1 = subject.pages.build
561
- @p2 = subject.pages.build
562
- end
559
+ let(:p1) { book.pages.build }
560
+ let(:p2) { book.pages.build }
561
+ let(:book) { LibraryBook.new }
563
562
  it "runs the hooks" do
564
- expect(subject).to receive(:say_hi).with(@p2)
565
- subject.pages.delete(@p2)
563
+ expect(book).to receive(:say_hi).with(p2)
564
+ book.pages.delete(p2)
566
565
  end
567
566
  end
568
567
  end
@@ -65,30 +65,40 @@ describe ActiveFedora::AttachedFiles do
65
65
  let(:obj) { ActiveFedora::Base.new }
66
66
 
67
67
  describe ".attached_files" do
68
- subject { obj.attached_files }
68
+ subject(:attached_files) { obj.attached_files }
69
69
  it "returns a Hash of datastreams from fedora" do
70
- expect(subject).to be_a_kind_of(ActiveFedora::FilesHash)
71
- expect(subject).to be_empty
70
+ expect(attached_files).to be_a_kind_of(ActiveFedora::FilesHash)
71
+ expect(attached_files).to be_empty
72
72
  end
73
73
 
74
74
  it "initializes the datastream pointers with @new_object=false" do
75
- subject.each_value do |ds|
75
+ attached_files.each_value do |ds|
76
76
  expect(ds).to_not be_new
77
77
  end
78
78
  end
79
79
  end
80
80
 
81
81
  describe ".metadata_streams" do
82
- let(:mds1) { ActiveFedora::QualifiedDublinCoreDatastream.new }
83
- let(:mds2) { ActiveFedora::QualifiedDublinCoreDatastream.new }
84
- let(:fds) { ActiveFedora::File.new }
85
82
  before do
86
- fds = ActiveFedora::File.new
83
+ class Metadata < ActiveFedora::File
84
+ def metadata?
85
+ true
86
+ end
87
+ end
88
+
87
89
  obj.attach_file(mds1, 'md1')
88
90
  obj.attach_file(mds2, 'qdc')
89
91
  obj.attach_file(fds, 'fds')
90
92
  end
91
93
 
94
+ let(:mds1) { Metadata.new }
95
+ let(:mds2) { Metadata.new }
96
+ let(:fds) { ActiveFedora::File.new }
97
+
98
+ after do
99
+ Object.send(:remove_const, :Metadata)
100
+ end
101
+
92
102
  it "returns all of the datastreams from the object that are kinds of OmDatastream" do
93
103
  expect(obj.metadata_streams).to match_array [mds1, mds2]
94
104
  end
@@ -20,9 +20,9 @@ describe "delegating attributes" do
20
20
 
21
21
  describe "#index_config" do
22
22
  context "on a class with properties" do
23
- subject { RdfObject.index_config }
23
+ subject(:index_config) { RdfObject.index_config }
24
24
  it "has configuration" do
25
- expect(subject[:resource_type].behaviors).to eq [:stored_searchable, :facetable]
25
+ expect(index_config[:resource_type].behaviors).to eq [:stored_searchable, :facetable]
26
26
  end
27
27
  end
28
28
 
@@ -36,42 +36,38 @@ describe "delegating attributes" do
36
36
  Object.send(:remove_const, :InheritedObject)
37
37
  end
38
38
 
39
- subject { InheritedObject.index_config }
39
+ subject(:index_config) { InheritedObject.index_config }
40
40
 
41
41
  it "has configuration" do
42
- expect(subject[:resource_type].behaviors).to eq [:stored_searchable, :facetable]
42
+ expect(index_config[:resource_type].behaviors).to eq [:stored_searchable, :facetable]
43
43
  end
44
44
 
45
45
  context "when the inherited config is modifed" do
46
46
  before do
47
47
  InheritedObject.index_config[:resource_type].behaviors.delete(:stored_searchable)
48
48
  end
49
- subject { RdfObject.index_config }
49
+ subject(:index_config) { RdfObject.index_config }
50
50
 
51
51
  it "the parent config is unchanged" do
52
- expect(subject[:resource_type].behaviors).to eq [:stored_searchable, :facetable]
52
+ expect(index_config[:resource_type].behaviors).to eq [:stored_searchable, :facetable]
53
53
  end
54
54
  end
55
55
  end
56
56
  end
57
57
 
58
58
  describe "previous_changes" do
59
- subject do
60
- TitledObject.create(title: ["Hydra for Dummies"])
61
- end
59
+ subject(:titled_object) { TitledObject.create(title: ["Hydra for Dummies"]) }
62
60
  it "keeps a list of changes after a successful save" do
63
- expect(subject.previous_changes).to_not be_empty
64
- expect(subject.previous_changes.keys).to include("title")
61
+ expect(titled_object.previous_changes).to_not be_empty
62
+ expect(titled_object.previous_changes.keys).to include("title")
65
63
  end
66
64
  end
67
65
 
68
66
  describe "#changes" do
69
- subject do
70
- TitledObject.create(title: ["Hydra for Dummies"])
71
- end
67
+ let(:titled_object) { TitledObject.create(title: ["Hydra for Dummies"]) }
72
68
  it "cleans out changes" do
73
- expect(subject).to_not be_title_changed
74
- expect(subject.changes).to be_empty
69
+ expect(titled_object).to_not be_title_changed
70
+ expect(titled_object.changes).to be_empty
75
71
  end
76
72
  end
77
73
  end
@@ -9,16 +9,16 @@ describe ActiveFedora::Base do
9
9
  Object.send(:remove_const, :MockAFBaseRelationship)
10
10
  end
11
11
 
12
- subject { MockAFBaseRelationship.new }
12
+ subject(:relationship) { MockAFBaseRelationship.new }
13
13
 
14
14
  context '#changed_for_autosave?' do
15
- before(:each) do
16
- expect(subject).to receive(:new_record?).and_return(false)
17
- expect(subject).to receive(:changed?).and_return(false)
18
- expect(subject).to receive(:marked_for_destruction?).and_return(false)
15
+ before do
16
+ expect(relationship).to receive(:new_record?).and_return(false)
17
+ expect(relationship).to receive(:changed?).and_return(false)
18
+ expect(relationship).to receive(:marked_for_destruction?).and_return(false)
19
19
  end
20
20
  it {
21
- expect { subject.changed_for_autosave? }.to_not raise_error
21
+ expect { relationship.changed_for_autosave? }.to_not raise_error
22
22
  }
23
23
  end
24
24
  end
@@ -145,7 +145,7 @@ describe ActiveFedora::Base do
145
145
  let(:conditions) { { foo: "bar" } }
146
146
  context "and at least one object matches the conditions" do
147
147
  it "returns true" do
148
- allow(ActiveFedora::SolrService).to receive(:query) { [double("solr document")] }
148
+ allow(ActiveFedora::SolrService).to receive(:query) { [instance_double(RSolr::HashWithResponse)] }
149
149
  expect(described_class.exists?(conditions)).to be true
150
150
  end
151
151
  end
@@ -159,7 +159,7 @@ describe ActiveFedora::Base do
159
159
  end
160
160
 
161
161
  describe "overriding resource_class_factory" do
162
- subject { TestBase.new }
162
+ subject(:test_base) { TestBase.new }
163
163
  before do
164
164
  class TestResource < ActiveTriples::Resource
165
165
  end
@@ -174,7 +174,7 @@ describe ActiveFedora::Base do
174
174
  Object.send(:remove_const, :TestBase)
175
175
  end
176
176
  it "uses that factory for #resource" do
177
- expect(subject.resource.class.ancestors).to include TestResource
177
+ expect(test_base.resource.class.ancestors).to include TestResource
178
178
  end
179
179
  end
180
180
  end
@@ -86,7 +86,7 @@ describe ActiveFedora::Base do
86
86
 
87
87
  it "has the two contained objects" do
88
88
  expect(model.contains.size).to eq 2
89
- expect(model.contains.map(&:title)).to eq [['title 1'], ['title 2']]
89
+ expect(model.contains.map(&:title)).to contain_exactly ['title 1'], ['title 2']
90
90
  end
91
91
  end
92
92
 
@@ -14,7 +14,7 @@ RSpec.describe ActiveFedora::CleanConnection do
14
14
  it "returns a clean graph" do
15
15
  graph = result.graph
16
16
  expect(graph.statements.to_a.length).to eq 1
17
- expect(graph.statements.to_a.first).to eq [asset.rdf_subject, RDF::Vocab::DC.title, "test"]
17
+ expect(graph.statements.to_a.first).to contain_exactly asset.rdf_subject, RDF::Vocab::DC.title, RDF::Literal.new("test")
18
18
  end
19
19
  end
20
20
  end