blacklight-spotlight 0.34.1 → 1.0.0.alpha1

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 (114) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/assets/javascripts/spotlight/pages.js.erb +1 -1
  4. data/app/controllers/concerns/spotlight/controller.rb +0 -12
  5. data/app/helpers/spotlight/crop_helper.rb +1 -5
  6. data/app/models/concerns/spotlight/resources/open_graph.rb +1 -5
  7. data/app/models/concerns/spotlight/solr_document.rb +20 -23
  8. data/app/models/concerns/spotlight/solr_document/finder.rb +16 -0
  9. data/app/models/spotlight/blacklight_configuration.rb +5 -11
  10. data/app/models/spotlight/contact.rb +2 -2
  11. data/app/models/spotlight/custom_field.rb +1 -1
  12. data/app/models/spotlight/exhibit.rb +3 -3
  13. data/app/models/spotlight/feature_page.rb +2 -2
  14. data/app/models/spotlight/field_metadata.rb +12 -4
  15. data/app/models/spotlight/filter.rb +1 -8
  16. data/app/models/spotlight/lock.rb +1 -1
  17. data/app/models/spotlight/page.rb +3 -3
  18. data/app/models/spotlight/reindexing_log_entry.rb +1 -1
  19. data/app/models/spotlight/resource.rb +1 -1
  20. data/app/models/spotlight/resources/upload.rb +1 -1
  21. data/app/models/spotlight/role.rb +4 -11
  22. data/app/models/spotlight/search.rb +2 -2
  23. data/app/models/spotlight/site.rb +1 -1
  24. data/app/models/spotlight/solr_document_sidecar.rb +5 -1
  25. data/app/uploaders/spotlight/featured_image_uploader.rb +1 -1
  26. data/app/views/shared/_exhibit_navbar.html.erb +1 -1
  27. data/app/views/spotlight/catalog/_edit_default.html.erb +1 -1
  28. data/db/migrate/20131119213142_create_spotlight_pages.rb +1 -1
  29. data/db/migrate/20131120172811_create_spotlight_attachments.rb +1 -1
  30. data/db/migrate/20140128155151_create_exhibits.rb +1 -1
  31. data/db/migrate/20140128155152_create_roles.rb +1 -1
  32. data/db/migrate/20140130155151_create_spotlight_searches.rb +1 -1
  33. data/db/migrate/20140130215634_create_spotlight_blacklight_configurations.rb +1 -1
  34. data/db/migrate/20140206152809_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb +1 -1
  35. data/db/migrate/20140206152810_add_missing_unique_indices.acts_as_taggable_on_engine.rb +1 -1
  36. data/db/migrate/20140211203403_create_spotlight_custom_fields.rb +1 -1
  37. data/db/migrate/20140211212626_create_spotlight_solr_document_sidecars.rb +1 -1
  38. data/db/migrate/20140218155151_create_contacts.rb +1 -1
  39. data/db/migrate/20140225180948_create_contact_emails.rb +1 -1
  40. data/db/migrate/20140228131207_create_resources.rb +1 -1
  41. data/db/migrate/20140401232956_change_featured_image_to_featured_image_id.rb +1 -1
  42. data/db/migrate/20140403180324_create_spotlight_main_navigations.rb +1 -1
  43. data/db/migrate/20141117111311_create_locks.rb +1 -1
  44. data/db/migrate/20141118233735_change_contact_details.rb +1 -1
  45. data/db/migrate/20141126231820_add_avatar_to_contacts.rb +1 -1
  46. data/db/migrate/20141205005902_add_layout_options_to_exhibit.rb +1 -1
  47. data/db/migrate/20150116161616_add_published_to_exhibit.rb +1 -1
  48. data/db/migrate/20150127173245_add_featured_image_to_exhibit.rb +1 -1
  49. data/db/migrate/20150217111511_add_polymorphic_document_to_sidecars.rb +1 -1
  50. data/db/migrate/20150304071512_add_spotlight_featured_images.rb +1 -1
  51. data/db/migrate/20150304111111_add_featured_image_to_spotlight_classes.rb +1 -1
  52. data/db/migrate/20150306202300_add_display_to_spotlight_main_navigations.rb +1 -1
  53. data/db/migrate/20150313175432_add_field_type_to_custom_fields.rb +1 -1
  54. data/db/migrate/20150410180014_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +1 -1
  55. data/db/migrate/20150410180015_add_missing_taggable_index.acts_as_taggable_on_engine.rb +1 -1
  56. data/db/migrate/20150410180016_change_collation_for_tag_names.acts_as_taggable_on_engine.rb +1 -1
  57. data/db/migrate/20150713160101_change_spotlight_searches_to_published.rb +1 -1
  58. data/db/migrate/20151016092343_remove_searchable_from_exhibit.rb +1 -1
  59. data/db/migrate/20151110082345_add_metadata_to_spotlight_resource.rb +1 -1
  60. data/db/migrate/20151117153210_change_spotlight_exhibit_published_default.rb +1 -1
  61. data/db/migrate/20151124101123_remove_default_from_spotlight_exhibit.rb +1 -1
  62. data/db/migrate/20151124105543_update_custom_field_names.rb +1 -1
  63. data/db/migrate/20151208085432_add_weight_to_exhibits.rb +1 -1
  64. data/db/migrate/20151210073829_create_spotlight_site.rb +1 -1
  65. data/db/migrate/20151211131415_add_site_to_spotlight_exhibits.rb +1 -1
  66. data/db/migrate/20151215141516_change_roles_to_support_polymorphic_associations.rb +1 -1
  67. data/db/migrate/20151215192845_add_index_status_to_resources.rb +1 -1
  68. data/db/migrate/20151217211019_create_spotlight_exhibit_filters.rb +1 -1
  69. data/db/migrate/20160329215014_add_readonly_to_custom_fields.rb +1 -1
  70. data/db/migrate/20160711121314_add_default_view_to_spotlight_searches.rb +1 -1
  71. data/db/migrate/20160714144125_add_iiif_urls_to_featured_image.rb +1 -1
  72. data/db/migrate/20160718194010_add_iiif_url_to_contact.rb +1 -1
  73. data/db/migrate/20160805143841_add_upload_id_to_resources.rb +1 -1
  74. data/db/migrate/20160815165432_add_resource_to_solr_document_sidecar.rb +1 -1
  75. data/db/migrate/20160816165432_add_index_status_to_solr_document_sidecar.rb +1 -1
  76. data/db/migrate/20160929180534_add_document_index_to_solr_document_sidecar.rb +1 -1
  77. data/db/migrate/20170105222939_create_spotlight_reindexing_log_entries.rb +1 -1
  78. data/db/migrate/20170204091234_add_theme_to_spotlight_exhibits.rb +1 -1
  79. data/db/migrate/20170803152134_migrate_tags_to_sidecars.rb +17 -0
  80. data/lib/spotlight/version.rb +1 -1
  81. data/spec/controllers/spotlight/appearances_controller_spec.rb +4 -11
  82. data/spec/controllers/spotlight/catalog_controller_spec.rb +5 -3
  83. data/spec/controllers/spotlight/solr_controller_spec.rb +1 -1
  84. data/spec/controllers/spotlight/tags_controller_spec.rb +1 -1
  85. data/spec/examples.txt +1133 -1135
  86. data/spec/features/add_custom_field_metadata_spec.rb +1 -1
  87. data/spec/features/add_iiif_manifest_spec.rb +1 -1
  88. data/spec/features/add_items_spec.rb +6 -2
  89. data/spec/features/autocomplete_typeahead_spec.rb +1 -0
  90. data/spec/features/exhibit_themes_spec.rb +1 -1
  91. data/spec/features/tags_admin_spec.rb +1 -1
  92. data/spec/jobs/spotlight/rename_sidecar_field_job_spec.rb +8 -2
  93. data/spec/models/solr_document_spec.rb +5 -5
  94. data/spec/models/spotlight/blacklight_configuration_spec.rb +3 -2
  95. data/spec/models/spotlight/contact_spec.rb +6 -0
  96. data/spec/models/spotlight/exhibit_spec.rb +0 -10
  97. data/spec/models/spotlight/field_metadata_spec.rb +4 -4
  98. data/spec/models/spotlight/reindexing_log_entry_spec.rb +1 -9
  99. data/spec/models/spotlight/resource_spec.rb +2 -0
  100. data/spec/models/spotlight/role_spec.rb +1 -1
  101. data/spec/serializers/spotlight/exhibit_export_serializer_spec.rb +3 -9
  102. data/spec/services/spotlight/solr_document_builder_spec.rb +2 -2
  103. data/spec/spec_helper.rb +2 -6
  104. data/spec/support/helpers/controller_level_helpers.rb +0 -2
  105. data/spec/test_app_templates/fixture.css +0 -0
  106. data/spec/test_app_templates/fixture.png +0 -0
  107. data/spec/test_app_templates/lib/generators/test_app_generator.rb +14 -0
  108. data/spec/uploaders/spotlight/featured_image_uploader_spec.rb +2 -2
  109. data/spec/views/spotlight/searches/edit.html.erb_spec.rb +2 -0
  110. data/spec/views/spotlight/tags/index.html.erb_spec.rb +2 -2
  111. metadata +18 -29
  112. data/app/models/concerns/spotlight/ar_light.rb +0 -86
  113. data/app/models/concerns/spotlight/solr_document/active_model_concern.rb +0 -37
  114. data/spec/support/backport_test_helpers.rb +0 -45
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b8049b771f549a0ba4549ba177511365d4c47a2
4
- data.tar.gz: 62cb02a402b05b63c6dbe6b0a112a77b46297d4c
3
+ metadata.gz: c850274c191873929f87b2e3bbc6459ff8508317
4
+ data.tar.gz: 871d6f41e445137655c2bb45ee01a466b5ffcb56
5
5
  SHA512:
