openstax_utilities 4.3.0 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/controllers/openstax/utilities/status_controller.rb +66 -0
  4. data/app/views/layouts/openstax/utilities/status.html.erb +26 -0
  5. data/app/views/openstax/utilities/status/index.html.erb +45 -0
  6. data/config/routes.rb +3 -0
  7. data/lib/openstax/utilities/assets/manifest.rb +4 -0
  8. data/lib/openstax/utilities/engine.rb +3 -2
  9. data/lib/openstax/utilities/version.rb +1 -1
  10. metadata +21 -113
  11. data/spec/cassettes/OpenStax_Utilities_Assets/loading_remote_manifest/uses_remote_json.yml +0 -353
  12. data/spec/dummy/README.md +0 -1
  13. data/spec/dummy/Rakefile +0 -6
  14. data/spec/dummy/app/access_policies/dummier_access_policy.rb +0 -10
  15. data/spec/dummy/app/access_policies/dummy_access_policy.rb +0 -10
  16. data/spec/dummy/app/assets/config/manifest.js +0 -3
  17. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  18. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  19. data/spec/dummy/app/controllers/application_controller.rb +0 -5
  20. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  21. data/spec/dummy/app/models/user.rb +0 -2
  22. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  23. data/spec/dummy/bin/bundle +0 -3
  24. data/spec/dummy/bin/rails +0 -4
  25. data/spec/dummy/bin/rake +0 -4
  26. data/spec/dummy/config.ru +0 -4
  27. data/spec/dummy/config/application.rb +0 -18
  28. data/spec/dummy/config/boot.rb +0 -5
  29. data/spec/dummy/config/database.yml +0 -25
  30. data/spec/dummy/config/environment.rb +0 -5
  31. data/spec/dummy/config/environments/development.rb +0 -37
  32. data/spec/dummy/config/environments/production.rb +0 -78
  33. data/spec/dummy/config/environments/test.rb +0 -39
  34. data/spec/dummy/config/initializers/access_policies.rb +0 -1
  35. data/spec/dummy/config/initializers/assets.rb +0 -8
  36. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  37. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
  38. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  39. data/spec/dummy/config/initializers/inflections.rb +0 -16
  40. data/spec/dummy/config/initializers/mime_types.rb +0 -4
  41. data/spec/dummy/config/initializers/search_users.rb +0 -26
  42. data/spec/dummy/config/initializers/session_store.rb +0 -3
  43. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  44. data/spec/dummy/config/locales/en.yml +0 -23
  45. data/spec/dummy/config/routes.rb +0 -2
  46. data/spec/dummy/config/secrets.yml +0 -19
  47. data/spec/dummy/db/migrate/0_create_users.rb +0 -16
  48. data/spec/dummy/db/schema.rb +0 -29
  49. data/spec/dummy/db/test.sqlite3 +0 -0
  50. data/spec/dummy/log/test.log +0 -32144
  51. data/spec/dummy/public/404.html +0 -67
  52. data/spec/dummy/public/422.html +0 -67
  53. data/spec/dummy/public/500.html +0 -66
  54. data/spec/dummy/public/favicon.ico +0 -0
  55. data/spec/dummy/tmp/cache/C09/760/6da7b2a29da9cb0f80ef102c7effb91fab3374db +0 -0
  56. data/spec/factories/user.rb +0 -8
  57. data/spec/lib/openstax/utilities/access_policy_spec.rb +0 -68
  58. data/spec/lib/openstax/utilities/assets_spec.rb +0 -40
  59. data/spec/rails_helper.rb +0 -53
  60. data/spec/routines/openstax/utilities/limit_and_paginate_relation_spec.rb +0 -72
  61. data/spec/routines/openstax/utilities/order_relation_spec.rb +0 -55
  62. data/spec/routines/openstax/utilities/search_and_organize_relation_spec.rb +0 -139
  63. data/spec/routines/openstax/utilities/search_relation_spec.rb +0 -81
  64. data/spec/spec_helper.rb +0 -85
  65. data/spec/vcr_helper.rb +0 -18
