dry_crud 6.0.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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +2 -2
  3. data/README.rdoc +7 -6
  4. data/VERSION +1 -1
  5. data/app/assets/stylesheets/sample.scss +45 -24
  6. data/app/controllers/crud_controller.rb +24 -26
  7. data/app/controllers/dry_crud/generic_model.rb +6 -12
  8. data/app/controllers/dry_crud/nestable.rb +1 -4
  9. data/app/controllers/dry_crud/rememberable.rb +1 -4
  10. data/app/controllers/dry_crud/render_callbacks.rb +4 -12
  11. data/app/controllers/dry_crud/searchable.rb +3 -10
  12. data/app/controllers/dry_crud/sortable.rb +3 -10
  13. data/app/controllers/list_controller.rb +1 -3
  14. data/app/helpers/actions_helper.rb +13 -15
  15. data/app/helpers/dry_crud/form/builder.rb +56 -62
  16. data/app/helpers/dry_crud/form/control.rb +12 -19
  17. data/app/helpers/dry_crud/table/actions.rb +15 -20
  18. data/app/helpers/dry_crud/table/builder.rb +12 -15
  19. data/app/helpers/dry_crud/table/col.rb +5 -8
  20. data/app/helpers/dry_crud/table/sorting.rb +3 -6
  21. data/app/helpers/form_helper.rb +11 -15
  22. data/app/helpers/format_helper.rb +18 -20
  23. data/app/helpers/i18n_helper.rb +13 -15
  24. data/app/helpers/table_helper.rb +16 -19
  25. data/app/helpers/utility_helper.rb +12 -14
  26. data/app/views/crud/new.html.erb +1 -1
  27. data/app/views/crud/new.html.haml +1 -1
  28. data/app/views/layouts/application.html.erb +8 -6
  29. data/app/views/layouts/application.html.haml +6 -5
  30. data/app/views/list/_search.html.erb +1 -3
  31. data/app/views/list/_search.html.haml +1 -2
  32. data/app/views/shared/_error_messages.html.erb +2 -2
  33. data/lib/dry_crud/engine.rb +1 -3
  34. data/lib/dry_crud.rb +1 -1
  35. data/lib/generators/dry_crud/dry_crud_generator.rb +18 -18
  36. data/lib/generators/dry_crud/dry_crud_generator_base.rb +8 -8
  37. data/lib/generators/dry_crud/file_generator.rb +6 -6
  38. data/lib/generators/dry_crud/templates/config/initializers/field_error_proc.rb +1 -1
  39. data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +122 -122
  40. data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb +55 -60
  41. data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/table/builder_spec.rb +24 -26
  42. data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +16 -18
  43. data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +90 -94
  44. data/lib/generators/dry_crud/templates/spec/helpers/i18n_helper_spec.rb +33 -34
  45. data/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb +59 -61
  46. data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +20 -23
  47. data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +66 -68
  48. data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +11 -13
  49. data/lib/generators/dry_crud/templates/test/controllers/crud_test_models_controller_test.rb +63 -65
  50. data/lib/generators/dry_crud/templates/test/helpers/custom_assertions_test.rb +25 -27
  51. data/lib/generators/dry_crud/templates/test/helpers/dry_crud/form/builder_test.rb +74 -74
  52. data/lib/generators/dry_crud/templates/test/helpers/dry_crud/table/builder_test.rb +21 -21
  53. data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +21 -23
  54. data/lib/generators/dry_crud/templates/test/helpers/format_helper_test.rb +68 -70
  55. data/lib/generators/dry_crud/templates/test/helpers/i18n_helper_test.rb +26 -28
  56. data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +28 -30
  57. data/lib/generators/dry_crud/templates/test/helpers/utility_helper_test.rb +17 -19
  58. data/lib/generators/dry_crud/templates/test/support/crud_controller_test_helper.rb +13 -15
  59. data/lib/generators/dry_crud/templates/test/support/crud_test_helper.rb +15 -19
  60. data/lib/generators/dry_crud/templates/test/support/crud_test_model.rb +9 -14
  61. data/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb +16 -20
  62. data/lib/generators/dry_crud/templates/test/support/custom_assertions.rb +8 -10
  63. metadata +9 -10