6
- metadata.gz: 0bb7738f311a695969355a30098a3730989e8c3d9d2802c6a155cf1e7412cdbc7b453c89c63a6380aba77a859be846895d8ca44650181a5c0975b20a5cb9b285
7
- data.tar.gz: 336c43cdced351a17ea4640f6238309f03756cc7471372d7d615a23279757d59360ef21210902ad40e9e5ba100f232e6492ea0976701fa2ae9f3be3e05c3f9be
6
+ metadata.gz: 3319d9fb7fe3bbbdd381c89e0144e048be7607580e777dd405f676bd16eae0e288d98cf7d67b3156ac2e6c8d1873cd01c8d37957a832ac71e4301e011009ecbf
7
+ data.tar.gz: 9b8a2f3d86c4e04ae579c3dac5324aed5eb859d0c2940b5ead8135fa6680eb3d4d28d96f2f3aa9e02b96c7760b3a4b27cff458967d1c34678216378f1d7d679e
data/README.md CHANGED
@@ -10,7 +10,7 @@ Read more about what Spotlight is, our motivations for creating it, and how to i
10
10
  ## Requirements
11
11
 
12
12
  1. Ruby (2.2.0 or greater)
13
- 2. Rails (4.2.0 or greater)
13
+ 2. Rails (5.0 or greater)
14
14
  3. Java (7 or greater) *for Solr*
