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.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -0
  3. data/Gemfile +1 -0
  4. data/README.md +157 -2
  5. data/lib/simple_crud/authorization/adapter.rb +7 -0
  6. data/lib/simple_crud/authorization/pundit_adapter.rb +6 -0
  7. data/lib/simple_crud/config.rb +6 -1
  8. data/lib/simple_crud/controller_helpers.rb +119 -0
  9. data/lib/simple_crud/pagination/adapter.rb +7 -1
  10. data/lib/simple_crud/pagination/kaminari_adapter.rb +23 -2
  11. data/lib/simple_crud/pagination/pagy_adapter.rb +7 -2
  12. data/lib/simple_crud/pagination/will_paginate_adapter.rb +7 -3
  13. data/lib/simple_crud/pagination/wor_paginate_adapter.rb +7 -2
  14. data/lib/simple_crud/rspec/config.rb +61 -0
  15. data/lib/simple_crud/rspec/helpers.rb +147 -0
  16. data/lib/simple_crud/rspec.rb +34 -0
  17. data/lib/simple_crud/simple_crud_controller.rb +51 -36
  18. data/lib/simple_crud/version.rb +1 -1
  19. data/lib/spec/shared_contexts/authenticate_user.rb +1 -7
  20. data/lib/spec/shared_examples/authorization_adapter_authorize.rb +11 -0
  21. data/lib/spec/shared_examples/simple_crud_for_create.rb +43 -11
  22. data/lib/spec/shared_examples/simple_crud_for_create_with_block.rb +18 -0
  23. data/lib/spec/shared_examples/simple_crud_for_create_with_build.rb +15 -0
  24. data/lib/spec/shared_examples/simple_crud_for_destroy.rb +19 -8
  25. data/lib/spec/shared_examples/simple_crud_for_destroy_with_block.rb +13 -0
  26. data/lib/spec/shared_examples/simple_crud_for_destroy_with_finder.rb +24 -0
  27. data/lib/spec/shared_examples/simple_crud_for_index.rb +8 -23
  28. data/lib/spec/shared_examples/simple_crud_for_index_with_block.rb +14 -0
  29. data/lib/spec/shared_examples/simple_crud_for_index_with_scope.rb +21 -0
  30. data/lib/spec/shared_examples/simple_crud_for_new.rb +29 -0
  31. data/lib/spec/shared_examples/simple_crud_for_new_with_block.rb +9 -0
  32. data/lib/spec/shared_examples/simple_crud_for_new_with_build.rb +13 -0
  33. data/lib/spec/shared_examples/simple_crud_for_show.rb +14 -10
  34. data/lib/spec/shared_examples/simple_crud_for_show_with_block.rb +11 -0
  35. data/lib/spec/shared_examples/simple_crud_for_show_with_finder.rb +24 -0
  36. data/lib/spec/shared_examples/simple_crud_for_update.rb +55 -15
  37. data/lib/spec/shared_examples/simple_crud_for_update_with_finder.rb +29 -0
  38. data/lib/spec/shared_examples/simple_crud_not_found_with_finder.rb +13 -0
  39. data/lib/spec/shared_examples/simple_crud_renders_template.rb +8 -0
  40. data/lib/spec/shared_examples/simple_crud_when_not_authorized.rb +18 -0
  41. data/lib/spec/shared_examples/simple_crud_without_authenticated_user.rb +9 -0
  42. data/lib/spec/shared_examples/unauthorized_when_not_logged_in.rb +2 -2
  43. data/spec/block/dummy_models_controller_spec.rb +8 -0
  44. data/spec/block_create/dummy_models_controller_spec.rb +7 -0
  45. data/spec/block_destroy/dummy_models_controller_spec.rb +7 -0
  46. data/spec/block_new/dummy_models_controller_spec.rb +7 -0
  47. data/spec/block_show/dummy_models_controller_spec.rb +7 -0
  48. data/spec/built/dummy_models_controller_spec.rb +8 -0
  49. data/spec/dummy/app/controllers/block/dummy_models_controller.rb +17 -0
  50. data/spec/dummy/app/controllers/block_create/dummy_models_controller.rb +13 -0
  51. data/spec/dummy/app/controllers/block_destroy/dummy_models_controller.rb +9 -0
  52. data/spec/dummy/app/controllers/block_modes/base_controller.rb +11 -0
  53. data/spec/dummy/app/controllers/block_new/dummy_models_controller.rb +9 -0
  54. data/spec/dummy/app/controllers/block_show/dummy_models_controller.rb +9 -0
  55. data/spec/dummy/app/controllers/built/dummy_models_controller.rb +21 -0
  56. data/spec/dummy/app/controllers/dummy_models_controller.rb +2 -1
  57. data/spec/dummy/app/controllers/finder/dummy_models_controller.rb +22 -0
  58. data/spec/dummy/app/controllers/html/dummy_models_controller.rb +7 -0
  59. data/spec/dummy/app/controllers/html_create/dummy_models_controller.rb +7 -0
  60. data/spec/dummy/app/controllers/html_destroy/dummy_models_controller.rb +7 -0
  61. data/spec/dummy/app/controllers/html_modes/base_controller.rb +17 -0
  62. data/spec/dummy/app/controllers/html_new/dummy_models_controller.rb +7 -0
  63. data/spec/dummy/app/controllers/html_scoped/dummy_models_controller.rb +8 -0
  64. data/spec/dummy/app/controllers/html_show/dummy_models_controller.rb +7 -0
  65. data/spec/dummy/app/controllers/html_update/dummy_models_controller.rb +7 -0
  66. data/spec/dummy/app/controllers/invalid_status/dummy_models_controller.rb +13 -0
  67. data/spec/dummy/app/controllers/nested/dummy_models_controller.rb +21 -0
  68. data/spec/dummy/app/controllers/nested_route/dummy_models_controller.rb +26 -0
  69. data/spec/dummy/app/controllers/redirect/dummy_models_controller.rb +10 -0
  70. data/spec/dummy/app/controllers/redirect_auth/dummy_models_controller.rb +28 -0
  71. data/spec/dummy/app/controllers/scoped/dummy_models_controller.rb +16 -0
  72. data/spec/dummy/app/controllers/scoped_params/dummy_models_controller.rb +16 -0
  73. data/spec/dummy/app/controllers/strict/dummy_models_controller.rb +21 -0
  74. data/spec/dummy/app/models/dummy_model.rb +4 -0
  75. data/spec/dummy/app/models/dummy_model_policy.rb +4 -0
  76. data/spec/dummy/app/views/block/dummy_models/index.html.erb +3 -0
  77. data/spec/dummy/app/views/block_new/dummy_models/new.html.erb +1 -0
  78. data/spec/dummy/app/views/block_show/dummy_models/show.html.erb +1 -0
  79. data/spec/dummy/app/views/html/dummy_models/index.html.erb +3 -0
  80. data/spec/dummy/app/views/html_create/dummy_models/new.html.erb +1 -0
  81. data/spec/dummy/app/views/html_destroy/dummy_models/show.html.erb +1 -0
  82. data/spec/dummy/app/views/html_new/dummy_models/new.html.erb +1 -0
  83. data/spec/dummy/app/views/html_scoped/dummy_models/index.html.erb +3 -0
  84. data/spec/dummy/app/views/html_show/dummy_models/show.html.erb +1 -0
  85. data/spec/dummy/app/views/html_update/dummy_models/edit.html.erb +1 -0
  86. data/spec/dummy/app/views/invalid_status/dummy_models/new.html.erb +1 -0
  87. data/spec/dummy/app/views/layouts/application.html.erb +4 -0
  88. data/spec/dummy/app/views/redirect/dummy_models/new.html.erb +1 -0
  89. data/spec/dummy/config/routes.rb +90 -0
  90. data/spec/dummy/db/migrate/20260806000000_add_slug_to_dummy_models.rb +7 -0
  91. data/spec/dummy/db/migrate/20260807000000_add_classroom_slug_to_dummy_models.rb +7 -0
  92. data/spec/dummy/db/schema.rb +3 -1
  93. data/spec/dummy/spec/factories/dummy_models.rb +1 -0
  94. data/spec/dummy_controller_spec.rb +1 -0
  95. data/spec/dummy_model_policy_spec.rb +8 -16
  96. data/spec/finder/dummy_models_controller_spec.rb +12 -0
  97. data/spec/html/dummy_models_controller_spec.rb +7 -0
  98. data/spec/html_create/dummy_models_controller_spec.rb +7 -0
  99. data/spec/html_destroy/dummy_models_controller_spec.rb +7 -0
  100. data/spec/html_new/dummy_models_controller_spec.rb +7 -0
  101. data/spec/html_scoped/dummy_models_controller_spec.rb +7 -0
  102. data/spec/html_show/dummy_models_controller_spec.rb +7 -0
  103. data/spec/html_update/dummy_models_controller_spec.rb +7 -0
  104. data/spec/invalid_status/dummy_models_controller_spec.rb +10 -0
  105. data/spec/nested/dummy_models_controller_spec.rb +12 -0
  106. data/spec/nested_route/dummy_models_controller_spec.rb +19 -0
  107. data/spec/redirect/dummy_models_controller_spec.rb +23 -0
  108. data/spec/redirect_auth/dummy_models_controller_spec.rb +11 -0
  109. data/spec/scoped/dummy_models_controller_spec.rb +7 -0
  110. data/spec/scoped_params/dummy_models_controller_spec.rb +11 -0
  111. data/spec/simple_crud/authorization/action_policy_adapter_spec.rb +1 -9
  112. data/spec/simple_crud/authorization/can_can_can_adapter_spec.rb +1 -7
  113. data/spec/simple_crud/authorization/pundit_adapter_spec.rb +41 -0
  114. data/spec/simple_crud/controller_helpers_spec.rb +49 -0
  115. data/spec/simple_crud/pagination/adapters_spec.rb +37 -13
  116. data/spec/simple_crud/rspec_config_spec.rb +67 -0
  117. data/spec/simple_crud_configuration_spec.rb +19 -16
  118. data/spec/simple_crud_controller_spec.rb +4 -4
  119. data/spec/spec_helper.rb +1 -0
  120. data/spec/strict/dummy_models_controller_spec.rb +23 -0
  121. metadata +87 -4
  122. data/lib/spec/shared_examples/helpers.rb +0 -50
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HtmlDestroy
4
+ class DummyModelsController < HtmlModes::BaseController
5
+ simple_crud_for :destroy, html: true, authenticate: false, authorize: false
6
+ end
7
+ end
@@ -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,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HtmlNew
4
+ class DummyModelsController < HtmlModes::BaseController
5
+ simple_crud_for :new, html: true, authenticate: false, authorize: false
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HtmlScoped
4
+ class DummyModelsController < HtmlModes::BaseController
5
+ simple_crud_for :index, html: true, scope: ->(user) { DummyModel.where(user: user) },
6
+ authenticate: false, authorize: false
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HtmlShow
4
+ class DummyModelsController < HtmlModes::BaseController
5
+ simple_crud_for :show, html: true, authenticate: false, authorize: false
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HtmlUpdate
4
+ class DummyModelsController < HtmlModes::BaseController
5
+ simple_crud_for :update, html: true, authenticate: false, authorize: false
6
+ end
7
+ 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
@@ -4,4 +4,8 @@ require_relative 'dummy_model_policy'
4
4
  class DummyModel < ApplicationRecord