@@ -1,4 +1,4 @@
1
- require 'support/crud_controller_test_helper'
1
+ require "support/crud_controller_test_helper"
2
2
 
3
3
  RSpec.configure do |c|
4
4
  c.before failing: true do
@@ -14,7 +14,7 @@ end
14
14
  # them by passing a skip parameter with context arrays:
15
15
  # include_examples 'crud controller',
16
16
  # skip: [%w(index html sort) %w(destroy json)]
17
- shared_examples 'crud controller' do |options|
17
+ shared_examples "crud controller" do |options|
18
18
  include CrudControllerTestHelper
19
19
 
20
20
  render_views
@@ -36,59 +36,57 @@ shared_examples 'crud controller' do |options|
36
36
 
37
37
  before do
38
38
  m = RSpec.current_example.metadata
39
- if m[:perform_request] != false && m[:action] && m[:method]
40
- perform_combined_request
41
- end
39
+ perform_combined_request if m[:perform_request] != false && m[:action] && m[:method]
42
40
  end
43
41
 
44
42
  describe_action :get, :index,
45
- unless: skip?(options, 'index') do
46
- context '.html',
43
+ unless: skip?(options, "index") do
44
+ context ".html",
47
45
  format: :html,
48
46
  unless: skip?(options, %w[index html]) do
49
- context 'plain',
47
+ context "plain",
50
48
  unless: skip?(options, %w[index html plain]),
51
- combine: 'ihp' do
49
+ combine: "ihp" do
52
50
  it_is_expected_to_respond
53
51
  end
54
52
 
55
- context 'search',
53
+ context "search",
56
54
  if: described_class.search_columns.present?,
57
55
  unless: skip?(options, %w[index html search]),
58
- combine: 'ihse' do
56
+ combine: "ihse" do
59
57
  let(:params) { { q: search_value } }
60
58
 
61
59
  it_is_expected_to_respond
62
60
 
63
- context 'entries' do
61
+ context "entries" do
64
62
  subject { entries }
65
63
  it { is_expected.to include(test_entry) }
66
64
  end
67
65
  end
68
66
 
69
- context 'sort',
67
+ context "sort",
70
68
  unless: skip?(options, %w[index html sort]) do
71
- context 'ascending',
69
+ context "ascending",
72
70
  unless: skip?(options, %w[index html sort ascending]),
73
- combine: 'ihso' do
74
- let(:params) { { sort: sort_column, sort_dir: 'asc' } }
71
+ combine: "ihso" do
72
+ let(:params) { { sort: sort_column, sort_dir: "asc" } }
75
73
 
76
74
  it_is_expected_to_respond
77
75
 
78
- it 'has sorted entries' do
76
+ it "has sorted entries" do
79
77
  sorted = entries.sort_by(&sort_column.to_sym)
80
78
  expect(entries).to eq(sorted)
81
79
  end
82
80
  end
83
81
 
84
- context 'descending',
82
+ context "descending",
85
83
  unless: skip?(options, %w[index html sort descending]),
86
- combine: 'ihsd' do
87
- let(:params) { { sort: sort_column, sort_dir: 'desc' } }
84
+ combine: "ihsd" do
85
+ let(:params) { { sort: sort_column, sort_dir: "desc" } }
88
86
 
89
87
  it_is_expected_to_respond
90
88
 
91
- it 'has sorted entries' do
89
+ it "has sorted entries" do
92
90
  sorted = entries.sort_by(&sort_column.to_sym)
93
91
  expect(entries).to eq(sorted.reverse)
94
92
  end
@@ -96,43 +94,43 @@ shared_examples 'crud controller' do |options|
96
94
  end
97
95
  end
98
96
 
99
- context '.json',
97
+ context ".json",
100
98
  format: :json,
101
99
  unless: skip?(options, %w[index json]),
102
- combine: 'ij' do
100
+ combine: "ij" do
103
101
  it_is_expected_to_respond
104
- it { expect(response.body).to start_with('[{') }
102
+ it { expect(response.body).to start_with("[{") }
105
103
  end
106
104
  end
107
105
 
108
106
  describe_action :get, :show,
109
107
  id: true,
110
- unless: skip?(options, 'show') do
111
- context '.html',
108
+ unless: skip?(options, "show") do
109
+ context ".html",
112
110
  format: :html,
