openstax_utilities 4.2.1 → 4.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +1 -1
  3. data/app/controllers/openstax/utilities/status_controller.rb +74 -0
  4. data/app/routines/openstax/utilities/search_relation.rb +7 -2
  5. data/app/views/layouts/openstax/utilities/status.html.erb +24 -0
  6. data/app/views/openstax/utilities/status/index.html.erb +50 -0
  7. data/config/routes.rb +3 -0
  8. data/lib/openstax/utilities/access_policy.rb +2 -1
  9. data/lib/openstax/utilities/assets.rb +29 -0
  10. data/lib/openstax/utilities/assets/manifest.rb +66 -0
  11. data/lib/openstax/utilities/engine.rb +3 -2
  12. data/lib/openstax/utilities/version.rb +1 -1
  13. data/lib/openstax_utilities.rb +7 -5
  14. metadata +86 -107
  15. data/spec/dummy/README.md +0 -1
  16. data/spec/dummy/Rakefile +0 -6
  17. data/spec/dummy/app/access_policies/dummier_access_policy.rb +0 -10
  18. data/spec/dummy/app/access_policies/dummy_access_policy.rb +0 -10
  19. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  20. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  21. data/spec/dummy/app/controllers/application_controller.rb +0 -5
  22. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  23. data/spec/dummy/app/models/user.rb +0 -2
  24. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  25. data/spec/dummy/bin/bundle +0 -3
  26. data/spec/dummy/bin/rails +0 -4
  27. data/spec/dummy/bin/rake +0 -4
  28. data/spec/dummy/config.ru +0 -4
  29. data/spec/dummy/config/application.rb +0 -23
  30. data/spec/dummy/config/boot.rb +0 -5
  31. data/spec/dummy/config/database.yml +0 -25
  32. data/spec/dummy/config/environment.rb +0 -5
  33. data/spec/dummy/config/environments/development.rb +0 -37
  34. data/spec/dummy/config/environments/production.rb +0 -78
  35. data/spec/dummy/config/environments/test.rb +0 -39
  36. data/spec/dummy/config/initializers/access_policies.rb +0 -1
  37. data/spec/dummy/config/initializers/assets.rb +0 -8
  38. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  39. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
  40. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  41. data/spec/dummy/config/initializers/inflections.rb +0 -16
  42. data/spec/dummy/config/initializers/mime_types.rb +0 -4
  43. data/spec/dummy/config/initializers/search_users.rb +0 -26
  44. data/spec/dummy/config/initializers/session_store.rb +0 -3
  45. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  46. data/spec/dummy/config/locales/en.yml +0 -23
  47. data/spec/dummy/config/routes.rb +0 -2
  48. data/spec/dummy/config/secrets.yml +0 -22
  49. data/spec/dummy/db/migrate/0_create_users.rb +0 -16
  50. data/spec/dummy/db/schema.rb +0 -29
  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/factories/user.rb +0 -8
  56. data/spec/lib/openstax/utilities/access_policy_spec.rb +0 -68
  57. data/spec/rails_helper.rb +0 -54
  58. data/spec/routines/openstax/utilities/limit_and_paginate_relation_spec.rb +0 -72
  59. data/spec/routines/openstax/utilities/order_relation_spec.rb +0 -57
  60. data/spec/routines/openstax/utilities/search_and_organize_relation_spec.rb +0 -139
  61. data/spec/routines/openstax/utilities/search_relation_spec.rb +0 -81
  62. data/spec/spec_helper.rb +0 -85