5
5
  belongs_to :user
6
6
  validates :name, presence: true
7
+
8
+ def self.find_by_slug(params)
9
+ find_by!(slug: params[:slug])
10
+ end
7
11
  end
@@ -24,6 +24,10 @@ class DummyModelPolicy
24
24
  check_user
25
25
  end
26
26
 
27
+ def new?
28
+ check_user
29
+ end
30
+
27
31
  def destroy?
28
32
  check_user
29
33
  end
@@ -0,0 +1,3 @@
1
+ <% models.each do |model| %>
2
+ <span class="model"><%= model.name %></span>
3
+ <% 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,3 @@
1
+ <% @records.each do |record| %>
2
+ <span class="record"><%= record.name %></span>
3
+ <% end %>
@@ -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,3 @@
1
+ <% @records.each do |record| %>
2
+ <span class="record"><%= record.name %></span>
3
+ <% end %>
@@ -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,4 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <body><%= yield %></body>
4
+ </html>
@@ -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
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddSlugToDummyModels < ActiveRecord::Migration[6.0]
4
+ def change
5
+ add_column :dummy_models, :slug, :string
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddClassroomSlugToDummyModels < ActiveRecord::Migration[6.0]
4
+ def change
5
+ add_column :dummy_models, :classroom_slug, :string
6
+ end
7
+ end
@@ -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: 20_200_120_165_657) do
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'
@@ -4,6 +4,7 @@ FactoryBot.define do
4
4
  factory :dummy_model do
