wor-simple_crud 0.2.1 → 0.3.1
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/.gitignore +5 -0
- data/CHANGELOG.md +46 -0
- data/Gemfile +1 -0
- data/README.md +200 -2
- data/lib/simple_crud/action_lambdas.rb +81 -0
- data/lib/simple_crud/authorization/adapter.rb +7 -0
- data/lib/simple_crud/authorization/pundit_adapter.rb +6 -0
- data/lib/simple_crud/config.rb +6 -1
- data/lib/simple_crud/controller_helpers.rb +128 -0
- data/lib/simple_crud/pagination/adapter.rb +7 -1
- data/lib/simple_crud/pagination/kaminari_adapter.rb +23 -2
- data/lib/simple_crud/pagination/pagy_adapter.rb +7 -2
- data/lib/simple_crud/pagination/will_paginate_adapter.rb +7 -3
- data/lib/simple_crud/pagination/wor_paginate_adapter.rb +7 -2
- data/lib/simple_crud/rspec/config.rb +74 -0
- data/lib/simple_crud/rspec/helpers/authentication.rb +32 -0
- data/lib/simple_crud/rspec/helpers/controller_options.rb +19 -0
- data/lib/simple_crud/rspec/helpers/models.rb +55 -0
- data/lib/simple_crud/rspec/helpers/policies.rb +25 -0
- data/lib/simple_crud/rspec/helpers/requests.rb +45 -0
- data/lib/simple_crud/rspec/helpers/settings.rb +49 -0
- data/lib/simple_crud/rspec/helpers.rb +25 -0
- data/lib/simple_crud/rspec.rb +35 -0
- data/lib/simple_crud/simple_crud_controller.rb +27 -75
- data/lib/simple_crud/version.rb +1 -1
- data/lib/spec/shared_contexts/authenticate_user.rb +1 -7
- data/lib/spec/shared_examples/authorization_adapter_authorize.rb +11 -0
- data/lib/spec/shared_examples/simple_crud_for_create.rb +46 -11
- data/lib/spec/shared_examples/simple_crud_for_create_with_block.rb +36 -0
- data/lib/spec/shared_examples/simple_crud_for_create_with_build.rb +15 -0
- data/lib/spec/shared_examples/simple_crud_for_destroy.rb +44 -8
- data/lib/spec/shared_examples/simple_crud_for_destroy_with_block.rb +21 -0
- data/lib/spec/shared_examples/simple_crud_for_destroy_with_finder.rb +35 -0
- data/lib/spec/shared_examples/simple_crud_for_edit.rb +79 -0
- data/lib/spec/shared_examples/simple_crud_for_index.rb +9 -24
- data/lib/spec/shared_examples/simple_crud_for_index_with_block.rb +22 -0
- data/lib/spec/shared_examples/simple_crud_for_index_with_scope.rb +33 -0
- data/lib/spec/shared_examples/simple_crud_for_new.rb +29 -0
- data/lib/spec/shared_examples/simple_crud_for_new_with_block.rb +20 -0
- data/lib/spec/shared_examples/simple_crud_for_new_with_build.rb +19 -0
- data/lib/spec/shared_examples/simple_crud_for_show.rb +14 -10
- data/lib/spec/shared_examples/simple_crud_for_show_with_block.rb +22 -0
- data/lib/spec/shared_examples/simple_crud_for_show_with_finder.rb +33 -0
- data/lib/spec/shared_examples/simple_crud_for_update.rb +61 -14
- data/lib/spec/shared_examples/simple_crud_for_update_with_finder.rb +39 -0
- data/lib/spec/shared_examples/simple_crud_not_found_with_finder.rb +14 -0
- data/lib/spec/shared_examples/simple_crud_renders_template.rb +8 -0
- data/lib/spec/shared_examples/simple_crud_when_not_authorized.rb +18 -0
- data/lib/spec/shared_examples/simple_crud_without_authenticated_user.rb +9 -0
- data/lib/spec/shared_examples/unauthorized_when_not_logged_in.rb +2 -2
- data/spec/block/dummy_models_controller_spec.rb +8 -0
- data/spec/block_create/dummy_models_controller_spec.rb +7 -0
- data/spec/block_destroy/dummy_models_controller_spec.rb +7 -0
- data/spec/block_finder/dummy_models_controller_spec.rb +10 -0
- data/spec/block_json/dummy_models_controller_spec.rb +9 -0
- data/spec/block_new/dummy_models_controller_spec.rb +7 -0
- data/spec/block_redirect/dummy_models_controller_spec.rb +7 -0
- data/spec/block_show/dummy_models_controller_spec.rb +7 -0
- data/spec/built/dummy_models_controller_spec.rb +8 -0
- data/spec/dummy/app/controllers/block/dummy_models_controller.rb +17 -0
- data/spec/dummy/app/controllers/block_create/dummy_models_controller.rb +13 -0
- data/spec/dummy/app/controllers/block_destroy/dummy_models_controller.rb +9 -0
- data/spec/dummy/app/controllers/block_finder/dummy_models_controller.rb +25 -0
- data/spec/dummy/app/controllers/block_json/dummy_models_controller.rb +17 -0
- data/spec/dummy/app/controllers/block_modes/base_controller.rb +11 -0
- data/spec/dummy/app/controllers/block_new/dummy_models_controller.rb +9 -0
- data/spec/dummy/app/controllers/block_redirect/dummy_models_controller.rb +13 -0
- data/spec/dummy/app/controllers/block_show/dummy_models_controller.rb +9 -0
- data/spec/dummy/app/controllers/built/dummy_models_controller.rb +21 -0
- data/spec/dummy/app/controllers/dummy_models_controller.rb +2 -1
- data/spec/dummy/app/controllers/finder/dummy_models_controller.rb +23 -0
- data/spec/dummy/app/controllers/html/dummy_models_controller.rb +7 -0
- data/spec/dummy/app/controllers/html_create/dummy_models_controller.rb +7 -0
- data/spec/dummy/app/controllers/html_destroy/dummy_models_controller.rb +7 -0
- data/spec/dummy/app/controllers/html_finder/dummy_models_controller.rb +17 -0
- data/spec/dummy/app/controllers/html_modes/base_controller.rb +17 -0
- data/spec/dummy/app/controllers/html_new/dummy_models_controller.rb +7 -0
- data/spec/dummy/app/controllers/html_scoped/dummy_models_controller.rb +8 -0
- data/spec/dummy/app/controllers/html_show/dummy_models_controller.rb +7 -0
- data/spec/dummy/app/controllers/html_update/dummy_models_controller.rb +7 -0
- data/spec/dummy/app/controllers/invalid_status/dummy_models_controller.rb +13 -0
- data/spec/dummy/app/controllers/nested/dummy_models_controller.rb +21 -0
- data/spec/dummy/app/controllers/nested_route/dummy_models_controller.rb +26 -0
- data/spec/dummy/app/controllers/redirect/dummy_models_controller.rb +10 -0
- data/spec/dummy/app/controllers/redirect_auth/dummy_models_controller.rb +28 -0
- data/spec/dummy/app/controllers/scoped/dummy_models_controller.rb +16 -0
- data/spec/dummy/app/controllers/scoped_params/dummy_models_controller.rb +16 -0
- data/spec/dummy/app/controllers/strict/dummy_models_controller.rb +21 -0
- data/spec/dummy/app/controllers/unpaginated_scoped/dummy_models_controller.rb +16 -0
- data/spec/dummy/app/models/dummy_model.rb +4 -0
- data/spec/dummy/app/models/dummy_model_policy.rb +9 -1
- data/spec/dummy/app/views/block/dummy_models/index.html.erb +3 -0
- data/spec/dummy/app/views/block_new/dummy_models/new.html.erb +1 -0
- data/spec/dummy/app/views/block_show/dummy_models/show.html.erb +1 -0
- data/spec/dummy/app/views/html/dummy_models/index.html.erb +3 -0
- data/spec/dummy/app/views/html_create/dummy_models/new.html.erb +1 -0
- data/spec/dummy/app/views/html_destroy/dummy_models/show.html.erb +1 -0
- data/spec/dummy/app/views/html_finder/dummy_models/edit.html.erb +1 -0
- data/spec/dummy/app/views/html_finder/dummy_models/new.html.erb +1 -0
- data/spec/dummy/app/views/html_finder/dummy_models/show.html.erb +1 -0
- data/spec/dummy/app/views/html_new/dummy_models/new.html.erb +1 -0
- data/spec/dummy/app/views/html_scoped/dummy_models/index.html.erb +3 -0
- data/spec/dummy/app/views/html_show/dummy_models/show.html.erb +1 -0
- data/spec/dummy/app/views/html_update/dummy_models/edit.html.erb +1 -0
- data/spec/dummy/app/views/invalid_status/dummy_models/new.html.erb +1 -0
- data/spec/dummy/app/views/layouts/application.html.erb +4 -0
- data/spec/dummy/app/views/redirect/dummy_models/new.html.erb +1 -0
- data/spec/dummy/config/routes.rb +110 -0
- data/spec/dummy/db/migrate/20260806000000_add_slug_to_dummy_models.rb +7 -0
- data/spec/dummy/db/migrate/20260807000000_add_classroom_slug_to_dummy_models.rb +7 -0
- data/spec/dummy/db/schema.rb +3 -1
- data/spec/dummy/spec/factories/dummy_models.rb +1 -0
- data/spec/dummy_controller_spec.rb +1 -0
- data/spec/dummy_model_policy_spec.rb +6 -4
- data/spec/finder/dummy_models_controller_spec.rb +13 -0
- data/spec/html/dummy_models_controller_spec.rb +7 -0
- data/spec/html_create/dummy_models_controller_spec.rb +7 -0
- data/spec/html_destroy/dummy_models_controller_spec.rb +7 -0
- data/spec/html_finder/dummy_models_controller_spec.rb +11 -0
- data/spec/html_new/dummy_models_controller_spec.rb +7 -0
- data/spec/html_scoped/dummy_models_controller_spec.rb +7 -0
- data/spec/html_show/dummy_models_controller_spec.rb +7 -0
- data/spec/html_update/dummy_models_controller_spec.rb +7 -0
- data/spec/invalid_status/dummy_models_controller_spec.rb +10 -0
- data/spec/nested/dummy_models_controller_spec.rb +12 -0
- data/spec/nested_route/dummy_models_controller_spec.rb +19 -0
- data/spec/redirect/dummy_models_controller_spec.rb +23 -0
- data/spec/redirect_auth/dummy_models_controller_spec.rb +11 -0
- data/spec/scoped/dummy_models_controller_spec.rb +7 -0
- data/spec/scoped_params/dummy_models_controller_spec.rb +12 -0
- data/spec/simple_crud/authorization/action_policy_adapter_spec.rb +1 -9
- data/spec/simple_crud/authorization/can_can_can_adapter_spec.rb +1 -7
- data/spec/simple_crud/authorization/pundit_adapter_spec.rb +41 -0
- data/spec/simple_crud/controller_helpers_spec.rb +49 -0
- data/spec/simple_crud/pagination/adapters_spec.rb +37 -13
- data/spec/simple_crud/rspec_config_spec.rb +100 -0
- data/spec/simple_crud_configuration_spec.rb +19 -16
- data/spec/simple_crud_controller_spec.rb +4 -4
- data/spec/spec_helper.rb +1 -0
- data/spec/strict/dummy_models_controller_spec.rb +23 -0
- data/spec/unpaginated_scoped/dummy_models_controller_spec.rb +7 -0
- metadata +108 -4
- data/lib/spec/shared_examples/helpers.rb +0 -50
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module NestedRoute
|
|
4
|
+
class DummyModelsController < ApplicationController
|
|
5
|
+
include Wor::Paginate
|
|
6
|
+
include Pundit::Authorization
|
|
7
|
+
extend SimpleCrudController
|
|
8
|
+
|
|
9
|
+
before_action :set_params
|
|
10
|
+
def set_params
|
|
11
|
+
SimpleCrudController.params = params
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def dummy_model_params
|
|
15
|
+
params.require(:dummy_model).permit(:name, :something, :user_id, :slug, :classroom_slug)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
NESTED_FINDER = lambda do |params|
|
|
19
|
+
DummyModel.find_by!(classroom_slug: params[:classroom_slug], slug: params[:slug])
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
simple_crud_for :show, finder: NESTED_FINDER
|
|
23
|
+
simple_crud_for :destroy, finder: NESTED_FINDER
|
|
24
|
+
simple_crud_for :create
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Redirect
|
|
4
|
+
class DummyModelsController < HtmlModes::BaseController
|
|
5
|
+
simple_crud_for :create, html: true, authenticate: false, authorize: false,
|
|
6
|
+
redirect: ->(_record) { dummy_models_path }
|
|
7
|
+
simple_crud_for :destroy, html: true, authenticate: false, authorize: false,
|
|
8
|
+
redirect: '/block_new/dummy_models/new'
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RedirectAuth
|
|
4
|
+
class UnauthenticatedError < StandardError; end
|
|
5
|
+
|
|
6
|
+
class DummyModelsController < ApplicationController
|
|
7
|
+
include Wor::Paginate
|
|
8
|
+
include Pundit::Authorization
|
|
9
|
+
extend SimpleCrudController
|
|
10
|
+
|
|
11
|
+
rescue_from UnauthenticatedError, with: :redirect_to_login
|
|
12
|
+
|
|
13
|
+
before_action :set_params
|
|
14
|
+
def set_params
|
|
15
|
+
SimpleCrudController.params = params
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def authenticate_user!
|
|
19
|
+
raise UnauthenticatedError unless current_user
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def redirect_to_login(_exception)
|
|
23
|
+
redirect_to '/login'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
simple_crud_for :index, authorize: false
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Scoped
|
|
4
|
+
class DummyModelsController < ApplicationController
|
|
5
|
+
include Wor::Paginate
|
|
6
|
+
include Pundit::Authorization
|
|
7
|
+
extend SimpleCrudController
|
|
8
|
+
|
|
9
|
+
before_action :set_params
|
|
10
|
+
def set_params
|
|
11
|
+
SimpleCrudController.params = params
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
simple_crud_for :index, scope: ->(user) { DummyModel.where(user: user) }
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ScopedParams
|
|
4
|
+
class DummyModelsController < ApplicationController
|
|
5
|
+
include Wor::Paginate
|
|
6
|
+
include Pundit::Authorization
|
|
7
|
+
extend SimpleCrudController
|
|
8
|
+
|
|
9
|
+
before_action :set_params
|
|
10
|
+
def set_params
|
|
11
|
+
SimpleCrudController.params = params
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
simple_crud_for :index, scope: ->(user, params) { DummyModel.where(user: user, something: params[:something]) }
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Strict
|
|
4
|
+
class DummyModelsController < ApplicationController
|
|
5
|
+
include Wor::Paginate
|
|
6
|
+
include Pundit::Authorization
|
|
7
|
+
extend SimpleCrudController
|
|
8
|
+
|
|
9
|
+
before_action :set_params
|
|
10
|
+
def set_params
|
|
11
|
+
SimpleCrudController.params = params
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def dummy_model_params
|
|
15
|
+
params.permit(:name, :something, :user_id, :slug)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
simple_crud_for :create, raise_on_invalid: true
|
|
19
|
+
simple_crud_for :update, raise_on_invalid: true
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module UnpaginatedScoped
|
|
4
|
+
class DummyModelsController < ApplicationController
|
|
5
|
+
include Wor::Paginate
|
|
6
|
+
include Pundit::Authorization
|
|
7
|
+
extend SimpleCrudController
|
|
8
|
+
|
|
9
|
+
before_action :set_params
|
|
10
|
+
def set_params
|
|
11
|
+
SimpleCrudController.params = params
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
simple_crud_for :index, paginate: false, scope: ->(user) { DummyModel.where(user: user) }
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -20,15 +20,23 @@ class DummyModelPolicy
|
|
|
20
20
|
check_user
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
def edit?
|
|
24
|
+
update?
|
|
25
|
+
end
|
|
26
|
+
|
|
23
27
|
def create?
|
|
24
28
|
check_user
|
|
25
29
|
end
|
|
26
30
|
|
|
31
|
+
def new?
|
|
32
|
+
check_user
|
|
33
|
+
end
|
|
34
|
+
|
|
27
35
|
def destroy?
|
|
28
36
|
check_user
|
|
29
37
|
end
|
|
30
38
|
|
|
31
39
|
def index?
|
|
32
|
-
|
|
40
|
+
user.present?
|
|
33
41
|
end
|
|
34
42
|
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<span class="record">new <%= model.new_record? %></span>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<span class="record"><%= model.name %></span>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<span class="record">errors: <%= @record.errors.full_messages.join(',') %></span>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<span class="record"><%= @record.name %></span>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<h1>Edit dummy model</h1>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<h1>New dummy model</h1>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<span class="record"><%= @record.name %></span>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<span class="record">new <%= @record.new_record? %></span>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<span class="record"><%= @record.name %></span>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<span class="record">errors: <%= @record.errors.full_messages.join(',') %></span>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<span class="record">errors: <%= @record.errors.full_messages.join(',') %></span>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
New
|
data/spec/dummy/config/routes.rb
CHANGED
|
@@ -7,4 +7,114 @@ Rails.application.routes.draw do
|
|
|
7
7
|
namespace :without_pagination do
|
|
8
8
|
resources :dummy_models, only: :index
|
|
9
9
|
end
|
|
10
|
+
|
|
11
|
+
namespace :html do
|
|
12
|
+
resources :dummy_models, only: :index
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
namespace :block do
|
|
16
|
+
resources :dummy_models, only: :index
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
namespace :finder do
|
|
20
|
+
resources :dummy_models, only: %i[show edit update destroy], param: :slug
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
namespace :html_finder do
|
|
24
|
+
resources :dummy_models, only: %i[new show edit update destroy], param: :slug
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
namespace :block_finder do
|
|
28
|
+
resources :dummy_models, only: %i[show edit update destroy], param: :slug
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
namespace :scoped do
|
|
32
|
+
resources :dummy_models, only: :index
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
namespace :unpaginated_scoped do
|
|
36
|
+
resources :dummy_models, only: :index
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
namespace :scoped_params do
|
|
40
|
+
resources :dummy_models, only: :index
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
namespace :strict do
|
|
44
|
+
resources :dummy_models, only: %i[create update]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
namespace :html_show do
|
|
48
|
+
resources :dummy_models, only: :show
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
namespace :block_show do
|
|
52
|
+
resources :dummy_models, only: :show
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
namespace :html_new do
|
|
56
|
+
resources :dummy_models, only: :new
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
namespace :block_new do
|
|
60
|
+
resources :dummy_models, only: :new
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
namespace :html_create do
|
|
64
|
+
resources :dummy_models, only: :create
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
namespace :redirect do
|
|
68
|
+
resources :dummy_models, only: %i[create destroy]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
namespace :block_create do
|
|
72
|
+
resources :dummy_models, only: :create
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
namespace :html_update do
|
|
76
|
+
resources :dummy_models, only: :update
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
namespace :html_destroy do
|
|
80
|
+
resources :dummy_models, only: :destroy
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
namespace :block_destroy do
|
|
84
|
+
resources :dummy_models, only: :destroy
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
namespace :block_redirect do
|
|
88
|
+
resources :dummy_models, only: %i[show destroy]
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
namespace :block_json do
|
|
92
|
+
resources :dummy_models, only: %i[index show new]
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
namespace :built do
|
|
96
|
+
resources :dummy_models, only: %i[new create]
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
namespace :redirect_auth do
|
|
100
|
+
resources :dummy_models, only: :index
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
namespace :html_scoped do
|
|
104
|
+
resources :dummy_models, only: :index
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
namespace :nested do
|
|
108
|
+
resources :dummy_models, only: %i[create update]
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
namespace :invalid_status do
|
|
112
|
+
resources :dummy_models, only: :create
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
namespace :nested_route do
|
|
116
|
+
resources :classrooms, only: [], param: :slug do
|
|
117
|
+
resources :dummy_models, param: :slug, only: %i[show create destroy]
|
|
118
|
+
end
|
|
119
|
+
end
|
|
10
120
|
end
|
data/spec/dummy/db/schema.rb
CHANGED
|
@@ -12,9 +12,11 @@
|
|
|
12
12
|
#
|
|
13
13
|
# It's strongly recommended that you check this file into your version control system.
|
|
14
14
|
|
|
15
|
-
ActiveRecord::Schema.define(version:
|
|
15
|
+
ActiveRecord::Schema.define(version: 20_260_807_000_000) do
|
|
16
16
|
create_table 'dummy_models', force: :cascade do |t|
|
|
17
17
|
t.string 'name'
|
|
18
|
+
t.string 'slug'
|
|
19
|
+
t.string 'classroom_slug'
|
|
18
20
|
t.integer 'something'
|
|
19
21
|
t.integer 'user_id'
|
|
20
22
|
t.index ['user_id'], name: 'index_dummy_models_on_user_id'
|
|
@@ -7,6 +7,7 @@ describe DummyModelsController, type: :controller do
|
|
|
7
7
|
include_examples 'simple crud for create'
|
|
8
8
|
include_examples 'simple crud for index'
|
|
9
9
|
include_examples 'simple crud for destroy'
|
|
10
|
+
include_examples 'simple crud for new'
|
|
10
11
|
|
|
11
12
|
describe 'POST #create with invalid attributes' do
|
|
12
13
|
include_context 'with authenticated user'
|
|
@@ -17,13 +17,15 @@ describe DummyModelPolicy do
|
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
+
# :index authorizes the model class, not an instance, so the policy can
|
|
21
|
+
# only reason about the user.
|
|
20
22
|
describe '#index?' do
|
|
21
|
-
it 'allows
|
|
22
|
-
expect(described_class.new(
|
|
23
|
+
it 'allows any signed-in user' do
|
|
24
|
+
expect(described_class.new(other_user, dummy_model).index?).to be true
|
|
23
25
|
end
|
|
24
26
|
|
|
25
|
-
it 'denies
|
|
26
|
-
expect(described_class.new(
|
|
27
|
+
it 'denies an anonymous user' do
|
|
28
|
+
expect(described_class.new(nil, dummy_model).index?).to be false
|
|
27
29
|
end
|
|
28
30
|
end
|
|
29
31
|
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Finder::DummyModelsController, type: :controller do
|
|
6
|
+
include_examples 'simple crud for edit'
|
|
7
|
+
include_examples 'simple crud for show with finder'
|
|
8
|
+
include_examples 'simple crud for update with finder'
|
|
9
|
+
include_examples 'simple crud for destroy with finder'
|
|
10
|
+
include_examples 'simple crud for show'
|
|
11
|
+
include_examples 'simple crud for update'
|
|
12
|
+
include_examples 'simple crud for destroy'
|
|
13
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe HtmlFinder::DummyModelsController, type: :controller do
|
|
6
|
+
include_examples 'simple crud for edit'
|
|
7
|
+
include_examples 'simple crud for show with finder'
|
|
8
|
+
include_examples 'simple crud for update with finder'
|
|
9
|
+
include_examples 'simple crud for destroy with finder'
|
|
10
|
+
include_examples 'simple crud for new with build'
|
|
11
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe InvalidStatus::DummyModelsController, type: :controller do
|
|
6
|
+
before { SimpleCrud::RSpec.configure { |c| c.invalid_status = 422 } }
|
|
7
|
+
after { SimpleCrud::RSpec.configure { |c| c.invalid_status = :ok } }
|
|
8
|
+
|
|
9
|
+
include_examples 'simple crud for create'
|
|
10
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Nested::DummyModelsController, type: :controller do
|
|
6
|
+
around do |example|
|
|
7
|
+
with_config_override(:params_key, :dummy_model) { example.run }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
include_examples 'simple crud for create'
|
|
11
|
+
include_examples 'simple crud for update'
|
|
12
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe NestedRoute::DummyModelsController, type: :controller do
|
|
6
|
+
let(:model_attributes) { { classroom_slug: 'room-1', user: current_user } }
|
|
7
|
+
|
|
8
|
+
around do |example|
|
|
9
|
+
with_config_override(:route_params, -> { { classroom_slug: 'room-1' } }) do
|
|
10
|
+
with_config_override(:params_key, :dummy_model) do
|
|
11
|
+
example.run
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
include_examples 'simple crud for show'
|
|
17
|
+
include_examples 'simple crud for create'
|
|
18
|
+
include_examples 'simple crud for destroy'
|
|
19
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Redirect::DummyModelsController, type: :controller do
|
|
6
|
+
describe 'POST #create' do
|
|
7
|
+
it 'redirects to the target resolved from the redirect proc' do
|
|
8
|
+
post :create, params: attributes_for(:dummy_model).merge(user_id: create(:user).id), format: :html
|
|
9
|
+
|
|
10
|
+
expect(response).to redirect_to(dummy_models_path)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe 'DELETE #destroy' do
|
|
15
|
+
it 'redirects to the literal redirect path' do
|
|
16
|
+
record = create(:dummy_model)
|
|
17
|
+
|
|
18
|
+
delete :destroy, params: { id: record.id }, format: :html
|
|
19
|
+
|
|
20
|
+
expect(response).to redirect_to('/block_new/dummy_models/new')
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe RedirectAuth::DummyModelsController, type: :controller do
|
|
6
|
+
around do |example|
|
|
7
|
+
with_config_override(:unauthenticated_status, :found) { example.run }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
include_examples 'simple crud for index'
|
|
11
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe ScopedParams::DummyModelsController, simple_crud: {
|
|
6
|
+
scoped_attributes: -> { { user: current_user, something: 42 } },
|
|
7
|
+
other_scoped_attributes: -> { { user: other_user, something: 7 } }
|
|
8
|
+
}, type: :controller do
|
|
9
|
+
include_examples 'simple crud for index with scope' do
|
|
10
|
+
let(:request_params) { { something: 42 } }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -35,15 +35,7 @@ describe SimpleCrud::Authorization::ActionPolicyAdapter do
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
describe '#authorize' do
|
|
38
|
-
|
|
39
|
-
expect { adapter.authorize(controller, ActionPolicyTestRecord.new(1)) }.not_to raise_error
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it 'raises for a record the policy denies' do
|
|
43
|
-
expect do
|
|
44
|
-
adapter.authorize(controller, ActionPolicyTestRecord.new(2))
|
|
45
|
-
end.to raise_error(ActionPolicy::Unauthorized)
|
|
46
|
-
end
|
|
38
|
+
include_examples 'authorization adapter #authorize', ActionPolicyTestRecord, ActionPolicy::Unauthorized
|
|
47
39
|
end
|
|
48
40
|
|
|
49
41
|
describe '#policy_defined?' do
|
|
@@ -36,13 +36,7 @@ describe SimpleCrud::Authorization::CanCanCanAdapter do
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
describe '#authorize' do
|
|
39
|
-
|
|
40
|
-
expect { adapter.authorize(controller, CanCanCanTestRecord.new(1)) }.not_to raise_error
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it 'raises for a record the ability denies' do
|
|
44
|
-
expect { adapter.authorize(controller, CanCanCanTestRecord.new(2)) }.to raise_error(CanCan::AccessDenied)
|
|
45
|
-
end
|
|
39
|
+
include_examples 'authorization adapter #authorize', CanCanCanTestRecord, CanCan::AccessDenied
|
|
46
40
|
end
|
|
47
41
|
|
|
48
42
|
describe '#policy_defined?' do
|