-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtind_validator_spec.rb
More file actions
113 lines (99 loc) · 2.92 KB
/
Copy pathtind_validator_spec.rb
File metadata and controls
113 lines (99 loc) · 2.92 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
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
require 'rails_helper'
require 'support/uploaded_file_context'
# describe TindValidator do
RSpec.describe TindValidator, type: :model do
include_context('uploaded file')
attr_reader :form
let(:input_file_path) { Rails.root.join('spec/data/tind_validator/fonoroff_with_errors.csv').to_s.freeze }
let(:input_file_basename) { File.basename(input_file_path) }
describe 'is valid' do
describe 'form' do
before do
params = {
'980__a': 'Librettos',
'982__a': 'Italian Librettos',
'982__b': 'Italian Librettos',
'982__p': 'Some larger project',
'540__a': 'some restriction text',
'5880_a': 'image, source of description',
'336__a': 'Image',
'852__c': 'The Bancroft Library',
'902__n': 'DMZ',
input_file: uploaded_file_from(input_file_path, mime_type: mime_type_xlsx),
'991__a': 'Resticted2Admin'
}
@form = TindValidator.new(params)
end
it 'is valid' do
expect(@form.valid?).to eq(true)
end
end
end
describe 'permitted params are valid' do
describe 'form' do
before do
@params = {
directory: '/some/directory',
'980__a': 'Librettos',
'982__a': 'Italian Librettos',
'982__b': 'Italian Librettos',
'982__p': 'Some parent collection',
'540__a': 'some restriction text',
'5880_a': 'image, source of description',
'336__a': 'Image',
'852__c': 'The Bancroft Library',
'902__n': 'DMZ',
'991__a': 'Restricted2Bancroft'
}
end
it 'is valid' do
expect(TindValidator.new(@params).permitted_params).to eq(@params)
end
end
end
describe 'has non-permitted params' do
describe 'form' do
before do
@params = {
initials: nil,
directory: nil,
f_980_a: nil,
f_982_a: nil,
f_982_b: nil,
f_540_a: nil,
resource_type: nil,
library: nil,
f_982_p: nil,
f_588_p: nil,
restriction: nil,
fail: nil
}
end
it 'is not valid' do
expect(TindValidator.new(@params).permitted_params).not_to eq(@params)
end
end
end
# Missing a required parameter should cause it to fail
describe 'is not valid' do
describe 'form' do
before do
params = {
'980__a': 'Librettos',
'982__a': 'Italian Librettos',
'982__b': 'Italian Librettos',
'982__p': 'Some parent collection',
'540__a': 'some restriction text',
'336__a': 'Image',
input_file: uploaded_file_from(input_file_path),
'902__n': 'DMZ',
'991__a': 'Restricted2Bancroft'
}
@form = TindValidator.new(params)
end
it 'is not valid' do
expect(@form.valid?).to eq(false)
end
end
end
end