113
111
  unless: skip?(options, %w[show html]) do
114
- context 'plain',
112
+ context "plain",
115
113
  unless: skip?(options, %w[show html plain]),
116
- combine: 'sh' do
114
+ combine: "sh" do
117
115
  it_is_expected_to_respond
118
116
  end
119
117
 
120
- context 'with non-existing id',
118
+ context "with non-existing id",
121
119
  unless: skip?(options,
122
120
  %w[show html with_non_existing_id]) do
123
121
  let(:params) { { id: 9999 } }
124
122
 
125
- it 'raises RecordNotFound', perform_request: false do
123
+ it "raises RecordNotFound", perform_request: false do
126
124
  expect { perform_request }
127
125
  .to raise_error(ActiveRecord::RecordNotFound)
128
126
  end
129
127
  end
130
128
  end
131
129
 
132
- context '.json',
130
+ context ".json",
133
131
  format: :json,
134
132
  unless: skip?(options, %w[show json]),
135
- combine: 'sj' do
133
+ combine: "sj" do
136
134
  it_is_expected_to_respond
137
135
  it_is_expected_to_render_json
138
136
  end
@@ -140,14 +138,14 @@ shared_examples 'crud controller' do |options|
140
138
 
141
139
  describe_action :get, :new,
142
140
  unless: skip?(options, %w[new]) do
143
- context 'plain',
141
+ context "plain",
144
142
  unless: skip?(options, %w[new plain]),
145
- combine: 'new' do
143
+ combine: "new" do
146
144
  it_is_expected_to_respond
147
- it_is_expected_to_persist_entry(false)
145
+ it_is_expected_to_persist_entry(persist: false)
148
146
  end
149
147
 
150
- context 'with params',
148
+ context "with params",
151
149
  unless: skip?(options, %w[new with_params]) do
152
150
  let(:params) { { model_identifier => new_entry_attrs } }
153
151
  it_is_expected_to_set_attrs(:new)
@@ -158,54 +156,54 @@ shared_examples 'crud controller' do |options|
158
156
  unless: skip?(options, %w[create]) do
159
157
  let(:params) { { model_identifier => new_entry_attrs } }
160
158
 
161
- it 'adds entry to database', perform_request: false do
159
+ it "adds entry to database", perform_request: false do
162
160
  expect { perform_request }.to change { model_class.count }.by(1)
163
161
  end
164
162
 
165
- context 'html',
163
+ context "html",
166
164
  format: :html,
167
165
  unless: skip?(options, %w[create html]) do
168
166
  it_is_expected_to_persist_entry # cannot combine this
169
167
 
170
- context 'with valid params',
168
+ context "with valid params",
171
169
  unless: skip?(options, %w[create html valid]),
172
- combine: 'chv' do
170
+ combine: "chv" do
173
171
  it_is_expected_to_redirect_to_show
174
172
  it_is_expected_to_set_attrs(:new)
175
173
  it_is_expected_to_have_flash(:notice)
176
174
  end
177
175
 
178
- context 'with invalid params',
176
+ context "with invalid params",
179
177
  failing: true,
180
178
  unless: skip?(options, %w[create html invalid]),
181
- combine: 'chi' do
182
- it_is_expected_to_persist_entry(false)
179
+ combine: "chi" do
180
+ it_is_expected_to_persist_entry(persist: false)
183
181
  it_is_expected_to_set_attrs(:new)
184
182
  it_is_expected_to_not_have_flash(:notice)
185
183
  end
186
184
  end
187
185
 
188
- context 'json',
186
+ context "json",
189
187
  format: :json,
190
188
  unless: skip?(options, %w[create json]) do
191
189
  it_is_expected_to_persist_entry # cannot combine this
192
190
 
193
- context 'with valid params',
191
+ context "with valid params",
194
192
  unless: skip?(options, %w[create json valid]),
195
- combine: 'cjv' do
193
+ combine: "cjv" do
196
194
  it_is_expected_to_respond(201)
197
195
  it_is_expected_to_set_attrs(:new)
198
196
  it_is_expected_to_render_json
199
197
  end
200
198
 
201
- context 'with invalid params',
199
+ context "with invalid params",
202
200
  failing: true,
203
201
  unless: skip?(options, %w[create json invalid]),