@@ -1,57 +0,0 @@
1
- require 'rails_helper'
2
-
3
- module OpenStax
4
- module Utilities
5
- describe SearchRelation do
6
-
7
- let!(:john_doe) { FactoryGirl.create :user, name: "John Doe",
8
- username: "doejohn",
9
- email: "john@doe.com" }
10
-
11
- let!(:jane_doe) { FactoryGirl.create :user, name: "Jane Doe",
12
- username: "doejane",
13
- email: "jane@doe.com" }
14
-
15
- let!(:jack_doe) { FactoryGirl.create :user, name: "Jack Doe",
16
- username: "doejack",
17
- email: "jack@doe.com" }
18
-
19
- before(:each) do
20
- 100.times do
21
- FactoryGirl.create(:user)
22
- end
23
-
24
- @relation = User.where{username.like 'doe%'}
25
- end
26
-
27
- it "orders results by multiple fields in different directions" do
28
- items = OrderRelation.call(relation: @relation,
29
- sortable_fields: SearchUsers::SORTABLE_FIELDS,
30
- order_by: 'cReAtEd_At AsC, iD')
31
- .outputs[:items]
32
- expect(items).to include(john_doe)
33
- expect(items).to include(jane_doe)
34
- expect(items).to include(jack_doe)
35
- john_index = items.index(john_doe)
36
- jane_index = items.index(jane_doe)
37
- jack_index = items.index(jack_doe)
38
- expect(jane_index).to be > john_index
39
- expect(jack_index).to be > jane_index
40
-
41
- items = OrderRelation.call(relation: @relation,
42
- sortable_fields: SearchUsers::SORTABLE_FIELDS,
43
- order_by: 'CrEaTeD_aT dEsC, Id DeSc')
44
- .outputs[:items]
45
- expect(items).to include(john_doe)
46
- expect(items).to include(jane_doe)
47
- expect(items).to include(jack_doe)
48
- john_index = items.index(john_doe)
49
- jane_index = items.index(jane_doe)
50
- jack_index = items.index(jack_doe)
51
- expect(jane_index).to be < john_index
52
- expect(jack_index).to be < jane_index
53
- end
54
-
55
- end
56
- end
57
- 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) { FactoryGirl.create :user, name: "John Doe",
15
- username: "doejohn",
16
- email: "john@doe.com" }
17
-
18
- let!(:jane_doe) { FactoryGirl.create :user, name: "Jane Doe",
19
- username: "doejane",
20
- email: "jane@doe.com" }
21
-
22
- let!(:jack_doe) { FactoryGirl.create :user, name: "Jack Doe",
23
- username: "doejack",
24
- email: "jack@doe.com" }
25
-
26
- before(:each) do
27
- 100.times do
28
- FactoryGirl.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
-
7
- let!(:john_doe) { FactoryGirl.create :user, name: "John Doe",
8
- username: "doejohn",
9
- email: "john@doe.com" }
10
-
11
- let!(:jane_doe) { FactoryGirl.create :user, name: "Jane Doe",
12
- username: "doejane",
13
- email: "jane@doe.com" }
14
-
15
- let!(:jack_doe) { FactoryGirl.create :user, name: "Jack Doe",
16
- username: "doejack",
17
- email: "jack@doe.com" }
18
-
19
- before(:each) do
20
- 100.times do
21
- FactoryGirl.create(:user)
22
- end
23
- end
24
-
25
- it "filters results based on one field" do
26
- items = SearchRelation.call(relation: SearchUsers::RELATION,
27
- search_proc: SearchUsers::SEARCH_PROC,
28
- query: 'last_name:dOe').outputs[:items]
29
-
30
- expect(items).to include(john_doe)
31
- expect(items).to include(jane_doe)
32
- expect(items).to include(jack_doe)
33
- items.each do |item|
34
- expect(item.name.downcase).to match(/\A[\w]* doe[\w]*\z/i)
35
- end
36
- end
37
-
38
- it "filters results based on multiple fields" do
39
- items = SearchRelation.call(relation: SearchUsers::RELATION,
40
- search_proc: SearchUsers::SEARCH_PROC,
41
- query: 'first_name:jOhN last_name:DoE')
42
- .outputs[:items]
43
-
44
- expect(items).to include(john_doe)
45
- expect(items).not_to include(jane_doe)
46
- expect(items).not_to include(jack_doe)
47
- items.each do |item|
48
- expect(item.name).to match(/\Ajohn[\w]* doe[\w]*\z/i)
49
- end
50
- end
51
-
52
- it "filters results based on multiple keywords per field" do
53
- items = SearchRelation.call(relation: SearchUsers::RELATION,
54
- search_proc: SearchUsers::SEARCH_PROC,
55
- query: 'first_name:JoHn,JaNe last_name:dOe')
56
- .outputs[:items]
57
-
58
- expect(items).to include(john_doe)
59
- expect(items).to include(jane_doe)
60
- expect(items).not_to include(jack_doe)
61
- items.each do |item|
62
- expect(item.name).to match(/\A[john|jane][\w]* doe[\w]*\z/i)
63
- end
64
- end
65
-
66
- it "filters scoped results" do
67
- items = SearchRelation.call(relation: User.where{name.like 'jOhN%'},
68
- search_proc: SearchUsers::SEARCH_PROC,
69
- query: 'last_name:dOe').outputs[:items]
70
-
71
- expect(items).to include(john_doe)
72
- expect(items).not_to include(jane_doe)
73
- expect(items).not_to include(jack_doe)
74
- items.each do |item|
75
- expect(item.name.downcase).to match(/\Ajohn[\w]* doe[\w]*\z/i)
76
- end
77
- end
78
-
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