5
5
  name { rand(36 * 4).to_s(36) }
6
6
  something { rand(100) }
7
+ slug { "slug-#{rand(36 * 6).to_s(36)}" }
7
8
  user
8
9
  end
9
10
  end
@@ -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
- describe '#destroy?' do
11
- it 'allows the owning user' do
12
- expect(described_class.new(user, dummy_model).destroy?).to be true
13
- end
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
- it 'denies a different user' do
26
- expect(described_class.new(other_user, dummy_model).index?).to be false
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,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Html::DummyModelsController, type: :controller do
6
+ include_examples 'simple crud for index'
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe HtmlCreate::DummyModelsController, type: :controller do
6
+ include_examples 'simple crud for create'
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe HtmlDestroy::DummyModelsController, type: :controller do
6
+ include_examples 'simple crud for destroy'
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe HtmlNew::DummyModelsController, type: :controller do
6
+ include_examples 'simple crud for new'
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe HtmlScoped::DummyModelsController, type: :controller do
6
+ include_examples 'simple crud for index'
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe HtmlShow::DummyModelsController, type: :controller do
6
+ include_examples 'simple crud for show'
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe HtmlUpdate::DummyModelsController, type: :controller do
6
+ include_examples 'simple crud for update'
7
+ 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,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Scoped::DummyModelsController, type: :controller do
6
+ include_examples 'simple crud for index with scope'
7
+ 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