Skip to content

Commit

Permalink
smol test refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rococodogs committed Dec 13, 2024
1 parent c43928b commit 0f26ab9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
21 changes: 11 additions & 10 deletions app/indexers/base_resource_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def to_solr

# Previously was a mixin (IndexesCitationMetadata) but parses the first :bibliographic_citation
# value and adds the metadata to the Solr document.
#
# @param [SolrDocument,Hash]
# @return [void]
def add_citation_metadata(document)
raw = Array.wrap(resource.bibliographic_citation).first
citation = ::AnyStyle.parse(raw)&.first
Expand All @@ -70,20 +73,18 @@ def add_citation_metadata(document)
document['citation_lastpage_ss'] = last_page
end

# Uses a) earliest date in +sortable_date_property+, b) resource's :created_at value to serve
# as the sort date for the object. Will return nil if neither of these are present.
#
# @return [String, nil]
def generate_sortable_date
object_date_values = resource.try(sortable_date_property) || []
date_value = object_date_values.sort.first
output_format_string = '%FT%TZ'
object_date_value = resource.try(sortable_date_property).presence || resource.try(:created_at).try(:strftime, '%FT%TZ')
date_value = Array.wrap(object_date_value).sort.first

# if the object doesn't have any date values, default to using
# its created_at value (note: this will return nil if the object
# doesn't have a :created_at value, typically assigned on persistence.
return resource.try(:created_at).try(:strftime, output_format_string) if date_value.nil?

parsed = Date.edtf(date_value)
parsed.strftime(output_format_string) if parsed.present?
Date.edtf(date_value).try(:strftime, '%FT%TZ')
end

# @return [String]
def generate_sortable_title
resource.title.first.to_s.downcase.gsub(/^(an?|the)\s+/, '').strip
end
Expand Down
13 changes: 4 additions & 9 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@

config.before :suite do
DatabaseCleaner.clean_with(:truncation)

Hyrax.config.enable_noids = false
end

Expand All @@ -141,22 +140,18 @@
DatabaseCleaner.start
end

config.after do
DatabaseCleaner.clean
end

config.before clean: true do
DatabaseCleaner.clean
ActiveFedora::Cleaner.clean!
end

config.after clean: true do
DatabaseCleaner.clean
end

config.before js: true do
DatabaseCleaner.strategy = :truncation
end

config.after do
DatabaseCleaner.clean
end
end

WebMock.disable_net_connect!(
Expand Down

0 comments on commit 0f26ab9

Please sign in to comment.