@@ -34,7 +34,7 @@ def app
34
34
grammar = create_grammar
35
35
36
36
config = VALID_GRAMMAR_CONFIG
37
- auth_header ( :admin )
37
+ auth_header ( :editor )
38
38
json_post ( '/gnomon/labors' , config : config , comment : 'eh' )
39
39
40
40
expect ( last_response . status ) . to eq ( 200 )
@@ -51,7 +51,7 @@ def app
51
51
config = {
52
52
text : "Some content"
53
53
}
54
- auth_header ( :admin )
54
+ auth_header ( :editor )
55
55
json_post ( '/gnomon/labors' , config : config , comment : 'eh' )
56
56
57
57
expect ( last_response . status ) . to eq ( 422 )
@@ -124,7 +124,7 @@ def app
124
124
context 'counter API' do
125
125
it 'throws exception with no grammar defined' do
126
126
expect ( Magma ::Gnomon ::Identifier . count ) . to eq ( 0 )
127
- auth_header ( :admin )
127
+ auth_header ( :editor )
128
128
post ( '/gnomon/labors/increment/victim/LABORS-LION-H2-C' )
129
129
expect ( last_response . status ) . to eq ( 422 )
130
130
expect ( Magma ::Gnomon ::Identifier . count ) . to eq ( 0 )
@@ -137,15 +137,15 @@ def app
137
137
138
138
context 'generates the next identifier when' do
139
139
it 'none exist' do
140
- auth_header ( :admin )
140
+ auth_header ( :editor )
141
141
post ( '/gnomon/labors/increment/victim/LABORS-LION-H2-C' )
142
142
expect ( last_response . status ) . to eq ( 200 )
143
143
expect ( last_response . body ) . to eq ( "1" )
144
144
end
145
145
146
146
it 'does not create the identifier' do
147
147
expect ( Magma ::Gnomon ::Identifier . count ) . to eq ( 0 )
148
- auth_header ( :admin )
148
+ auth_header ( :editor )
149
149
post ( '/gnomon/labors/increment/victim/LABORS-LION-H2-C' )
150
150
expect ( last_response . status ) . to eq ( 200 )
151
151
expect ( last_response . body ) . to eq ( "1" )
@@ -154,23 +154,23 @@ def app
154
154
155
155
it 'sequence exists' do
156
156
identifier = create_identifier ( "LABORS-LION-H2-C1" , rule : 'victim' , grammar : @grammar )
157
- auth_header ( :admin )
157
+ auth_header ( :editor )
158
158
post ( '/gnomon/labors/increment/victim/LABORS-LION-H2-C' )
159
159
expect ( last_response . status ) . to eq ( 200 )
160
160
expect ( last_response . body ) . to eq ( "2" )
161
161
end
162
162
163
163
it 'sequence in other token value exists' do
164
164
identifier = create_identifier ( "LABORS-LION-H2-C1" , rule : 'victim' , grammar : @grammar )
165
- auth_header ( :admin )
165
+ auth_header ( :editor )
166
166
post ( '/gnomon/labors/increment/victim/LABORS-LION-H2-S' )
167
167
expect ( last_response . status ) . to eq ( 200 )
168
168
expect ( last_response . body ) . to eq ( "1" )
169
169
end
170
170
171
171
it 'change in parent token counter' do
172
172
identifier = create_identifier ( "LABORS-LION-H2-C1" , rule : 'victim' , grammar : @grammar )
173
- auth_header ( :admin )
173
+ auth_header ( :editor )
174
174
post ( '/gnomon/labors/increment/victim/LABORS-LION-H1-C' )
175
175
expect ( last_response . status ) . to eq ( 200 )
176
176
expect ( last_response . body ) . to eq ( "1" )
@@ -185,13 +185,13 @@ def app
185
185
end
186
186
187
187
it 'rule does not exist' do
188
- auth_header ( :admin )
188
+ auth_header ( :editor )
189
189
post ( '/gnomon/labors/increment/habitat/LABORS-MARSH' )
190
190
expect ( last_response . status ) . to eq ( 422 )
191
191
end
192
192
193
193
it 'identifier_root does not match rule' do
194
- auth_header ( :admin )
194
+ auth_header ( :editor )
195
195
post ( '/gnomon/labors/increment/victim/LABORS-LION-H2-Q' )
196
196
expect ( last_response . status ) . to eq ( 422 )
197
197
post ( '/gnomon/labors/increment/victim/LABORS-PARROT-H' )
@@ -200,7 +200,7 @@ def app
200
200
201
201
it 'but does not create identifier' do
202
202
expect ( Magma ::Gnomon ::Identifier . count ) . to eq ( 0 )
203
- auth_header ( :admin )
203
+ auth_header ( :editor )
204
204
post ( '/gnomon/labors/increment/victim/LABORS-LION-H2-Q' )
205
205
expect ( last_response . status ) . to eq ( 422 )
206
206
expect ( Magma ::Gnomon ::Identifier . count ) . to eq ( 0 )
@@ -372,7 +372,7 @@ def app
372
372
context 'generate API' do
373
373
374
374
it 'throws exception when no grammar for project' do
375
- auth_header ( :admin )
375
+ auth_header ( :editor )
376
376
post ( '/gnomon/labors/generate/victim/LABORS-LION-H2-C1' )
377
377
expect ( last_response . status ) . to eq ( 422 )
378
378
expect ( Magma ::Gnomon ::Identifier . count ) . to eq ( 0 )
@@ -386,7 +386,7 @@ def app
386
386
it 'creates the identifier' do
387
387
identifier = "LABORS-LION-H2-C1"
388
388
expect ( Magma ::Gnomon ::Identifier . count ) . to eq ( 0 )
389
- auth_header ( :admin )
389
+ auth_header ( :editor )
390
390
post ( "/gnomon/labors/generate/victim/#{ identifier } " )
391
391
392
392
rules = {
@@ -406,7 +406,7 @@ def app
406
406
407
407
it 'ignores identifiers that already exists' do
408
408
identifier = create_identifier ( "LABORS-LION-H2-C1" , rule : 'victim' , grammar : @grammar )
409
- auth_header ( :admin )
409
+ auth_header ( :editor )
410
410
post ( '/gnomon/labors/generate/victim/LABORS-LION-H2-C1' )
411
411
expect ( last_response . status ) . to eq ( 200 )
412
412
expect ( json_body [ :rules ] . size ) . to eq ( 4 )
@@ -416,7 +416,7 @@ def app
416
416
417
417
context 'throws exception when' do
418
418
it 'invalid rule name provided' do
419
- auth_header ( :admin )
419
+ auth_header ( :editor )
420
420
post ( '/gnomon/labors/generate/alias/LABORS-LION-H2-C1' )
421
421
expect ( last_response . status ) . to eq ( 422 )
422
422
expect ( Magma ::Gnomon ::Identifier . count ) . to eq ( 0 )
@@ -430,7 +430,7 @@ def app
430
430
end
431
431
432
432
it 'identifier does not match rule' do
433
- auth_header ( :admin )
433
+ auth_header ( :editor )
434
434
post ( '/gnomon/labors/generate/victim/LABORS-LION-H2-X1' )
435
435
expect ( last_response . status ) . to eq ( 422 )
436
436
expect ( Magma ::Gnomon ::Identifier . count ) . to eq ( 0 )
@@ -439,10 +439,60 @@ def app
439
439
end
440
440
end
441
441
442
+ context 'delete identifiers' do
443
+ before ( :each ) do
444
+ @grammar = create_grammar ( config : VALID_GRAMMAR_CONFIG )
445
+ identifier1 = create_identifier ( "LABORS-LION-H2-C1" , rule : 'victim' , grammar : @grammar )
446
+ identifier2 = create_identifier ( "LABORS-LION-H2-C2" , rule : 'victim' , grammar : @grammar )
447
+ identifier3 = create_identifier ( "LABORS-LION-H3-C2" , rule : 'victim' , grammar : @grammar )
448
+
449
+ end
450
+
451
+ it 'allows deletion with confirmation' do
452
+ auth_header ( :editor )
453
+ json_post ( '/gnomon/labors/delete' ,
454
+ identifiers : [
455
+ "LABORS-LION-H2-C1" ,
456
+ "LABORS-LION-H2-C2" ,
457
+ "LABORS-LION-H3-C2" ,
458
+ ] ,
459
+ confirmation : "df44036473e8537e83c267c86909bd23"
460
+ )
461
+
462
+ expect ( last_response . status ) . to eq ( 200 )
463
+ expect ( Magma ::Gnomon ::Identifier . count ) . to eq ( 0 )
464
+ end
465
+
466
+ it 'refuses deletion without confirmation' do
467
+ auth_header ( :editor )
468
+ post ( '/gnomon/labors/delete' , identifiers : [
469
+ "LABORS-LION-H2-C1" ,
470
+ "LABORS-LION-H2-C2" ,
471
+ "LABORS-LION-H3-C2" ,
472
+ ] )
473
+
474
+ expect ( last_response . status ) . to eq ( 422 )
475
+ expect ( json_body [ :error ] ) . to eq ( "Missing confirmation code df44036473e8537e83c267c86909bd23" )
476
+ expect ( Magma ::Gnomon ::Identifier . count ) . to eq ( 3 )
477
+ end
478
+
479
+ it 'refuses deletion with an unknown identifier' do
480
+ auth_header ( :editor )
481
+ post ( '/gnomon/labors/delete' , identifiers : [
482
+ "LABORS-LION-H2-C1" ,
483
+ "LABORS-LOON-H2-C2" ,
484
+ "LABORS-LION-H3-C2" ,
485
+ ] )
486
+
487
+ expect ( last_response . status ) . to eq ( 422 )
488
+ expect ( Magma ::Gnomon ::Identifier . count ) . to eq ( 3 )
489
+ end
490
+ end
491
+
442
492
context 'bulk generate API' do
443
493
444
494
it 'throws exception when no grammar for project' do
445
- auth_header ( :admin )
495
+ auth_header ( :editor )
446
496
json_post ( '/gnomon/labors/generate' , names : [ ] )
447
497
expect ( last_response . status ) . to eq ( 422 )
448
498
expect ( json_body [ :error ] ) . to eq ( 'No grammar found for project labors.' )
@@ -454,7 +504,7 @@ def app
454
504
end
455
505
456
506
it 'creates identifiers' do
457
- auth_header ( :admin )
507
+ auth_header ( :editor )
458
508
json_post ( "/gnomon/labors/generate" , names : [
459
509
{
460
510
rule_name : 'village' ,
@@ -482,7 +532,7 @@ def app
482
532
483
533
it 'ignores identifiers that already exists' do
484
534
identifier = create_identifier ( "LABORS-LION-H2-C1" , rule : 'victim' , grammar : @grammar )
485
- auth_header ( :admin )
535
+ auth_header ( :editor )
486
536
names = [ { rule_name : 'victim' , name : 'LABORS-LION-H2-C1' } ]
487
537
json_post ( '/gnomon/labors/generate' , names : names )
488
538
expect ( last_response . status ) . to eq ( 200 )
@@ -493,7 +543,7 @@ def app
493
543
494
544
context 'throws exception when' do
495
545
it 'invalid rule name provided' do
496
- auth_header ( :admin )
546
+ auth_header ( :editor )
497
547
json_post ( '/gnomon/labors/generate' , names : [ { rule_name : 'alias' , name : 'LABORS-LION-H2-C1' } ] )
498
548
expect ( last_response . status ) . to eq ( 422 )
499
549
expect ( Magma ::Gnomon ::Identifier . count ) . to eq ( 0 )
@@ -507,7 +557,7 @@ def app
507
557
end
508
558
509
559
it 'identifier does not match rule' do
510
- auth_header ( :admin )
560
+ auth_header ( :editor )
511
561
json_post ( '/gnomon/labors/generate' , names : [ { rule_name : 'victim' , name : 'LABORS-LION-H2-X1' } ] )
512
562
expect ( last_response . status ) . to eq ( 422 )
513
563
expect ( Magma ::Gnomon ::Identifier . count ) . to eq ( 0 )
0 commit comments