-
Notifications
You must be signed in to change notification settings - Fork 2
/
bundle_context_spec.rb
152 lines (131 loc) · 5.2 KB
/
bundle_context_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
RSpec.describe BundleContext, type: :model do
subject(:bc) do
BundleContext.new(
project_name: "SmokeTest",
content_structure: 1,
bundle_dir: "spec/test_data/bundle_input_g/",
staging_style_symlink: false,
content_metadata_creation: 1,
user: user
)
end
let(:user) { User.new(sunet_id: "Jdoe") }
context "validation" do
it "is not valid unless it has all required attributes" do
expect(BundleContext.new).not_to be_valid
expect(bc).to be_valid
end
context "defines enum with expected values" do
it "content_structure enum" do
is_expected.to define_enum_for(:content_structure).with(
"simple_image_structure" => 0,
"simple_book_structure" => 1,
"book_as_iamge_structure" => 2,
"file_structure" => 3,
"smpl_structure" => 4
)
end
it "content_metadata_creation enum" do
is_expected.to define_enum_for(:content_metadata_creation).with(
"default_style" => 0,
"filename_style" => 1,
"smpl_style" => 2
)
end
end
describe "#content_structure=" do
it "validation rejects a value if it does not match the enum" do
expect { described_class.new(content_structure: 654) }
.to raise_error(ArgumentError, "'654' is not a valid content_structure")
expect { described_class.new(content_structure: 'book_as_pdf') }
.to raise_error(ArgumentError, "'book_as_pdf' is not a valid content_structure")
end
it "will accept a symbol, but will always return a string" do
expect(described_class.new(content_structure: :smpl_structure).content_structure).to eq 'smpl_structure'
end
end
describe "#content_metadata_creation=" do
it "validation rejects a value if it does not match the enum" do
expect { described_class.new(content_metadata_creation: 654) }
.to raise_error(ArgumentError, "'654' is not a valid content_metadata_creation")
expect { described_class.new(content_metadata_creation: 'dpg') }
.to raise_error(ArgumentError, "'dpg' is not a valid content_metadata_creation")
end
it "will accept a symbol, but will always return a string" do
expect(described_class.new(content_metadata_creation: :smpl_style).content_metadata_creation).to eq 'smpl_style'
end
end
context "bundle_dir path does not exist" do
it "object does not pass validation" do
expect { bc.bundle_dir = 'does/not/exist' }.to change { bc.valid? }.to(false)
end
end
it { is_expected.to validate_presence_of(:project_name) }
it { is_expected.to validate_presence_of(:content_structure) }
it { is_expected.to validate_presence_of(:bundle_dir) }
it { is_expected.to validate_presence_of(:content_metadata_creation) }
it { is_expected.to belong_to(:user) }
end
describe "#staging_dir" do
it 'is hardcoded to the correct path' do
expect(described_class.new.staging_dir).to eq '/dor/assembly'
end
end
describe "#normalize_bundle_dir" do
it "removes the trailing forward slash" do
expect(bc.normalize_bundle_dir).to eq "spec/test_data/bundle_input_g"
end
end
describe "#content_tag_override?" do
it "is set to true" do
expect(described_class.new.content_tag_override?).to be true
end
end
describe "#smpl_manifest" do
it "returns the file name" do
expect(described_class.new.smpl_manifest).to eq 'smpl_manifest.csv'
end
end
describe "#manifest" do
it "returns the file name" do
expect(described_class.new.manifest).to eq 'manifest.csv'
end
end
describe "#path_in_bundle" do
it "creates a relative path" do
expect(bc.path_in_bundle("manifest.csv")).to eq "spec/test_data/bundle_input_g/manifest.csv"
end
end
describe "#progress_log_file" do
skip("Need to figure out where to set this path via planning meeting 9/10/18")
end
describe "manifest_rows" do
it "loads the manifest CSV" do
expect(CsvImporter).to receive(:parse_to_hash).with("spec/test_data/bundle_input_g/manifest.csv")
bc.manifest_rows
end
it "memoizes the manifest rows" do
expect(CsvImporter).to receive(:parse_to_hash).once.with("spec/test_data/bundle_input_g/manifest.csv").and_call_original
2.times { bc.manifest_rows }
end
it "expect the content of manifest rows" do
expect(bc.manifest_rows).to eq(
[
{"druid"=>"druid:jy812bp9403", "sourceid"=>"bar-1.0", "folder"=>"jy812bp9403", "label"=>"Label 1", "description"=>"This is a description for label 1"},
{"druid"=>"druid:tz250tk7584", "sourceid"=>"bar-2.1", "folder"=>"tz250tk7584", "label"=>"Label 2", "description"=>"This is a description for label 2"},
{"druid"=>"druid:gn330dv6119", "sourceid"=>"bar-3.1", "folder"=>"gn330dv6119", "label"=>"Label 3", "description"=>"This is a description for label 3"}
]
)
end
end
describe "manifest_cols" do
it "sets the column names" do
expect(bc.manifest_cols).to eq(
label: 'label',
source_id: 'sourceid',
object_container: 'object', # object referring to filename or foldername
druid: 'druid'
)
end
end
end