@@ -1,55 +0,0 @@
1
- require 'rails_helper'
2
-
3
- module OpenStax
4
- module Utilities
5
- describe SearchRelation do
6
- let!(:john_doe) do
7
- FactoryBot.create :user, name: "John Doe", username: "doejohn", email: "john@doe.com"
8
- end
9
-
10
- let!(:jane_doe) do
11
- FactoryBot.create :user, name: "Jane Doe", username: "doejane", email: "jane@doe.com"
12
- end
13
-
14
- let!(:jack_doe) do
15
- FactoryBot.create :user, name: "Jack Doe", username: "doejack", email: "jack@doe.com"
16
- end
17
-
18
- before(:each) do
19
- 100.times { FactoryBot.create(:user) }
20
-
21
- @relation = User.where(User.arel_table[:username].matches('doe%'))
22
- end
23
-
24
- it "orders results by multiple fields in different directions" do
25
- items = OrderRelation.call(
26
- relation: @relation,
27
- sortable_fields: SearchUsers::SORTABLE_FIELDS,
28
- order_by: 'cReAtEd_At AsC, iD'
29
- ).outputs[:items]
30
- expect(items).to include(john_doe)
31
- expect(items).to include(jane_doe)
32
- expect(items).to include(jack_doe)
33
- john_index = items.index(john_doe)
34
- jane_index = items.index(jane_doe)
35
- jack_index = items.index(jack_doe)
36
- expect(jane_index).to be > john_index
37
- expect(jack_index).to be > jane_index
38
-
39
- items = OrderRelation.call(
40
- relation: @relation,
41
- sortable_fields: SearchUsers::SORTABLE_FIELDS,
42
- order_by: 'CrEaTeD_aT dEsC, Id DeSc'
43
- ).outputs[:items]
44
- expect(items).to include(john_doe)
45
- expect(items).to include(jane_doe)
46
- expect(items).to include(jack_doe)
47
- john_index = items.index(john_doe)
48
- jane_index = items.index(jane_doe)
49
- jack_index = items.index(jack_doe)
50
- expect(jane_index).to be < john_index
51
- expect(jack_index).to be < jane_index
52
- end
53
- end
54
- end
55
- end
@@ -1,139 +0,0 @@
1
- require 'rails_helper'
2
-
3
- module OpenStax
4
- module Utilities
5
- describe SearchAndOrganizeRelation do
6
-
7
- OPTIONS = {
8
- relation: SearchUsers::RELATION,
9
- search_proc: SearchUsers::SEARCH_PROC,
10
- sortable_fields: SearchUsers::SORTABLE_FIELDS,
11
- max_items: SearchUsers::MAX_ITEMS
12
- }
13
-
14
- let!(:john_doe) { FactoryBot.create :user, name: "John Doe",
15
- username: "doejohn",
16
- email: "john@doe.com" }
17
-
18
- let!(:jane_doe) { FactoryBot.create :user, name: "Jane Doe",
19
- username: "doejane",
20
- email: "jane@doe.com" }
21
-
22
- let!(:jack_doe) { FactoryBot.create :user, name: "Jack Doe",
23
- username: "doejack",
24
- email: "jack@doe.com" }
25
-
26
- before(:each) do
27
- 100.times do
28
- FactoryBot.create(:user)
29
- end
30
- end
31
-
32
- it "filters results" do
33
- items = SearchAndOrganizeRelation.call(OPTIONS.merge(params: {
34
- q: 'last_name:dOe'})).outputs[:items]
35
-
36
- expect(items).to include(john_doe)
37
- expect(items).to include(jane_doe)
38
- expect(items).to include(jack_doe)
39
- items.each do |item|
40
- expect(item.name.downcase).to match(/\A[\w]* doe[\w]*\z/i)
41
- end
42
-
43
- items = SearchAndOrganizeRelation.call(OPTIONS.merge(params: {
44
- q: 'first_name:jOhN last_name:DoE'})).outputs[:items]
45
-
46
- expect(items).to include(john_doe)
47
- expect(items).not_to include(jane_doe)
48
- expect(items).not_to include(jack_doe)
49
- items.each do |item|
50
- expect(item.name).to match(/\Ajohn[\w]* doe[\w]*\z/i)
51
- end
52
-
53
- items = SearchAndOrganizeRelation.call(OPTIONS.merge(params: {
54
- q: 'first_name:JoHn,JaNe last_name:dOe'})).outputs[:items]
55
-
56
- expect(items).to include(john_doe)
57
- expect(items).to include(jane_doe)
58
- expect(items).not_to include(jack_doe)
59
- items.each do |item|
60
- expect(item.name).to match(/\A[john|jane][\w]* doe[\w]*\z/i)
61
- end
62
- end
63
-
64
- it "orders results" do
65
- items = SearchAndOrganizeRelation.call(OPTIONS.merge(params: {
66
- order_by: 'cReAtEd_At AsC, iD',
67
- q: 'username:dOe'})).outputs[:items].to_a
68
- expect(items).to include(john_doe)
69
- expect(items).to include(jane_doe)
70
- expect(items).to include(jack_doe)
71
- john_index = items.index(john_doe)
72
- jane_index = items.index(jane_doe)
73
- jack_index = items.index(jack_doe)
74
- expect(jane_index).to be > john_index
75
- expect(jack_index).to be > jane_index
76
-
77
- items = SearchAndOrganizeRelation.call(OPTIONS.merge(params: {
78
- order_by: 'CrEaTeD_aT dEsC, Id DeSc',
79
- q: 'username:dOe'})).outputs[:items].to_a
80
- expect(items).to include(john_doe)
81
- expect(items).to include(jane_doe)
82
- expect(items).to include(jack_doe)
83
- john_index = items.index(john_doe)
84
- jane_index = items.index(jane_doe)
85
- jack_index = items.index(jack_doe)
86
- expect(jane_index).to be < john_index
87
- expect(jack_index).to be < jane_index
88
- end
89
-
90
- it "returns nothing if too many results" do
91
- routine = SearchAndOrganizeRelation.call(OPTIONS.merge(params: {
92
- q: ''}))
93
- outputs = routine.outputs
94
- errors = routine.errors
95
- expect(outputs).not_to be_empty
96
- expect(outputs[:total_count]).to eq User.count
97
- expect(outputs[:items]).to be_empty
98
- expect(errors).not_to be_empty
99
- expect(errors.first.code).to eq :too_many_items
100
- end
101
-
102
- it "paginates results" do
103
- all_items = SearchUsers::RELATION.to_a
104
-
105
- items = SearchAndOrganizeRelation.call(OPTIONS
106
- .except(:max_items)
107
- .merge(params: {q: '',
108
- per_page: 20})).outputs[:items]
109
- expect(items.limit(nil).offset(nil).count).to eq all_items.length
110
- expect(items.limit(nil).offset(nil).to_a).to eq all_items
111
- expect(items.count).to eq 20
112
- expect(items.to_a).to eq all_items[0..19]
113
-
114
- for page in 1..5
115
- items = SearchAndOrganizeRelation.call(OPTIONS
116
- .except(:max_items)
117
- .merge(params: {q: '',
118
- page: page,
119
- per_page: 20})).outputs[:items]
120
- expect(items.limit(nil).offset(nil).count).to eq all_items.count
121
- expect(items.limit(nil).offset(nil).to_a).to eq all_items
122
- expect(items.count).to eq 20
123
- expect(items.to_a).to eq all_items.slice(20*(page-1), 20)
124
- end
125
-
126
- items = SearchAndOrganizeRelation.call(OPTIONS
127
- .except(:max_items)
128
- .merge(params: {q: '',
129
- page: 1000,
130
- per_page: 20})).outputs[:items]
131
- expect(items.limit(nil).offset(nil).count).to eq all_items.count
132
- expect(items.limit(nil).offset(nil).to_a).to eq all_items
133
- expect(items.count).to eq 0
134
- expect(items.to_a).to be_empty
135
- end
136
-
137
- end
138
- end
139
- end
@@ -1,81 +0,0 @@
1
- require 'rails_helper'
2
-
3
- module OpenStax
4
- module Utilities
5
- describe SearchRelation do
6
- let!(:john_doe) do
7
- FactoryBot.create :user, name: "John Doe", username: "doejohn", email: "john@doe.com"
8
- end
9
-
10
- let!(:jane_doe) do
11
- FactoryBot.create :user, name: "Jane Doe", username: "doejane", email: "jane@doe.com"
12
- end
13
-
14
- let!(:jack_doe) do
15
- FactoryBot.create :user, name: "Jack Doe", username: "doejack", email: "jack@doe.com"
16
- end
17
-
18
- before(:each) do
19
- 100.times do
20
- FactoryBot.create(:user)
21
- end
22
- end
23
-
24
- it "filters results based on one field" do
25
- items = SearchRelation.call(relation: SearchUsers::RELATION,
26
- search_proc: SearchUsers::SEARCH_PROC,
27
- query: 'last_name:dOe').outputs[:items]
28
-
29
- expect(items).to include(john_doe)
30
- expect(items).to include(jane_doe)
31
- expect(items).to include(jack_doe)
32
- items.each do |item|
33
- expect(item.name.downcase).to match(/\A[\w]* doe[\w]*\z/i)
34
- end
35
- end
36
-
37
- it "filters results based on multiple fields" do
38
- items = SearchRelation.call(relation: SearchUsers::RELATION,
39
- search_proc: SearchUsers::SEARCH_PROC,
40
- query: 'first_name:jOhN last_name:DoE')
41
- .outputs[:items]
42
-
43
- expect(items).to include(john_doe)
44
- expect(items).not_to include(jane_doe)
45
- expect(items).not_to include(jack_doe)
46
- items.each do |item|
47
- expect(item.name).to match(/\Ajohn[\w]* doe[\w]*\z/i)
48
- end
49
- end
50
-
51
- it "filters results based on multiple keywords per field" do
52
- items = SearchRelation.call(relation: SearchUsers::RELATION,
53
- search_proc: SearchUsers::SEARCH_PROC,
54
- query: 'first_name:JoHn,JaNe last_name:dOe')
55
- .outputs[:items]
56
-
57
- expect(items).to include(john_doe)
58
- expect(items).to include(jane_doe)
59
- expect(items).not_to include(jack_doe)
60
- items.each do |item|
61
- expect(item.name).to match(/\A[john|jane][\w]* doe[\w]*\z/i)
62
- end
63
- end
64
-
65
- it "filters scoped results" do
66
- items = SearchRelation.call(
67
- relation: User.where(User.arel_table[:name].matches('jOhN%')),
68
- search_proc: SearchUsers::SEARCH_PROC,
69
- query: 'last_name:dOe'
70
- ).outputs[:items]
71
-
72
- expect(items).to include(john_doe)
73
- expect(items).not_to include(jane_doe)
74
- expect(items).not_to include(jack_doe)
75
- items.each do |item|
76
- expect(item.name.downcase).to match(/\Ajohn[\w]* doe[\w]*\z/i)
77
- end
78
- end
79
- end
80
- end
81
- end
@@ -1,85 +0,0 @@
1
- # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
- # file to always be loaded, without a need to explicitly require it in any files.
5
- #
6
- # Given that it is always loaded, you are encouraged to keep this file as
7
- # light-weight as possible. Requiring heavyweight dependencies from this file
8
- # will add to the boot time of your test suite on EVERY test run, even for an
9
- # individual file that may not need all of that loaded. Instead, consider making
10
- # a separate helper file that requires the additional dependencies and performs
11
- # the additional setup, and require it from the spec files that actually need it.
12
- #
13
- # The `.rspec` file also contains a few flags that are not defaults but that
14
- # users commonly want.
15
- #
16
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
- RSpec.configure do |config|
18
- # rspec-expectations config goes here. You can use an alternate
19
- # assertion/expectation library such as wrong or the stdlib/minitest
20
- # assertions if you prefer.
21
- config.expect_with :rspec do |expectations|
22
- # This option will default to `true` in RSpec 4. It makes the `description`
23
- # and `failure_message` of custom matchers include text for helper methods
24
- # defined using `chain`, e.g.:
25
- # be_bigger_than(2).and_smaller_than(4).description
26
- # # => "be bigger than 2 and smaller than 4"
27
- # ...rather than:
28
- # # => "be bigger than 2"
29
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
- end
31
-
32
- # rspec-mocks config goes here. You can use an alternate test double
33
- # library (such as bogus or mocha) by changing the `mock_with` option here.
34
- config.mock_with :rspec do |mocks|
35
- # Prevents you from mocking or stubbing a method that does not exist on
36
- # a real object. This is generally recommended, and will default to
37
- # `true` in RSpec 4.
38
- mocks.verify_partial_doubles = true
39
- end
40
-
41
- # The settings below are suggested to provide a good initial experience
42
- # with RSpec, but feel free to customize to your heart's content.
43
- =begin
44
- # These two settings work together to allow you to limit a spec run
45
- # to individual examples or groups you care about by tagging them with
46
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
47
- # get run.
48
- config.filter_run :focus
49
- config.run_all_when_everything_filtered = true
50
-
51
- # Limits the available syntax to the non-monkey patched syntax that is recommended.
52
- # For more details, see:
53
- # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
54
- # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
55
- # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
56
- config.disable_monkey_patching!
57
-
58
- # Many RSpec users commonly either run the entire suite or an individual
59
- # file, and it's useful to allow more verbose output when running an
60
- # individual spec file.
61
- if config.files_to_run.one?
62
- # Use the documentation formatter for detailed output,
63
- # unless a formatter has already been configured
64
- # (e.g. via a command-line flag).
65
- config.default_formatter = 'doc'
66
- end
67
-
68
- # Print the 10 slowest examples and example groups at the
69
- # end of the spec run, to help surface which specs are running
70
- # particularly slow.
71
- config.profile_examples = 10
72
-
73
- # Run specs in random order to surface order dependencies. If you find an
74
- # order dependency and want to debug it, you can fix the order by providing
75
- # the seed, which is printed after each run.
76
- # --seed 1234
77
- config.order = :random
78
-
79
- # Seed global randomization in this process using the `--seed` CLI option.
80
- # Setting this allows you to use `--seed` to deterministically reproduce
81
- # test failures related to randomization by passing the same `--seed` value
82
- # as the one that triggered the failure.
83
- Kernel.srand config.seed
84
- =end
85
- end
@@ -1,18 +0,0 @@
1
- require 'vcr'
2
-
3
- VCR.configure do |c|
4
- c.cassette_library_dir = 'spec/cassettes'
5
- c.hook_into :webmock
6
- c.configure_rspec_metadata!
7
- c.allow_http_connections_when_no_cassette = Rails.env.development?
8
- c.ignore_localhost = true
9
- c.ignore_request { |request| Addressable::URI.parse(request.uri).path == '/oauth/token' } \
10
- if Rails.env.development?
11
- c.preserve_exact_body_bytes { |http_message| !http_message.body.valid_encoding? }
12
- end
13
-
14
- VCR_OPTS = {
15
- # This should default to :none
16
- record: ENV.fetch('VCR_OPTS_RECORD', :none).to_sym,
17
- allow_unused_http_interactions: Rails.env.development?
18
- }