blacklight-spotlight 0.31.0 → 0.32.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spotlight/dashboards_controller.rb +1 -0
  3. data/app/controllers/spotlight/resources_controller.rb +1 -1
  4. data/app/helpers/spotlight/browse_helper.rb +2 -0
  5. data/app/helpers/spotlight/pages_helper.rb +3 -1
  6. data/app/helpers/spotlight/rendering_helper.rb +7 -0
  7. data/app/jobs/spotlight/reindex_job.rb +30 -4
  8. data/app/models/concerns/spotlight/solr_document.rb +1 -1
  9. data/app/models/concerns/spotlight/user.rb +1 -0
  10. data/app/models/spotlight/exhibit.rb +8 -3
  11. data/app/models/spotlight/reindex_progress.rb +19 -29
  12. data/app/models/spotlight/reindexing_log_entry.rb +39 -0
  13. data/app/models/spotlight/resource.rb +10 -59
  14. data/app/serializers/spotlight/exhibit_export_serializer.rb +7 -7
  15. data/app/serializers/spotlight/page_representer.rb +1 -1
  16. data/app/views/spotlight/browse/_search.html.erb +1 -1
  17. data/app/views/spotlight/browse/show.html.erb +1 -1
  18. data/app/views/spotlight/catalog/_edit_default.html.erb +2 -1
  19. data/app/views/spotlight/dashboards/_reindexing_activity.html.erb +28 -0
  20. data/app/views/spotlight/dashboards/show.html.erb +4 -0
  21. data/config/locales/spotlight.en.yml +15 -0
  22. data/db/migrate/20170105222939_create_spotlight_reindexing_log_entries.rb +15 -0
  23. data/lib/spotlight/version.rb +1 -1
  24. data/spec/examples.txt +1066 -8
  25. data/spec/factories/reindexing_log_entries.rb +52 -0
  26. data/spec/features/javascript/reindex_monitor_spec.rb +3 -3
  27. data/spec/jobs/spotlight/reindex_job_spec.rb +37 -0
  28. data/spec/models/spotlight/exhibit_spec.rb +43 -4
  29. data/spec/models/spotlight/reindex_progress_spec.rb +128 -96
  30. data/spec/models/spotlight/reindexing_log_entry_spec.rb +135 -0
  31. data/spec/models/spotlight/resource_spec.rb +16 -28
  32. data/spec/support/views/test_view_helpers.rb +1 -0
  33. data/spec/views/spotlight/browse/show.html.erb_spec.rb +6 -0
  34. data/spec/views/spotlight/dashboards/_reindexing_activity.html.erb_spec.rb +87 -0
  35. metadata +26 -2
