wor-simple_crud 0.2.1 → 0.3.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 +4 -4
- data/CHANGELOG.md +32 -0
- data/Gemfile +1 -0
- data/README.md +157 -2
- 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 +119 -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 +61 -0
- data/lib/simple_crud/rspec/helpers.rb +147 -0
- data/lib/simple_crud/rspec.rb +34 -0
- data/lib/simple_crud/simple_crud_controller.rb +51 -36
- 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 +43 -11
- data/lib/spec/shared_examples/simple_crud_for_create_with_block.rb +18 -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 +19 -8
- data/lib/spec/shared_examples/simple_crud_for_destroy_with_block.rb +13 -0
- data/lib/spec/shared_examples/simple_crud_for_destroy_with_finder.rb +24 -0
- data/lib/spec/shared_examples/simple_crud_for_index.rb +8 -23
- data/lib/spec/shared_examples/simple_crud_for_index_with_block.rb +14 -0
- data/lib/spec/shared_examples/simple_crud_for_index_with_scope.rb +21 -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 +9 -0
- data/lib/spec/shared_examples/simple_crud_for_new_with_build.rb +13 -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 +11 -0
- data/lib/spec/shared_examples/simple_crud_for_show_with_finder.rb +24 -0
- data/lib/spec/shared_examples/simple_crud_for_update.rb +55 -15
- data/lib/spec/shared_examples/simple_crud_for_update_with_finder.rb +29 -0
- data/lib/spec/shared_examples/simple_crud_not_found_with_finder.rb +13 -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_new/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_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_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 +22 -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_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/models/dummy_model.rb +4 -0
- data/spec/dummy/app/models/dummy_model_policy.rb +4 -0
- 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_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 +90 -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 +8 -16
- data/spec/finder/dummy_models_controller_spec.rb +12 -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_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 +11 -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 +67 -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
- metadata +87 -4
- data/lib/spec/shared_examples/helpers.rb +0 -50
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module HtmlModes
|
|
4
|
+
class BaseController < ApplicationController
|
|
5
|
+
include Wor::Paginate
|
|
6
|
+
extend SimpleCrudController
|
|
7
|
+
|
|
8
|
+
before_action :set_params
|
|
9
|
+
def set_params
|
|
10
|
+
SimpleCrudController.params = params
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def dummy_model_params
|
|
14
|
+
params.permit(:name, :something, :user_id, :slug)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module InvalidStatus
|
|
4
|
+
class DummyModelsController < HtmlModes::BaseController
|
|
5
|
+
simple_crud_for :create, authenticate: false, authorize: false do |record, saved|
|
|
6
|
+
if saved
|
|
7
|
+
redirect_to(record)
|
|
8
|
+
else
|
|
9
|
+
render :new, status: 422
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nested
|
|
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)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
simple_crud_for :create
|
|
19
|
+
simple_crud_for :update
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -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 @@
|
|
|
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
|
+
<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,94 @@ 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 update destroy], param: :slug
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
namespace :scoped do
|
|
24
|
+
resources :dummy_models, only: :index
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
namespace :scoped_params do
|
|
28
|
+
resources :dummy_models, only: :index
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
namespace :strict do
|
|
32
|
+
resources :dummy_models, only: %i[create update]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
namespace :html_show do
|
|
36
|
+
resources :dummy_models, only: :show
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
namespace :block_show do
|
|
40
|
+
resources :dummy_models, only: :show
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
namespace :html_new do
|
|
44
|
+
resources :dummy_models, only: :new
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
namespace :block_new do
|
|
48
|
+
resources :dummy_models, only: :new
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
namespace :html_create do
|
|
52
|
+
resources :dummy_models, only: :create
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
namespace :redirect do
|
|
56
|
+
resources :dummy_models, only: %i[create destroy]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
namespace :block_create do
|
|
60
|
+
resources :dummy_models, only: :create
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
namespace :html_update do
|
|
64
|
+
resources :dummy_models, only: :update
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
namespace :html_destroy do
|
|
68
|
+
resources :dummy_models, only: :destroy
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
namespace :block_destroy do
|
|
72
|
+
resources :dummy_models, only: :destroy
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
namespace :built do
|
|
76
|
+
resources :dummy_models, only: %i[new create]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
namespace :redirect_auth do
|
|
80
|
+
resources :dummy_models, only: :index
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
namespace :html_scoped do
|
|
84
|
+
resources :dummy_models, only: :index
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
namespace :nested do
|
|
88
|
+
resources :dummy_models, only: %i[create update]
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
namespace :invalid_status do
|
|
92
|
+
resources :dummy_models, only: :create
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
namespace :nested_route do
|
|
96
|
+
resources :classrooms, only: [], param: :slug do
|
|
97
|
+
resources :dummy_models, param: :slug, only: %i[show create destroy]
|
|
98
|
+
end
|
|
99
|
+
end
|
|
10
100
|
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'
|
|
@@ -7,23 +7,15 @@ describe DummyModelPolicy do
|
|
|
7
7
|
let(:other_user) { create(:user) }
|
|
8
8
|
let(:dummy_model) { create(:dummy_model, user: user) }
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
it 'denies a different user' do
|
|
16
|
-
expect(described_class.new(other_user, dummy_model).destroy?).to be false
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe '#index?' do
|
|
21
|
-
it 'allows the owning user' do
|
|
22
|
-
expect(described_class.new(user, dummy_model).index?).to be true
|
|
23
|
-
end
|
|
10
|
+
%i[destroy? index?].each do |policy_method|
|
|
11
|
+
describe "##{policy_method}" do
|
|
12
|
+
it 'allows the owning user' do
|
|
13
|
+
expect(described_class.new(user, dummy_model).public_send(policy_method)).to be true
|
|
14
|
+
end
|
|
24
15
|
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
it 'denies a different user' do
|
|
17
|
+
expect(described_class.new(other_user, dummy_model).public_send(policy_method)).to be false
|
|
18
|
+
end
|
|
27
19
|
end
|
|
28
20
|
end
|
|
29
21
|
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Finder::DummyModelsController, type: :controller do
|
|
6
|
+
include_examples 'simple crud for show with finder'
|
|
7
|
+
include_examples 'simple crud for update with finder'
|
|
8
|
+
include_examples 'simple crud for destroy with finder'
|
|
9
|
+
include_examples 'simple crud for show'
|
|
10
|
+
include_examples 'simple crud for update'
|
|
11
|
+
include_examples 'simple crud for destroy'
|
|
12
|
+
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,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe ScopedParams::DummyModelsController, type: :controller do
|
|
6
|
+
include_examples 'simple crud for index with scope' do
|
|
7
|
+
let(:my_models) { create_list(:dummy_model, 2, user: user, something: 42) }
|
|
8
|
+
let(:other_models) { create_list(:dummy_model, 1, user: user, something: 7) }
|
|
9
|
+
let(:request_params) { { something: 42 } }
|
|
10
|
+
end
|
|
11
|
+
end
|