-
Notifications
You must be signed in to change notification settings - Fork 51
/
media_objects_controller_spec.rb
664 lines (599 loc) · 27.6 KB
/
media_objects_controller_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
# Copyright 2011-2015, The Trustees of Indiana University and Northwestern
# University. Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
# --- END LICENSE_HEADER BLOCK ---
require 'spec_helper'
describe MediaObjectsController, type: :controller do
render_views
before(:each) do
request.env["HTTP_REFERER"] = '/'
end
context "JSON API methods" do
let!(:collection) { FactoryGirl.create(:collection) }
let!(:testdir) {'spec/fixtures/'}
let!(:filename) {'videoshort.high.mp4'}
let!(:absolute_location) {File.join(testdir, filename)}
let!(:structure) {File.read(File.join(testdir, 'structure.xml'))}
let!(:bib_id) { '7763100' }
let!(:sru_url) { "http://zgate.example.edu:9000/db?version=1.1&operation=searchRetrieve&maximumRecords=1&recordSchema=marcxml&query=rec.id=#{bib_id}" }
let!(:sru_response) { File.read(File.expand_path("../../fixtures/#{bib_id}.xml",__FILE__)) }
let!(:masterfile) {{
file_location: absolute_location,
label: "Part 1",
file_checksum: "7ae24368ccb7a6c6422a14ff73f33c9a",
file_size: "199160",
duration: "6315",
display_aspect_ratio: "1.7777777777777777",
original_frame_size: "200x110",
file_format: "Moving image",
poster_offset: "0:02",
thumbnail_offset: "0:02",
workflow_name: "avalon",
percent_complete: "100.0",
percent_succeeded: "100.0",
percent_failed: "0",
status_code: "COMPLETED",
structure: structure
}}
let!(:descMetadata_fields) {[
:title,
:alternative_title,
:translated_title,
:uniform_title,
:statement_of_responsibility,
:creator,
:date_created,
:date_issued,
:copyright_date,
:abstract,
:note,
:format,
:resource_type,
:contributor,
:publisher,
:genre,
:subject,
:related_item_url,
:geographic_subject,
:temporal_subject,
:topical_subject,
:bibliographic_id,
:language,
:terms_of_use,
:table_of_contents,
:physical_description,
:other_identifier
]}
describe "#create" do
it "should return 403 if bad token passed" do
post 'create', format: 'json', collection_id: collection.pid, api_key:'badtoken'
expect(response.status).to eq(403)
end
it "should respond with 422 if collection not found" do
post 'create', collection_id: "avalon:doesnt_exist", api_key:'secret_token'
expect(response.status).to eq(422)
expect(JSON.parse(response.body)).to include('errors')
expect(JSON.parse(response.body)["errors"].class).to eq Array
expect(JSON.parse(response.body)["errors"].first.class).to eq String
end
it "should create a new mediaobject" do
media_object = FactoryGirl.create(:multiple_entries)
fields = media_object.attributes.select {|k,v| descMetadata_fields.include? k.to_sym }
post 'create', fields: fields, files: [masterfile], collection_id: collection.pid, api_key:'secret_token'
expect(response.status).to eq(200)
new_media_object = MediaObject.find(JSON.parse(response.body)['id'])
expect(new_media_object.title).to eq media_object.title
expect(new_media_object.creator).to eq media_object.creator
expect(new_media_object.date_issued).to eq media_object.date_issued
expect(new_media_object.parts_with_order).to eq new_media_object.parts
end
it "should create a new mediaobject with successful bib import" do
Avalon::Configuration['bib_retriever'] = { 'protocol' => 'sru', 'url' => 'http://zgate.example.edu:9000/db' }
FakeWeb.register_uri :get, sru_url, body: sru_response
fields = { bibliographic_id: bib_id }
post 'create', import_bib_record: true, fields: fields, files: [masterfile], collection_id: collection.pid, api_key:'secret_token'
expect(response.status).to eq(200)
new_media_object = MediaObject.find(JSON.parse(response.body)['id'])
expect(new_media_object.bibliographic_id).to eq(['local', bib_id])
expect(new_media_object.title).to eq('245 A : B F G K N P S')
end
end
describe "#update" do
let!(:media_object) { FactoryGirl.create(:media_object_with_master_file) }
it "should route json format to #json_update" do
assert_routing({ path: 'media_objects/avalon:1.json', method: :put },
{ controller: 'media_objects', action: 'json_update', id: 'avalon:1', format: 'json' })
end
it "should route unspecified format to #update" do
assert_routing({ path: 'media_objects/avalon:1', method: :put },
{ controller: 'media_objects', action: 'update', id: 'avalon:1', format: 'html' })
end
it "should return 403 if bad token passed" do
put 'json_update', format: 'json', id: media_object.pid, fields: {title: media_object.title}, collection_id: media_object.collection_id, api_key:'badtoken'
expect(response.status).to eq(403)
end
it "should update a mediaobject's metadata" do
old_title = media_object.title
put 'json_update', format: 'json', id: media_object.pid, fields: {title: old_title+'new'}, collection_id: media_object.collection_id, api_key:'secret_token'
expect(JSON.parse(response.body)['id'].class).to eq String
expect(JSON.parse(response.body)).not_to include('errors')
media_object.reload
expect(media_object.title).to eq old_title+'new'
end
it "should add a masterfile to a mediaobject" do
put 'json_update', format: 'json', id: media_object.pid, files: [masterfile], collection_id: media_object.collection_id, api_key:'secret_token'
expect(JSON.parse(response.body)['id'].class).to eq String
expect(JSON.parse(response.body)).not_to include('errors')
media_object.reload
expect(media_object.parts.count).to eq 2
end
it "should return 404 if media object doesn't exist" do
allow_any_instance_of(MediaObject).to receive(:save).and_return false
put 'json_update', format: 'json', id: 'avalon:doesnt_exist', fields: {}, collection_id: media_object.collection_id, api_key:'secret_token'
expect(response.status).to eq(404)
end
it "should return 422 if media object update failed" do
allow_any_instance_of(MediaObject).to receive(:save).and_return false
put 'json_update', format: 'json', id: media_object.pid, fields: {}, collection_id: media_object.collection_id, api_key:'secret_token'
expect(response.status).to eq(422)
expect(JSON.parse(response.body)).to include('errors')
expect(JSON.parse(response.body)["errors"].class).to eq Array
expect(JSON.parse(response.body)["errors"].first.class).to eq String
end
end
end
describe "#new" do
let!(:collection) { FactoryGirl.create(:collection) }
it "should redirect to sign in page with a notice when unauthenticated" do
expect { get 'new', collection_id: collection.pid }.not_to change { MediaObject.count }
expect(flash[:notice]).not_to be_nil
expect(response).to redirect_to(new_user_session_path)
end
it "should redirect to home page with a notice when authenticated but unauthorized" do
login_as :user
expect { get 'new', collection_id: collection.pid }.not_to change { MediaObject.count }
expect(flash[:notice]).not_to be_nil
expect(response).to redirect_to(root_path)
end
it "should not let manager of other collections create an item in this collection" do
skip
end
context "Default permissions should be applied" do
it "should be editable by the creator" do
login_user collection.managers.first
expect { get 'new', collection_id: collection.pid }.to change { MediaObject.count }
pid = MediaObject.all.last.pid
expect(response).to redirect_to(edit_media_object_path(id: pid))
end
it "should copy default permissions from its owning collection" do
login_user collection.depositors.first
get 'new', collection_id: collection.pid
#MediaObject.all.last.edit_users.should include(collection.managers)
#MediaObject.all.last.edit_users.should include(collection.depositors)
end
end
end
describe "#edit" do
let!(:media_object) { FactoryGirl.create(:media_object) }
it "should redirect to sign in page with a notice when unauthenticated" do
get 'edit', id: media_object.pid
expect(flash[:notice]).not_to be_nil
expect(response).to redirect_to(new_user_session_path)
end
it "should redirect to show page with a notice when authenticated but unauthorized" do
login_as :user
get 'edit', id: media_object.pid
expect(flash[:notice]).not_to be_nil
expect(response).to redirect_to(media_object_path(media_object.pid) )
end
it "should redirect to first workflow step if authorized to edit" do
login_user media_object.collection.managers.first
get 'edit', id: media_object.pid
expect(response).to be_success
expect(response).to render_template "_#{HYDRANT_STEPS.first.template}"
end
it "should not default to the Access Control page" do
skip "[VOV-1165] Wait for product owner feedback on which step to default to"
end
context "Updating the metadata should result in valid input" do
it "should ignore the PID if provided as a parameter"
it "should ignore invalid attributes"
it "should be able to retrieve an existing record from Fedora" do
media_object.workflow.last_completed_step = 'resource-description'
media_object.save
# Set the task so that it can get to the resource-description step
login_user media_object.collection.managers.first
get :edit, {id: media_object.pid, step: 'resource-description'}
expect(response.response_code).to eq(200)
end
end
context "Persisting Permalinks" do
before(:each) { login_user mo.collection.managers.first }
context "Persisting Permalinks on unpublished mediaobject" do
subject(:mo) { media_object }
it "should persist new permalink on unpublished media_object" do
expect { put 'update', id: mo.pid, step: 'resource-description',
media_object: { permalink: 'newpermalink', title: 'newtitle',
creator: 'newcreator', date_issued: 'newdateissued' }}
.to change { MediaObject.find(mo.pid).permalink }
.to('newpermalink')
end
it "should persist new permalink on unpublished media_object part" do
part1 = FactoryGirl.create(:master_file, mediaobject: mo)
expect {put 'update', id: mo.pid, step: 'file-upload',
parts: { part1.pid => { permalink: 'newpermalinkpart' }}}
.to change { MasterFile.find(part1.pid).permalink }
.to('newpermalinkpart')
end
end
context "Persisting Permalinks on published mediaobject" do
subject(:mo) { FactoryGirl.create(:published_media_object, permalink: 'oldpermalink') }
it "should persist updated permalink on published media_object" do
expect { put 'update', id: mo.pid, step: 'resource-description',
media_object: { permalink: 'newpermalink', title: mo.title,
creator: mo.creator, date_issued: mo.date_issued }}
.to change { MediaObject.find(mo.pid).permalink }
.to('newpermalink')
end
it "should persist updated permalink on published media_object part" do
part1 = FactoryGirl.create(:master_file, permalink: 'oldpermalinkpart1', mediaobject: mo)
expect { put 'update', id: mo.pid, step: 'file-upload',
parts: { part1.pid => { permalink: 'newpermalinkpart' }}}
.to change { MasterFile.find(part1.pid).permalink }
.to('newpermalinkpart')
end
end
end
end
describe "#index" do
let!(:media_object) { FactoryGirl.create(:published_media_object, visibility: 'public') }
subject(:json) { JSON.parse(response.body) }
it "should return 403 if bad token passed" do
get 'index', format:'json', api_key:'badtoken'
expect(response.status).to eq(403)
end
it "should return list of media_objects" do
get 'index', format:'json', api_key:'secret_token'
expect(json.count).to eq(1)
expect(json.first['id']).to eq(media_object.pid)
expect(json.first['title']).to eq(media_object.title)
expect(json.first['collection']).to eq(media_object.collection.name)
expect(json.first['main_contributors']).to eq(media_object.creator)
expect(json.first['publication_date']).to eq(media_object.date_created)
expect(json.first['published_by']).to eq(media_object.avalon_publisher)
expect(json.first['published']).to eq(media_object.published?)
expect(json.first['summary']).to eq(media_object.abstract)
end
end
describe 'pagination' do
let(:collection) { FactoryGirl.create(:collection) }
subject(:json) { JSON.parse(response.body) }
before do
5.times { FactoryGirl.create(:published_media_object, visibility: 'public', collection: collection) }
login_as(:administrator)
get 'index', format:'json', per_page: '2', api_key:'secret_token'
end
it 'should paginate' do
expect(json.count).to eq(2)
expect(response.headers['Per-Page']).to eq('2')
expect(response.headers['Total']).to eq('5')
end
end
describe "#show" do
let!(:media_object) { FactoryGirl.create(:published_media_object, visibility: 'public') }
context "Known items should be retrievable" do
it "should be accesible by its PID" do
get :show, id: media_object.pid
expect(response.response_code).to eq(200)
end
it "should return an error if the PID does not exist" do
expect(MediaObject).to receive(:find).with('no-such-object') { raise ActiveFedora::ObjectNotFoundError }
get :show, id: 'no-such-object'
expect(response.response_code).to eq(404)
end
it "should be available to a manager when unpublished" do
login_user media_object.collection.managers.first
get 'show', id: media_object.pid
expect(response).not_to redirect_to new_user_session_path
end
it "should provide a JSON stream description to the client" do
master_file = FactoryGirl.create(:master_file)
master_file.mediaobject = media_object
master_file.save
mopid = media_object.pid
media_object = MediaObject.find(mopid)
media_object.parts.collect { |part|
get 'show', id: media_object.pid, format: 'js', content: part.pid
json_obj = JSON.parse(response.body)
expect(json_obj['is_video']).to eq(part.is_video?)
}
end
end
context "Conditional Share partials should be rendered" do
context "Normal login" do
it "administrators: should include lti, embed, and share" do
login_as(:administrator)
get :show, id: media_object.pid
expect(response).to render_template(:_share_resource)
expect(response).to render_template(:_embed_resource)
expect(response).to render_template(:_lti_url)
end
it "managers: should include lti, embed, and share" do
login_user media_object.collection.managers.first
get :show, id: media_object.pid
expect(response).to render_template(:_share_resource)
expect(response).to render_template(:_embed_resource)
expect(response).to render_template(:_lti_url)
end
it "editors: should include lti, embed, and share" do
login_user media_object.collection.editors.first
get :show, id: media_object.pid
expect(response).to render_template(:_share_resource)
expect(response).to render_template(:_embed_resource)
expect(response).to render_template(:_lti_url)
end
it "others: should include embed and share and NOT lti" do
login_as(:user)
get :show, id: media_object.pid
expect(response).to render_template(:_share_resource)
expect(response).to render_template(:_embed_resource)
expect(response).to_not render_template(:_lti_url)
end
end
context "LTI login" do
it "administrators/managers/editors: should include lti, embed, and share" do
user = login_lti 'administrator'
lti_group = @controller.user_session[:virtual_groups].first
mo = FactoryGirl.create(:published_media_object, visibility: 'private', read_groups: [lti_group])
get :show, id: media_object.pid
expect(response).to render_template(:_share_resource)
expect(response).to render_template(:_embed_resource)
expect(response).to render_template(:_lti_url)
end
it "others: should include only lti" do
user = login_lti 'student'
lti_group = @controller.user_session[:virtual_groups].first
mo = FactoryGirl.create(:published_media_object, visibility: 'private', read_groups: [lti_group])
get :show, id: media_object.pid
expect(response).to_not render_template(:_share_resource)
expect(response).to_not render_template(:_embed_resource)
expect(response).to render_template(:_lti_url)
end
end
context "No share tabs rendered" do
it "should not render Share button" do
allow(@controller).to receive(:evaluate_if_unless_configuration).and_return false
expect(response).to_not render_template(:_share)
end
end
context "No LTI configuration" do
around do |example|
providers = Avalon::Authentication::Providers
Avalon::Authentication::Providers = Avalon::Authentication::Providers.reject{|p| p[:provider] == :lti}
example.run
Avalon::Authentication::Providers = providers
end
it "should not include lti" do
login_as(:administrator)
get :show, id: media_object.pid
expect(response).to render_template(:_share_resource)
expect(response).to render_template(:_embed_resource)
expect(response).to_not render_template(:_lti_url)
end
end
end
context "correctly handle unfound streams/sections" do
subject(:mo){FactoryGirl.create(:media_object_with_master_file)}
before do
mo.save(validate: false)
login_user mo.collection.managers.first
end
it "redirects to first stream when currentStream is nil" do
expect(get 'show', id: mo.pid, content: 'foo').to redirect_to(media_object_path(id: mo.pid))
end
it "responds with 404 when non-existant section is requested" do
get 'show', id: mo.pid, part: 100
expect(response.code).to eq('404')
end
end
describe 'Redirect back to media object after sign in' do
let(:media_object){ FactoryGirl.create(:media_object, visibility: 'private') }
context 'Before sign in' do
it 'persists the current url on the session' do
get 'show', id: media_object.pid
expect(session[:previous_url]).to eql media_object_path(media_object)
end
end
context 'After sign in' do
before do
@user = FactoryGirl.create(:user)
@media_object = FactoryGirl.create(:media_object, visibility: 'private', read_users: [@user.username] )
end
it 'redirects to the previous url' do
end
it 'removes the previous url from the session' do
end
end
end
context "Items should not be available to unauthorized users" do
it "should redirect to sign in when not logged in and item is unpublished" do
media_object.publish!(nil)
expect(media_object).not_to be_published
get 'show', id: media_object.pid
expect(response).to redirect_to new_user_session_path
end
it "should redirect to home page when logged in and item is unpublished" do
media_object.publish!(nil)
expect(media_object).not_to be_published
login_as :user
get 'show', id: media_object.pid
expect(response).to redirect_to root_path
end
end
context "with json format" do
subject(:json) { JSON.parse(response.body) }
let!(:media_object) { FactoryGirl.create(:media_object) }
it "should return 403 if bad token passed" do
get 'show', id: media_object.pid, format:'json', api_key:'badtoken'
expect(response.status).to eq(403)
end
it "should return json for specific media_object" do
get 'show', id: media_object.pid, format:'json', api_key:'secret_token'
expect(json['id']).to eq(media_object.pid)
expect(json['title']).to eq(media_object.title)
expect(json['collection']).to eq(media_object.collection.name)
expect(json['main_contributors']).to eq(media_object.creator)
expect(json['publication_date']).to eq(media_object.date_created)
expect(json['published_by']).to eq(media_object.avalon_publisher)
expect(json['published']).to eq(media_object.published?)
expect(json['summary']).to eq(media_object.abstract)
end
it "should return 404 if requested media_object not present" do
login_as(:administrator)
get 'show', id: 'avalon:doesnt_exist', format: 'json', api_key:'secret_token'
expect(response.status).to eq(404)
expect(JSON.parse(response.body)["errors"].class).to eq Array
expect(JSON.parse(response.body)["errors"].first.class).to eq String
end
end
end
describe "#destroy" do
let!(:collection) { FactoryGirl.create(:collection) }
before(:each) do
login_user collection.managers.first
end
it "should remove the MediaObject and MasterFiles from the system" do
media_object = FactoryGirl.create(:media_object_with_master_file, collection: collection)
delete :destroy, id: media_object.pid
expect(flash[:notice]).to include("success")
expect(MediaObject.exists?(media_object.pid)).to be_falsey
expect(MasterFile.exists?(media_object.parts.first.id)).to be_falsey
end
it "should fail when id doesn't exist" do
delete :destroy, id: 'avalon:this-pid-is-fake'
expect(response.code).to eq '404'
end
it "should fail if user is not authorized" do
media_object = FactoryGirl.create(:media_object)
expect(delete :destroy, id: media_object.id).to redirect_to root_path
expect(flash[:notice]).to include("permission denied")
end
it "should remove multiple items" do
media_objects = []
3.times { media_objects << FactoryGirl.create(:media_object, collection: collection) }
delete :destroy, id: media_objects.map(&:id)
expect(flash[:notice]).to include('3 media objects')
media_objects.each {|mo| expect(MediaObject.exists?(mo.pid)).to be_falsey }
end
end
describe "#update_status" do
let!(:collection) { FactoryGirl.create(:collection) }
before(:each) do
login_user collection.managers.first
request.env["HTTP_REFERER"] = '/'
end
context 'publishing' do
before(:each) do
Permalink.on_generate { |obj| "http://example.edu/permalink" }
end
it 'publishes media object' do
media_object = FactoryGirl.create(:media_object, collection: collection)
get 'update_status', id: media_object.pid, status: 'publish'
media_object.reload
expect(media_object).to be_published
expect(media_object.permalink).to be_present
end
it "should fail when id doesn't exist" do
get 'update_status', id: 'avalon:this-pid-is-fake', status: 'publish'
expect(response.code).to eq '404'
end
it "should fail if user is not authorized" do
media_object = FactoryGirl.create(:media_object)
expect(get 'update_status', id: media_object.pid, status: 'publish').to be_redirect
expect(flash[:notice]).to include("permission denied")
end
it "should publish multiple items" do
media_objects = []
3.times { media_objects << FactoryGirl.create(:media_object, collection: collection) }
get 'update_status', id: media_objects.map(&:id), status: 'publish'
expect(flash[:notice]).to include('3 media objects')
media_objects.each do |mo|
mo.reload
expect(mo).to be_published
expect(mo.permalink).to be_present
end
end
end
context 'unpublishing' do
it 'unpublishes media object' do
media_object = FactoryGirl.create(:published_media_object, collection: collection)
get 'update_status', :id => media_object.pid, :status => 'unpublish'
media_object.reload
expect(media_object).not_to be_published
end
it "should fail when id doesn't exist" do
get 'update_status', id: 'avalon:this-pid-is-fake', status: 'unpublish'
expect(response.code).to eq '404'
end
it "should fail if user is not authorized" do
media_object = FactoryGirl.create(:media_object)
expect(get 'update_status', id: media_object.pid, status: 'unpublish').to be_redirect
expect(flash[:notice]).to include("permission denied")
end
it "should unpublish multiple items" do
media_objects = []
3.times { media_objects << FactoryGirl.create(:published_media_object, collection: collection) }
get 'update_status', id: media_objects.map(&:id), status: 'unpublish'
expect(flash[:notice]).to include('3 media objects')
media_objects.each do |mo|
mo.reload
expect(mo).not_to be_published
end
end
end
end
describe "#save" do
it 'removes bookmarks that are no longer viewable' do
media_object = FactoryGirl.create(:published_media_object)
user = FactoryGirl.create(:public)
bookmark = Bookmark.create(document_id: media_object.pid, user_id: user.id)
login_user media_object.collection.managers.first
request.env["HTTP_REFERER"] = '/'
expect {
get 'update_status', id: media_object.pid, status: 'unpublish'
}.to change { Bookmark.exists? bookmark }.from( true ).to( false )
end
end
describe "#update" do
it 'updates the order' do
media_object = FactoryGirl.create(:media_object)
media_object.parts << FactoryGirl.create(:master_file)
media_object.parts << FactoryGirl.create(:master_file)
master_file_pids = media_object.parts.map(&:id)
media_object.section_pid = master_file_pids
media_object.save( validate: false )
login_user media_object.collection.managers.first
put 'update', :id => media_object.pid, :masterfile_ids => master_file_pids.reverse, :step => 'structure'
media_object.reload
expect(media_object.section_pid).to eq master_file_pids.reverse
end
it 'sets the MIME type' do
media_object = FactoryGirl.create(:media_object)
media_object.parts << FactoryGirl.create(:master_file_with_derivative)
media_object.section_pid = media_object.parts.map(&:id)
media_object.set_media_types!
media_object.save( validate: false )
media_object.reload
expect(media_object.descMetadata.media_type).to eq(["video/mp4"])
end
end
end