@@ -0,0 +1,135 @@
1
+ describe Spotlight::ReindexingLogEntry, type: :model do
2
+ subject { FactoryGirl.build(:reindexing_log_entry) }
3
+
4
+ describe 'scope' do
5
+ before(:all) do
6
+ # we only want to persist these rows for the duration a given test run...
7
+ DatabaseCleaner.start
8
+ # create (and save) entries in the log that can be queried, so that we can test our scopes
9
+ (0..10).to_a.each { FactoryGirl.create(:recent_reindexing_log_entry) }
10
+ FactoryGirl.create(:unstarted_reindexing_log_entry)
11
+ (0..10).to_a.each { FactoryGirl.create(:recent_reindexing_log_entry) }
12
+ end
13
+
14
+ after(:all) do
15
+ # ...remove the entries we created, now that we're done with them
16
+ DatabaseCleaner.clean
17
+ end
18
+
19
+ let(:sorted_log_entry_list) do
20
+ unstarted_entries = Spotlight::ReindexingLogEntry.where(start_time: nil).to_a
21
+ started_entries = Spotlight::ReindexingLogEntry.where.not(start_time: nil).to_a.sort_by(&:start_time).reverse
22
+ unstarted_entries + started_entries # null start times should be first
23
+ end
24
+
25
+ context 'default' do
26
+ it 'sorts by start_time in descending order' do
27
+ default_log_entry_list = Spotlight::ReindexingLogEntry.all.to_a
28
+ expect(default_log_entry_list).to eq sorted_log_entry_list
29
+ end
30
+ end
31
+
32
+ context 'recent' do
33
+ it 'returns the most recent 5 entries (sorted by start_time descending)' do
34
+ recent_log_entry_list = Spotlight::ReindexingLogEntry.recent.to_a
35
+ expect(recent_log_entry_list).to eq sorted_log_entry_list[0..4]
36
+ end
37
+ end
38
+ end
39
+
40
+ describe '#duration' do
41
+ context 'when end_time is present' do
42
+ it 'is calculated as difference between end_time and start_time' do
43
+ expect(subject.duration).to eq 300
44
+ end
45
+ end
46
+
47
+ context 'when end_time is not present' do
48
+ subject { FactoryGirl.build(:in_progress_reindexing_log_entry) }
49
+
50
+ it 'is nil' do
51
+ expect(subject.duration).to be nil
52
+ end
53
+ end
54
+ end
55
+
56
+ describe 'state updating methods' do
57
+ describe '#in_progress!' do
58
+ subject { FactoryGirl.build(:unstarted_reindexing_log_entry) }
59
+
60
+ context 'executes normally' do
61
+ it 'sets start_time and job_status' do
62
+ lower_time_bound = Time.zone.now
63
+ subject.in_progress!
64
+ upper_time_bound = Time.zone.now
65
+
66
+ expect(subject.start_time).to be_between(lower_time_bound, upper_time_bound)
67
+ expect(subject.job_status).to eq 'in_progress'
68
+ end
69
+ end
70
+
71
+ context 'encounters an unexpected error' do
72
+ it "traps the exception and logs an error so that the caller doesn't have to deal with it" do
73
+ expect(subject).to receive(:'start_time=').and_raise StandardError.new # try to blow up the in_progress! call
74
+ expect(Rails.logger).to receive(:error) do |arg|
75
+ expect(arg).to match(/^unexpected error updating log entry to :in_progress from \[".*reindexing_log_entry.rb/)
76
+ end
77
+
78
+ expect { subject.in_progress! }.not_to raise_error
79
+ end
80
+ end
81
+ end
82
+
83
+ describe '#succeeded!' do
84
+ subject { FactoryGirl.build(:in_progress_reindexing_log_entry) }
85
+
86
+ context 'executes normally' do
87
+ it 'sets end_time and job_status' do
88
+ lower_time_bound = Time.zone.now
89
+ subject.succeeded!
90
+ upper_time_bound = Time.zone.now
91
+
92
+ expect(subject.end_time).to be_between(lower_time_bound, upper_time_bound)
93
+ expect(subject.job_status).to eq 'succeeded'
94
+ end
95
+ end
96
+
97
+ context 'encounters an unexpected error' do
98
+ it "traps the exception and logs an error so that the caller doesn't have to deal with it" do
99
+ expect(subject).to receive(:'end_time=').and_raise StandardError.new # try to blow up the succeeded! call
100
+ expect(Rails.logger).to receive(:error) do |arg|
101
+ expect(arg).to match(/^unexpected error updating log entry to :succeeded from \[".*reindexing_log_entry.rb/)
102
+ end
103
+
104
+ expect { subject.succeeded! }.not_to raise_error
105
+ end
106
+ end
107
+ end
108
+
109
+ describe '#failed!' do
110
+ subject { FactoryGirl.build(:in_progress_reindexing_log_entry) }
111
+
112
+ context 'executes normally' do
113
+ it 'sets end_time and job_status' do
114
+ lower_time_bound = Time.zone.now
115
+ subject.failed!
116
+ upper_time_bound = Time.zone.now
117
+
118
+ expect(subject.end_time).to be_between(lower_time_bound, upper_time_bound)
119
+ expect(subject.job_status).to eq 'failed'
120
+ end
121
+ end
122
+
123
+ context 'encounters an unexpected error' do
124
+ it "traps the exception and logs an error so that the caller doesn't have to deal with it" do
125
+ expect(subject).to receive(:'end_time=').and_raise StandardError.new # try to blow up the failed! call
126
+ expect(Rails.logger).to receive(:error) do |arg|
127
+ expect(arg).to match(/^unexpected error updating log entry to :failed from \[".*reindexing_log_entry.rb/)
128
+ end
129
+
130
+ expect { subject.failed! }.not_to raise_error
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
@@ -4,29 +4,6 @@ describe Spotlight::Resource, type: :model do
4
4
  end
5
5
  let(:exhibit) { FactoryGirl.create(:exhibit) }
6
6
 
7
- describe '#enqueued_at' do
8
- it 'casts values to Time objects' do
9
- t = Time.zone.now.at_beginning_of_minute
10
- subject.enqueued_at = t
11
-
12
- expect(subject.enqueued_at).to eq t
13
- end
14
-
15
- it 'handles blank values' do
16
- subject.enqueued_at = nil
17
- expect(subject.enqueued_at).to be_nil
18
- end
19
- end
20
-
21
- describe '#last_indexed_finished' do
22
- it 'casts values to Time objects' do
23
- t = Time.zone.now.at_beginning_of_minute
24
- subject.last_indexed_finished = t
25
-
26
- expect(subject.last_indexed_finished).to eq t
27
- end
28
- end
29
-
30
7
  describe '#reindex' do
31
8
  context 'with a provider that generates ids' do
32
9
  subject do
@@ -55,6 +32,18 @@ describe Spotlight::Resource, type: :model do
55
32
  subject.reindex
56
33
  end
57
34
 
35
+ context 'reindexing_log_entry is provided' do
36
+ before do
37
+ allow(subject.send(:blacklight_solr)).to receive(:update)
38
+ end
39
+
40
+ it 'updates the count of reindexed items in the log entry' do
41
+ reindexing_log_entry = double(Spotlight::ReindexingLogEntry)
42
+ expect(reindexing_log_entry).to receive(:update).with(items_reindexed_count: 1)
43
+ subject.reindex reindexing_log_entry
44
+ end
45
+ end
46
+
58
47
  context 'when the index is not writable' do
59
48
  before do
60
49
  allow(Spotlight::Engine.config).to receive_messages(writable_index: false)
@@ -83,13 +72,12 @@ describe Spotlight::Resource, type: :model do
83
72
  subject.reindex
84
73
  end
85
74
 
86
- it 'records indexing metadata as document attributes' do
75
+ it 'touches the exhibit to clear any caches' do
76
+ allow(subject.exhibit).to receive(:touch)
77
+
87
78
  subject.reindex
88
79
 
89
- expect(subject.indexed_at).to be > Time.zone.now - 5.seconds
90
- expect(subject.last_indexed_estimate).to eq 2
91
- expect(subject.last_indexed_count).to eq 2
92
- expect(subject.last_index_elapsed_time).to be < 1
80
+ expect(subject.exhibit).to have_received(:touch)
93
81
  end
94
82
  end
95
83
  end
@@ -4,6 +4,7 @@ module Spotlight
4
4
 
5
5
  included do
6
6
  before do
7
+ view.send(:extend, Spotlight::RenderingHelper)
7
8
  view.send(:extend, Spotlight::MainAppHelpers)
8
9
  view.send(:extend, Spotlight::CrudLinkHelpers)
9
10
  view.send(:extend, Spotlight::TitleHelper)
@@ -45,6 +45,12 @@ describe 'spotlight/browse/show', type: :view do
45
45
  expect(response).to have_selector 'p', text: search.long_description
46
46
  end
47
47
 
48
+ it 'renders the long description as markdown' do
49
+ allow(search).to receive_messages(long_description: '[some link](/somewhere)')
50
+ render
51
+ expect(response).to have_selector 'p a', text: 'some link'
52
+ end
53
+
48
54
  it 'displays search results actions' do
49
55
  render
50
56
  expect(response).to have_content 'Sort and Per Page actions'
@@ -0,0 +1,87 @@
1
+ describe 'spotlight/dashboards/_reindexing_activity.html.erb', type: :view do
2
+ # recent reindexing entries should be sorted by start_time in descending order, so mock that behavior
3
+ let(:recent_reindexing) do
4
+ [FactoryGirl.build(:unstarted_reindexing_log_entry)] + # nil start_time is trouble for the sort_by used to create the rest of the fixture's rows
5
+ [
6
+ FactoryGirl.build(:reindexing_log_entry),
7
+ FactoryGirl.build(:in_progress_reindexing_log_entry),
8
+ FactoryGirl.build(:recent_reindexing_log_entry),
9
+ FactoryGirl.build(:failed_reindexing_log_entry)
10
+ ].sort_by(&:start_time).reverse
11
+ end
12
+ let(:p) { 'spotlight/dashboards/reindexing_activity' }
13
+
14
+ context 'the reindexing log is empty' do
15
+ before do
16
+ assign(:recent_reindexing, [])
17
+ render p
18
+ end
19
+
20
+ it 'displays the section header' do
21
+ expect(rendered).to have_css('h3', text: 'Recent Item Indexing Activity')
22
+ end
23
+
24
+ it 'displays an explanatory message when there are no reindexing attempts in the log' do
25
+ expect(rendered).to have_content 'There has been no reindexing activity'
26
+ end
27
+ end
28
+
29
+ context 'the reindexing log has entries' do
30
+ before do
31
+ assign(:recent_reindexing, recent_reindexing)
32
+ render p
33
+ end
34
+
35
+ it 'displays the correct localized column headings when there are reindexing attempts in the log' do
36
+ expect(rendered).to have_css('table.table-striped th.col-md-3', text: 'Date', count: 1)
37
+ expect(rendered).to have_css('table.table-striped th.col-md-2', text: 'Requested By', count: 1)
38
+ expect(rendered).to have_css('table.table-striped th.col-md-1', text: 'Items Indexed', count: 1)
39
+ expect(rendered).to have_css('table.table-striped th.col-md-2', text: 'Elapsed Time', count: 1)
40
+ expect(rendered).to have_css('table.table-striped th.col-md-2', text: 'Status', count: 1)
41
+ end
42
+
43
+ it 'formats the start time correctly' do
44
+ expect(rendered).to have_css('table.table-striped td', text: '05 Jan 23:00', count: 1)
45
+ expect(rendered).to have_css('table.table-striped td', text: '10 Jan 23:00', count: 1)
46
+ end
47
+
48
+ it 'displays the user that initiated the reindexing' do
49
+ expect(rendered).to have_css('table.table-striped td', text: /user\d+@example.com/, count: 5)
50
+ end
51
+
52
+ it 'displays the count of reindexed items' do
53
+ expect(rendered).to have_css('table.table-striped td', text: /^10$/, count: 2)
54
+ expect(rendered).to have_css('table.table-striped td', text: /^100$/, count: 1)
55
+ end
56
+
57
+ it 'displays the duration of completed reindexing attempts' do
58
+ expect(rendered).to have_css('table.table-striped td', text: '5 minutes', count: 3)
59
+ end
60
+
61
+ it 'displays nothing in the duration column or start time column when the info is unavailable (e.g. unstarted or in_progress attempts)' do
62
+ # we expect 2 blank durations, and 1 blank start time (1 unstarted log entry w/ blank start and duration, 1 in_progress w/ blank duration)
63
+ expect(rendered).to have_css('table.table-striped td', text: /^$/, count: 3)
64
+ end
65
+
66
+ it 'displays the status of the reindexing attempt using localized text' do
67
+ expect(rendered).to have_css('table.table-striped td', text: 'Not Yet Started', count: 1)
68
+ expect(rendered).to have_css('table.table-striped td', text: 'Successful', count: 2)
69
+ expect(rendered).to have_css('table.table-striped td', text: 'In Progress', count: 1)
70
+ expect(rendered).to have_css('table.table-striped td', text: 'Failed', count: 1)
71
+ end
72
+ end
73
+
74
+ context 'a reindexing log entry has a null user' do
75
+ it 'displays blank in the user field and renders without error' do
76
+ assign(:recent_reindexing, [FactoryGirl.build(:reindexing_log_entry_no_user)])
77
+ expect { render p }.not_to raise_error
78
+
79
+ # we expect one blank table cell for the user, and values for everything else
80
+ expect(rendered).to have_css('table.table-striped td', text: /^$/, count: 1)
81
+ expect(rendered).to have_css('table.table-striped td', text: '05 Jan 23:00', count: 1)
82
+ expect(rendered).to have_css('table.table-striped td', text: /^10$/, count: 1)
83
+ expect(rendered).to have_css('table.table-striped td', text: '5 minutes', count: 1)
84
+ expect(rendered).to have_css('table.table-striped td', text: 'Successful', count: 1)
85
+ end
86
+ end
87
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight-spotlight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.31.0
4
+ version: 0.32.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-01-09 00:00:00.000000000 Z
14
+ date: 2017-02-01 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -249,6 +249,20 @@ dependencies:
249
249
  - - "~>"
250
250
  - !ruby/object:Gem::Version
251
251
  version: '1.6'
252
+ - !ruby/object:Gem::Dependency
253
+ name: roar
254
+ requirement: !ruby/object:Gem::Requirement
255
+ requirements:
256
+ - - "~>"
257
+ - !ruby/object:Gem::Version
258
+ version: '1.1'
259
+ type: :runtime
260
+ prerelease: false
261
+ version_requirements: !ruby/object:Gem::Requirement
262
+ requirements:
263
+ - - "~>"
264
+ - !ruby/object:Gem::Version
265
+ version: '1.1'
252
266
  - !ruby/object:Gem::Dependency
253
267
  name: roar-rails
254
268
  requirement: !ruby/object:Gem::Requirement
@@ -825,6 +839,7 @@ files:
825
839
  - app/helpers/spotlight/meta_helper.rb
826
840
  - app/helpers/spotlight/navbar_helper.rb
827
841
  - app/helpers/spotlight/pages_helper.rb
842
+ - app/helpers/spotlight/rendering_helper.rb
828
843
  - app/helpers/spotlight/roles_helper.rb
829
844
  - app/helpers/spotlight/search_configurations_helper.rb
830
845
  - app/helpers/spotlight/searches_helper.rb
@@ -888,6 +903,7 @@ files:
888
903
  - app/models/spotlight/masthead.rb
889
904
  - app/models/spotlight/page.rb
890
905
  - app/models/spotlight/reindex_progress.rb
906
+ - app/models/spotlight/reindexing_log_entry.rb
891
907
  - app/models/spotlight/resource.rb
892
908
  - app/models/spotlight/resources/csv_upload.rb
893
909
  - app/models/spotlight/resources/json_upload.rb
@@ -973,6 +989,7 @@ files:
973
989
  - app/views/spotlight/dashboards/_analytics.html.erb
974
990
  - app/views/spotlight/dashboards/_page.html.erb
975
991
  - app/views/spotlight/dashboards/_page_activity.html.erb
992
+ - app/views/spotlight/dashboards/_reindexing_activity.html.erb
976
993
  - app/views/spotlight/dashboards/_solr_document_activity.html.erb
977
994
  - app/views/spotlight/dashboards/analytics.html.erb
978
995
  - app/views/spotlight/dashboards/show.html.erb
@@ -1122,6 +1139,7 @@ files:
1122
1139
  - db/migrate/20160815165432_add_resource_to_solr_document_sidecar.rb
1123
1140
  - db/migrate/20160816165432_add_index_status_to_solr_document_sidecar.rb
1124
1141
  - db/migrate/20160929180534_add_document_index_to_solr_document_sidecar.rb
1142
+ - db/migrate/20170105222939_create_spotlight_reindexing_log_entries.rb
1125
1143
  - lib/blacklight/spotlight.rb
1126
1144
  - lib/generators/spotlight/install_generator.rb
1127
1145
  - lib/generators/spotlight/scaffold_resource_generator.rb
@@ -1173,6 +1191,7 @@ files:
1173
1191
  - spec/factories/exhibits.rb
1174
1192
  - spec/factories/featured_images.rb
1175
1193
  - spec/factories/pages.rb
1194
+ - spec/factories/reindexing_log_entries.rb
1176
1195
  - spec/factories/resources.rb
1177
1196
  - spec/factories/roles.rb
1178
1197
  - spec/factories/searches.rb
@@ -1277,6 +1296,7 @@ files:
1277
1296
  - spec/models/spotlight/masthead_spec.rb
1278
1297
  - spec/models/spotlight/page_spec.rb
1279
1298
  - spec/models/spotlight/reindex_progress_spec.rb
1299
+ - spec/models/spotlight/reindexing_log_entry_spec.rb
1280
1300
  - spec/models/spotlight/resource_spec.rb
1281
1301
  - spec/models/spotlight/resources/open_graph_spec.rb
1282
1302
  - spec/models/spotlight/resources/upload_spec.rb
@@ -1325,6 +1345,7 @@ files:
1325
1345
  - spec/views/spotlight/catalog/edit.html.erb_spec.rb
1326
1346
  - spec/views/spotlight/contacts/edit.html.erb_spec.rb
1327
1347
  - spec/views/spotlight/dashboards/_analytics.html.erb_spec.rb
1348
+ - spec/views/spotlight/dashboards/_reindexing_activity.html.erb_spec.rb
1328
1349
  - spec/views/spotlight/dashboards/analytics.html.erb_spec.rb
1329
1350
  - spec/views/spotlight/exhibits/_exhibit_card_front.html.erb_spec.rb
1330
1351
  - spec/views/spotlight/exhibits/edit.html.erb_spec.rb
@@ -1446,6 +1467,7 @@ test_files:
1446
1467
  - spec/factories/exhibits.rb
1447
1468
  - spec/factories/featured_images.rb
1448
1469
  - spec/factories/pages.rb
1470
+ - spec/factories/reindexing_log_entries.rb
1449
1471
  - spec/factories/resources.rb
1450
1472
  - spec/factories/roles.rb
1451
1473
  - spec/factories/searches.rb
@@ -1550,6 +1572,7 @@ test_files:
1550
1572
  - spec/models/spotlight/masthead_spec.rb
1551
1573
  - spec/models/spotlight/page_spec.rb
1552
1574
  - spec/models/spotlight/reindex_progress_spec.rb
1575
+ - spec/models/spotlight/reindexing_log_entry_spec.rb
1553
1576
  - spec/models/spotlight/resource_spec.rb
1554
1577
  - spec/models/spotlight/resources/open_graph_spec.rb
1555
1578
  - spec/models/spotlight/resources/upload_spec.rb
@@ -1598,6 +1621,7 @@ test_files:
1598
1621
  - spec/views/spotlight/catalog/edit.html.erb_spec.rb
1599
1622
  - spec/views/spotlight/contacts/edit.html.erb_spec.rb
1600
1623
  - spec/views/spotlight/dashboards/_analytics.html.erb_spec.rb
1624
+ - spec/views/spotlight/dashboards/_reindexing_activity.html.erb_spec.rb
1601
1625
  - spec/views/spotlight/dashboards/analytics.html.erb_spec.rb
1602
1626
  - spec/views/spotlight/exhibits/_exhibit_card_front.html.erb_spec.rb
1603
1627
  - spec/views/spotlight/exhibits/edit.html.erb_spec.rb