sufia 6.3.0 → 6.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -2
- data/.rubocop.yml +10 -0
- data/Gemfile +16 -7
- data/History.md +43 -0
- data/README.md +26 -19
- data/SUFIA_VERSION +1 -1
- data/app/assets/javascripts/notifications_check.js.erb +46 -0
- data/app/assets/javascripts/sufia.js +1 -2
- data/app/assets/javascripts/sufia/uploader.js +3 -3
- data/app/assets/stylesheets/sufia/_collections.scss +5 -0
- data/app/assets/stylesheets/sufia/_dashboard.scss +6 -1
- data/app/assets/stylesheets/sufia/_file-listing.scss +44 -6
- data/app/assets/stylesheets/sufia/_file-show.scss +4 -0
- data/app/assets/stylesheets/sufia/_settings.scss +3 -0
- data/app/controllers/api/items_controller.rb +7 -3
- data/app/controllers/concerns/sufia/admin/depositor_stats.rb +1 -1
- data/app/controllers/concerns/sufia/admin/stats_behavior.rb +6 -76
- data/app/controllers/concerns/sufia/batch_controller_behavior.rb +10 -2
- data/app/controllers/concerns/sufia/contact_form_controller_behavior.rb +1 -0
- data/app/controllers/concerns/sufia/files_controller_behavior.rb +11 -1
- data/app/controllers/concerns/sufia/homepage_controller.rb +1 -1
- data/app/controllers/concerns/sufia/my_controller_behavior.rb +2 -0
- data/app/controllers/concerns/sufia/users_controller_behavior.rb +2 -2
- data/app/helpers/generic_file_helper.rb +8 -5
- data/app/jobs/content_delete_event_job.rb +16 -11
- data/app/jobs/content_deposit_event_job.rb +4 -16
- data/app/jobs/content_depositor_change_event_job.rb +32 -20
- data/app/jobs/content_event_job.rb +39 -0
- data/app/jobs/content_new_version_event_job.rb +4 -16
- data/app/jobs/content_restored_version_event_job.rb +6 -19
- data/app/jobs/content_update_event_job.rb +4 -16
- data/app/jobs/event_job.rb +48 -4
- data/app/jobs/user_edit_profile_event_job.rb +4 -17
- data/app/jobs/user_follow_event_job.rb +10 -12
- data/app/jobs/user_unfollow_event_job.rb +10 -15
- data/app/models/concerns/sufia/solr_document_behavior.rb +11 -1
- data/app/models/system_stats.rb +108 -0
- data/app/presenters/sufia/admin_stats_presenter.rb +49 -0
- data/app/views/_controls.html.erb +1 -1
- data/app/views/_footer.html.erb +1 -1
- data/app/views/_logo.html.erb +1 -3
- data/app/views/admin/stats/_date_form.html.erb +8 -0
- data/app/views/admin/stats/_deposits.html.erb +2 -10
- data/app/views/admin/stats/_files.html.erb +6 -14
- data/app/views/admin/stats/_new_users.html.erb +7 -14
- data/app/views/admin/stats/_stats_by_date.html.erb +8 -0
- data/app/views/admin/stats/_top_data.html.erb +24 -0
- data/app/views/admin/stats/index.html.erb +5 -31
- data/app/views/collections/_form_for_select_collection.html.erb +5 -4
- data/app/views/collections/_show_actions.html.erb +7 -2
- data/app/views/collections/_show_document_list_row.html.erb +1 -9
- data/app/views/generic_files/_browse_everything.html.erb +3 -0
- data/app/views/generic_files/_descriptions.html.erb +1 -1
- data/app/views/generic_files/_generic_file.html.erb +1 -1
- data/app/views/generic_files/_local_file_import.html.erb +3 -0
- data/app/views/generic_files/_show_actions.html.erb +4 -0
- data/app/views/generic_files/upload/_form.html.erb +3 -0
- data/app/views/generic_files/upload/_to_collection.html.erb +5 -0
- data/app/views/homepage/_recent_document.html.erb +1 -7
- data/app/views/my/_index_partials/_default_group.html.erb +1 -1
- data/app/views/my/_index_partials/_list_collections.html.erb +3 -10
- data/app/views/my/_index_partials/_list_files.html.erb +13 -22
- data/app/views/my/_sort_and_per_page.html.erb +3 -3
- data/app/views/records/edit_fields/_rights.html.erb +2 -1
- data/app/views/static/terms.html.erb +1 -1
- data/config/locales/sufia.en.yml +13 -0
- data/lib/generators/sufia/templates/catalog_controller.rb +2 -2
- data/lib/sufia/version.rb +1 -1
- data/spec/actors/generic_file/actor_spec.rb +35 -0
- data/spec/controllers/admin_stats_controller_spec.rb +53 -23
- data/spec/controllers/api/items_controller_spec.rb +47 -41
- data/spec/controllers/batch_controller_spec.rb +1 -0
- data/spec/controllers/generic_files_controller_spec.rb +35 -1
- data/spec/controllers/my/files_controller_spec.rb +5 -0
- data/spec/factories/generic_files.rb +3 -0
- data/spec/features/collection_spec.rb +91 -0
- data/spec/features/contact_form_spec.rb +1 -0
- data/spec/forms/collection_edit_form_spec.rb +3 -3
- data/spec/forms/generic_file_edit_form_spec.rb +1 -1
- data/spec/jobs/create_derivatives_job_spec.rb +6 -0
- data/spec/models/file_content_datastream_spec.rb +1 -1
- data/spec/models/file_download_stat_spec.rb +4 -4
- data/spec/models/file_usage_spec.rb +2 -2
- data/spec/models/file_view_stat_spec.rb +4 -4
- data/spec/models/generic_file_spec.rb +15 -3
- data/spec/models/geo_names_resource_spec.rb +10 -0
- data/spec/models/solr_document_spec.rb +28 -0
- data/spec/models/system_stats_spec.rb +184 -0
- data/spec/models/user_spec.rb +1 -1
- data/spec/models/user_usage_stats_spec.rb +1 -1
- data/spec/services/generic_file_csv_service_spec.rb +66 -0
- data/spec/services/generic_file_indexing_service_spec.rb +35 -0
- data/spec/services/lock_manager_spec.rb +12 -0
- data/spec/spec_helper.rb +2 -1
- data/spec/views/admin/stats/index.html.erb_spec.rb +11 -10
- data/spec/views/catalog/sort_and_per_page.html.erb_spec.rb +1 -1
- data/spec/views/collections/_form_for_select_collection.html.erb_spec.rb +51 -0
- data/spec/views/generic_file/_browse_everything.html.erb_spec.rb +4 -0
- data/spec/views/generic_file/edit.html.erb_spec.rb +31 -24
- data/spec/views/generic_file/new.html.erb_spec.rb +70 -0
- data/spec/views/generic_file/show.html.erb_spec.rb +23 -0
- data/sufia.gemspec +3 -2
- data/tasks/sufia-dev.rake +2 -0
- metadata +42 -9
- data/lib/sufia/role_mapper.rb +0 -7
@@ -20,11 +20,11 @@ class CatalogController < ApplicationController
|
|
20
20
|
skip_before_filter :default_html_head
|
21
21
|
|
22
22
|
def self.uploaded_field
|
23
|
-
solr_name('
|
23
|
+
solr_name('system_create', :stored_sortable, type: :date)
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.modified_field
|
27
|
-
solr_name('
|
27
|
+
solr_name('system_modified', :stored_sortable, type: :date)
|
28
28
|
end
|
29
29
|
|
30
30
|
configure_blacklight do |config|
|
data/lib/sufia/version.rb
CHANGED
@@ -69,6 +69,41 @@ describe Sufia::GenericFile::Actor do
|
|
69
69
|
expect(VersionCommitter.where(version_id: versions.last.uri).pluck(:committer_login)).to eq [second_user.user_key]
|
70
70
|
end
|
71
71
|
end
|
72
|
+
|
73
|
+
context "with collection" do
|
74
|
+
let(:file) { "world.png" }
|
75
|
+
let(:actor) { described_class.new(generic_file, user) }
|
76
|
+
let(:col_editable) do
|
77
|
+
Collection.new(title: 'editable', description: 'user can edit this collection') do |c|
|
78
|
+
c.apply_depositor_metadata(user)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
let(:col_editable_id) { col_editable.id }
|
82
|
+
let(:col_not_editable) { Collection.new(title: 'not editable', description: 'user cannot edit this collection') }
|
83
|
+
let(:col_not_editable_id) { col_not_editable.id }
|
84
|
+
before do
|
85
|
+
allow(generic_file).to receive(:label).and_return(file)
|
86
|
+
allow(col_editable).to receive(:id).and_return('ce')
|
87
|
+
allow(Collection).to receive(:find).with(col_editable_id).and_return(col_editable)
|
88
|
+
allow(user).to receive(:can?).with(:edit, col_editable).and_return(true)
|
89
|
+
allow(col_not_editable).to receive(:id).and_return('cne')
|
90
|
+
allow(Collection).to receive(:find).with(col_not_editable_id).and_return(col_not_editable)
|
91
|
+
allow(user).to receive(:can?).with(:edit, col_not_editable).and_return(false)
|
92
|
+
allow(Sufia.queue).to receive(:push)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "adds file to collection when user can edit the collection" do
|
96
|
+
actor.create_content(fixture_file_upload(file), file, 'content', 'image/png', col_editable_id)
|
97
|
+
updated_collection = Collection.find(col_editable_id)
|
98
|
+
expect(updated_collection.member_ids).to eq [generic_file.id]
|
99
|
+
end
|
100
|
+
|
101
|
+
it "does not add file to collection when user can NOT edit the collection" do
|
102
|
+
actor.create_content(fixture_file_upload(file), file, 'content', 'image/png', col_not_editable_id)
|
103
|
+
updated_collection = Collection.find(col_not_editable_id)
|
104
|
+
expect(updated_collection.member_ids).to eq []
|
105
|
+
end
|
106
|
+
end
|
72
107
|
end
|
73
108
|
|
74
109
|
describe "#virus_check" do
|
@@ -14,6 +14,10 @@ describe Admin::StatsController, type: :controller do
|
|
14
14
|
before do
|
15
15
|
sign_in user1
|
16
16
|
end
|
17
|
+
it "counts the users" do
|
18
|
+
get :index
|
19
|
+
expect(assigns[:presenter].users_count).to eq 2
|
20
|
+
end
|
17
21
|
|
18
22
|
it 'allows an authorized user to view the page' do
|
19
23
|
get :index
|
@@ -22,26 +26,26 @@ describe Admin::StatsController, type: :controller do
|
|
22
26
|
expect(response.body).to include('Total Blacklight Users')
|
23
27
|
end
|
24
28
|
|
25
|
-
describe "querying
|
26
|
-
let(:one_day_ago_date) { 1.
|
29
|
+
describe "querying stats_filters" do
|
30
|
+
let(:one_day_ago_date) { 1.day.ago.to_datetime }
|
27
31
|
let(:two_days_ago_date) { 2.days.ago.to_datetime.end_of_day }
|
28
32
|
let(:one_day_ago) { one_day_ago_date.strftime("%Y-%m-%d") }
|
29
33
|
let(:two_days_ago) { two_days_ago_date.strftime("%Y-%m-%d") }
|
30
34
|
|
31
35
|
it "defaults to latest 5 users" do
|
32
36
|
get :index
|
33
|
-
expect(assigns[:recent_users
|
37
|
+
expect(assigns[:presenter].recent_users).to eq(User.order('created_at DESC').limit(5))
|
34
38
|
end
|
35
|
-
it "allows queries against
|
39
|
+
it "allows queries against stats_filters without an end date " do
|
36
40
|
expect(User).to receive(:where).with('id' => user1.id).once.and_return([user1])
|
37
41
|
expect(User).to receive(:recent_users).with(one_day_ago_date, nil).and_return([user2])
|
38
|
-
get :index,
|
39
|
-
expect(assigns[:recent_users
|
42
|
+
get :index, stats_filters: { start_date: one_day_ago }
|
43
|
+
expect(assigns[:presenter].recent_users).to eq([user2])
|
40
44
|
end
|
41
|
-
it "allows queries against
|
45
|
+
it "allows queries against stats_filters with an end date" do
|
42
46
|
expect(User).to receive(:recent_users).with(two_days_ago_date, one_day_ago_date).and_return([user2])
|
43
|
-
get :index,
|
44
|
-
expect(assigns[:recent_users
|
47
|
+
get :index, stats_filters: { start_date: two_days_ago, end_date: one_day_ago }
|
48
|
+
expect(assigns[:presenter].recent_users).to eq([user2])
|
45
49
|
end
|
46
50
|
end
|
47
51
|
|
@@ -56,7 +60,7 @@ describe Admin::StatsController, type: :controller do
|
|
56
60
|
end
|
57
61
|
it "provides accurate files_count, ensuring that solr deletes have been expunged first" do
|
58
62
|
get :index
|
59
|
-
expect(assigns[:files_count
|
63
|
+
expect(assigns[:presenter].files_count[:total]).to eq(original_files_count - 1)
|
60
64
|
end
|
61
65
|
end
|
62
66
|
|
@@ -72,28 +76,28 @@ describe Admin::StatsController, type: :controller do
|
|
72
76
|
end
|
73
77
|
it "includes files but not collections" do
|
74
78
|
get :index
|
75
|
-
expect(assigns[:files_count
|
76
|
-
expect(assigns[:files_count
|
77
|
-
expect(assigns[:files_count
|
78
|
-
expect(assigns[:files_count
|
79
|
+
expect(assigns[:presenter].files_count[:total]).to eq(3)
|
80
|
+
expect(assigns[:presenter].files_count[:public]).to eq(1)
|
81
|
+
expect(assigns[:presenter].files_count[:registered]).to eq(1)
|
82
|
+
expect(assigns[:presenter].files_count[:private]).to eq(1)
|
79
83
|
end
|
80
84
|
end
|
81
85
|
|
82
86
|
context "when start date set" do
|
83
87
|
it "queries by start date" do
|
84
|
-
expect(GenericFile).to receive(:find_by_date_created).exactly(3).times.with(1.
|
88
|
+
expect(GenericFile).to receive(:find_by_date_created).exactly(3).times.with(1.day.ago.to_datetime, nil).and_call_original
|
85
89
|
expect(GenericFile).to receive(:where_public).and_call_original
|
86
90
|
expect(GenericFile).to receive(:where_registered).and_call_original
|
87
|
-
get :index,
|
91
|
+
get :index, stats_filters: { start_date: 1.day.ago.strftime("%Y-%m-%d") }
|
88
92
|
end
|
89
93
|
end
|
90
94
|
|
91
95
|
context "when date range set" do
|
92
96
|
it "queries by start and date" do
|
93
|
-
expect(GenericFile).to receive(:find_by_date_created).exactly(3).times.with(1.
|
97
|
+
expect(GenericFile).to receive(:find_by_date_created).exactly(3).times.with(1.day.ago.to_datetime, 0.days.ago.to_datetime.end_of_day).and_call_original
|
94
98
|
expect(GenericFile).to receive(:where_public).and_call_original
|
95
99
|
expect(GenericFile).to receive(:where_registered).and_call_original
|
96
|
-
get :index,
|
100
|
+
get :index, stats_filters: { start_date: 1.day.ago.strftime("%Y-%m-%d"), end_date: 0.days.ago.strftime("%Y-%m-%d") }
|
97
101
|
end
|
98
102
|
end
|
99
103
|
end
|
@@ -121,12 +125,13 @@ describe Admin::StatsController, type: :controller do
|
|
121
125
|
|
122
126
|
it "gathers user deposits" do
|
123
127
|
get :index
|
124
|
-
expect(assigns[:depositors
|
128
|
+
expect(assigns[:presenter].depositors).to include({ key: user1.user_key, deposits: 2, user: user1 }, key: user2.user_key, deposits: 1, user: user2)
|
129
|
+
expect(assigns[:presenter].active_users).to eq("example.com" => 4, user1.user_key.split('@')[0] => 3, user2.user_key.split('@')[0] => 1)
|
125
130
|
end
|
126
131
|
|
127
132
|
it "gathers user deposits during a date range" do
|
128
|
-
get :index,
|
129
|
-
expect(assigns[:depositors
|
133
|
+
get :index, stats_filters: { start_date: 1.day.ago.strftime("%Y-%m-%d"), end_date: 0.days.ago.strftime("%Y-%m-%d") }
|
134
|
+
expect(assigns[:presenter].depositors).to include({ key: user1.user_key, deposits: 1, user: user1 }, key: user2.user_key, deposits: 1, user: user2)
|
130
135
|
end
|
131
136
|
|
132
137
|
context "more than 10 users" do
|
@@ -144,10 +149,35 @@ describe Admin::StatsController, type: :controller do
|
|
144
149
|
|
145
150
|
it "gathers user deposits" do
|
146
151
|
get :index
|
147
|
-
expect(assigns[:depositors
|
148
|
-
users.each { |user| expect(assigns[:depositors
|
152
|
+
expect(assigns[:presenter].depositors).to include({ key: user1.user_key, deposits: 2, user: user1 }, key: user2.user_key, deposits: 1, user: user2)
|
153
|
+
users.each { |user| expect(assigns[:presenter].depositors).to include(key: user.user_key, deposits: 1, user: user) }
|
149
154
|
end
|
150
155
|
end
|
151
156
|
end
|
157
|
+
describe "top formats" do
|
158
|
+
before do
|
159
|
+
GenericFile.new(id: "abc123") do |gf|
|
160
|
+
gf.apply_depositor_metadata(user1)
|
161
|
+
gf.mime_type = 'image/png'
|
162
|
+
gf.update_index
|
163
|
+
end
|
164
|
+
GenericFile.new(id: "def123") do |gf|
|
165
|
+
gf.apply_depositor_metadata(user2)
|
166
|
+
gf.mime_type = 'image/png'
|
167
|
+
gf.update_index
|
168
|
+
end
|
169
|
+
GenericFile.new(id: "zzz123") do |gf|
|
170
|
+
gf.create_date = [2.days.ago]
|
171
|
+
gf.apply_depositor_metadata(user1)
|
172
|
+
gf.mime_type = 'image/jpeg'
|
173
|
+
gf.update_index
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
it "gathers formats" do
|
178
|
+
get :index
|
179
|
+
expect(assigns[:presenter].top_formats).to eq("png" => 2, "jpeg" => 1)
|
180
|
+
end
|
181
|
+
end
|
152
182
|
end
|
153
183
|
end
|
@@ -7,19 +7,25 @@ describe API::ItemsController, type: :controller do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
let(:user) { FactoryGirl.find_or_create(:jill) }
|
10
|
+
let!(:default_file) do
|
11
|
+
GenericFile.create(title: ['Foo Bar']) do |gf|
|
12
|
+
gf.apply_depositor_metadata(user)
|
13
|
+
gf.arkivo_checksum = '6872d21557992f6ad1d07375f19fbfaf'
|
14
|
+
end
|
15
|
+
end
|
10
16
|
|
11
17
|
context 'with an HTTP GET or HEAD' do
|
12
18
|
before do
|
13
|
-
post :create, format: :json
|
19
|
+
post :create, item, format: :json
|
14
20
|
end
|
15
21
|
|
16
|
-
let(:deposited_file) { GenericFile.where(label: item['file']['filename']).take }
|
17
22
|
let(:token) { user.arkivo_token }
|
18
23
|
let(:item) { FactoryGirl.json(:post_item, token: token) }
|
24
|
+
let(:item_hash) { JSON.parse(item) }
|
19
25
|
|
20
26
|
context 'with a missing token' do
|
21
27
|
before do
|
22
|
-
get :show, format: :json, id:
|
28
|
+
get :show, format: :json, id: default_file.id
|
23
29
|
end
|
24
30
|
|
25
31
|
subject { response }
|
@@ -33,7 +39,7 @@ describe API::ItemsController, type: :controller do
|
|
33
39
|
|
34
40
|
context 'with an unfamiliar token' do
|
35
41
|
before do
|
36
|
-
get :show, format: :json, id:
|
42
|
+
get :show, format: :json, id: default_file.id, token: get_token
|
37
43
|
end
|
38
44
|
|
39
45
|
let(:get_token) { 'foobar' }
|
@@ -49,8 +55,8 @@ describe API::ItemsController, type: :controller do
|
|
49
55
|
|
50
56
|
context 'with an unauthorized resource' do
|
51
57
|
before do
|
52
|
-
allow_any_instance_of(User).to receive(:can?).with(:edit,
|
53
|
-
get :show, format: :json, id:
|
58
|
+
allow_any_instance_of(User).to receive(:can?).with(:edit, default_file) { false }
|
59
|
+
get :show, format: :json, id: default_file.id, token: token
|
54
60
|
end
|
55
61
|
|
56
62
|
subject { response }
|
@@ -58,18 +64,18 @@ describe API::ItemsController, type: :controller do
|
|
58
64
|
it { is_expected.to have_http_status(401) }
|
59
65
|
|
60
66
|
it 'loads the file' do
|
61
|
-
expect(assigns[:file]).to eq
|
67
|
+
expect(assigns[:file]).to eq default_file
|
62
68
|
end
|
63
69
|
|
64
70
|
it 'provides a reason for refusing to act' do
|
65
|
-
expect(subject.body).to include("#{user} lacks access to #{
|
71
|
+
expect(subject.body).to include("#{user} lacks access to #{default_file}")
|
66
72
|
end
|
67
73
|
end
|
68
74
|
|
69
75
|
context 'with a resource not deposited via Arkivo' do
|
70
76
|
before do
|
71
77
|
allow_any_instance_of(GenericFile).to receive(:arkivo_checksum) { nil }
|
72
|
-
get :show, format: :json, id:
|
78
|
+
get :show, format: :json, id: default_file.id, token: token
|
73
79
|
end
|
74
80
|
|
75
81
|
subject { response }
|
@@ -77,14 +83,14 @@ describe API::ItemsController, type: :controller do
|
|
77
83
|
it { is_expected.to have_http_status(403) }
|
78
84
|
|
79
85
|
it 'provides a reason for refusing to act' do
|
80
|
-
expect(subject.body).to include("Forbidden: #{
|
86
|
+
expect(subject.body).to include("Forbidden: #{default_file} not deposited via Arkivo")
|
81
87
|
end
|
82
88
|
end
|
83
89
|
|
84
90
|
context 'with a resource not found in the repository' do
|
85
91
|
before do
|
86
|
-
allow(GenericFile).to receive(:find).with(
|
87
|
-
get :show, format: :json, id:
|
92
|
+
allow(GenericFile).to receive(:find).with(default_file.id).and_raise(ActiveFedora::ObjectNotFoundError)
|
93
|
+
get :show, format: :json, id: default_file.id, token: token
|
88
94
|
end
|
89
95
|
|
90
96
|
subject { response }
|
@@ -92,13 +98,13 @@ describe API::ItemsController, type: :controller do
|
|
92
98
|
it { is_expected.to have_http_status(404) }
|
93
99
|
|
94
100
|
it 'provides a reason for refusing to act' do
|
95
|
-
expect(subject.body).to include("id '#{
|
101
|
+
expect(subject.body).to include("id '#{default_file.id}' not found")
|
96
102
|
end
|
97
103
|
end
|
98
104
|
|
99
105
|
context 'with an authorized Arkivo-deposited resource' do
|
100
106
|
before do
|
101
|
-
get :show, format: :json, id:
|
107
|
+
get :show, format: :json, id: default_file.id, token: token
|
102
108
|
end
|
103
109
|
|
104
110
|
subject { response }
|
@@ -128,7 +134,7 @@ describe API::ItemsController, type: :controller do
|
|
128
134
|
|
129
135
|
context 'with an invalid item' do
|
130
136
|
before do
|
131
|
-
post :create, format: :json
|
137
|
+
post :create, item, format: :json
|
132
138
|
end
|
133
139
|
|
134
140
|
let(:item) { { foo: 'bar' }.to_json }
|
@@ -144,10 +150,10 @@ describe API::ItemsController, type: :controller do
|
|
144
150
|
|
145
151
|
context 'with a valid item and matching token' do
|
146
152
|
before do
|
147
|
-
expect { post :create, format: :json
|
153
|
+
expect { post :create, item, format: :json }.to change { GenericFile.count }.by(1)
|
148
154
|
end
|
149
155
|
|
150
|
-
let(:deposited_file) { GenericFile.where(label:
|
156
|
+
let!(:deposited_file) { GenericFile.where(label: item_hash['file']['filename']).take }
|
151
157
|
let(:token) { user.arkivo_token }
|
152
158
|
let(:item) { FactoryGirl.json(:post_item, token: token) }
|
153
159
|
let(:item_hash) { JSON.parse(item) }
|
@@ -195,7 +201,7 @@ describe API::ItemsController, type: :controller do
|
|
195
201
|
|
196
202
|
context 'with a valid item and unfamiliar token' do
|
197
203
|
before do
|
198
|
-
post :create, format: :json
|
204
|
+
post :create, item, format: :json
|
199
205
|
end
|
200
206
|
|
201
207
|
let(:token) { 'unfamiliar_token' }
|
@@ -216,21 +222,21 @@ describe API::ItemsController, type: :controller do
|
|
216
222
|
end
|
217
223
|
|
218
224
|
context 'with an HTTP PUT' do
|
219
|
-
let(:post_deposited_file) { GenericFile.where(label:
|
225
|
+
let(:post_deposited_file) { GenericFile.where(label: post_item_hash['file']['filename']).take }
|
220
226
|
let(:post_token) { user.arkivo_token }
|
221
227
|
let(:post_item) { FactoryGirl.json(:post_item, token: post_token) }
|
222
228
|
let(:post_item_hash) { JSON.parse(post_item) }
|
223
229
|
|
224
230
|
before do
|
225
|
-
expect { post :create, format: :json
|
231
|
+
expect { post :create, post_item, format: :json }.to change { GenericFile.count }.by(1)
|
226
232
|
end
|
227
233
|
|
228
234
|
context 'with a valid item, matching token, and authorized resource' do
|
229
235
|
before do
|
230
|
-
put :update, id: post_deposited_file.id, format: :json
|
236
|
+
put :update, put_item, id: post_deposited_file.id, format: :json
|
231
237
|
end
|
232
238
|
|
233
|
-
let(:put_deposited_file) {
|
239
|
+
let(:put_deposited_file) { post_deposited_file.reload }
|
234
240
|
let(:put_token) { user.arkivo_token }
|
235
241
|
let(:put_item) { FactoryGirl.json(:put_item, token: put_token) }
|
236
242
|
let(:put_item_hash) { JSON.parse(put_item) }
|
@@ -272,7 +278,7 @@ describe API::ItemsController, type: :controller do
|
|
272
278
|
context 'with a valid item, matching token, authorized resource, but not Arkivo-deposited' do
|
273
279
|
before do
|
274
280
|
allow_any_instance_of(GenericFile).to receive(:arkivo_checksum) { nil }
|
275
|
-
put :update, id: post_deposited_file.id, format: :json
|
281
|
+
put :update, item, id: post_deposited_file.id, format: :json
|
276
282
|
end
|
277
283
|
|
278
284
|
let(:item) { FactoryGirl.json(:put_item, token: post_token) }
|
@@ -295,7 +301,7 @@ describe API::ItemsController, type: :controller do
|
|
295
301
|
allow(GenericFile).to receive(:find).with(post_deposited_file.id) do
|
296
302
|
raise(ActiveFedora::ObjectNotFoundError)
|
297
303
|
end
|
298
|
-
put :update, id: post_deposited_file.id, format: :json
|
304
|
+
put :update, item, id: post_deposited_file.id, format: :json
|
299
305
|
end
|
300
306
|
|
301
307
|
subject { response }
|
@@ -311,7 +317,7 @@ describe API::ItemsController, type: :controller do
|
|
311
317
|
context 'with a valid item, matching token, and unauthorized resource' do
|
312
318
|
before do
|
313
319
|
allow_any_instance_of(User).to receive(:can?).with(:edit, post_deposited_file) { false }
|
314
|
-
put :update, id: post_deposited_file.id, format: :json
|
320
|
+
put :update, item, id: post_deposited_file.id, format: :json
|
315
321
|
end
|
316
322
|
|
317
323
|
let(:item) { FactoryGirl.json(:put_item, token: post_token) }
|
@@ -335,7 +341,7 @@ describe API::ItemsController, type: :controller do
|
|
335
341
|
|
336
342
|
context 'with a valid item and unfamiliar token' do
|
337
343
|
before do
|
338
|
-
put :update, id: post_deposited_file.id, format: :json
|
344
|
+
put :update, item, id: post_deposited_file.id, format: :json
|
339
345
|
end
|
340
346
|
|
341
347
|
let(:token) { 'unfamiliar_token' }
|
@@ -356,7 +362,7 @@ describe API::ItemsController, type: :controller do
|
|
356
362
|
|
357
363
|
context 'with an invalid item' do
|
358
364
|
before do
|
359
|
-
put :update, id: post_deposited_file.id, format: :json
|
365
|
+
put :update, item, id: post_deposited_file.id, format: :json
|
360
366
|
end
|
361
367
|
|
362
368
|
let(:item) { { foo: 'bar' }.to_json }
|
@@ -373,16 +379,16 @@ describe API::ItemsController, type: :controller do
|
|
373
379
|
|
374
380
|
context 'with an HTTP DELETE' do
|
375
381
|
before do
|
376
|
-
post :create, format: :json
|
382
|
+
post :create, item, format: :json
|
377
383
|
end
|
378
384
|
|
379
|
-
let(:deposited_file) { GenericFile.where(label: item['file']['filename']).take }
|
380
385
|
let(:token) { user.arkivo_token }
|
381
386
|
let(:item) { FactoryGirl.json(:post_item, token: token) }
|
387
|
+
let(:item_hash) { JSON.parse(item) }
|
382
388
|
|
383
389
|
context 'with a missing token' do
|
384
390
|
before do
|
385
|
-
delete :destroy, format: :json, id:
|
391
|
+
delete :destroy, format: :json, id: default_file.id
|
386
392
|
end
|
387
393
|
|
388
394
|
subject { response }
|
@@ -396,7 +402,7 @@ describe API::ItemsController, type: :controller do
|
|
396
402
|
|
397
403
|
context 'with an unfamiliar token' do
|
398
404
|
before do
|
399
|
-
delete :destroy, format: :json, id:
|
405
|
+
delete :destroy, format: :json, id: default_file.id, token: delete_token
|
400
406
|
end
|
401
407
|
|
402
408
|
let(:delete_token) { 'foobar' }
|
@@ -412,8 +418,8 @@ describe API::ItemsController, type: :controller do
|
|
412
418
|
|
413
419
|
context 'with an unauthorized resource' do
|
414
420
|
before do
|
415
|
-
allow_any_instance_of(User).to receive(:can?).with(:edit,
|
416
|
-
delete :destroy, format: :json, id:
|
421
|
+
allow_any_instance_of(User).to receive(:can?).with(:edit, default_file) { false }
|
422
|
+
delete :destroy, format: :json, id: default_file.id, token: token
|
417
423
|
end
|
418
424
|
|
419
425
|
subject { response }
|
@@ -421,18 +427,18 @@ describe API::ItemsController, type: :controller do
|
|
421
427
|
it { is_expected.to have_http_status(401) }
|
422
428
|
|
423
429
|
it 'loads the file' do
|
424
|
-
expect(assigns[:file]).to eq
|
430
|
+
expect(assigns[:file]).to eq default_file
|
425
431
|
end
|
426
432
|
|
427
433
|
it 'provides a reason for refusing to act' do
|
428
|
-
expect(subject.body).to include("#{user} lacks access to #{
|
434
|
+
expect(subject.body).to include("#{user} lacks access to #{default_file}")
|
429
435
|
end
|
430
436
|
end
|
431
437
|
|
432
438
|
context 'with a resource not deposited via Arkivo' do
|
433
439
|
before do
|
434
440
|
allow_any_instance_of(GenericFile).to receive(:arkivo_checksum) { nil }
|
435
|
-
delete :destroy, format: :json, id:
|
441
|
+
delete :destroy, format: :json, id: default_file.id, token: token
|
436
442
|
end
|
437
443
|
|
438
444
|
subject { response }
|
@@ -440,14 +446,14 @@ describe API::ItemsController, type: :controller do
|
|
440
446
|
it { is_expected.to have_http_status(403) }
|
441
447
|
|
442
448
|
it 'provides a reason for refusing to act' do
|
443
|
-
expect(subject.body).to include("Forbidden: #{
|
449
|
+
expect(subject.body).to include("Forbidden: #{default_file} not deposited via Arkivo")
|
444
450
|
end
|
445
451
|
end
|
446
452
|
|
447
453
|
context 'with a resource not found in the repository' do
|
448
454
|
before do
|
449
|
-
allow(GenericFile).to receive(:find).with(
|
450
|
-
delete :destroy, format: :json, id:
|
455
|
+
allow(GenericFile).to receive(:find).with(default_file.id).and_raise(ActiveFedora::ObjectNotFoundError)
|
456
|
+
delete :destroy, format: :json, id: default_file.id, token: token
|
451
457
|
end
|
452
458
|
|
453
459
|
subject { response }
|
@@ -455,13 +461,13 @@ describe API::ItemsController, type: :controller do
|
|
455
461
|
it { is_expected.to have_http_status(404) }
|
456
462
|
|
457
463
|
it 'provides a reason for refusing to act' do
|
458
|
-
expect(subject.body).to include("id '#{
|
464
|
+
expect(subject.body).to include("id '#{default_file.id}' not found")
|
459
465
|
end
|
460
466
|
end
|
461
467
|
|
462
468
|
context 'with an authorized Arkivo-deposited resource' do
|
463
469
|
before do
|
464
|
-
expect { delete :destroy, format: :json, id:
|
470
|
+
expect { delete :destroy, format: :json, id: default_file.id, token: token }.to change { GenericFile.count }.by(-1)
|
465
471
|
end
|
466
472
|
|
467
473
|
subject { response }
|