specify_cli 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +117 -0
- data/LICENSE.txt +21 -0
- data/README.rdoc +43 -0
- data/Rakefile +15 -0
- data/bin/specify_cli +248 -0
- data/lib/specify.rb +45 -0
- data/lib/specify/branch_parser.rb +85 -0
- data/lib/specify/cli.rb +11 -0
- data/lib/specify/cli/database_setup.rb +46 -0
- data/lib/specify/cli/stubs.rb +63 -0
- data/lib/specify/cli/viewset.rb +21 -0
- data/lib/specify/configuration.rb +12 -0
- data/lib/specify/configuration/config.rb +120 -0
- data/lib/specify/configuration/db_config.rb +162 -0
- data/lib/specify/configuration/host_config.rb +37 -0
- data/lib/specify/database.rb +140 -0
- data/lib/specify/models.rb +43 -0
- data/lib/specify/models/accession.rb +33 -0
- data/lib/specify/models/agent.rb +138 -0
- data/lib/specify/models/app_resource_data.rb +32 -0
- data/lib/specify/models/app_resource_dir.rb +43 -0
- data/lib/specify/models/auto_numbering_scheme.rb +94 -0
- data/lib/specify/models/collecting_event.rb +38 -0
- data/lib/specify/models/collection.rb +67 -0
- data/lib/specify/models/collection_object.rb +127 -0
- data/lib/specify/models/createable.rb +21 -0
- data/lib/specify/models/determination.rb +63 -0
- data/lib/specify/models/discipline.rb +61 -0
- data/lib/specify/models/division.rb +26 -0
- data/lib/specify/models/geography.rb +5 -0
- data/lib/specify/models/geography/administrative_division.rb +32 -0
- data/lib/specify/models/geography/geographic_name.rb +66 -0
- data/lib/specify/models/geography/geography.rb +23 -0
- data/lib/specify/models/institution.rb +13 -0
- data/lib/specify/models/locality.rb +50 -0
- data/lib/specify/models/preparation.rb +53 -0
- data/lib/specify/models/preparation_type.rb +30 -0
- data/lib/specify/models/record_set.rb +55 -0
- data/lib/specify/models/record_set_item.rb +29 -0
- data/lib/specify/models/taxonomy.rb +6 -0
- data/lib/specify/models/taxonomy/common_name.rb +14 -0
- data/lib/specify/models/taxonomy/rank.rb +31 -0
- data/lib/specify/models/taxonomy/taxon.rb +54 -0
- data/lib/specify/models/taxonomy/taxonomy.rb +21 -0
- data/lib/specify/models/tree_queryable.rb +55 -0
- data/lib/specify/models/updateable.rb +20 -0
- data/lib/specify/models/user.rb +104 -0
- data/lib/specify/models/view_set_object.rb +32 -0
- data/lib/specify/number_format.rb +60 -0
- data/lib/specify/services.rb +18 -0
- data/lib/specify/services/service.rb +51 -0
- data/lib/specify/services/stub_generator.rb +291 -0
- data/lib/specify/services/view_loader.rb +177 -0
- data/lib/specify/session.rb +77 -0
- data/lib/specify/user_type.rb +61 -0
- data/lib/specify/version.rb +19 -0
- data/man/specify_cli-database.1 +60 -0
- data/man/specify_cli-database.1.html +137 -0
- data/man/specify_cli-database.1.ronn +53 -0
- data/man/specify_cli-repository.1 +55 -0
- data/man/specify_cli-repository.1.html +128 -0
- data/man/specify_cli-repository.1.ronn +42 -0
- data/man/specify_cli-stubs.1 +177 -0
- data/man/specify_cli-stubs.1.html +239 -0
- data/man/specify_cli-stubs.1.ronn +147 -0
- data/man/specify_cli-viewset.1 +92 -0
- data/man/specify_cli-viewset.1.html +154 -0
- data/man/specify_cli-viewset.1.ronn +72 -0
- data/man/specify_cli.1 +213 -0
- data/man/specify_cli.1.html +252 -0
- data/man/specify_cli.1.ronn +157 -0
- data/spec/branch_parser_spec.rb +94 -0
- data/spec/cli/stubs_spec.rb +44 -0
- data/spec/configuration/config_spec.rb +269 -0
- data/spec/configuration/db_config_spec.rb +299 -0
- data/spec/configuration/host_config_spec.rb +64 -0
- data/spec/database_spec.rb +83 -0
- data/spec/examples.txt +217 -0
- data/spec/helpers.rb +15 -0
- data/spec/models/app_resource_data_spec.rb +38 -0
- data/spec/models/app_resource_dir_spec.rb +8 -0
- data/spec/models/auto_numbering_scheme_spec.rb +78 -0
- data/spec/models/collection_object_spec.rb +92 -0
- data/spec/models/collection_spec.rb +32 -0
- data/spec/models/discipline_spec.rb +31 -0
- data/spec/models/record_set_spec.rb +18 -0
- data/spec/models/user_spec.rb +182 -0
- data/spec/models/view_set_object_spec.rb +70 -0
- data/spec/number_format_spec.rb +43 -0
- data/spec/services/stub_generator_spec.rb +635 -0
- data/spec/services/view_loader_spec.rb +436 -0
- data/spec/session_spec.rb +105 -0
- data/spec/spec_helper.rb +116 -0
- data/spec/support/db.yml +12 -0
- data/spec/support/stub.yaml +17 -0
- data/spec/support/stub_locality.yaml +19 -0
- data/spec/support/viewsets/paleo.views.xml +30 -0
- data/spec/support/viewsets/paleo.xml +30 -0
- data/spec/user_type_spec.rb +79 -0
- data/specify_cli.gemspec +27 -0
- data/specify_cli.rdoc +1 -0
- metadata +246 -0
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Tests for the
|
|
4
|
+
module Specify
|
|
5
|
+
module Service
|
|
6
|
+
RSpec.describe ViewLoader do
|
|
7
|
+
let :config do
|
|
8
|
+
Pathname.new(Dir.pwd).join('spec', 'support', 'db.yml')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
let(:path) { 'sp_resource' }
|
|
12
|
+
|
|
13
|
+
describe '.from_branch(name, config)' do
|
|
14
|
+
context 'when branch is discipline level' do
|
|
15
|
+
subject do
|
|
16
|
+
bname = 'SPSPEC/TestCollection/discipline'
|
|
17
|
+
described_class.from_branch(path: path,
|
|
18
|
+
name: bname,
|
|
19
|
+
config: config).target
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it do
|
|
23
|
+
is_expected
|
|
24
|
+
.to be_a(Model::Discipline)
|
|
25
|
+
.and have_attributes Name: 'Test Discipline'
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context 'when branch is collection level' do
|
|
30
|
+
subject do
|
|
31
|
+
bname = 'SPSPEC/TestCollection/collection'
|
|
32
|
+
described_class.from_branch(path: path,
|
|
33
|
+
name: bname,
|
|
34
|
+
config: config).target
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it do
|
|
38
|
+
is_expected
|
|
39
|
+
.to be_a(Model::Collection)
|
|
40
|
+
.and have_attributes CollectionName: 'Test Collection'
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context 'when branch is user type level' do
|
|
45
|
+
subject do
|
|
46
|
+
bname = 'SPSPEC/TestCollection/Manager'
|
|
47
|
+
described_class.from_branch(path: path,
|
|
48
|
+
name: bname,
|
|
49
|
+
config: config).target
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it do
|
|
53
|
+
is_expected
|
|
54
|
+
.to be_a(UserType)
|
|
55
|
+
.and have_attributes name: :manager
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
context 'when branch is user level' do
|
|
60
|
+
subject do
|
|
61
|
+
bname = 'SPSPEC/TestCollection/user/specuser'
|
|
62
|
+
described_class.from_branch(path: path,
|
|
63
|
+
name: bname,
|
|
64
|
+
config: config).target
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it do
|
|
68
|
+
is_expected
|
|
69
|
+
.to be_a(Model::User)
|
|
70
|
+
.and have_attributes EMail: 'john.doe@example.com',
|
|
71
|
+
Name: 'specuser'
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe '.user_target(hash)' do
|
|
77
|
+
subject { described_class.user_target(user: 'specuser') }
|
|
78
|
+
|
|
79
|
+
it do
|
|
80
|
+
is_expected.to be_a(Model::User)
|
|
81
|
+
.and have_attributes Name: 'specuser'
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
describe '.user_type_target(hash)' do
|
|
86
|
+
subject { described_class.user_type_target(user_type: 'manager') }
|
|
87
|
+
|
|
88
|
+
it do
|
|
89
|
+
is_expected.to be_a(UserType)
|
|
90
|
+
.and have_attributes name: 'manager'
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
describe '#target=(level)' do
|
|
95
|
+
let :view_loader do
|
|
96
|
+
described_class.new host: 'localhost',
|
|
97
|
+
database: 'SPSPEC',
|
|
98
|
+
collection: 'Test Collection',
|
|
99
|
+
config: config
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
context 'when level is :discipline' do
|
|
103
|
+
it do
|
|
104
|
+
expect { view_loader.target = :discipline }
|
|
105
|
+
.to change(view_loader, :target)
|
|
106
|
+
.from(be_nil)
|
|
107
|
+
.to a_kind_of(Model::Discipline)
|
|
108
|
+
.and have_attributes Name: 'Test Discipline'
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
context 'when level is :collection' do
|
|
113
|
+
it do
|
|
114
|
+
expect { view_loader.target = :collection }
|
|
115
|
+
.to change(view_loader, :target)
|
|
116
|
+
.from(be_nil)
|
|
117
|
+
.to a_kind_of(Model::Collection)
|
|
118
|
+
.and have_attributes CollectionName: 'Test Collection'
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
context 'when level is { user_type: :manager }' do
|
|
123
|
+
it do
|
|
124
|
+
expect { view_loader.target = { user_type: 'manager' } }
|
|
125
|
+
.to change(view_loader, :target)
|
|
126
|
+
.from(be_nil)
|
|
127
|
+
.to a_kind_of(UserType)
|
|
128
|
+
.and have_attributes name: 'manager'
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
context 'when level is { user: \'specuser\' }' do
|
|
133
|
+
it do
|
|
134
|
+
expect { view_loader.target = { user: 'specuser' } }
|
|
135
|
+
.to change(view_loader, :target)
|
|
136
|
+
.from(be_nil)
|
|
137
|
+
.to a_kind_of(Model::User)
|
|
138
|
+
.and have_attributes EMail: 'john.doe@example.com',
|
|
139
|
+
Name: 'specuser'
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
context 'when level is nil' do
|
|
144
|
+
it do
|
|
145
|
+
expect { view_loader.target = nil }
|
|
146
|
+
.not_to change(view_loader, :target)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
describe '#import(file)' do
|
|
152
|
+
let :file do
|
|
153
|
+
Pathname.new(Dir.pwd).join('spec', 'support',
|
|
154
|
+
'viewsets', 'paleo.views.xml')
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
context 'when the app_resource_dir exists' do
|
|
158
|
+
let :view_loader do
|
|
159
|
+
described_class.new host: 'localhost',
|
|
160
|
+
database: 'SPSPEC',
|
|
161
|
+
collection: 'Test Collection',
|
|
162
|
+
level: :collection,
|
|
163
|
+
config: config
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
context 'when file is not a .views.xml file' do
|
|
167
|
+
let :wrong_file do
|
|
168
|
+
Pathname.new(Dir.pwd).join('spec', 'support',
|
|
169
|
+
'viewsets', 'paleo.xml')
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
it do
|
|
173
|
+
expect { view_loader.import(wrong_file) }
|
|
174
|
+
.to raise_error ArgumentError, FileError::VIEWS_FILE
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
context 'when file does not exist' do
|
|
179
|
+
it do
|
|
180
|
+
expect { view_loader.import('no_file.xml') }
|
|
181
|
+
.to raise_error ArgumentError, FileError::NO_FILE
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
context 'when file is a .views.xml file' do
|
|
186
|
+
before do
|
|
187
|
+
datadir = view_loader.target.view_set.app_resource_data
|
|
188
|
+
datadir.data = nil
|
|
189
|
+
datadir.save
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it do
|
|
193
|
+
expect { view_loader.import(file) }
|
|
194
|
+
.to change { view_loader.target.view_set.app_resource_data.data }
|
|
195
|
+
.from(nil).to(Sequel.blob(File.read(file)))
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
context 'when the app_resource_dir does not exist' do
|
|
201
|
+
let :view_loader do
|
|
202
|
+
described_class.new host: 'localhost',
|
|
203
|
+
database: 'SPSPEC',
|
|
204
|
+
collection: 'Another Collection',
|
|
205
|
+
config: config
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
context 'when uploading to the collection' do
|
|
209
|
+
before { view_loader.target = :collection }
|
|
210
|
+
|
|
211
|
+
it do
|
|
212
|
+
expect { view_loader.import(file) }
|
|
213
|
+
.to change { view_loader.target.view_set }
|
|
214
|
+
.from(nil).to(an_instance_of(Model::ViewSetObject))
|
|
215
|
+
.and change { view_loader.target.view_set&.app_resource_data&.data }
|
|
216
|
+
.from(nil).to(Sequel.blob(File.read(file)))
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
context 'when uploading to the user type' do
|
|
221
|
+
before { view_loader.target = { user_type: 'manager' } }
|
|
222
|
+
|
|
223
|
+
let(:collection) { Model::Collection.first(Code: 'NECE') }
|
|
224
|
+
|
|
225
|
+
it do
|
|
226
|
+
expect { view_loader.import(file) }
|
|
227
|
+
.to change { view_loader.target.view_set(collection) }
|
|
228
|
+
.from(nil).to(an_instance_of(Model::ViewSetObject))
|
|
229
|
+
.and change { view_loader.target.view_set(collection)&.app_resource_data&.data }
|
|
230
|
+
.from(nil).to(Sequel.blob(File.read(file)))
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
describe '#view_collection' do
|
|
237
|
+
subject { view_loader.view_collection }
|
|
238
|
+
|
|
239
|
+
let :view_loader do
|
|
240
|
+
described_class.new host: 'localhost',
|
|
241
|
+
database: 'SPSPEC',
|
|
242
|
+
collection: 'Test Collection',
|
|
243
|
+
config: config
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
context 'when level is not discipline' do
|
|
247
|
+
before { view_loader.target = :collection }
|
|
248
|
+
|
|
249
|
+
it do
|
|
250
|
+
is_expected.to be view_loader.session.collection
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
context 'when level is discipline' do
|
|
255
|
+
before { view_loader.target = :discipline }
|
|
256
|
+
|
|
257
|
+
it do
|
|
258
|
+
is_expected.to be_nil
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
describe '#view_discipline' do
|
|
264
|
+
subject { view_loader.view_discipline }
|
|
265
|
+
|
|
266
|
+
let :view_loader do
|
|
267
|
+
described_class.new host: 'localhost',
|
|
268
|
+
database: 'SPSPEC',
|
|
269
|
+
collection: 'Test Collection',
|
|
270
|
+
config: config
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
it do
|
|
274
|
+
is_expected.to be_a(Model::Discipline)
|
|
275
|
+
.and have_attributes Name: 'Test Discipline'
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
describe '#personal?' do
|
|
280
|
+
subject { view_loader.personal? }
|
|
281
|
+
|
|
282
|
+
let :view_loader do
|
|
283
|
+
described_class.new host: 'localhost',
|
|
284
|
+
database: 'SPSPEC',
|
|
285
|
+
collection: 'Test Collection',
|
|
286
|
+
config: config
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
context 'when discipline level' do
|
|
290
|
+
before { view_loader.target = :discipline }
|
|
291
|
+
|
|
292
|
+
it { is_expected.to be_falsey }
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
context 'when collection level' do
|
|
296
|
+
before { view_loader.target = :collection }
|
|
297
|
+
|
|
298
|
+
it { is_expected.to be_falsey }
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
context 'when user type level' do
|
|
302
|
+
before { view_loader.target = { user_type: 'manager' } }
|
|
303
|
+
|
|
304
|
+
it { is_expected.to be_falsey }
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
context 'when user level' do
|
|
308
|
+
before { view_loader.target = { user: 'specguest' } }
|
|
309
|
+
|
|
310
|
+
it { is_expected.to be_truthy }
|
|
311
|
+
end
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
describe '#view_level' do
|
|
315
|
+
subject { view_loader.view_level }
|
|
316
|
+
|
|
317
|
+
let :view_loader do
|
|
318
|
+
described_class.new host: 'localhost',
|
|
319
|
+
database: 'SPSPEC',
|
|
320
|
+
collection: 'Test Collection',
|
|
321
|
+
config: config
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
context 'when discipline level' do
|
|
325
|
+
before { view_loader.target = :discipline }
|
|
326
|
+
|
|
327
|
+
it { is_expected.to be 0 }
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
context 'when collection level' do
|
|
331
|
+
before { view_loader.target = :collection }
|
|
332
|
+
|
|
333
|
+
it { is_expected.to be 2 }
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
context 'when user type level' do
|
|
337
|
+
before { view_loader.target = { user_type: 'manager' } }
|
|
338
|
+
|
|
339
|
+
it { is_expected.to be 0 }
|
|
340
|
+
end
|
|
341
|
+
|
|
342
|
+
context 'when user level' do
|
|
343
|
+
before { view_loader.target = { user: 'specuser' } }
|
|
344
|
+
|
|
345
|
+
it { is_expected.to be 0 }
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
describe '#view_type' do
|
|
350
|
+
subject { view_loader.view_type }
|
|
351
|
+
|
|
352
|
+
let :view_loader do
|
|
353
|
+
described_class.new host: 'localhost',
|
|
354
|
+
database: 'SPSPEC',
|
|
355
|
+
collection: 'Test Collection',
|
|
356
|
+
config: config
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
it { is_expected.to eq 'Test Discipline' }
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
describe '#view_user' do
|
|
363
|
+
subject { view_loader.view_user }
|
|
364
|
+
|
|
365
|
+
let :view_loader do
|
|
366
|
+
described_class.new host: 'localhost',
|
|
367
|
+
database: 'SPSPEC',
|
|
368
|
+
collection: 'Test Collection',
|
|
369
|
+
config: config
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
context 'when discipline level' do
|
|
373
|
+
before { view_loader.target = :discipline }
|
|
374
|
+
|
|
375
|
+
it { is_expected.to be view_loader.session.user }
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
context 'when collection level' do
|
|
379
|
+
before { view_loader.target = :collection }
|
|
380
|
+
|
|
381
|
+
it { is_expected.to be view_loader.session.user }
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
context 'when user type level' do
|
|
385
|
+
before { view_loader.target = { user_type: 'manager' } }
|
|
386
|
+
|
|
387
|
+
it { is_expected.to be view_loader.session.user }
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
context 'when user level' do
|
|
391
|
+
before { view_loader.target = { user: 'specguest' } }
|
|
392
|
+
|
|
393
|
+
it do
|
|
394
|
+
is_expected.to be_a(Model::User)
|
|
395
|
+
.and have_attributes Name: 'specguest'
|
|
396
|
+
end
|
|
397
|
+
end
|
|
398
|
+
end
|
|
399
|
+
|
|
400
|
+
describe '#view_user_type' do
|
|
401
|
+
subject { view_loader.view_user_type }
|
|
402
|
+
|
|
403
|
+
let :view_loader do
|
|
404
|
+
described_class.new host: 'localhost',
|
|
405
|
+
database: 'SPSPEC',
|
|
406
|
+
collection: 'Test Collection',
|
|
407
|
+
config: config
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
context 'when discipline level' do
|
|
411
|
+
before { view_loader.target = :discipline }
|
|
412
|
+
|
|
413
|
+
it { is_expected.to be_nil }
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
context 'when collection level' do
|
|
417
|
+
before { view_loader.target = :collection }
|
|
418
|
+
|
|
419
|
+
it { is_expected.to be_nil }
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
context 'when user type level' do
|
|
423
|
+
before { view_loader.target = { user_type: 'manager' } }
|
|
424
|
+
|
|
425
|
+
it { is_expected.to eq 'manager' }
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
context 'when user level' do
|
|
429
|
+
before { view_loader.target = { user: 'specguest' } }
|
|
430
|
+
|
|
431
|
+
it { is_expected.to eq 'guest' }
|
|
432
|
+
end
|
|
433
|
+
end
|
|
434
|
+
end
|
|
435
|
+
end
|
|
436
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Specify
|
|
4
|
+
RSpec.describe Session do
|
|
5
|
+
let :session do
|
|
6
|
+
described_class.new('specuser', 'Test Collection')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe '#close' do
|
|
10
|
+
let :collection do
|
|
11
|
+
Model::Collection.first CollectionName: 'Test Collection'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
let(:user) { Model::User.first Name: 'specuser' }
|
|
15
|
+
|
|
16
|
+
before { user.log_in(collection) }
|
|
17
|
+
|
|
18
|
+
it do
|
|
19
|
+
expect(session.close)
|
|
20
|
+
.to be_a(described_class)
|
|
21
|
+
.and have_attributes active: false,
|
|
22
|
+
collection: collection,
|
|
23
|
+
user: user
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it do
|
|
27
|
+
expect { session.close }
|
|
28
|
+
.to change { Model::User.first(Name: 'specuser').IsLoggedIn }
|
|
29
|
+
.from(true).to(false)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
context 'when observed by a database' do
|
|
33
|
+
before { SPSPEC << session }
|
|
34
|
+
|
|
35
|
+
it do
|
|
36
|
+
expect { session.close }
|
|
37
|
+
.to change(SPSPEC, :sessions)
|
|
38
|
+
.from(including(an_instance_of(described_class)))
|
|
39
|
+
.to be_empty
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe '#open' do
|
|
45
|
+
let :collection do
|
|
46
|
+
Model::Collection.first CollectionName: 'Test Collection'
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
let(:user) { Model::User.first Name: 'specuser' }
|
|
50
|
+
|
|
51
|
+
before { user.log_out }
|
|
52
|
+
|
|
53
|
+
it do
|
|
54
|
+
expect(session.open)
|
|
55
|
+
.to be_a(described_class)
|
|
56
|
+
.and have_attributes active: true,
|
|
57
|
+
collection: collection,
|
|
58
|
+
user: user
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'opens a session' do
|
|
62
|
+
expect { session.open }
|
|
63
|
+
.to change { Model::User.first(Name: 'specuser').IsLoggedIn }
|
|
64
|
+
.from(false).to(true)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe '#open?' do
|
|
69
|
+
context 'when the session is open' do
|
|
70
|
+
subject { session.open? }
|
|
71
|
+
|
|
72
|
+
before { session.open }
|
|
73
|
+
|
|
74
|
+
it { is_expected.to be_truthy }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
context 'when the session is closed' do
|
|
78
|
+
subject { session.open? }
|
|
79
|
+
|
|
80
|
+
before { session.close }
|
|
81
|
+
|
|
82
|
+
it { is_expected.to be_falsey }
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe '#session_agent' do
|
|
87
|
+
subject { session.session_agent }
|
|
88
|
+
|
|
89
|
+
let :division do
|
|
90
|
+
Model::Collection.first(CollectionName: 'Test Collection')
|
|
91
|
+
.discipline.division
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
before { session.open }
|
|
95
|
+
|
|
96
|
+
it do
|
|
97
|
+
is_expected.to be_a(Model::Agent)
|
|
98
|
+
.and have_attributes Email: 'john.doe@example.com',
|
|
99
|
+
FirstName: 'John',
|
|
100
|
+
LastName: 'Doe',
|
|
101
|
+
division: division
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|