openstax_api 8.3.1 → 8.3.2
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 +4 -4
- data/lib/openstax/api/version.rb +1 -1
- metadata +2 -120
- data/spec/controllers/openstax/api/v1/api_controller_spec.rb +0 -176
- data/spec/dummy/README.md +0 -1
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/controllers/api/v1/dummy_controller.rb +0 -23
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/models/user.rb +0 -2
- data/spec/dummy/app/representers/user_representer.rb +0 -13
- data/spec/dummy/app/representers/user_search_representer.rb +0 -5
- data/spec/dummy/app/routines/search_users.rb +0 -42
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/application.rb +0 -23
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -7
- data/spec/dummy/config/environments/development.rb +0 -37
- data/spec/dummy/config/environments/production.rb +0 -78
- data/spec/dummy/config/environments/test.rb +0 -39
- data/spec/dummy/config/initializers/assets.rb +0 -8
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy/config/initializers/doorkeeper.rb +0 -75
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/openstax_api.rb +0 -4
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -23
- data/spec/dummy/config/routes.rb +0 -6
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/0_create_doorkeeper_tables.rb +0 -42
- data/spec/dummy/db/migrate/1_create_users.rb +0 -16
- data/spec/dummy/db/schema.rb +0 -68
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/controller_includes.rb +0 -3
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/user.rb +0 -8
- data/spec/lib/openstax/api/apipie_spec.rb +0 -15
- data/spec/lib/openstax/api/constraints_spec.rb +0 -84
- data/spec/lib/openstax/api/doorkeeper_application_includes_spec.rb +0 -17
- data/spec/lib/openstax/api/params_spec.rb +0 -78
- data/spec/lib/openstax/api/representable_schema_printer_spec.rb +0 -27
- data/spec/lib/openstax/api/roar_spec.rb +0 -45
- data/spec/lib/openstax/api/routing_mapper_includes_spec.rb +0 -20
- data/spec/lib/openstax_api_spec.rb +0 -19
- data/spec/models/openstax/api/api_user_spec.rb +0 -47
- data/spec/rails_helper.rb +0 -54
- data/spec/representers/openstax/api/v1/abstract_search_representer_spec.rb +0 -144
- data/spec/spec_helper.rb +0 -86
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7296239fd11318616e99546c687c2f99a387e17425f0f6efca8f6b4f77059fc6
|
4
|
+
data.tar.gz: 0dcbc6e75158fda3afe0ded916182726a285d6bf565ac1bb131b4115290bcebc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3296d8f4e8354e4fb26ebd43d75ce509160a2c2d4b1a74c245b111514431ce50f9bc330f1eb8ba49975f7db00d592f81a7374bd0fe98303b7fb6341144b9d6b3
|
7
|
+
data.tar.gz: 6483a27055e0b8f01850dd77cf22ecfe39ffb3d74d9a41ef2bbd52ece5fda56754d0ea50fd2a8c0c259b57a8f4129d4fb7739cedc453dfe955f8e0bbf95aab84
|
data/lib/openstax/api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openstax_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.3.
|
4
|
+
version: 8.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dante Soares
|
@@ -275,65 +275,6 @@ files:
|
|
275
275
|
- lib/openstax/api/rspec_helpers.rb
|
276
276
|
- lib/openstax/api/version.rb
|
277
277
|
- lib/openstax_api.rb
|
278
|
-
- spec/controllers/openstax/api/v1/api_controller_spec.rb
|
279
|
-
- spec/dummy/README.md
|
280
|
-
- spec/dummy/Rakefile
|
281
|
-
- spec/dummy/app/assets/javascripts/application.js
|
282
|
-
- spec/dummy/app/assets/stylesheets/application.css
|
283
|
-
- spec/dummy/app/controllers/api/v1/dummy_controller.rb
|
284
|
-
- spec/dummy/app/helpers/application_helper.rb
|
285
|
-
- spec/dummy/app/models/user.rb
|
286
|
-
- spec/dummy/app/representers/user_representer.rb
|
287
|
-
- spec/dummy/app/representers/user_search_representer.rb
|
288
|
-
- spec/dummy/app/routines/search_users.rb
|
289
|
-
- spec/dummy/app/views/layouts/application.html.erb
|
290
|
-
- spec/dummy/bin/bundle
|
291
|
-
- spec/dummy/bin/rails
|
292
|
-
- spec/dummy/bin/rake
|
293
|
-
- spec/dummy/config.ru
|
294
|
-
- spec/dummy/config/application.rb
|
295
|
-
- spec/dummy/config/boot.rb
|
296
|
-
- spec/dummy/config/database.yml
|
297
|
-
- spec/dummy/config/environment.rb
|
298
|
-
- spec/dummy/config/environments/development.rb
|
299
|
-
- spec/dummy/config/environments/production.rb
|
300
|
-
- spec/dummy/config/environments/test.rb
|
301
|
-
- spec/dummy/config/initializers/assets.rb
|
302
|
-
- spec/dummy/config/initializers/backtrace_silencers.rb
|
303
|
-
- spec/dummy/config/initializers/cookies_serializer.rb
|
304
|
-
- spec/dummy/config/initializers/doorkeeper.rb
|
305
|
-
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
306
|
-
- spec/dummy/config/initializers/inflections.rb
|
307
|
-
- spec/dummy/config/initializers/mime_types.rb
|
308
|
-
- spec/dummy/config/initializers/openstax_api.rb
|
309
|
-
- spec/dummy/config/initializers/session_store.rb
|
310
|
-
- spec/dummy/config/initializers/wrap_parameters.rb
|
311
|
-
- spec/dummy/config/locales/en.yml
|
312
|
-
- spec/dummy/config/routes.rb
|
313
|
-
- spec/dummy/config/secrets.yml
|
314
|
-
- spec/dummy/db/development.sqlite3
|
315
|
-
- spec/dummy/db/migrate/0_create_doorkeeper_tables.rb
|
316
|
-
- spec/dummy/db/migrate/1_create_users.rb
|
317
|
-
- spec/dummy/db/schema.rb
|
318
|
-
- spec/dummy/db/test.sqlite3
|
319
|
-
- spec/dummy/lib/controller_includes.rb
|
320
|
-
- spec/dummy/public/404.html
|
321
|
-
- spec/dummy/public/422.html
|
322
|
-
- spec/dummy/public/500.html
|
323
|
-
- spec/dummy/public/favicon.ico
|
324
|
-
- spec/factories/user.rb
|
325
|
-
- spec/lib/openstax/api/apipie_spec.rb
|
326
|
-
- spec/lib/openstax/api/constraints_spec.rb
|
327
|
-
- spec/lib/openstax/api/doorkeeper_application_includes_spec.rb
|
328
|
-
- spec/lib/openstax/api/params_spec.rb
|
329
|
-
- spec/lib/openstax/api/representable_schema_printer_spec.rb
|
330
|
-
- spec/lib/openstax/api/roar_spec.rb
|
331
|
-
- spec/lib/openstax/api/routing_mapper_includes_spec.rb
|
332
|
-
- spec/lib/openstax_api_spec.rb
|
333
|
-
- spec/models/openstax/api/api_user_spec.rb
|
334
|
-
- spec/rails_helper.rb
|
335
|
-
- spec/representers/openstax/api/v1/abstract_search_representer_spec.rb
|
336
|
-
- spec/spec_helper.rb
|
337
278
|
homepage: https://github.com/openstax/openstax_api
|
338
279
|
licenses:
|
339
280
|
- MIT
|
@@ -358,63 +299,4 @@ rubygems_version: 2.7.3
|
|
358
299
|
signing_key:
|
359
300
|
specification_version: 4
|
360
301
|
summary: API utilities for OpenStax products and tools.
|
361
|
-
test_files:
|
362
|
-
- spec/spec_helper.rb
|
363
|
-
- spec/dummy/app/representers/user_representer.rb
|
364
|
-
- spec/dummy/app/representers/user_search_representer.rb
|
365
|
-
- spec/dummy/app/models/user.rb
|
366
|
-
- spec/dummy/app/routines/search_users.rb
|
367
|
-
- spec/dummy/app/controllers/api/v1/dummy_controller.rb
|
368
|
-
- spec/dummy/app/views/layouts/application.html.erb
|
369
|
-
- spec/dummy/app/assets/javascripts/application.js
|
370
|
-
- spec/dummy/app/assets/stylesheets/application.css
|
371
|
-
- spec/dummy/app/helpers/application_helper.rb
|
372
|
-
- spec/dummy/bin/rake
|
373
|
-
- spec/dummy/bin/bundle
|
374
|
-
- spec/dummy/bin/rails
|
375
|
-
- spec/dummy/config/secrets.yml
|
376
|
-
- spec/dummy/config/routes.rb
|
377
|
-
- spec/dummy/config/locales/en.yml
|
378
|
-
- spec/dummy/config/environments/production.rb
|
379
|
-
- spec/dummy/config/environments/development.rb
|
380
|
-
- spec/dummy/config/environments/test.rb
|
381
|
-
- spec/dummy/config/environment.rb
|
382
|
-
- spec/dummy/config/application.rb
|
383
|
-
- spec/dummy/config/database.yml
|
384
|
-
- spec/dummy/config/boot.rb
|
385
|
-
- spec/dummy/config/initializers/backtrace_silencers.rb
|
386
|
-
- spec/dummy/config/initializers/mime_types.rb
|
387
|
-
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
388
|
-
- spec/dummy/config/initializers/session_store.rb
|
389
|
-
- spec/dummy/config/initializers/wrap_parameters.rb
|
390
|
-
- spec/dummy/config/initializers/assets.rb
|
391
|
-
- spec/dummy/config/initializers/cookies_serializer.rb
|
392
|
-
- spec/dummy/config/initializers/doorkeeper.rb
|
393
|
-
- spec/dummy/config/initializers/openstax_api.rb
|
394
|
-
- spec/dummy/config/initializers/inflections.rb
|
395
|
-
- spec/dummy/config.ru
|
396
|
-
- spec/dummy/README.md
|
397
|
-
- spec/dummy/Rakefile
|
398
|
-
- spec/dummy/public/favicon.ico
|
399
|
-
- spec/dummy/public/422.html
|
400
|
-
- spec/dummy/public/500.html
|
401
|
-
- spec/dummy/public/404.html
|
402
|
-
- spec/dummy/lib/controller_includes.rb
|
403
|
-
- spec/dummy/db/schema.rb
|
404
|
-
- spec/dummy/db/test.sqlite3
|
405
|
-
- spec/dummy/db/migrate/0_create_doorkeeper_tables.rb
|
406
|
-
- spec/dummy/db/migrate/1_create_users.rb
|
407
|
-
- spec/dummy/db/development.sqlite3
|
408
|
-
- spec/representers/openstax/api/v1/abstract_search_representer_spec.rb
|
409
|
-
- spec/models/openstax/api/api_user_spec.rb
|
410
|
-
- spec/factories/user.rb
|
411
|
-
- spec/lib/openstax/api/representable_schema_printer_spec.rb
|
412
|
-
- spec/lib/openstax/api/apipie_spec.rb
|
413
|
-
- spec/lib/openstax/api/doorkeeper_application_includes_spec.rb
|
414
|
-
- spec/lib/openstax/api/params_spec.rb
|
415
|
-
- spec/lib/openstax/api/routing_mapper_includes_spec.rb
|
416
|
-
- spec/lib/openstax/api/constraints_spec.rb
|
417
|
-
- spec/lib/openstax/api/roar_spec.rb
|
418
|
-
- spec/lib/openstax_api_spec.rb
|
419
|
-
- spec/controllers/openstax/api/v1/api_controller_spec.rb
|
420
|
-
- spec/rails_helper.rb
|
302
|
+
test_files: []
|
@@ -1,176 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
module OpenStax
|
4
|
-
module Api
|
5
|
-
module V1
|
6
|
-
describe ApiController do
|
7
|
-
|
8
|
-
let!(:user) { FactoryBot.create :user }
|
9
|
-
let!(:user_2) { FactoryBot.create :user }
|
10
|
-
let!(:application) { double('Doorkeeper::Application') }
|
11
|
-
let!(:doorkeeper_token) { double('Doorkeeper::AccessToken') }
|
12
|
-
let!(:non_doorkeeper_user_proc) { lambda { user } }
|
13
|
-
let!(:controller) { ApiController.new }
|
14
|
-
let!(:dummy_controller) {
|
15
|
-
c = ::Api::V1::DummyController.new
|
16
|
-
c.response = ActionDispatch::TestResponse.new
|
17
|
-
c
|
18
|
-
}
|
19
|
-
|
20
|
-
context 'no authentication' do
|
21
|
-
before (:each) do
|
22
|
-
controller.doorkeeper_token = nil
|
23
|
-
controller.present_user = nil
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'has no human_user and no application' do
|
27
|
-
expect(controller.send :session_user?).to eq false
|
28
|
-
expect(controller.current_application).to be_nil
|
29
|
-
expect(controller.current_human_user).to be_nil
|
30
|
-
expect(controller.current_session_user).to be_nil
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'session' do
|
35
|
-
before (:each) do
|
36
|
-
controller.doorkeeper_token = nil
|
37
|
-
controller.present_user = user
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'has a human_user but no application' do
|
41
|
-
expect(controller.send :session_user?).to eq true
|
42
|
-
expect(controller.current_application).to be_nil
|
43
|
-
expect(controller.current_human_user).to eq user
|
44
|
-
expect(controller.current_session_user).to eq user
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'token with application and human user' do
|
49
|
-
before (:each) do
|
50
|
-
controller.doorkeeper_token = doorkeeper_token
|
51
|
-
controller.present_user = nil
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'has a human_user from token and an application' do
|
55
|
-
allow(doorkeeper_token).to receive(:application).and_return(application)
|
56
|
-
allow(doorkeeper_token).to receive(:resource_owner_id).and_return(user.id)
|
57
|
-
|
58
|
-
expect(controller.send :session_user?).to eq false
|
59
|
-
expect(controller.current_application).to eq application
|
60
|
-
expect(controller.current_human_user).to eq user
|
61
|
-
expect(controller.current_session_user).to be_nil
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'token with application only' do
|
66
|
-
before (:each) do
|
67
|
-
controller.doorkeeper_token = doorkeeper_token
|
68
|
-
controller.present_user = nil
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'has an application but no human_user' do
|
72
|
-
allow(doorkeeper_token).to receive(:application).and_return(application)
|
73
|
-
allow(doorkeeper_token).to receive(:resource_owner_id).and_return(nil)
|
74
|
-
|
75
|
-
expect(controller.send :session_user?).to eq false
|
76
|
-
expect(controller.current_application).to eq application
|
77
|
-
expect(controller.current_human_user).to eq nil
|
78
|
-
expect(controller.current_session_user).to eq nil
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'session and token' do
|
83
|
-
before (:each) do
|
84
|
-
controller.doorkeeper_token = doorkeeper_token
|
85
|
-
controller.present_user = user_2
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'ignores the session unless explicitly asked' do
|
89
|
-
allow(doorkeeper_token).to receive(:application).and_return(application)
|
90
|
-
allow(doorkeeper_token).to receive(:resource_owner_id).and_return(user)
|
91
|
-
|
92
|
-
expect(controller.send :session_user?).to eq false
|
93
|
-
expect(controller.current_application).to eq application
|
94
|
-
expect(controller.current_human_user).to eq user
|
95
|
-
expect(controller.current_session_user).to eq user_2
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context 'date' do
|
100
|
-
before(:each) do
|
101
|
-
instance_variable_set('@controller', dummy_controller)
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'sets the Date header for successful API calls' do
|
105
|
-
@controller.present_user = user
|
106
|
-
get 'dummy'
|
107
|
-
expect(Time.parse(response.headers['Date'])).to be_within(1.second).of(Time.now)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context 'cors without origin configured' do
|
112
|
-
before(:each) do
|
113
|
-
instance_variable_set('@controller', dummy_controller)
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'sets the CORS headers for anonymous users' do
|
117
|
-
get 'dummy'
|
118
|
-
expect(response.headers['Access-Control-Allow-Origin']).to be_nil
|
119
|
-
expect(response.headers['Access-Control-Allow-Credentials']).to be_nil
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'sets the CORS headers for token users' do
|
123
|
-
token = Doorkeeper::AccessToken.create!.token
|
124
|
-
@request.headers['Authorization'] = "Bearer #{token}"
|
125
|
-
get 'dummy'
|
126
|
-
expect(response.headers['Access-Control-Allow-Origin']).to be_nil
|
127
|
-
expect(response.headers['Access-Control-Allow-Credentials']).to be_nil
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'sets the CORS headers for session users (the browser should block the request due to no Access-Control-Allow-Credentials header)' do
|
131
|
-
@controller.present_user = user
|
132
|
-
get 'dummy'
|
133
|
-
expect(response.headers['Access-Control-Allow-Origin']).to be_nil
|
134
|
-
expect(response.headers['Access-Control-Allow-Credentials']).to be_nil
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
context 'cors with origin configured' do
|
139
|
-
before(:each) do
|
140
|
-
instance_variable_set('@controller', dummy_controller)
|
141
|
-
OpenStax::Api.configuration.validate_cors_origin = lambda{ |request|
|
142
|
-
request.headers["HTTP_ORIGIN"] == @valid_origin
|
143
|
-
}
|
144
|
-
end
|
145
|
-
after(:each) { OpenStax::Api.configuration.validate_cors_origin = nil }
|
146
|
-
|
147
|
-
context 'when configured proc is true' do
|
148
|
-
before(:each) do
|
149
|
-
@valid_origin = 'http://good-host'
|
150
|
-
@request.headers['HTTP_ORIGIN'] = @valid_origin
|
151
|
-
end
|
152
|
-
|
153
|
-
it 'sets the origin to whatever was reqeusted' do
|
154
|
-
get 'dummy'
|
155
|
-
expect(response.headers['Access-Control-Allow-Origin']).to eq @valid_origin
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'sets the origin to whatever was requested even if there was an exception raised' do
|
159
|
-
get 'explode'
|
160
|
-
expect(response.headers['Access-Control-Allow-Origin']).to eq @valid_origin
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'clears the headers if the configured proc is falsy' do
|
165
|
-
@valid_origin = 'http://good-host'
|
166
|
-
@request.headers['HTTP_ORIGIN'] = 'http://evil-host'
|
167
|
-
get 'dummy'
|
168
|
-
expect(response.headers['Access-Control-Allow-Origin']).to eq ''
|
169
|
-
end
|
170
|
-
|
171
|
-
end
|
172
|
-
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
data/spec/dummy/README.md
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Dummy application used to test the openstax_api gem.
|
data/spec/dummy/Rakefile
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
-
// listed below.
|
3
|
-
//
|
4
|
-
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
-
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
-
//
|
7
|
-
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// compiled file.
|
9
|
-
//
|
10
|
-
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
-
// about supported directives.
|
12
|
-
//
|
13
|
-
//= require_tree .
|
@@ -1,15 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
-
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
-
* file per style scope.
|
12
|
-
*
|
13
|
-
*= require_tree .
|
14
|
-
*= require_self
|
15
|
-
*/
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Api
|
2
|
-
module V1
|
3
|
-
|
4
|
-
class DummyControllerError < StandardError; end
|
5
|
-
|
6
|
-
class DummyController < OpenStax::Api::V1::ApiController
|
7
|
-
|
8
|
-
rescue_from DummyControllerError do |e|
|
9
|
-
render nothing: true, status: 500
|
10
|
-
end
|
11
|
-
|
12
|
-
def dummy
|
13
|
-
head(:ok)
|
14
|
-
end
|
15
|
-
|
16
|
-
def explode
|
17
|
-
raise DummyControllerError, "kaboom"
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'representable/json'
|
2
|
-
|
3
|
-
class UserRepresenter < Roar::Decorator
|
4
|
-
|
5
|
-
include Roar::JSON
|
6
|
-
|
7
|
-
property :unused, as: :username, readable: false, writeable: false,
|
8
|
-
schema_info: { required: true }
|
9
|
-
property :name, readable: true, writeable: true
|
10
|
-
property :email, readable: false, writeable: true
|
11
|
-
property :password_hash, readable: false, writeable: false
|
12
|
-
|
13
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# Dummy routine for testing the abstract search representer
|
2
|
-
|
3
|
-
class SearchUsers
|
4
|
-
|
5
|
-
lev_routine
|
6
|
-
|
7
|
-
uses_routine OSU::SearchAndOrganizeRelation,
|
8
|
-
as: :search,
|
9
|
-
translations: { outputs: { type: :verbatim } }
|
10
|
-
|
11
|
-
SORTABLE_FIELDS = {
|
12
|
-
'name' => :name,
|
13
|
-
'created_at' => :created_at
|
14
|
-
}
|
15
|
-
|
16
|
-
protected
|
17
|
-
|
18
|
-
def exec(params = {})
|
19
|
-
run(:search, relation: User.unscoped,
|
20
|
-
sortable_fields: SORTABLE_FIELDS,
|
21
|
-
params: params) do |with|
|
22
|
-
with.keyword :username do |names|
|
23
|
-
snames = to_string_array(names, append_wildcard: true)
|
24
|
-
next @items = @items.none if snames.empty?
|
25
|
-
@items = @items.where{username.like_any snames}
|
26
|
-
end
|
27
|
-
|
28
|
-
with.keyword :first_name do |names|
|
29
|
-
snames = to_string_array(names, append_wildcard: true)
|
30
|
-
next @items = @items.none if snames.empty?
|
31
|
-
@items = @items.where{name.like_any snames}
|
32
|
-
end
|
33
|
-
|
34
|
-
with.keyword :last_name do |names|
|
35
|
-
snames = to_string_array(names, append_wildcard: true)
|
36
|
-
.collect{|name| "% #{name}"}
|
37
|
-
next @items = @items.none if snames.empty?
|
38
|
-
@items = @items.where{name.like_any snames}
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|