-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbibliographics_spec.rb
More file actions
84 lines (69 loc) · 2.29 KB
/
Copy pathbibliographics_spec.rb
File metadata and controls
84 lines (69 loc) · 2.29 KB
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
require 'calnet_helper'
RSpec.describe BibliographicsController, type: :request do
context 'specs for unauthorized user' do
before do
logout!
end
context 'new/create' do
it 'GET requires login' do
get bibliographics_path
expect(response).to have_http_status :unauthorized
end
it 'POST requires login' do
post bibliographics_path, params: { upload_file: nil }
expect(response).to have_http_status :unauthorized
end
end
# context 'index' do
# it 'GET requires login' do
# get bibliographics_index_path
# expect(response).to have_http_status :unauthorized
# end
# end
context 'response' do
it 'GET requires login' do
get bibliographics_response_path
expect(response).to have_http_status :unauthorized
end
end
end
context 'specs for authorized user' do
after do
logout!
end
shared_examples 'an authorized user' do
context 'GET #create' do
it 'response' do
get bibliographics_path
expect(response).to have_http_status :ok
expect(response.body).to include('Please choose a '.txt' file')
end
end
context 'POST #create' do
it 'created without error' do
upload_file = Rack::Test::UploadedFile.new(Rails.root.join('spec', 'data', 'bibliographic', 'upload_file.txt'), 'plain/text')
post bibliographics_path, params: { upload_file: }
expect(response).to redirect_to(action: :response)
end
it 'created with error' do
upload_file = Rack::Test::UploadedFile.new(Rails.root.join('spec', 'data', 'bibliographic', 'upload_file.csv'), 'plain/text')
post bibliographics_path, params: { upload_file: }
expect(flash[:danger]).to eq("The file must be in the '.txt' format,The file is empty")
expect(response).to redirect_to(bibliographics_path)
end
end
end
context 'specs for Framework admins' do
before do
login_as_patron(Alma::FRAMEWORK_ADMIN_ID)
end
it_behaves_like 'an authorized user'
end
context 'specs for Alma admins' do
before do
login_as_patron(Alma::ALMA_ADMIN_ID)
end
it_behaves_like 'an authorized user'
end
end
end