sufia 7.0.0.beta1 → 7.0.0.beta2
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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/sufia.js +3 -4
- data/app/assets/stylesheets/sufia/_styles.scss +2 -1
- data/app/controllers/concerns/sufia/transfers_controller_behavior.rb +1 -0
- data/app/controllers/errors_controller.rb +1 -1
- data/app/indexers/sufia/work_indexer.rb +1 -0
- data/app/presenters/sufia/admin_stats_presenter.rb +17 -11
- data/app/search_builders/sufia/catalog_search_builder.rb +29 -0
- data/app/search_builders/sufia/my_collections_search_builder.rb +7 -0
- data/app/search_builders/sufia/my_highlights_search_builder.rb +9 -3
- data/app/search_builders/sufia/my_shares_search_builder.rb +8 -1
- data/app/search_builders/sufia/search_builder.rb +0 -59
- data/app/services/sufia/analytics.rb +25 -8
- data/app/services/sufia/query_service.rb +1 -1
- data/app/services/sufia/statistics/collections/over_time.rb +13 -0
- data/app/services/sufia/statistics/depositors/summary.rb +54 -0
- data/app/services/sufia/statistics/file_sets/by_format.rb +14 -0
- data/app/services/sufia/statistics/over_time.rb +11 -3
- data/app/services/sufia/statistics/system_stats.rb +61 -0
- data/app/services/sufia/statistics/term_query.rb +65 -0
- data/app/services/sufia/statistics/works/by_depositor.rb +13 -0
- data/app/services/sufia/statistics/works/by_resource_type.rb +13 -0
- data/app/services/sufia/statistics/works/count.rb +49 -0
- data/app/services/sufia/statistics/works/over_time.rb +13 -0
- data/app/views/admin/stats/_stats_by_date.html.erb +1 -1
- data/app/views/admin/stats/_top_data.html.erb +4 -4
- data/app/views/admin/stats/_works.html.erb +8 -0
- data/app/views/collections/_form.html.erb +1 -1
- data/app/views/curation_concerns/base/_attribute_rows.html.erb +10 -10
- data/app/views/curation_concerns/base/_metadata.html.erb +1 -1
- data/app/views/curation_concerns/base/_relationships.html.erb +1 -1
- data/app/views/curation_concerns/file_sets/_descriptions.html.erb +1 -1
- data/app/views/error/404.html.erb +8 -19
- data/app/views/layouts/error.html.erb +3 -3
- data/app/views/layouts/homepage.html.erb +1 -1
- data/app/views/layouts/sufia-dashboard.html.erb +1 -1
- data/app/views/layouts/sufia-one-column.html.erb +1 -1
- data/app/views/{_footer.html.erb → shared/_footer.html.erb} +1 -1
- data/app/views/stats/file.html.erb +0 -1
- data/app/views/stats/work.html.erb +0 -2
- data/lib/generators/sufia/install_generator.rb +6 -0
- data/lib/sufia/engine.rb +1 -0
- data/lib/sufia/version.rb +1 -1
- data/spec/controllers/my/shares_controller_spec.rb +6 -7
- data/spec/controllers/transfers_controller_spec.rb +10 -0
- data/spec/features/batch_edit_spec.rb +1 -1
- data/spec/lib/sufia/analytics_spec.rb +18 -10
- data/spec/presenters/sufia/admin_stats_presenter_spec.rb +21 -14
- data/spec/search_builder/{sufia_search_builder_spec.rb → sufia/catalog_search_builder_spec.rb} +1 -1
- data/spec/search_builder/sufia/my_shares_search_builder_spec.rb +18 -0
- data/spec/services/statistics/{collections_spec.rb → collections/over_time_spec.rb} +1 -1
- data/spec/services/{sufia/admin/depositor_stats_spec.rb → statistics/depositors/summary_spec.rb} +5 -7
- data/spec/services/statistics/file_sets/by_format_spec.rb +30 -0
- data/spec/services/statistics/system_stats_spec.rb +54 -0
- data/spec/services/statistics/works/by_depositor_spec.rb +25 -0
- data/spec/services/statistics/works/by_resource_type_spec.rb +21 -0
- data/spec/services/statistics/works/count_spec.rb +42 -0
- data/spec/services/statistics/{works_spec.rb → works/over_time_spec.rb} +1 -1
- data/spec/views/admin/stats/index.html.erb_spec.rb +3 -6
- data/spec/views/curation_concerns/base/_relationships.html.erb_spec.rb +4 -1
- data/sufia.gemspec +2 -1
- metadata +49 -25
- data/app/services/sufia/admin/depositor_stats.rb +0 -48
- data/app/services/sufia/statistics/collections.rb +0 -12
- data/app/services/sufia/statistics/works.rb +0 -12
- data/app/services/sufia/system_stats.rb +0 -120
- data/app/views/admin/stats/_files.html.erb +0 -8
- data/lib/generators/sufia/fulltext_generator.rb +0 -26
- data/spec/services/sufia/system_stats_spec.rb +0 -224
- data/vendor/assets/javascripts/flot/excanvas.js +0 -1428
- data/vendor/assets/javascripts/flot/jquery.flot.js +0 -3168
- data/vendor/assets/javascripts/flot/jquery.flot.selection.js +0 -360
- data/vendor/assets/javascripts/flot/jquery.flot.time.js +0 -432
data/lib/sufia/version.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
describe My::SharesController, type: :controller do
|
3
2
|
describe "logged in user" do
|
4
3
|
let(:user) { create(:user) }
|
@@ -11,11 +10,11 @@ describe My::SharesController, type: :controller do
|
|
11
10
|
let(:other_user) { create(:user) }
|
12
11
|
let(:someone_else) { create(:user) }
|
13
12
|
|
14
|
-
let!(:
|
15
|
-
let!(:
|
16
|
-
let!(:shared_with_me) { create(:
|
17
|
-
let!(:read_shared_with_me) { create(:
|
18
|
-
let!(:shared_with_someone_else) { create(:
|
13
|
+
let!(:my_work) { create(:work, user: user) }
|
14
|
+
let!(:unshared_work) { create(:work, user: other_user) }
|
15
|
+
let!(:shared_with_me) { create(:work, user: other_user, edit_users: [user, other_user]) }
|
16
|
+
let!(:read_shared_with_me) { create(:work, user: other_user, read_users: [user, other_user]) }
|
17
|
+
let!(:shared_with_someone_else) { create(:work, user: other_user, edit_users: [someone_else, other_user]) }
|
19
18
|
let!(:my_collection) { create(:public_collection, user: user) }
|
20
19
|
|
21
20
|
it "responds with success" do
|
@@ -24,7 +23,7 @@ describe My::SharesController, type: :controller do
|
|
24
23
|
end
|
25
24
|
|
26
25
|
context "with multiple pages of results" do
|
27
|
-
before { 2.times { create(:
|
26
|
+
before { 2.times { create(:work, user: other_user, edit_users: [user, other_user]) } }
|
28
27
|
it "paginates" do
|
29
28
|
get :index, per_page: 2
|
30
29
|
expect(assigns[:document_list].length).to eq 2
|
@@ -1,4 +1,14 @@
|
|
1
1
|
describe TransfersController, type: :controller do
|
2
|
+
describe "without a signed in user" do
|
3
|
+
describe "#index" do
|
4
|
+
it "redirects to sign in" do
|
5
|
+
get :index
|
6
|
+
expect(flash[:alert]).to eq "You need to sign in or sign up before continuing."
|
7
|
+
expect(response).to redirect_to main_app.new_user_session_path
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
2
12
|
describe "with a signed in user" do
|
3
13
|
let(:another_user) { create(:user) }
|
4
14
|
let(:user) { create(:user) }
|
@@ -54,7 +54,7 @@ describe 'Batch management of works', type: :feature do
|
|
54
54
|
expand("contributor")
|
55
55
|
expect(page).to have_css "input#generic_work_contributor[value*='NEW contributor']"
|
56
56
|
expand("description")
|
57
|
-
expect(page).to have_css "textarea#generic_work_description", 'NEW description'
|
57
|
+
expect(page).to have_css "textarea#generic_work_description", text: 'NEW description'
|
58
58
|
expand("keyword")
|
59
59
|
expect(page).to have_css "input#generic_work_keyword[value*='NEW keyword']"
|
60
60
|
expand("publisher")
|
@@ -4,20 +4,28 @@ describe Sufia::Analytics do
|
|
4
4
|
allow(subject).to receive(:token).and_return(token)
|
5
5
|
end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
7
|
+
describe "configuration" do
|
8
|
+
context "When the yaml file has values" do
|
9
|
+
it 'reads its config from a yaml file' do
|
10
|
+
expect(subject.send(:config).keys.sort).to eql ['app_name', 'app_version', 'client_email', 'privkey_path', 'privkey_secret']
|
11
|
+
end
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
14
|
+
context "When the yaml file has no values" do
|
15
|
+
before do
|
16
|
+
described_class.send(:remove_instance_variable, :@config)
|
17
|
+
allow(File).to receive(:read).and_return("# Just comments\n# and comments\n")
|
18
|
+
end
|
19
|
+
it 'returns nil' do
|
20
|
+
expect(Rails.logger).to receive(:error)
|
21
|
+
.with(starting_with("Unable to fetch any keys from"))
|
22
|
+
expect(subject.send(:config)).to be nil
|
23
|
+
end
|
24
|
+
end
|
17
25
|
end
|
18
26
|
|
19
27
|
it 'instantiates a user' do
|
20
|
-
expect(subject.user).to be_a(Legato::User)
|
28
|
+
expect(subject.send(:user)).to be_a(Legato::User)
|
21
29
|
end
|
22
30
|
|
23
31
|
it 'responds to :profile' do
|
@@ -26,7 +26,7 @@ describe Sufia::AdminStatsPresenter do
|
|
26
26
|
|
27
27
|
subject { service.active_users }
|
28
28
|
it "returns statistics" do
|
29
|
-
expect(subject).to eq
|
29
|
+
expect(subject).to eq [{ label: user1.user_key, data: 3 }, { label: user2.user_key, data: 1 }]
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -48,11 +48,11 @@ describe Sufia::AdminStatsPresenter do
|
|
48
48
|
subject { service.top_formats }
|
49
49
|
|
50
50
|
it "gathers formats" do
|
51
|
-
expect(subject).to eq
|
51
|
+
expect(subject).to eq [{ label: "png", data: 2 }, { label: "jpeg", data: 1 }]
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
describe "#
|
55
|
+
describe "#works_count" do
|
56
56
|
before do
|
57
57
|
build(:generic_work, user: user1, id: "abc1223").update_index
|
58
58
|
build(:public_generic_work, user: user1, id: "bbb1223").update_index
|
@@ -63,7 +63,7 @@ describe Sufia::AdminStatsPresenter do
|
|
63
63
|
let(:one_day_ago) { one_day_ago_date.strftime("%Y-%m-%d") }
|
64
64
|
let(:two_days_ago) { two_days_ago_date.strftime("%Y-%m-%d") }
|
65
65
|
|
66
|
-
subject { service.
|
66
|
+
subject { service.works_count }
|
67
67
|
|
68
68
|
it "includes files but not collections" do
|
69
69
|
expect(subject[:total]).to eq(3)
|
@@ -73,22 +73,26 @@ describe Sufia::AdminStatsPresenter do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
context "when there is uncommitted work" do
|
76
|
-
let(:
|
76
|
+
let(:original_works_count) do
|
77
77
|
work = create(:generic_work, user: user1)
|
78
78
|
original_files_count = GenericWork.count
|
79
79
|
ActiveFedora::SolrService.instance.conn.delete_by_id(work.id)
|
80
80
|
original_files_count
|
81
81
|
end
|
82
|
-
|
83
|
-
|
82
|
+
|
83
|
+
it "provides accurate count, ensuring that solr deletes have been expunged first" do
|
84
|
+
expect(subject[:total]).to eq(original_works_count - 1)
|
84
85
|
end
|
85
86
|
end
|
86
87
|
|
87
88
|
context "when start date is provided" do
|
88
89
|
let(:start_date) { one_day_ago }
|
89
|
-
let(:system_stats) { double(
|
90
|
+
let(:system_stats) { double(by_permission: {}) }
|
90
91
|
it "queries by start date" do
|
91
|
-
expect(Sufia::
|
92
|
+
expect(Sufia::Statistics::Works::Count).to receive(:new)
|
93
|
+
.with(one_day_ago_date.beginning_of_day,
|
94
|
+
nil)
|
95
|
+
.and_return(system_stats)
|
92
96
|
subject
|
93
97
|
end
|
94
98
|
end
|
@@ -96,9 +100,12 @@ describe Sufia::AdminStatsPresenter do
|
|
96
100
|
context "when start and end date is provided" do
|
97
101
|
let(:start_date) { two_days_ago }
|
98
102
|
let(:end_date) { one_day_ago }
|
99
|
-
let(:system_stats) { double(
|
103
|
+
let(:system_stats) { double(by_permission: {}) }
|
100
104
|
it "queries by start and date" do
|
101
|
-
expect(Sufia::
|
105
|
+
expect(Sufia::Statistics::Works::Count).to receive(:new)
|
106
|
+
.with(two_days_ago_date.beginning_of_day,
|
107
|
+
one_day_ago_date.end_of_day)
|
108
|
+
.and_return(system_stats)
|
102
109
|
subject
|
103
110
|
end
|
104
111
|
end
|
@@ -151,15 +158,15 @@ describe Sufia::AdminStatsPresenter do
|
|
151
158
|
|
152
159
|
context "with a start and no end date" do
|
153
160
|
let(:start_date) { '2015-12-14' }
|
154
|
-
let(:today) { Time.zone.today.
|
155
|
-
it { is_expected.to eq "
|
161
|
+
let(:today) { Time.zone.today.to_date.to_s(:standard) }
|
162
|
+
it { is_expected.to eq "12/14/2015 to #{today}" }
|
156
163
|
end
|
157
164
|
|
158
165
|
context 'with start and end dates' do
|
159
166
|
let(:start_date) { '2015-12-14' }
|
160
167
|
let(:end_date) { '2016-05-12' }
|
161
168
|
|
162
|
-
it { is_expected.to eq '
|
169
|
+
it { is_expected.to eq '12/14/2015 to 05/12/2016' }
|
163
170
|
end
|
164
171
|
end
|
165
172
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
describe Sufia::MySharesSearchBuilder do
|
2
|
+
let(:me) { create(:user) }
|
3
|
+
let(:config) { CatalogController.blacklight_config }
|
4
|
+
let(:scope) { double('The scope',
|
5
|
+
blacklight_config: config,
|
6
|
+
params: {},
|
7
|
+
current_ability: Ability.new(me),
|
8
|
+
current_user: me) }
|
9
|
+
let(:builder) { described_class.new(scope) }
|
10
|
+
|
11
|
+
subject { builder.to_hash['fq'] }
|
12
|
+
|
13
|
+
it "filters things we have access to in which we are not the depositor" do
|
14
|
+
expect(subject).to eq ["edit_access_group_ssim:public OR edit_access_group_ssim:registered OR edit_access_person_ssim:#{me.user_key}",
|
15
|
+
"{!terms f=has_model_ssim}GenericWork,Collection",
|
16
|
+
"-_query_:\"{!field f=depositor_ssim}#{me.user_key}\""]
|
17
|
+
end
|
18
|
+
end
|
data/spec/services/{sufia/admin/depositor_stats_spec.rb → statistics/depositors/summary_spec.rb}
RENAMED
@@ -1,13 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe Sufia::Admin::DepositorStats do
|
1
|
+
describe Sufia::Statistics::Depositors::Summary do
|
4
2
|
let(:user1) { create(:user) }
|
5
3
|
let(:user2) { create(:user) }
|
6
4
|
let!(:old_work) { create(:work, user: user1) }
|
7
5
|
let(:two_days_ago_date) { Time.zone.now - 2.days }
|
8
6
|
|
9
|
-
let(:start_date) {
|
10
|
-
let(:end_date) {
|
7
|
+
let(:start_date) { nil }
|
8
|
+
let(:end_date) { nil }
|
11
9
|
let!(:work1) { create(:work, user: user1) }
|
12
10
|
let!(:work2) { create(:work, user: user2) }
|
13
11
|
let!(:collection1) { create(:public_collection, user: user1) }
|
@@ -30,8 +28,8 @@ describe Sufia::Admin::DepositorStats do
|
|
30
28
|
end
|
31
29
|
|
32
30
|
context "when dates are present" do
|
33
|
-
let(:start_date) { 1.day.ago.
|
34
|
-
let(:end_date) { 0.days.ago.
|
31
|
+
let(:start_date) { 1.day.ago.beginning_of_day }
|
32
|
+
let(:end_date) { 0.days.ago.end_of_day }
|
35
33
|
it "gathers user deposits during a date range" do
|
36
34
|
expect(subject).to eq [{ key: user1.user_key, deposits: 1, user: user1 },
|
37
35
|
{ key: user2.user_key, deposits: 1, user: user2 }]
|
@@ -0,0 +1,30 @@
|
|
1
|
+
RSpec.describe Sufia::Statistics::FileSets::ByFormat do
|
2
|
+
let(:service) { described_class.new }
|
3
|
+
|
4
|
+
describe "#query" do
|
5
|
+
let(:fs1) { build(:file_set, id: '1234567') }
|
6
|
+
let(:fs2) { build(:file_set, id: '2345678') }
|
7
|
+
let(:fs3) { build(:file_set, id: '3456789') }
|
8
|
+
let(:fs4) { build(:file_set, id: '4567890') }
|
9
|
+
before do
|
10
|
+
allow(fs1).to receive_messages(mime_type: 'text/plain', format_label: ["plain text"])
|
11
|
+
fs1.update_index
|
12
|
+
allow(fs2).to receive_messages(mime_type: 'image/jpg', format_label: ["JPEG image"])
|
13
|
+
fs2.update_index
|
14
|
+
allow(fs3).to receive_messages(mime_type: 'image/tiff', format_label: ["TIFF image"])
|
15
|
+
fs3.update_index
|
16
|
+
allow(fs4).to receive_messages(mime_type: 'image/jpg', format_label: ["JPEG image"])
|
17
|
+
fs4.update_index
|
18
|
+
end
|
19
|
+
|
20
|
+
subject { service.query }
|
21
|
+
|
22
|
+
it "is a list of categories" do
|
23
|
+
expect(subject).to eq [{ label: 'jpg (JPEG image)', data: 2 },
|
24
|
+
{ label: 'plain (plain text)', data: 1 },
|
25
|
+
{ label: 'tiff (TIFF image)', data: 1 }]
|
26
|
+
expect(subject.first.label).to eq 'jpg (JPEG image)'
|
27
|
+
expect(subject.first.value).to eq 2
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
describe Sufia::Statistics::SystemStats do
|
2
|
+
let(:user1) { create(:user) }
|
3
|
+
let(:start_date) { nil }
|
4
|
+
let(:end_date) { nil }
|
5
|
+
let(:stats) { described_class.new(depositor_count, start_date, end_date) }
|
6
|
+
|
7
|
+
describe "#recent_users" do
|
8
|
+
let!(:user2) { create(:user) }
|
9
|
+
|
10
|
+
let(:two_days_ago_date) { 2.days.ago.beginning_of_day }
|
11
|
+
let(:one_day_ago_date) { 1.day.ago.end_of_day }
|
12
|
+
|
13
|
+
let(:depositor_count) { nil }
|
14
|
+
|
15
|
+
subject { stats.recent_users }
|
16
|
+
|
17
|
+
context "without dates" do
|
18
|
+
let(:mock_order) { double }
|
19
|
+
let(:mock_limit) { double }
|
20
|
+
it "defaults to latest 5 users" do
|
21
|
+
expect(mock_order).to receive(:limit).with(5).and_return(mock_limit)
|
22
|
+
expect(User).to receive(:order).with('created_at DESC').and_return(mock_order)
|
23
|
+
is_expected.to eq mock_limit
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "with start date" do
|
28
|
+
let(:start_date) { two_days_ago_date }
|
29
|
+
|
30
|
+
it "allows queries without an end date " do
|
31
|
+
expect(User).to receive(:recent_users).with(two_days_ago_date, nil).and_return([user2])
|
32
|
+
is_expected.to eq([user2])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
context "with start date and end date" do
|
36
|
+
let(:start_date) { two_days_ago_date }
|
37
|
+
let(:end_date) { one_day_ago_date }
|
38
|
+
it "queries" do
|
39
|
+
expect(User).to receive(:recent_users).with(two_days_ago_date, one_day_ago_date).and_return([user2])
|
40
|
+
is_expected.to eq([user2])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#users_count" do
|
46
|
+
let(:depositor_count) { nil }
|
47
|
+
let!(:user1) { create(:user) }
|
48
|
+
let!(:user2) { create(:user) }
|
49
|
+
|
50
|
+
subject { stats.users_count }
|
51
|
+
|
52
|
+
it { is_expected.to eq 2 }
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
RSpec.describe Sufia::Statistics::Works::ByDepositor do
|
2
|
+
let(:service) { described_class.new }
|
3
|
+
|
4
|
+
describe "#query" do
|
5
|
+
let(:user1) { create(:user) }
|
6
|
+
let(:user2) { create(:user) }
|
7
|
+
before do
|
8
|
+
gf = build(:generic_work, user: user1, id: '1234567')
|
9
|
+
gf.update_index
|
10
|
+
gf = build(:generic_work, user: user2, id: '2345678')
|
11
|
+
gf.update_index
|
12
|
+
gf = build(:generic_work, user: user1, id: '3456789')
|
13
|
+
gf.update_index
|
14
|
+
gf = build(:generic_work, user: user1, id: '4567890')
|
15
|
+
gf.update_index
|
16
|
+
end
|
17
|
+
|
18
|
+
subject { service.query }
|
19
|
+
|
20
|
+
it "is a list of categories" do
|
21
|
+
expect(subject).to eq [{ label: user1.user_key, data: 3 },
|
22
|
+
{ label: user2.user_key, data: 1 }]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
RSpec.describe Sufia::Statistics::Works::ByResourceType do
|
2
|
+
let(:service) { described_class.new }
|
3
|
+
|
4
|
+
describe "#query" do
|
5
|
+
before do
|
6
|
+
create(:generic_work, resource_type: ['Conference Proceeding'])
|
7
|
+
create(:generic_work, resource_type: ['Conference Proceeding'])
|
8
|
+
create(:generic_work, resource_type: ['Image'])
|
9
|
+
create(:generic_work, resource_type: ['Journal'])
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { service.query }
|
13
|
+
|
14
|
+
it "is a list of categories" do
|
15
|
+
expect(subject).to eq [{ label: 'Conference Proceeding', data: 2 },
|
16
|
+
{ label: 'Image', data: 1 },
|
17
|
+
{ label: 'Journal', data: 1 }]
|
18
|
+
expect(subject.to_json).to eq "[{\"label\":\"Conference Proceeding\",\"data\":2},{\"label\":\"Image\",\"data\":1},{\"label\":\"Journal\",\"data\":1}]"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
RSpec.describe Sufia::Statistics::Works::Count do
|
2
|
+
let(:user1) { create(:user) }
|
3
|
+
let(:service) { described_class.new(start_date, end_date) }
|
4
|
+
let(:start_date) { nil }
|
5
|
+
let(:end_date) { nil }
|
6
|
+
|
7
|
+
describe "#by_permission" do
|
8
|
+
subject { service.by_permission }
|
9
|
+
|
10
|
+
before do
|
11
|
+
build(:public_generic_work, user: user1, id: "pdf1223").update_index
|
12
|
+
build(:public_generic_work, user: user1, id: "wav1223").update_index
|
13
|
+
build(:public_generic_work, user: user1, id: "mp31223", create_date: [2.days.ago]).update_index
|
14
|
+
build(:registered_generic_work, user: user1, id: "reg1223").update_index
|
15
|
+
build(:generic_work, user: user1, id: "private1223").update_index
|
16
|
+
Collection.new(id: "ccc123") do |c|
|
17
|
+
c.apply_depositor_metadata(user1)
|
18
|
+
c.update_index
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "retrieves all documents by permissions" do
|
23
|
+
expect(subject).to include(public: 3, private: 1, registered: 1, total: 5)
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when passing a start date" do
|
27
|
+
let(:yesterday) { 1.day.ago }
|
28
|
+
let(:start_date) { yesterday.beginning_of_day }
|
29
|
+
it "gets documents after date by permissions" do
|
30
|
+
expect(subject).to include(public: 2, private: 1, registered: 1, total: 4)
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when passing an end date" do
|
34
|
+
let(:start_date) { 2.days.ago.beginning_of_day }
|
35
|
+
let(:end_date) { yesterday.end_of_day }
|
36
|
+
it "get documents between dates by permissions" do
|
37
|
+
expect(subject).to include(public: 1, private: 0, registered: 0, total: 1)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -11,9 +11,7 @@ describe "admin/stats/index.html.erb" do
|
|
11
11
|
|
12
12
|
context "default depositors" do
|
13
13
|
let(:top_5_active_users) do
|
14
|
-
|
15
|
-
5.times { |i| users[i.to_s] = i }
|
16
|
-
users
|
14
|
+
(1..5).map { |i| double(label: i.to_s, value: i) }
|
17
15
|
end
|
18
16
|
before do
|
19
17
|
allow(presenter).to receive(:active_users).and_return(top_5_active_users)
|
@@ -27,15 +25,14 @@ describe "admin/stats/index.html.erb" do
|
|
27
25
|
|
28
26
|
context "top 20 depositors" do
|
29
27
|
let(:top_20_active_users) do
|
30
|
-
|
31
|
-
20.times { |i| users[i.to_s] = i }
|
32
|
-
users
|
28
|
+
(1..20).map { |i| double(label: i.to_s, value: i) }
|
33
29
|
end
|
34
30
|
before do
|
35
31
|
allow(presenter).to receive(:active_users).and_return(top_20_active_users)
|
36
32
|
allow(presenter).to receive(:limit).and_return(20)
|
37
33
|
render
|
38
34
|
end
|
35
|
+
|
39
36
|
it "shows top 20 depositors, without an option to view more" do
|
40
37
|
expect(rendered).to have_content("(top 20)")
|
41
38
|
expect(rendered).to_not have_content("View top 20")
|