openstax_utilities 4.2.0 → 4.4.0
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 +5 -5
- data/README.md +1 -1
- data/app/controllers/openstax/utilities/status_controller.rb +66 -0
- data/app/routines/openstax/utilities/search_relation.rb +7 -2
- data/app/views/layouts/openstax/utilities/status.html.erb +26 -0
- data/app/views/openstax/utilities/status/index.html.erb +45 -0
- data/config/routes.rb +3 -0
- data/lib/openstax/utilities/access_policy.rb +4 -3
- data/lib/openstax/utilities/assets.rb +29 -0
- data/lib/openstax/utilities/assets/manifest.rb +66 -0
- data/lib/openstax/utilities/engine.rb +3 -2
- data/lib/openstax/utilities/version.rb +1 -1
- data/lib/openstax_utilities.rb +5 -5
- metadata +86 -105
- data/spec/dummy/README.md +0 -1
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/access_policies/dummy_access_policy.rb +0 -10
- 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/application_controller.rb +0 -5
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/models/user.rb +0 -2
- 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 -5
- 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/access_policies.rb +0 -1
- 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/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/search_users.rb +0 -26
- 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 -2
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/db/migrate/0_create_users.rb +0 -16
- data/spec/dummy/db/schema.rb +0 -29
- 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/utilities/access_policy_spec.rb +0 -67
- data/spec/rails_helper.rb +0 -54
- data/spec/routines/openstax/utilities/limit_and_paginate_relation_spec.rb +0 -72
- data/spec/routines/openstax/utilities/order_relation_spec.rb +0 -57
- data/spec/routines/openstax/utilities/search_and_organize_relation_spec.rb +0 -139
- data/spec/routines/openstax/utilities/search_relation_spec.rb +0 -81
- data/spec/spec_helper.rb +0 -85
data/spec/dummy/config/routes.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# Be sure to restart your server when you modify this file.
|
2
|
-
|
3
|
-
# Your secret key is used for verifying the integrity of signed cookies.
|
4
|
-
# If you change this key, all old signed cookies will become invalid!
|
5
|
-
|
6
|
-
# Make sure the secret is at least 30 characters and all random,
|
7
|
-
# no regular words or you'll be exposed to dictionary attacks.
|
8
|
-
# You can use `rake secret` to generate a secure secret key.
|
9
|
-
|
10
|
-
# Make sure the secrets in this file are kept private
|
11
|
-
# if you're sharing your code publicly.
|
12
|
-
|
13
|
-
development:
|
14
|
-
secret_key_base: 29e54ca73023838b463db707b1229ec66e43c4fb9a6302b136f4a09ba9f14fcfe39bf238f139a8475a6840e9a197abfbef5034ff1e227551cd914bac2000d958
|
15
|
-
|
16
|
-
test:
|
17
|
-
secret_key_base: e96d972e503764aa27f184c2c9e1e14598be32d4471d93ffbeed148df0c8af572e7e9e60dfb32d21176118ace6a5de4075be4671d03937e6aa15527ea1800383
|
18
|
-
|
19
|
-
# Do not keep production secrets in the repository,
|
20
|
-
# instead read values from the environment.
|
21
|
-
production:
|
22
|
-
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class CreateUsers < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_table :users do |t|
|
4
|
-
t.string :username, null: false
|
5
|
-
t.string :password_hash, null: false
|
6
|
-
t.string :name, null: false
|
7
|
-
t.string :email, null: false
|
8
|
-
|
9
|
-
t.timestamps
|
10
|
-
end
|
11
|
-
|
12
|
-
add_index :users, :username
|
13
|
-
add_index :users, :name
|
14
|
-
add_index :users, :email
|
15
|
-
end
|
16
|
-
end
|
data/spec/dummy/db/schema.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# This file is auto-generated from the current state of the database. Instead
|
3
|
-
# of editing this file, please use the migrations feature of Active Record to
|
4
|
-
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
-
#
|
6
|
-
# Note that this schema.rb definition is the authoritative source for your
|
7
|
-
# database schema. If you need to create the application database on another
|
8
|
-
# system, you should be using db:schema:load, not running all the migrations
|
9
|
-
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
-
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
-
#
|
12
|
-
# It's strongly recommended that you check this file into your version control system.
|
13
|
-
|
14
|
-
ActiveRecord::Schema.define(version: 0) do
|
15
|
-
|
16
|
-
create_table "users", force: true do |t|
|
17
|
-
t.string "username", null: false
|
18
|
-
t.string "password_hash", null: false
|
19
|
-
t.string "name", null: false
|
20
|
-
t.string "email", null: false
|
21
|
-
t.datetime "created_at"
|
22
|
-
t.datetime "updated_at"
|
23
|
-
end
|
24
|
-
|
25
|
-
add_index "users", ["email"], name: "index_users_on_email"
|
26
|
-
add_index "users", ["name"], name: "index_users_on_name"
|
27
|
-
add_index "users", ["username"], name: "index_users_on_username"
|
28
|
-
|
29
|
-
end
|
data/spec/dummy/public/404.html
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
-
<style>
|
7
|
-
body {
|
8
|
-
background-color: #EFEFEF;
|
9
|
-
color: #2E2F30;
|
10
|
-
text-align: center;
|
11
|
-
font-family: arial, sans-serif;
|
12
|
-
margin: 0;
|
13
|
-
}
|
14
|
-
|
15
|
-
div.dialog {
|
16
|
-
width: 95%;
|
17
|
-
max-width: 33em;
|
18
|
-
margin: 4em auto 0;
|
19
|
-
}
|
20
|
-
|
21
|
-
div.dialog > div {
|
22
|
-
border: 1px solid #CCC;
|
23
|
-
border-right-color: #999;
|
24
|
-
border-left-color: #999;
|
25
|
-
border-bottom-color: #BBB;
|
26
|
-
border-top: #B00100 solid 4px;
|
27
|
-
border-top-left-radius: 9px;
|
28
|
-
border-top-right-radius: 9px;
|
29
|
-
background-color: white;
|
30
|
-
padding: 7px 12% 0;
|
31
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
-
}
|
33
|
-
|
34
|
-
h1 {
|
35
|
-
font-size: 100%;
|
36
|
-
color: #730E15;
|
37
|
-
line-height: 1.5em;
|
38
|
-
}
|
39
|
-
|
40
|
-
div.dialog > p {
|
41
|
-
margin: 0 0 1em;
|
42
|
-
padding: 1em;
|
43
|
-
background-color: #F7F7F7;
|
44
|
-
border: 1px solid #CCC;
|
45
|
-
border-right-color: #999;
|
46
|
-
border-left-color: #999;
|
47
|
-
border-bottom-color: #999;
|
48
|
-
border-bottom-left-radius: 4px;
|
49
|
-
border-bottom-right-radius: 4px;
|
50
|
-
border-top-color: #DADADA;
|
51
|
-
color: #666;
|
52
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
-
}
|
54
|
-
</style>
|
55
|
-
</head>
|
56
|
-
|
57
|
-
<body>
|
58
|
-
<!-- This file lives in public/404.html -->
|
59
|
-
<div class="dialog">
|
60
|
-
<div>
|
61
|
-
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
-
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
-
</div>
|
64
|
-
<p>If you are the application owner check the logs for more information.</p>
|
65
|
-
</div>
|
66
|
-
</body>
|
67
|
-
</html>
|
data/spec/dummy/public/422.html
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>The change you wanted was rejected (422)</title>
|
5
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
-
<style>
|
7
|
-
body {
|
8
|
-
background-color: #EFEFEF;
|
9
|
-
color: #2E2F30;
|
10
|
-
text-align: center;
|
11
|
-
font-family: arial, sans-serif;
|
12
|
-
margin: 0;
|
13
|
-
}
|
14
|
-
|
15
|
-
div.dialog {
|
16
|
-
width: 95%;
|
17
|
-
max-width: 33em;
|
18
|
-
margin: 4em auto 0;
|
19
|
-
}
|
20
|
-
|
21
|
-
div.dialog > div {
|
22
|
-
border: 1px solid #CCC;
|
23
|
-
border-right-color: #999;
|
24
|
-
border-left-color: #999;
|
25
|
-
border-bottom-color: #BBB;
|
26
|
-
border-top: #B00100 solid 4px;
|
27
|
-
border-top-left-radius: 9px;
|
28
|
-
border-top-right-radius: 9px;
|
29
|
-
background-color: white;
|
30
|
-
padding: 7px 12% 0;
|
31
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
-
}
|
33
|
-
|
34
|
-
h1 {
|
35
|
-
font-size: 100%;
|
36
|
-
color: #730E15;
|
37
|
-
line-height: 1.5em;
|
38
|
-
}
|
39
|
-
|
40
|
-
div.dialog > p {
|
41
|
-
margin: 0 0 1em;
|
42
|
-
padding: 1em;
|
43
|
-
background-color: #F7F7F7;
|
44
|
-
border: 1px solid #CCC;
|
45
|
-
border-right-color: #999;
|
46
|
-
border-left-color: #999;
|
47
|
-
border-bottom-color: #999;
|
48
|
-
border-bottom-left-radius: 4px;
|
49
|
-
border-bottom-right-radius: 4px;
|
50
|
-
border-top-color: #DADADA;
|
51
|
-
color: #666;
|
52
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
-
}
|
54
|
-
</style>
|
55
|
-
</head>
|
56
|
-
|
57
|
-
<body>
|
58
|
-
<!-- This file lives in public/422.html -->
|
59
|
-
<div class="dialog">
|
60
|
-
<div>
|
61
|
-
<h1>The change you wanted was rejected.</h1>
|
62
|
-
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
-
</div>
|
64
|
-
<p>If you are the application owner check the logs for more information.</p>
|
65
|
-
</div>
|
66
|
-
</body>
|
67
|
-
</html>
|
data/spec/dummy/public/500.html
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>We're sorry, but something went wrong (500)</title>
|
5
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
-
<style>
|
7
|
-
body {
|
8
|
-
background-color: #EFEFEF;
|
9
|
-
color: #2E2F30;
|
10
|
-
text-align: center;
|
11
|
-
font-family: arial, sans-serif;
|
12
|
-
margin: 0;
|
13
|
-
}
|
14
|
-
|
15
|
-
div.dialog {
|
16
|
-
width: 95%;
|
17
|
-
max-width: 33em;
|
18
|
-
margin: 4em auto 0;
|
19
|
-
}
|
20
|
-
|
21
|
-
div.dialog > div {
|
22
|
-
border: 1px solid #CCC;
|
23
|
-
border-right-color: #999;
|
24
|
-
border-left-color: #999;
|
25
|
-
border-bottom-color: #BBB;
|
26
|
-
border-top: #B00100 solid 4px;
|
27
|
-
border-top-left-radius: 9px;
|
28
|
-
border-top-right-radius: 9px;
|
29
|
-
background-color: white;
|
30
|
-
padding: 7px 12% 0;
|
31
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
-
}
|
33
|
-
|
34
|
-
h1 {
|
35
|
-
font-size: 100%;
|
36
|
-
color: #730E15;
|
37
|
-
line-height: 1.5em;
|
38
|
-
}
|
39
|
-
|
40
|
-
div.dialog > p {
|
41
|
-
margin: 0 0 1em;
|
42
|
-
padding: 1em;
|
43
|
-
background-color: #F7F7F7;
|
44
|
-
border: 1px solid #CCC;
|
45
|
-
border-right-color: #999;
|
46
|
-
border-left-color: #999;
|
47
|
-
border-bottom-color: #999;
|
48
|
-
border-bottom-left-radius: 4px;
|
49
|
-
border-bottom-right-radius: 4px;
|
50
|
-
border-top-color: #DADADA;
|
51
|
-
color: #666;
|
52
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
-
}
|
54
|
-
</style>
|
55
|
-
</head>
|
56
|
-
|
57
|
-
<body>
|
58
|
-
<!-- This file lives in public/500.html -->
|
59
|
-
<div class="dialog">
|
60
|
-
<div>
|
61
|
-
<h1>We're sorry, but something went wrong.</h1>
|
62
|
-
</div>
|
63
|
-
<p>If you are the application owner check the logs for more information.</p>
|
64
|
-
</div>
|
65
|
-
</body>
|
66
|
-
</html>
|
File without changes
|
data/spec/factories/user.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
module OpenStax
|
4
|
-
module Utilities
|
5
|
-
|
6
|
-
describe AccessPolicy do
|
7
|
-
|
8
|
-
let!(:user) { FactoryGirl.create :user }
|
9
|
-
|
10
|
-
it 'responds to any _allowed? calls' do
|
11
|
-
AccessPolicy.register(User, DummyAccessPolicy)
|
12
|
-
|
13
|
-
DummyAccessPolicy.last_action = nil
|
14
|
-
DummyAccessPolicy.last_requestor = nil
|
15
|
-
DummyAccessPolicy.last_resource = nil
|
16
|
-
|
17
|
-
expect(AccessPolicy.respond_to? :wacky_allowed?).to eq(true)
|
18
|
-
expect(AccessPolicy.wacky_allowed?(user, user)).to eq(true)
|
19
|
-
|
20
|
-
expect(DummyAccessPolicy.last_action).to eq(:wacky)
|
21
|
-
expect(DummyAccessPolicy.last_requestor).to eq(user)
|
22
|
-
expect(DummyAccessPolicy.last_resource).to eq(user)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'delegates checks to policy classes based on resource class' do
|
26
|
-
dummy_object = double('Dummy')
|
27
|
-
dummy_policy = double('Dummy Policy', :action_allowed? => true)
|
28
|
-
|
29
|
-
AccessPolicy.register(User, DummyAccessPolicy)
|
30
|
-
AccessPolicy.register(dummy_object.class, dummy_policy)
|
31
|
-
|
32
|
-
DummyAccessPolicy.last_action = nil
|
33
|
-
DummyAccessPolicy.last_requestor = nil
|
34
|
-
DummyAccessPolicy.last_resource = nil
|
35
|
-
|
36
|
-
expect(AccessPolicy.action_allowed?(:read, user, dummy_object)).to(
|
37
|
-
eq(true))
|
38
|
-
|
39
|
-
expect{AccessPolicy.require_action_allowed!(:read, user, dummy_object)
|
40
|
-
}.not_to raise_error
|
41
|
-
|
42
|
-
expect(DummyAccessPolicy.last_action).to be_nil
|
43
|
-
expect(DummyAccessPolicy.last_requestor).to be_nil
|
44
|
-
expect(DummyAccessPolicy.last_resource).to be_nil
|
45
|
-
|
46
|
-
expect(AccessPolicy.action_allowed?(:create, user, User.new)).to(
|
47
|
-
eq(true))
|
48
|
-
|
49
|
-
expect{AccessPolicy.require_action_allowed!(:create, user, User.new)
|
50
|
-
}.not_to raise_error
|
51
|
-
|
52
|
-
expect(DummyAccessPolicy.last_action).to eq(:create)
|
53
|
-
expect(DummyAccessPolicy.last_requestor).to eq(user)
|
54
|
-
expect(DummyAccessPolicy.last_resource).to be_instance_of(User)
|
55
|
-
expect(DummyAccessPolicy.last_resource.id).to be_nil
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'denies permission if the policy class is not registered' do
|
59
|
-
expect(OSU::AccessPolicy.action_allowed?(:destroy, user, Object)).to eq(false)
|
60
|
-
|
61
|
-
expect{OSU::AccessPolicy.require_action_allowed!(:destroy, user, Object)}.to raise_error(SecurityTransgression)
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
data/spec/rails_helper.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
ENV["RAILS_ENV"] ||= 'test'
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require File.expand_path("../dummy/config/environment", __FILE__)
|
5
|
-
require 'rspec/rails'
|
6
|
-
require 'factory_girl_rails'
|
7
|
-
require 'faker'
|
8
|
-
require 'squeel'
|
9
|
-
|
10
|
-
# Add additional requires below this line. Rails is not loaded until this point!
|
11
|
-
|
12
|
-
# Requires supporting ruby files with custom matchers and macros, etc, in
|
13
|
-
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
14
|
-
# run as spec files by default. This means that files in spec/support that end
|
15
|
-
# in _spec.rb will both be required and run as specs, causing the specs to be
|
16
|
-
# run twice. It is recommended that you do not name files matching this glob to
|
17
|
-
# end with _spec.rb. You can configure this pattern with the --pattern
|
18
|
-
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
19
|
-
#
|
20
|
-
# The following line is provided for convenience purposes. It has the downside
|
21
|
-
# of increasing the boot-up time by auto-requiring all files in the support
|
22
|
-
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
23
|
-
# require only the support files necessary.
|
24
|
-
#
|
25
|
-
# Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
26
|
-
|
27
|
-
# Checks for pending migrations before tests are run.
|
28
|
-
# If you are not using ActiveRecord, you can remove this line.
|
29
|
-
ActiveRecord::Migration.maintain_test_schema!
|
30
|
-
|
31
|
-
RSpec.configure do |config|
|
32
|
-
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
33
|
-
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
34
|
-
|
35
|
-
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
36
|
-
# examples within a transaction, remove the following line or assign false
|
37
|
-
# instead of true.
|
38
|
-
# config.use_transactional_fixtures = true
|
39
|
-
|
40
|
-
# RSpec Rails can automatically mix in different behaviours to your tests
|
41
|
-
# based on their file location, for example enabling you to call `get` and
|
42
|
-
# `post` in specs under `spec/controllers`.
|
43
|
-
#
|
44
|
-
# You can disable this behaviour by removing the line below, and instead
|
45
|
-
# explicitly tag your specs with their type, e.g.:
|
46
|
-
#
|
47
|
-
# RSpec.describe UsersController, :type => :controller do
|
48
|
-
# # ...
|
49
|
-
# end
|
50
|
-
#
|
51
|
-
# The different available types are documented in the features, such as in
|
52
|
-
# https://relishapp.com/rspec/rspec-rails/docs
|
53
|
-
config.infer_spec_type_from_file_location!
|
54
|
-
end
|
@@ -1,72 +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.unscoped
|
25
|
-
end
|
26
|
-
|
27
|
-
it "returns nothing if too many results" do
|
28
|
-
routine = LimitAndPaginateRelation.call(relation: @relation,
|
29
|
-
max_items: 10)
|
30
|
-
outputs = routine.outputs
|
31
|
-
errors = routine.errors
|
32
|
-
expect(outputs).not_to be_empty
|
33
|
-
expect(outputs[:total_count]).to eq User.count
|
34
|
-
expect(outputs[:items]).to be_empty
|
35
|
-
expect(errors).not_to be_empty
|
36
|
-
expect(errors.first.code).to eq :too_many_items
|
37
|
-
end
|
38
|
-
|
39
|
-
it "paginates results" do
|
40
|
-
all_items = @relation.to_a
|
41
|
-
|
42
|
-
items = LimitAndPaginateRelation.call(relation: @relation,
|
43
|
-
per_page: 20).outputs[:items]
|
44
|
-
expect(items.limit(nil).offset(nil).count).to eq all_items.count
|
45
|
-
expect(items.limit(nil).offset(nil).to_a).to eq all_items
|
46
|
-
expect(items.count).to eq 20
|
47
|
-
expect(items.to_a).to eq all_items[0..19]
|
48
|
-
|
49
|
-
for page in 1..5
|
50
|
-
items = LimitAndPaginateRelation.call(relation: @relation,
|
51
|
-
page: page,
|
52
|
-
per_page: 20)
|
53
|
-
.outputs[:items]
|
54
|
-
expect(items.limit(nil).offset(nil).count).to eq all_items.count
|
55
|
-
expect(items.limit(nil).offset(nil).to_a).to eq all_items
|
56
|
-
expect(items.count).to eq 20
|
57
|
-
expect(items.to_a).to eq all_items.slice(20*(page-1), 20)
|
58
|
-
end
|
59
|
-
|
60
|
-
items = LimitAndPaginateRelation.call(relation: @relation,
|
61
|
-
page: 1000,
|
62
|
-
per_page: 20)
|
63
|
-
.outputs[:items]
|
64
|
-
expect(items.limit(nil).offset(nil).count).to eq all_items.count
|
65
|
-
expect(items.limit(nil).offset(nil).to_a).to eq all_items
|
66
|
-
expect(items.count).to eq 0
|
67
|
-
expect(items.to_a).to be_empty
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|