dry_crud 7.1.0 → 8.0.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/VERSION +1 -1
- data/app/controllers/crud_controller.rb +5 -7
- data/app/controllers/dry_crud/generic_model.rb +4 -8
- data/app/controllers/dry_crud/nestable.rb +1 -4
- data/app/controllers/dry_crud/rememberable.rb +1 -4
- data/app/controllers/dry_crud/render_callbacks.rb +2 -10
- data/app/controllers/dry_crud/searchable.rb +3 -10
- data/app/controllers/dry_crud/sortable.rb +3 -10
- data/app/controllers/list_controller.rb +0 -2
- data/app/helpers/actions_helper.rb +8 -10
- data/app/helpers/dry_crud/form/builder.rb +23 -26
- data/app/helpers/dry_crud/form/control.rb +7 -11
- data/app/helpers/dry_crud/table/actions.rb +8 -13
- data/app/helpers/dry_crud/table/builder.rb +3 -6
- data/app/helpers/dry_crud/table/col.rb +1 -4
- data/app/helpers/dry_crud/table/sorting.rb +3 -6
- data/app/helpers/form_helper.rb +5 -7
- data/app/helpers/format_helper.rb +11 -13
- data/app/helpers/i18n_helper.rb +8 -10
- data/app/helpers/table_helper.rb +2 -4
- data/app/helpers/utility_helper.rb +9 -11
- data/app/views/layouts/application.html.erb +1 -1
- data/app/views/layouts/application.html.haml +1 -1
- data/lib/dry_crud/engine.rb +1 -3
- data/lib/dry_crud.rb +1 -1
- data/lib/generators/dry_crud/dry_crud_generator.rb +17 -17
- data/lib/generators/dry_crud/dry_crud_generator_base.rb +8 -8
- data/lib/generators/dry_crud/file_generator.rb +6 -6
- data/lib/generators/dry_crud/templates/config/initializers/field_error_proc.rb +1 -1
- data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +119 -119
- data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb +54 -59
- data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/table/builder_spec.rb +23 -25
- data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +10 -13
- data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +88 -92
- data/lib/generators/dry_crud/templates/spec/helpers/i18n_helper_spec.rb +33 -34
- data/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb +57 -59
- data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +18 -21
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +62 -62
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +8 -10
- data/lib/generators/dry_crud/templates/test/controllers/crud_test_models_controller_test.rb +63 -65
- data/lib/generators/dry_crud/templates/test/helpers/custom_assertions_test.rb +20 -22
- data/lib/generators/dry_crud/templates/test/helpers/dry_crud/form/builder_test.rb +74 -74
- data/lib/generators/dry_crud/templates/test/helpers/dry_crud/table/builder_test.rb +21 -21
- data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +13 -15
- data/lib/generators/dry_crud/templates/test/helpers/format_helper_test.rb +68 -70
- data/lib/generators/dry_crud/templates/test/helpers/i18n_helper_test.rb +26 -28
- data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +25 -27
- data/lib/generators/dry_crud/templates/test/helpers/utility_helper_test.rb +15 -17
- data/lib/generators/dry_crud/templates/test/support/crud_controller_test_helper.rb +13 -15
- data/lib/generators/dry_crud/templates/test/support/crud_test_helper.rb +9 -13
- data/lib/generators/dry_crud/templates/test/support/crud_test_model.rb +7 -11
- data/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb +13 -15
- data/lib/generators/dry_crud/templates/test/support/custom_assertions.rb +2 -4
- metadata +5 -5
@@ -3,7 +3,6 @@
|
|
3
3
|
# #test_entry_attrs to test the basic crud functionality. Override the test
|
4
4
|
# methods if you changed the behaviour in your subclass controller.
|
5
5
|
module CrudControllerTestHelper # rubocop:disable Metrics/ModuleLength
|
6
|
-
|
7
6
|
def test_index # :nodoc:
|
8
7
|
get :index, params: test_params
|
9
8
|
assert_response :success
|
@@ -11,13 +10,13 @@ module CrudControllerTestHelper # rubocop:disable Metrics/ModuleLength
|
|
11
10
|
end
|
12
11
|
|
13
12
|
def test_index_json # :nodoc:
|
14
|
-
get :index, params: test_params(format:
|
13
|
+
get :index, params: test_params(format: "json")
|
15
14
|
assert_response :success
|
16
15
|
assert entries.present?
|
17
|
-
assert @response.body.starts_with?(
|
16
|
+
assert @response.body.starts_with?("[{"), @response.body
|
18
17
|
end
|
19
18
|
|
20
|
-
def test_index_search # rubocop:disable Metrics/AbcSize :nodoc:
|
19
|
+
def test_index_search # rubocop:disable Metrics/AbcSize -- :nodoc:
|
21
20
|
field = @controller.search_columns.first
|
22
21
|
val = field && test_entry[field].to_s
|
23
22
|
return if val.blank? # does not support search or no value in this field
|
@@ -30,7 +29,7 @@ module CrudControllerTestHelper # rubocop:disable Metrics/ModuleLength
|
|
30
29
|
|
31
30
|
def test_index_sort_asc # :nodoc:
|
32
31
|
col = model_class.column_names.first
|
33
|
-
get :index, params: test_params(sort: col, sort_dir:
|
32
|
+
get :index, params: test_params(sort: col, sort_dir: "asc")
|
34
33
|
assert_response :success
|
35
34
|
assert entries.present?
|
36
35
|
sorted = entries.sort_by(&col.to_sym)
|
@@ -39,7 +38,7 @@ module CrudControllerTestHelper # rubocop:disable Metrics/ModuleLength
|
|
39
38
|
|
40
39
|
def test_index_sort_desc # :nodoc:
|
41
40
|
col = model_class.column_names.first
|
42
|
-
get :index, params: test_params(sort: col, sort_dir:
|
41
|
+
get :index, params: test_params(sort: col, sort_dir: "desc")
|
43
42
|
assert_response :success
|
44
43
|
assert entries.present?
|
45
44
|
sorted = entries.to_a.sort_by(&col.to_sym)
|
@@ -53,10 +52,10 @@ module CrudControllerTestHelper # rubocop:disable Metrics/ModuleLength
|
|
53
52
|
end
|
54
53
|
|
55
54
|
def test_show_json # :nodoc:
|
56
|
-
get :show, params: test_params(id: test_entry.id, format:
|
55
|
+
get :show, params: test_params(id: test_entry.id, format: "json")
|
57
56
|
assert_response :success
|
58
57
|
assert_equal test_entry, entry
|
59
|
-
assert @response.body.starts_with?(
|
58
|
+
assert @response.body.starts_with?("{")
|
60
59
|
end
|
61
60
|
|
62
61
|
def test_show_with_non_existing_id_raises_record_not_found # :nodoc:
|
@@ -83,7 +82,7 @@ module CrudControllerTestHelper # rubocop:disable Metrics/ModuleLength
|
|
83
82
|
def test_create_json # :nodoc:
|
84
83
|
assert_difference("#{model_class.name}.count") do
|
85
84
|
post :create, params: test_params(model_identifier => new_entry_attrs,
|
86
|
-
format:
|
85
|
+
format: "json")
|
87
86
|
end
|
88
87
|
assert_response :success
|
89
88
|
assert @response.body.starts_with?('{"id":')
|
@@ -108,7 +107,7 @@ module CrudControllerTestHelper # rubocop:disable Metrics/ModuleLength
|
|
108
107
|
assert_no_difference("#{model_class.name}.count") do
|
109
108
|
put :update, params: test_params(id: test_entry.id,
|
110
109
|
model_identifier => edit_entry_attrs,
|
111
|
-
format:
|
110
|
+
format: "json")
|
112
111
|
end
|
113
112
|
assert_response :success
|
114
113
|
assert @response.body.starts_with?('{"id":')
|
@@ -124,22 +123,22 @@ module CrudControllerTestHelper # rubocop:disable Metrics/ModuleLength
|
|
124
123
|
def test_destroy_json # :nodoc:
|
125
124
|
assert_difference("#{model_class.name}.count", -1) do
|
126
125
|
delete :destroy, params: test_params(id: test_entry.id,
|
127
|
-
format:
|
126
|
+
format: "json")
|
128
127
|
end
|
129
128
|
assert_response :success
|
130
|
-
assert_equal
|
129
|
+
assert_equal "", @response.body.strip
|
131
130
|
end
|
132
131
|
|
133
132
|
private
|
134
133
|
|
135
134
|
def assert_redirected_to_index # :nodoc:
|
136
|
-
assert_redirected_to test_params(action:
|
135
|
+
assert_redirected_to test_params(action: "index",
|
137
136
|
id: nil,
|
138
137
|
returning: true)
|
139
138
|
end
|
140
139
|
|
141
140
|
def assert_redirected_to_show(entry) # :nodoc:
|
142
|
-
assert_redirected_to test_params(action:
|
141
|
+
assert_redirected_to test_params(action: "show",
|
143
142
|
id: entry.id)
|
144
143
|
end
|
145
144
|
|
@@ -212,5 +211,4 @@ module CrudControllerTestHelper # rubocop:disable Metrics/ModuleLength
|
|
212
211
|
end
|
213
212
|
params
|
214
213
|
end
|
215
|
-
|
216
214
|
end
|
@@ -8,7 +8,6 @@ REGEXP_ACTION_CELL = /<td class="action"><a .*?href.+?<\/a><\/td>/m.freeze
|
|
8
8
|
# This helper is used to test the CrudController and various helpers
|
9
9
|
# without the need for an application based model.
|
10
10
|
module CrudTestHelper
|
11
|
-
|
12
11
|
# Controller helper methods for the tests
|
13
12
|
|
14
13
|
def model_class
|
@@ -16,11 +15,11 @@ module CrudTestHelper
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def controller_name
|
19
|
-
|
18
|
+
"crud_test_models"
|
20
19
|
end
|
21
20
|
|
22
21
|
def action_name
|
23
|
-
|
22
|
+
"index"
|
24
23
|
end
|
25
24
|
|
26
25
|
def params
|
@@ -35,9 +34,7 @@ module CrudTestHelper
|
|
35
34
|
true
|
36
35
|
end
|
37
36
|
|
38
|
-
|
39
|
-
ERB::Util.h(text)
|
40
|
-
end
|
37
|
+
delegate :h, to: :'ERB::Util'
|
41
38
|
|
42
39
|
private
|
43
40
|
|
@@ -85,8 +82,8 @@ module CrudTestHelper
|
|
85
82
|
def create_crud_test_models_other_crud_test_models(connection)
|
86
83
|
connection.create_table :crud_test_models_other_crud_test_models,
|
87
84
|
force: true do |t|
|
88
|
-
t.belongs_to :crud_test_model, index: { name:
|
89
|
-
t.belongs_to :other_crud_test_model, index: { name:
|
85
|
+
t.belongs_to :crud_test_model, index: { name: "parent" }
|
86
|
+
t.belongs_to :other_crud_test_model, index: { name: "other" }
|
90
87
|
end
|
91
88
|
end
|
92
89
|
|
@@ -116,7 +113,7 @@ module CrudTestHelper
|
|
116
113
|
with_routing do |set|
|
117
114
|
set.draw { resources :crud_test_models }
|
118
115
|
# used to define a controller in these tests
|
119
|
-
set.default_url_options = { controller:
|
116
|
+
set.default_url_options = { controller: "crud_test_models" }
|
120
117
|
yield
|
121
118
|
end
|
122
119
|
end
|
@@ -181,16 +178,15 @@ module CrudTestHelper
|
|
181
178
|
def without_transaction
|
182
179
|
c = ActiveRecord::Base.connection
|
183
180
|
start_transaction = false
|
184
|
-
if c.adapter_name.downcase.include?(
|
181
|
+
if c.adapter_name.downcase.include?("mysql") &&
|
185
182
|
c.open_transactions.positive?
|
186
183
|
# in transactional tests, we may simply rollback
|
187
|
-
c.execute(
|
184
|
+
c.execute("ROLLBACK")
|
188
185
|
start_transaction = true
|
189
186
|
end
|
190
187
|
|
191
188
|
yield
|
192
189
|
|
193
|
-
c.execute(
|
190
|
+
c.execute("BEGIN") if start_transaction
|
194
191
|
end
|
195
|
-
|
196
192
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
# A dummy model used for general testing.
|
2
2
|
class CrudTestModel < ApplicationRecord # :nodoc:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
has_many :mores, class_name: 'OtherCrudTestModel',
|
3
|
+
belongs_to :companion, class_name: "CrudTestModel", optional: true
|
4
|
+
has_and_belongs_to_many :others, class_name: "OtherCrudTestModel"
|
5
|
+
has_many :mores, class_name: "OtherCrudTestModel",
|
7
6
|
foreign_key: :more_id
|
8
7
|
|
9
|
-
has_one :comrad, class_name:
|
8
|
+
has_one :comrad, class_name: "CrudTestModel", foreign_key: :companion_id
|
10
9
|
|
11
10
|
before_destroy :protect_if_companion
|
12
11
|
|
@@ -25,23 +24,20 @@ class CrudTestModel < ApplicationRecord # :nodoc:
|
|
25
24
|
|
26
25
|
def protect_if_companion
|
27
26
|
if companion.present?
|
28
|
-
errors.add(:base,
|
27
|
+
errors.add(:base, "Cannot destroy model with companion")
|
29
28
|
throw :abort
|
30
29
|
end
|
31
30
|
end
|
32
|
-
|
33
31
|
end
|
34
32
|
|
35
33
|
# Second dummy model to test associations.
|
36
34
|
class OtherCrudTestModel < ApplicationRecord # :nodoc:
|
37
|
-
|
38
|
-
has_and_belongs_to_many :others, class_name: 'CrudTestModel'
|
35
|
+
has_and_belongs_to_many :others, class_name: "CrudTestModel"
|
39
36
|
belongs_to :more,
|
40
|
-
class_name:
|
37
|
+
class_name: "CrudTestModel",
|
41
38
|
optional: true
|
42
39
|
|
43
40
|
def to_s
|
44
41
|
name
|
45
42
|
end
|
46
|
-
|
47
43
|
end
|
@@ -1,15 +1,14 @@
|
|
1
1
|
# Controller for the dummy model.
|
2
2
|
class CrudTestModelsController < CrudController # :nodoc:
|
3
|
-
|
4
|
-
HANDLE_PREFIX = 'handle_'.freeze
|
3
|
+
HANDLE_PREFIX = "handle_".freeze
|
5
4
|
|
6
5
|
self.search_columns = %i[name whatever remarks]
|
7
|
-
self.sort_mappings = { chatty:
|
8
|
-
self.default_sort =
|
9
|
-
self.permitted_attrs = [:name, :email, :password, :whatever, :children,
|
6
|
+
self.sort_mappings = { chatty: "length(remarks)" }
|
7
|
+
self.default_sort = "name"
|
8
|
+
self.permitted_attrs = [ :name, :email, :password, :whatever, :children,
|
10
9
|
:companion_id, :rating, :income, :birthdate,
|
11
10
|
:gets_up_at, :last_seen, :human, :remarks,
|
12
|
-
{ other_ids: [] }]
|
11
|
+
{ other_ids: [] } ]
|
13
12
|
|
14
13
|
before_create :possibly_redirect
|
15
14
|
before_create :handle_name
|
@@ -27,16 +26,16 @@ class CrudTestModelsController < CrudController # :nodoc:
|
|
27
26
|
|
28
27
|
def index
|
29
28
|
entries
|
30
|
-
render plain:
|
29
|
+
render plain: "index js" if request.format.js?
|
31
30
|
end
|
32
31
|
|
33
32
|
def show
|
34
|
-
render html:
|
33
|
+
render html: "custom html" if entry.name == "BBBBB"
|
35
34
|
end
|
36
35
|
|
37
36
|
def create
|
38
37
|
super do |_format, success|
|
39
|
-
flash[:notice] =
|
38
|
+
flash[:notice] = "model got created" if success
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
@@ -45,9 +44,9 @@ class CrudTestModelsController < CrudController # :nodoc:
|
|
45
44
|
def list_entries
|
46
45
|
entries = super
|
47
46
|
if params[:filter]
|
48
|
-
entries = entries.where(
|
47
|
+
entries = entries.where(rating: ...3)
|
49
48
|
.except(:order)
|
50
|
-
.order(
|
49
|
+
.order("children DESC")
|
51
50
|
end
|
52
51
|
entries
|
53
52
|
end
|
@@ -60,15 +59,15 @@ class CrudTestModelsController < CrudController # :nodoc:
|
|
60
59
|
|
61
60
|
# custom callback
|
62
61
|
def handle_name
|
63
|
-
if entry.name ==
|
64
|
-
flash[:alert] =
|
62
|
+
if entry.name == "illegal"
|
63
|
+
flash[:alert] = "illegal name"
|
65
64
|
throw :abort
|
66
65
|
end
|
67
66
|
end
|
68
67
|
|
69
68
|
# callback to redirect if @should_redirect is set
|
70
69
|
def possibly_redirect
|
71
|
-
redirect_to action:
|
70
|
+
redirect_to action: "index" if should_redirect && !performed?
|
72
71
|
end
|
73
72
|
|
74
73
|
def set_companions
|
@@ -107,5 +106,4 @@ class CrudTestModelsController < CrudController # :nodoc:
|
|
107
106
|
@called_callbacks ||= []
|
108
107
|
@called_callbacks << callback
|
109
108
|
end
|
110
|
-
|
111
109
|
end
|
@@ -8,9 +8,8 @@
|
|
8
8
|
# # inside the class definition:
|
9
9
|
# include CustomAssertions
|
10
10
|
module CustomAssertions
|
11
|
-
|
12
11
|
# Asserts that regexp occurs exactly expected times in string.
|
13
|
-
def assert_count(expected, regexp, string, msg =
|
12
|
+
def assert_count(expected, regexp, string, msg = "")
|
14
13
|
actual = string.scan(regexp).size
|
15
14
|
msg = message(msg) do
|
16
15
|
"Expected #{mu_pp(regexp)} to occur #{expected} time(s), " \
|
@@ -21,7 +20,7 @@ module CustomAssertions
|
|
21
20
|
|
22
21
|
# Asserts that the given active model record is valid.
|
23
22
|
# This method used to be part of Rails but was deprecated, no idea why.
|
24
|
-
def assert_valid(record, msg =
|
23
|
+
def assert_valid(record, msg = "")
|
25
24
|
record.valid?
|
26
25
|
msg = message(msg) do
|
27
26
|
"Expected #{mu_pp(record)} to be valid, " \
|
@@ -77,5 +76,4 @@ module CustomAssertions
|
|
77
76
|
assert invalid_attrs.include?(error.attribute), msg
|
78
77
|
end
|
79
78
|
end
|
80
|
-
|
81
79
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry_crud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 8.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pascal Zumkehr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '8.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '8.0'
|
27
27
|
description: |
|
28
28
|
Generates simple and extendable controller, views and helpers that support you
|
29
29
|
to DRY up the CRUD code in your Rails project. Start with these elements and
|
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
162
|
- !ruby/object:Gem::Version
|
163
163
|
version: '0'
|
164
164
|
requirements: []
|
165
|
-
rubygems_version: 3.
|
165
|
+
rubygems_version: 3.4.19
|
166
166
|
signing_key:
|
167
167
|
specification_version: 4
|
168
168
|
summary: Generates DRY and specifically extendable CRUD controller, views and helpers
|