204
- combine: 'cji' do
202
+ combine: "cji" do
205
203
  it_is_expected_to_respond(422)
206
204
  it_is_expected_to_set_attrs(:new)
207
205
  it_is_expected_to_render_json
208
- it_is_expected_to_persist_entry(false)
206
+ it_is_expected_to_persist_entry(persist: false)
209
207
  end
210
208
  end
211
209
  end
@@ -213,7 +211,7 @@ shared_examples 'crud controller' do |options|
213
211
  describe_action :get, :edit,
214
212
  id: true,
215
213
  unless: skip?(options, %w[edit]),
216
- combine: 'edit' do
214
+ combine: "edit" do
217
215
  it_is_expected_to_respond
218
216
  end
219
217
 
@@ -222,47 +220,47 @@ shared_examples 'crud controller' do |options|
222
220
  unless: skip?(options, %w[update]) do
223
221
  let(:params) { { model_identifier => edit_entry_attrs } }
224
222
 
225
- it 'updates entry in database', perform_request: false do
223
+ it "updates entry in database", perform_request: false do
226
224
  expect { perform_request }.to change { model_class.count }.by(0)
227
225
  end
228
226
 
229
- context '.html',
227
+ context ".html",
230
228
  format: :html,
231
229
  unless: skip?(options, %w[update html]) do
232
- context 'with valid params',
230
+ context "with valid params",
233
231
  unless: skip?(options, %w[update html valid]),
234
- combine: 'uhv' do
232
+ combine: "uhv" do
235
233
  it_is_expected_to_set_attrs(:edit)
236
234
  it_is_expected_to_redirect_to_show
237
235
  it_is_expected_to_persist_entry
238
236
  it_is_expected_to_have_flash(:notice)
239
237
  end
240
238
 
241
- context 'with invalid params',
239
+ context "with invalid params",
242
240
  failing: true,
243
241
  unless: skip?(options, %w[update html invalid]),
244
- combine: 'uhi' do
242
+ combine: "uhi" do
245
243
  it_is_expected_to_set_attrs(:edit)
246
244
  it_is_expected_to_not_have_flash(:notice)
247
245
  end
248
246
  end
249
247
 
250
- context '.json',
248
+ context ".json",
251
249
  format: :json,
252
250
  unless: skip?(options, %w[update json]) do
253
- context 'with valid params',
251
+ context "with valid params",
254
252
  unless: skip?(options, %w[update json valid]),
255
- combine: 'ujv' do
253
+ combine: "ujv" do
256
254
  it_is_expected_to_respond(200)
257
255
  it_is_expected_to_set_attrs(:edit)
258
256
  it_is_expected_to_render_json
259
257
  it_is_expected_to_persist_entry
260
258
  end
261
259
 
262
- context 'with invalid params',
260
+ context "with invalid params",
263
261
  failing: true,
264
262
  unless: skip?(options, %w[update json invalid]),
265
- combine: 'uji' do
263
+ combine: "uji" do
266
264
  it_is_expected_to_respond(422)
267
265
  it_is_expected_to_set_attrs(:edit)
268
266
  it_is_expected_to_render_json
@@ -273,33 +271,33 @@ shared_examples 'crud controller' do |options|
273
271
  describe_action :delete, :destroy,
274
272
  id: true,
275
273
  unless: skip?(options, %w[destroy]) do
276
- it 'removes entry from database', perform_request: false do
274
+ it "removes entry from database", perform_request: false do
277
275
  expect { perform_request }.to change { model_class.count }.by(-1)
278
276
  end
279
277
 
280
- context '.html',
278
+ context ".html",
281
279
  format: :html,
282
280
  unless: skip?(options, %w[destroy html]) do
283
- context 'successfull', combine: 'dhs' do
281
+ context "successfull", combine: "dhs" do
284
282
  it_is_expected_to_redirect_to_index
285
283
  it_is_expected_to_have_flash(:notice)
286
284
  end
287
285
 
288
- context 'with failure', failing: true, combine: 'dhf' do
286
+ context "with failure", failing: true, combine: "dhf" do
289
287
  it_is_expected_to_redirect_to_index
290
288
  it_is_expected_to_have_flash(:alert)
291
289
  end
292
290
  end
293
291
 