15
15
  4. ImageMagick (http://www.imagemagick.org/script/index.php) due to [carrierwave](https://github.com/carrierwaveuploader/carrierwave#adding-versions)
16
16
 
@@ -7,7 +7,7 @@ Spotlight.onLoad(function(){
7
7
  uploadUrl: $('[data-attachment-endpoint]').data('attachment-endpoint'),
8
8
  ajaxOptions: {
9
9
  headers: {
10
- 'X-CSRF-Token': $.rails.csrfToken() || ''
10
+ 'X-CSRF-Token': (Rails || $.rails).csrfToken() || ''
11
11
  },
12
12
  credentials: 'same-origin'
13
13
  }
@@ -8,7 +8,6 @@ module Spotlight
8
8
 
9
9
  included do
10
10
  helper_method :current_site, :current_exhibit, :current_masthead, :exhibit_masthead?, :resource_masthead?
11
- helper_method :redirect_back # helper method backported from Rails 5
12
11
  end
13
12
 
14
13
  def current_site
@@ -86,16 +85,5 @@ module Spotlight
86
85
  options = Blacklight::Parameters.sanitize(params.to_unsafe_h.with_indifferent_access).merge(options).except(:exhibit_id, :only_path)
87
86
  spotlight.facet_exhibit_catalog_url(current_exhibit, *args, options)
88
87
  end
89
-
90
- # Backport from Rails 5
91
- def redirect_back(fallback_location:, **args)
92
- if defined?(super)
93
- super
94
- elsif request.headers['Referer']
95
- redirect_to request.headers['Referer'], **args
96
- else
97
- redirect_to fallback_location, **args
98
- end
99
- end
100
88
  end
101
89
  end
@@ -27,11 +27,7 @@ module Spotlight
27
27
  end
28
28
 
29
29
  def form_prefix(f)
30
- if Rails::VERSION::MAJOR >= 5
31
- f.object_name.parameterize(separator: '_')
32
- else
33
- f.object_name.parameterize('_')
34
- end
30
+ f.object_name.parameterize(separator: '_')
35
31
  end
36
32
  end
37
33
  end
@@ -27,11 +27,7 @@ module Spotlight
27
27
  private
28
28
 
29
29
  def opengraph_solr_field_name(field)
30
- if Rails::VERSION::MAJOR >= 5
31
- field.parameterize(separator: '_')
32
- else
33
- field.parameterize('_')
34
- end
30
+ field.parameterize(separator: '_')
35
31
  end
36
32
  end
37
33
  end
@@ -4,19 +4,10 @@ module Spotlight
4
4
  module SolrDocument
5
5
  extend ActiveSupport::Concern
6
6
 
7
- include Spotlight::SolrDocument::ActiveModelConcern
8
7
  include Spotlight::SolrDocument::Finder
9
8
  include GlobalID::Identification
10
9
 
11
10
  included do
12
- extend ActsAsTaggableOn::Taggable
13
-
14
- acts_as_taggable
15
- has_many :sidecars, class_name: 'Spotlight::SolrDocumentSidecar', as: :document
16
-
17
- before_save :save_owned_tags
18
- after_save :reindex
19
-
20
11
  use_extension(Spotlight::SolrDocument::UploadedResource, &:uploaded_resource?)
21
12
  end
22
13
 
@@ -24,7 +15,7 @@ module Spotlight
24
15
  # Class-level methods
25
16
  module ClassMethods
26
17
  def build_for_exhibit(id, exhibit, attributes = {})
27
- new(unique_key => id) do |doc|
18
+ new(unique_key => id).tap do |doc|
28
19
  doc.sidecar(exhibit).tap { |x| x.assign_attributes(attributes) }.save! # save is a nop if the sidecar isn't modified.
29
20
  end
30
21
  end
@@ -66,11 +57,15 @@ module Spotlight
66
57
  sidecar(current_exhibit).update(custom_data) if custom_data
67
58
 
68
59
  # Note: this causes a save
69
- current_exhibit.tag(self, with: tags, on: :tags) if tags
60
+ current_exhibit.tag(sidecar(current_exhibit), with: tags, on: :tags) if tags
70
61
 
71
62
  update_exhibit_resource(resource_attributes) if uploaded_resource?
72
63
  end
73
64
 
65
+ def save
66
+ reindex
67
+ end
68
+
74
69
  def update_exhibit_resource(resource_attributes)
75
70
  return unless resource_attributes && resource_attributes['url']
76
71
  uploaded_resource.upload.update image: resource_attributes['url']
@@ -80,8 +75,12 @@ module Spotlight
80
75
  # no-op reindex implementation
81
76
  end
82
77
 
78
+ def sidecars
79
+ Spotlight::SolrDocumentSidecar.where(document_id: id, document_type: self.class.to_s)
80
+ end
81
+
83
82
  def sidecar(exhibit)
84
- sidecars.find_or_initialize_by exhibit: exhibit
83
+ sidecars.find_or_initialize_by exhibit: exhibit, document_id: id, document_type: self.class.to_s
85
84
  end
86
85
 
87
86
  def to_solr
@@ -118,16 +117,14 @@ module Spotlight
118
117
  def tags_to_solr
119
118
  h = {}
120
119
 
121
- # Adding a placeholder entry in case the last tag for an exhibit
122
- # is removed, so we clear out the solr field too.
123
- Spotlight::Exhibit.find_each do |exhibit|
124
- h[self.class.solr_field_for_tagger(exhibit)] = nil
125
- end
120
+ sidecars.each do |sidecar|
121
+ h[self.class.solr_field_for_tagger(sidecar.exhibit)] = nil
126
122
 
127
- taggings.includes(:tag, :tagger).map do |tagging|
128
- key = self.class.solr_field_for_tagger(tagging.tagger)
129
- h[key] ||= []
130
- h[key] << tagging.tag.name
123
+ sidecar.taggings.includes(:tag, :tagger).map do |tagging|
124
+ key = self.class.solr_field_for_tagger(tagging.tagger)
125
+ h[key] ||= []
126
+ h[key] << tagging.tag.name
127
+ end
131
128
  end
132
129
  h
133
130
  end
@@ -135,7 +132,7 @@ module Spotlight
135
132
  end
136
133
 
137
134
  ActsAsTaggableOn::Tagging.after_destroy do |obj|
138
- if obj.tagger.is_a? Spotlight::Exhibit
139
- obj.tagger.blacklight_config.document_model.reindex(obj.taggable_id)
135
+ if obj.tagger.is_a?(Spotlight::Exhibit) && obj.taggable.is_a?(Spotlight::SolrDocumentSidecar)
136
+ obj.tagger.blacklight_config.document_model.reindex(obj.taggable.document_id)
140
137
  end
141
138
  end
@@ -38,6 +38,22 @@ module Spotlight
38
38
  end
39
39
  end
40
40
 
41
+ # Returns true if +comparison_object+ is the same exact object, or +comparison_object+
42
+ # is of the same type and +self+ has an ID and it is equal to +comparison_object.id+.
43
+ #
44
+ # Note that new records are different from any other record by definition, unless the
45
+ # other record is the receiver itself. Besides, if you fetch existing records with
46
+ # +select+ and leave the ID out, you're on your own, this predicate will return false.
47
+ #
48
+ # Note also that destroying a record preserves its ID in the model instance, so deleted
49
+ # models are still comparable.
50
+ def ==(other)
51
+ super ||
52
+ (other.instance_of?(self.class) &&
53
+ id &&
54
+ other.id == id)
55
+ end
56
+
41
57
  def blacklight_solr
42
58
  self.class.index.connection
43
59
  end
@@ -5,7 +5,7 @@ module Spotlight
5
5
  # Exhibit-specific blacklight configuration model
6
6
  # rubocop:disable Metrics/ClassLength
7
7
  class BlacklightConfiguration < ActiveRecord::Base
8
- belongs_to :exhibit, touch: true
8
+ belongs_to :exhibit, touch: true, optional: true
9
9
  serialize :facet_fields, Hash
10
10
  serialize :index_fields, Hash
11
11
  serialize :search_fields, Hash
@@ -198,7 +198,7 @@ module Spotlight
198
198
  # rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
199
199
 
200
200
  def custom_index_fields
201
- Hash[exhibit.custom_fields.map do |x|
201
+ Hash[exhibit.custom_fields.reject(&:new_record?).map do |x|
202
202
  field = Blacklight::Configuration::IndexField.new x.configuration.merge(
203
203
  key: x.field, field: x.solr_field, custom_field: true
204
204
  )
@@ -207,12 +207,13 @@ module Spotlight
207
207
  end
208
208
 
209
209
  def custom_facet_fields
210
- Hash[exhibit.custom_fields.vocab.map do |x|
210
+ Hash[exhibit.custom_fields.vocab.reject(&:new_record?).map do |x|
211
211
  field = Blacklight::Configuration::FacetField.new x.configuration.merge(
212
212
  key: x.field, field: x.solr_field, show: false, custom_field: true
213
213
  )
214
214
  field.if = :field_enabled?
215
215
  field.enabled = false
216
+ field.limit = true
216
217
  [x.field, field]
217
218
  end]
218
219
  end
@@ -344,14 +345,7 @@ module Spotlight
344
345
  end
345
346
 
346
347
  def value_to_boolean(v)
347
- if defined? ActiveModel::Type::Boolean
348
- ActiveModel::Type::Boolean.new.cast v
349
- elsif defined? ActiveRecord::Type::Boolean
350
- # Rails 4.2+
351
- ActiveRecord::Type::Boolean.new.type_cast_from_database v
352
- else
353
- ActiveRecord::ConnectionAdapters::Column.value_to_boolean v
354
- end
348
+ ActiveModel::Type::Boolean.new.cast v
355
349
  end
356
350
  end
357
351
  end
@@ -2,7 +2,7 @@ module Spotlight
2
2
  ##
3
3
  # Exhibit curator contact information
4
4
  class Contact < ActiveRecord::Base
5
- belongs_to :exhibit, touch: true
5
+ belongs_to :exhibit, touch: true, optional: true
6
6
  scope :published, -> { where(show_in_sidebar: true) }
7
7
  default_scope { order('weight ASC') }
8
8
  serialize :contact_info, Hash
@@ -10,7 +10,7 @@ module Spotlight
10
10
  extend FriendlyId
11
11
  friendly_id :name, use: [:slugged, :scoped, :finders], scope: :exhibit
12
12
 
13
- belongs_to :avatar, class_name: 'Spotlight::ContactImage', dependent: :destroy
13
+ belongs_to :avatar, class_name: 'Spotlight::ContactImage', dependent: :destroy, optional: true
14
14
  accepts_nested_attributes_for :avatar, update_only: true, reject_if: proc { |attr| attr['iiif_tilesource'].blank? }
15
15
 
16
16
  before_save do
@@ -3,7 +3,7 @@ module Spotlight
3
3
  # Exhibit custom fields
4
4
  class CustomField < ActiveRecord::Base
5
5
  serialize :configuration, Hash
6
- belongs_to :exhibit
6
+ belongs_to :exhibit, optional: true
7
7
 
8
8
  extend FriendlyId
9
9
  friendly_id :slug_candidates, use: [:slugged, :scoped, :finders], scope: :exhibit
@@ -45,9 +45,9 @@ module Spotlight
45
45
  has_one :blacklight_configuration, class_name: 'Spotlight::BlacklightConfiguration', dependent: :delete
46
46
  has_one :home_page
47
47
 
48
- belongs_to :site
49
- belongs_to :masthead, dependent: :destroy
50
- belongs_to :thumbnail, class_name: 'Spotlight::ExhibitThumbnail', dependent: :destroy
48
+ belongs_to :site, optional: true
49
+ belongs_to :masthead, dependent: :destroy, optional: true
50
+ belongs_to :thumbnail, class_name: 'Spotlight::ExhibitThumbnail', dependent: :destroy, optional: true
51
51
 
52
52
  accepts_nested_attributes_for :about_pages, :attachments, :contacts, :custom_fields, :feature_pages,
53
53
  :main_navigations, :owned_taggings, :resources, :searches, :solr_document_sidecars
@@ -6,11 +6,11 @@ module Spotlight
6
6
  friendly_id :title, use: [:slugged, :scoped, :finders, :history], scope: :exhibit
7
7
 
8
8
  has_many :child_pages, class_name: 'Spotlight::FeaturePage', inverse_of: :parent_page, foreign_key: 'parent_page_id'
9
- belongs_to :parent_page, class_name: 'Spotlight::FeaturePage'
9
+ belongs_to :parent_page, class_name: 'Spotlight::FeaturePage', optional: true
10
10
 
11
11
  accepts_nested_attributes_for :child_pages
12
12
 
13
- belongs_to :thumbnail, class_name: 'Spotlight::FeaturedImage', dependent: :destroy
13
+ belongs_to :thumbnail, class_name: 'Spotlight::FeaturedImage', dependent: :destroy, optional: true
14
14
  accepts_nested_attributes_for :thumbnail, update_only: true, reject_if: proc { |attr| attr['iiif_tilesource'].blank? }
15
15
 
16
16
  before_validation unless: :top_level_page? do
@@ -12,11 +12,11 @@ module Spotlight
12
12
  @blacklight_config = blacklight_config
13
13
  end
14
14
 
15
- def field(field_name)
15
+ def field(key)
16
16
  {
17
- document_count: document_counts.fetch(field_name, 0),
18
- value_count: terms.fetch(field_name, []).length,
19
- terms: terms.fetch(field_name, [])
17
+ document_count: document_counts.fetch(field_name(key), 0),
18
+ value_count: terms.fetch(field_name(key), []).length,
19
+ terms: terms.fetch(field_name(key), [])
20
20
  }
21
21
  end
22
22
 
@@ -26,6 +26,14 @@ module Spotlight
26
26
 
27
27
  private
28
28
 
29
+ def field_name(key)
30
+ if blacklight_config.facet_fields[key]
31
+ blacklight_config.facet_fields[key].field
32
+ else
33
+ key
34
+ end
35
+ end
36
+
29
37
  def search_builder_class
30
38
  blacklight_config.search_builder_class
31
39
  end
@@ -24,14 +24,7 @@ module Spotlight
24
24
  end
25
25
 
26
26
  def value_to_boolean(v)
27
- if defined? ActiveModel::Type::Boolean
28
- ActiveModel::Type::Boolean.new.cast v
29
- elsif defined? ActiveRecord::Type::Boolean
30
- # Rails 4.2+
31
- ActiveRecord::Type::Boolean.new.type_cast_from_database v
32
- else
33
- ActiveRecord::ConnectionAdapters::Column.value_to_boolean v
34
- end
27
+ ActiveModel::Type::Boolean.new.cast v
35
28
  end
36
29
  end
37
30
  end
@@ -3,7 +3,7 @@ module Spotlight
3
3
  # Page-level locking to discourage update conflicts
4
4
  class Lock < ActiveRecord::Base
5
5
  belongs_to :on, polymorphic: true
6
- belongs_to :by, polymorphic: true
6
+ belongs_to :by, polymorphic: true, optional: true
7
7
 
8
8
  def current_session!
9
9
  @current_session = true
@@ -8,9 +8,9 @@ module Spotlight
8
8
  friendly_id :title, use: [:slugged, :scoped, :finders, :history], scope: :exhibit
9
9
 
10
10
  belongs_to :exhibit, touch: true
11
- belongs_to :created_by, class_name: Spotlight::Engine.config.user_class
12
- belongs_to :last_edited_by, class_name: Spotlight::Engine.config.user_class
13
- belongs_to :thumbnail, class_name: 'Spotlight::FeaturedImage', dependent: :destroy
11
+ belongs_to :created_by, class_name: Spotlight::Engine.config.user_class, optional: true
12
+ belongs_to :last_edited_by, class_name: Spotlight::Engine.config.user_class, optional: true
13
+ belongs_to :thumbnail, class_name: 'Spotlight::FeaturedImage', dependent: :destroy, optional: true
14
14
 
15
15
  validates :weight, inclusion: { in: proc { 0..Spotlight::Page::MAX_PAGES } }
16
16
 
@@ -5,7 +5,7 @@ module Spotlight
5
5
  enum job_status: { unstarted: 0, in_progress: 1, succeeded: 2, failed: 3 }
6
6
 
7
7
  belongs_to :exhibit, class_name: 'Spotlight::Exhibit'
8
- belongs_to :user, class_name: '::User'
8
+ belongs_to :user, class_name: '::User', optional: true
9
9
 
10
10
  # null start times sort to the top, to more easily surface pending reindexing
11
11
  default_scope { order('start_time IS NOT NULL, start_time DESC') }
@@ -68,7 +68,7 @@ module Spotlight
68
68
  private
69
69
 
70
70
  def blacklight_solr
71
- @solr ||= RSolr.connect(connection_config)
71
+ @solr ||= RSolr.connect(connection_config.merge(adapter: connection_config[:http_adapter]))
72
72
  end
73
73
 
74
74
  def connection_config
@@ -4,7 +4,7 @@ module Spotlight
4
4
  ##
5
5
  # Exhibit-specific resources, created using uploaded and custom fields
6
6
  class Upload < Spotlight::Resource
7
- belongs_to :upload, class_name: 'Spotlight::FeaturedImage'
7
+ belongs_to :upload, class_name: 'Spotlight::FeaturedImage', optional: true
8
8
 
9
9
  # we want to do this before reindexing
10
10
  after_create :update_document_sidecar
@@ -3,11 +3,9 @@ module Spotlight
3
3
  # Exhibit authorization roles
4
4
  class Role < ActiveRecord::Base
5
5
  ROLES = %w(admin curator).freeze
6
- belongs_to :resource, polymorphic: true
7
- belongs_to :user, class_name: Spotlight::Engine.config.user_class, autosave: true
6
+ belongs_to :resource, polymorphic: true, optional: true
7
+ belongs_to :user, class_name: Spotlight::Engine.config.user_class, autosave: true, required: true
8
8
  validates :role, inclusion: { in: ROLES }
9
- validates :user_key, presence: true
10
- validate :user_must_exist, if: -> { user_key.present? }
11
9
  validate :user_must_be_unique, if: :user
12
10
 
13
11
  def user_key
@@ -22,17 +20,12 @@ module Spotlight
22
20
  def user_key=(key)
23
21
  @user_key = key
24
22
  self.user ||= Spotlight::Engine.user_class.find_by_user_key(key)
25
- user.user_key = key if user
23
+ self.user ||= Spotlight::Engine.user_class.invite!(email: user_key, skip_invitation: true)
24
+ user.user_key = key
26
25
  end
27
26
 
28
27
  protected
29
28
 
30
- def user_must_exist
31
- return if user.present?
32
-
33
- self.user ||= Spotlight::Engine.user_class.invite!(email: user_key, skip_invitation: true)
34
- end
35
-
36
29
  # This is just like
37
30
  # validates :user, uniqueness: { scope: :exhibit}
38
31
  # but it puts the error message on the user_key instead of user so that the form will render correctly
@@ -13,8 +13,8 @@ module Spotlight
13
13
  validates :title, presence: true
14
14
  has_paper_trail
15
15
 
16
- belongs_to :masthead, dependent: :destroy
17
- belongs_to :thumbnail, class_name: 'Spotlight::FeaturedImage', dependent: :destroy
16
+ belongs_to :masthead, dependent: :destroy, optional: true
17
+ belongs_to :thumbnail, class_name: 'Spotlight::FeaturedImage', dependent: :destroy, optional: true
18
18
  accepts_nested_attributes_for :thumbnail, update_only: true, reject_if: proc { |attr| attr['iiif_tilesource'].blank? }
19
19
  accepts_nested_attributes_for :masthead, update_only: true, reject_if: proc { |attr| attr['iiif_tilesource'].blank? }
20
20