294
- context '.json',
292
+ context ".json",
295
293
  format: :json,
296
294
  unless: skip?(options, %w[destroy json]) do
297
- context 'successfull', combine: 'djs' do
295
+ context "successfull", combine: "djs" do
298
296
  it_is_expected_to_respond(204)
299
297
  it { expect(response.body).to be_blank }
300
298
  end
301
299
 
302
- context 'with failure', failing: true, combine: 'djf' do
300
+ context "with failure", failing: true, combine: "djf" do
303
301
  it_is_expected_to_respond(422)
304
302
  it_is_expected_to_render_json
305
303
  end
@@ -56,7 +56,7 @@ module CrudControllerTestHelper
56
56
  end
57
57
 
58
58
  def ivar(name)
59
- controller.instance_variable_get("@#{name}")
59
+ controller.instance_variable_get(:"@#{name}")
60
60
  end
61
61
 
62
62
  # The params defining the nesting of the test entry.
@@ -77,7 +77,6 @@ module CrudControllerTestHelper
77
77
 
78
78
  # Helper methods to describe contexts.
79
79
  module ClassMethods
80
-
81
80
  # Describe a certain action and provide some usefull metadata.
82
81
  # Tests whether this action is configured to be skipped.
83
82
  def describe_action(method, action, metadata = {}, &block)
@@ -96,7 +95,7 @@ module CrudControllerTestHelper
96
95
  options ||= {}
97
96
  contexts = Array(contexts).flatten
98
97
  skips = Array(options[:skip])
99
- skips = [skips] if skips.blank? || !skips.first.is_a?(Array)
98
+ skips = [ skips ] if skips.blank? || !skips.first.is_a?(Array)
100
99
 
101
100
  skips.flatten.present? &&
102
101
  skips.any? { |skip| skip == contexts.take(skip.size) }
@@ -109,15 +108,15 @@ module CrudControllerTestHelper
109
108
 
110
109
  # Test that a json response is rendered.
111
110
  def it_is_expected_to_render_json
112
- it { expect(response.body).to start_with('{') }
111
+ it { expect(response.body).to start_with("{") }
113
112
  end
114
113
 
115
114
  # Test that test_entry_attrs are set on entry.
116
115
  def it_is_expected_to_set_attrs(action = nil)
117
- it 'sets params as entry attributes' do
118
- attrs = send("#{action}_entry_attrs")
116
+ it "sets params as entry attributes" do
117
+ attrs = send(:"#{action}_entry_attrs")
119
118
  actual = {}
120
- attrs.keys.each do |key|
119
+ attrs.each_key do |key|
121
120
  actual[key] = entry.attributes[key.to_s]
122
121
  end
123
122
  expect(actual).to eq(attrs)
@@ -127,7 +126,7 @@ module CrudControllerTestHelper
127
126
  # Test that the response redirects to the index action.
128
127
  def it_is_expected_to_redirect_to_index
129
128
  it do
130
- is_expected.to redirect_to scope_params.merge(action: 'index',
129
+ is_expected.to redirect_to scope_params.merge(action: "index",
131
130
  id: nil,
132
131
  returning: true)
133
132
  end
@@ -136,7 +135,7 @@ module CrudControllerTestHelper
136
135
  # Test that the response redirects to the show action of the current entry.
137
136
  def it_is_expected_to_redirect_to_show
138
137
  it do
139
- is_expected.to redirect_to scope_params.merge(action: 'show',
138
+ is_expected.to redirect_to scope_params.merge(action: "show",
140
139
  id: entry.id)
141
140
  end
142
141
  end
@@ -156,11 +155,11 @@ module CrudControllerTestHelper
156
155
  end
157
156
 
158
157
  # Test that the current entry is persistend and valid, or not.
159
- def it_is_expected_to_persist_entry(bool = true)
160
- context 'entry' do
158
+ def it_is_expected_to_persist_entry(persist: true)
159
+ context "entry" do
161
160
  subject { entry }
162
161
 
163
- if bool
162
+ if persist
164
163
  it { is_expected.not_to be_new_record }
165
164
  it { is_expected.to be_valid }
166
165
  else
@@ -169,5 +168,4 @@ module CrudControllerTestHelper
169
168
  end
170
169
  end
171
170
  end
172
-
173
171
  end