dry_crud 5.0.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. data/README.rdoc +2 -2
  3. data/VERSION +1 -1
  4. data/app/assets/stylesheets/sample.scss +8 -11
  5. data/app/controllers/crud_controller.rb +63 -45
  6. data/app/controllers/dry_crud/generic_model.rb +0 -2
  7. data/app/controllers/dry_crud/nestable.rb +0 -2
  8. data/app/controllers/dry_crud/rememberable.rb +1 -3
  9. data/app/controllers/dry_crud/render_callbacks.rb +0 -2
  10. data/app/controllers/dry_crud/searchable.rb +0 -2
  11. data/app/controllers/dry_crud/sortable.rb +1 -3
  12. data/app/controllers/list_controller.rb +0 -2
  13. data/app/helpers/actions_helper.rb +1 -3
  14. data/app/helpers/dry_crud/form/builder.rb +7 -8
  15. data/app/helpers/dry_crud/form/control.rb +3 -5
  16. data/app/helpers/dry_crud/table/actions.rb +10 -12
  17. data/app/helpers/dry_crud/table/builder.rb +4 -6
  18. data/app/helpers/dry_crud/table/col.rb +0 -2
  19. data/app/helpers/dry_crud/table/sorting.rb +4 -6
  20. data/app/helpers/form_helper.rb +1 -3
  21. data/app/helpers/format_helper.rb +4 -5
  22. data/app/helpers/i18n_helper.rb +0 -2
  23. data/app/helpers/table_helper.rb +0 -2
  24. data/app/helpers/utility_helper.rb +1 -2
  25. data/app/views/layouts/_nav.html.erb +4 -4
  26. data/app/views/layouts/_nav.html.haml +4 -4
  27. data/app/views/layouts/application.html.erb +3 -23
  28. data/app/views/layouts/application.html.haml +3 -21
  29. data/app/views/list/_search.html.erb +4 -4
  30. data/app/views/list/_search.html.haml +2 -2
  31. data/config/locales/crud.it.yml +64 -0
  32. data/lib/dry_crud.rb +1 -0
  33. data/lib/dry_crud/engine.rb +9 -3
  34. data/lib/generators/dry_crud/dry_crud_generator.rb +3 -5
  35. data/lib/generators/dry_crud/dry_crud_generator_base.rb +5 -4
  36. data/lib/generators/dry_crud/file_generator.rb +11 -5
  37. data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +48 -23
  38. data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb +6 -8
  39. data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/table/builder_spec.rb +1 -2
  40. data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +0 -1
  41. data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +23 -7
  42. data/lib/generators/dry_crud/templates/spec/helpers/i18n_helper_spec.rb +43 -11
  43. data/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb +8 -6
  44. data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +8 -8
  45. data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +32 -35
  46. data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +1 -3
  47. data/lib/generators/dry_crud/templates/test/controllers/crud_test_models_controller_test.rb +38 -17
  48. data/lib/generators/dry_crud/templates/test/helpers/custom_assertions_test.rb +0 -1
  49. data/lib/generators/dry_crud/templates/test/helpers/dry_crud/form/builder_test.rb +6 -6
  50. data/lib/generators/dry_crud/templates/test/helpers/dry_crud/table/builder_test.rb +1 -2
  51. data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +1 -2
  52. data/lib/generators/dry_crud/templates/test/helpers/format_helper_test.rb +13 -3
  53. data/lib/generators/dry_crud/templates/test/helpers/i18n_helper_test.rb +28 -11
  54. data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +5 -5
  55. data/lib/generators/dry_crud/templates/test/helpers/utility_helper_test.rb +11 -18
  56. data/lib/generators/dry_crud/templates/test/support/crud_controller_test_helper.rb +5 -7
  57. data/lib/generators/dry_crud/templates/test/support/crud_test_helper.rb +17 -16
  58. data/lib/generators/dry_crud/templates/test/support/crud_test_model.rb +4 -4
  59. data/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb +11 -6
  60. data/lib/generators/dry_crud/templates/test/support/custom_assertions.rb +1 -3
  61. metadata +14 -12
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  require 'rails_helper'
3
2
 
4
3
  # Tests all actions of the CrudController based on a dummy model
@@ -91,7 +90,7 @@ describe CrudTestModelsController do
91
90
  it_is_expected_to_respond
92
91
 
93
92
  it 'entries have one item' do
94
- expect(entries).to eq([CrudTestModel.find_by_name('BBBBB')])
93
+ expect(entries).to eq([CrudTestModel.find_by(name: 'BBBBB')])
95
94
  end
96
95
 
97
96
  it 'session has query list param' do
@@ -113,7 +112,8 @@ describe CrudTestModelsController do
113
112
 
114
113
  it 'session has sort list param' do
115
114
  expect(session[:list_params]['/crud_test_models.html']).to eq(
116
- 'sort' => 'children', 'sort_dir' => 'asc')
115
+ 'sort' => 'children', 'sort_dir' => 'asc'
116
+ )
117
117
  end
118
118
  end
119
119
 
@@ -134,7 +134,8 @@ describe CrudTestModelsController do
134
134
 
135
135
  it 'session has sort list param' do
136
136
  expect(session[:list_params]['/crud_test_models.html']).to eq(
137
- 'sort' => 'chatty', 'sort_dir' => 'desc')
137
+ 'sort' => 'chatty', 'sort_dir' => 'desc'
138
+ )
138
139
  end
139
140
  end
140
141
 
@@ -146,12 +147,13 @@ describe CrudTestModelsController do
146
147
  it_is_expected_to_respond
147
148
 
148
149
  it 'entries are in correct order' do
149
- expect(entries.map(&:name)).to eq(%w(CCCCC DDDDD BBBBB))
150
+ expect(entries.map(&:name)).to eq(%w[CCCCC DDDDD BBBBB])
150
151
  end
151
152
 
152
153
  it 'session has sort list param' do
153
154
  expect(session[:list_params]['/crud_test_models.html']).to eq(
154
- 'q' => 'DDD', 'sort' => 'chatty', 'sort_dir' => 'asc')
155
+ 'q' => 'DDD', 'sort' => 'chatty', 'sort_dir' => 'asc'
156
+ )
155
157
  end
156
158
  end
157
159
  end
@@ -179,7 +181,7 @@ describe CrudTestModelsController do
179
181
  it_is_expected_to_respond
180
182
 
181
183
  it 'entries are in correct order' do
182
- expect(entries.map(&:name)).to eq(%w(BBBBB DDDDD CCCCC))
184
+ expect(entries.map(&:name)).to eq(%w[BBBBB DDDDD CCCCC])
183
185
  end
184
186
 
185
187
  it 'params are set' do
@@ -204,7 +206,8 @@ describe CrudTestModelsController do
204
206
 
205
207
  it 'calls two render callbacks' do
206
208
  expect(controller.called_callbacks).to eq(
207
- [:before_render_new, :before_render_form])
209
+ %i[before_render_new before_render_form]
210
+ )
208
211
  end
209
212
  end
210
213
 
@@ -228,7 +231,8 @@ describe CrudTestModelsController do
228
231
 
229
232
  it 'calls the correct callbacks' do
230
233
  expect(controller.called_callbacks).to eq(
231
- [:before_create, :before_save, :after_save, :after_create])
234
+ %i[before_create before_save after_save after_create]
235
+ )
232
236
  end
233
237
 
234
238
  context 'with before callback' do
@@ -254,7 +258,8 @@ describe CrudTestModelsController do
254
258
 
255
259
  it 'calls the correct callbacks' do
256
260
  expect(controller.called_callbacks).to eq(
257
- [:before_render_new, :before_render_form])
261
+ %i[before_render_new before_render_form]
262
+ )
258
263
  end
259
264
  end
260
265
 
@@ -297,8 +302,9 @@ describe CrudTestModelsController do
297
302
 
298
303
  it 'calls the correct callbacks' do
299
304
  expect(controller.called_callbacks).to eq(
300
- [:before_create, :before_save,
301
- :before_render_new, :before_render_form])
305
+ %i[before_create before_save
306
+ before_render_new before_render_form]
307
+ )
302
308
  end
303
309
  end
304
310
  end
@@ -321,7 +327,8 @@ describe CrudTestModelsController do
321
327
 
322
328
  it 'calls the correct callbacks' do
323
329
  expect(controller.called_callbacks).to eq(
324
- [:before_create, :before_save])
330
+ %i[before_create before_save]
331
+ )
325
332
  end
326
333
  end
327
334
  end
@@ -331,7 +338,8 @@ describe CrudTestModelsController do
331
338
  describe_action :get, :edit, id: true do
332
339
  it 'calls the correct callbacks' do
333
340
  expect(controller.called_callbacks).to eq(
334
- [:before_render_edit, :before_render_form])
341
+ %i[before_render_edit before_render_form]
342
+ )
335
343
  end
336
344
  end
337
345
 
@@ -340,11 +348,19 @@ describe CrudTestModelsController do
340
348
 
341
349
  it 'calls the correct callbacks' do
342
350
  expect(controller.called_callbacks).to eq(
343
- [:before_update, :before_save, :after_save, :after_update])
351
+ %i[before_update before_save after_save after_update]
352
+ )
344
353
  end
345
354
 
346
355
  context 'with invalid params' do
347
- let(:params) { { crud_test_model: { rating: 20 } } }
356
+ let(:params) do
357
+ {
358
+ crud_test_model: {
359
+ rating: 20,
360
+ other_ids: [OtherCrudTestModel.first.id]
361
+ }
362
+ }
363
+ end
348
364
 
349
365
  context '.html', combine: 'uhivp' do
350
366
  it_is_expected_to_respond
@@ -360,8 +376,13 @@ describe CrudTestModelsController do
360
376
 
361
377
  it 'calls the correct callbacks' do
362
378
  expect(controller.called_callbacks).to eq(
363
- [:before_update, :before_save,
364
- :before_render_edit, :before_render_form])
379
+ %i[before_update before_save
380
+ before_render_edit before_render_form]
381
+ )
382
+ end
383
+
384
+ it 'does not update has_many ids' do
385
+ expect(test_entry.reload.other_ids).to eq([])
365
386
  end
366
387
  end
367
388
 
@@ -372,7 +393,8 @@ describe CrudTestModelsController do
372
393
 
373
394
  it 'calls the correct callbacks' do
374
395
  expect(controller.called_callbacks).to eq(
375
- [:before_update, :before_save])
396
+ %i[before_update before_save]
397
+ )
376
398
  end
377
399
  end
378
400
  end
@@ -381,7 +403,8 @@ describe CrudTestModelsController do
381
403
  describe_action :delete, :destroy, id: true do
382
404
  it 'calls the correct callbacks' do
383
405
  expect(controller.called_callbacks).to eq(
384
- [:before_destroy, :after_destroy])
406
+ %i[before_destroy after_destroy]
407
+ )
385
408
  end
386
409
 
387
410
  context 'with failure' do
@@ -389,7 +412,7 @@ describe CrudTestModelsController do
389
412
  context '.html' do
390
413
  it 'does not delete entry from database',
391
414
  perform_request: false do
392
- expect { perform_request }.not_to change { CrudTestModel.count }
415
+ expect { perform_request }.not_to(change { CrudTestModel.count })
393
416
  end
394
417
 
395
418
  it 'redirects to referer',
@@ -411,11 +434,13 @@ describe CrudTestModelsController do
411
434
 
412
435
  context 'callback', perform_request: false do
413
436
  before do
414
- test_entry.update_attribute :name, 'illegal'
437
+ # rubocop:disable Rails/SkipsModelValidations
438
+ test_entry.update_attribute(:name, 'illegal')
439
+ # rubocop:enable Rails/SkipsModelValidations
415
440
  end
416
441
 
417
442
  it 'does not delete entry from database' do
418
- expect { perform_request }.not_to change { CrudTestModel.count }
443
+ expect { perform_request }.not_to(change { CrudTestModel.count })
419
444
  end
420
445
 
421
446
  it 'redirects to index' do
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  require 'rails_helper'
3
2
 
4
3
  describe 'DryCrud::Form::Builder' do
@@ -41,9 +40,8 @@ describe 'DryCrud::Form::Builder' do
41
40
  last_seen: :datetime_field,
42
41
  companion_id: :belongs_to_field,
43
42
  other_ids: :has_many_field,
44
- more_ids: :has_many_field
45
- }.each do |attr, method|
46
- it 'dispatches #{attr} attr to #{method}' do
43
+ more_ids: :has_many_field }.each do |attr, method|
44
+ it "dispatches #{attr} attr to #{method}" do
47
45
  expect(form).to receive(method).with(attr, {})
48
46
  form.input_field(attr)
49
47
  end
@@ -65,12 +63,12 @@ describe 'DryCrud::Form::Builder' do
65
63
  describe '#labeled_input_field' do
66
64
  context 'when required' do
67
65
  subject { form.labeled_input_field(:name) }
68
- it { is_expected.to include('input-group-addon') }
66
+ it { is_expected.to include('input-group-append') }
69
67
  end
70
68
 
71
69
  context 'when not required' do
72
70
  subject { form.labeled_input_field(:remarks) }
73
- it { is_expected.not_to include('input-group-addon') }
71
+ it { is_expected.not_to include('input-group-append') }
74
72
  end
75
73
 
76
74
  context 'with help text' do
@@ -227,8 +225,8 @@ describe 'DryCrud::Form::Builder' do
227
225
  end
228
226
  end
229
227
 
230
- def expect_n_options(f, n)
231
- expect(f.scan('</option>').size).to eq(n)
228
+ def expect_n_options(form, count)
229
+ expect(form.scan('</option>').size).to eq(count)
232
230
  end
233
231
 
234
232
  end
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  require 'rails_helper'
3
2
 
4
3
  describe 'DryCrud::Table::Builder' do
@@ -6,7 +5,7 @@ describe 'DryCrud::Table::Builder' do
6
5
  include FormatHelper
7
6
  include UtilityHelper
8
7
 
9
- let(:entries) { %w(foo bahr) }
8
+ let(:entries) { %w[foo bahr] }
10
9
  let(:table) { DryCrud::Table::Builder.new(entries, self) }
11
10
 
12
11
  def format_size(obj) #:nodoc:
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  require 'rails_helper'
3
2
 
4
3
  describe FormHelper do
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  require 'rails_helper'
3
2
 
4
3
  describe FormatHelper do
@@ -32,7 +31,8 @@ describe FormatHelper do
32
31
  it do
33
32
  expect(subject.squish).to match(
34
33
  /^<dt>label<\/dt>
35
- \ <dd\ class=['"]value['"]>value<\/dd>$/x)
34
+ \ <dd\ class=['"]value['"]>value<\/dd>$/x
35
+ )
36
36
  end
37
37
  end
38
38
 
@@ -45,7 +45,8 @@ describe FormatHelper do
45
45
  /<dt>label<\/dt>
46
46
  \ <dd\ class=['"]value['"]>
47
47
  #{UtilityHelper::EMPTY_STRING}
48
- <\/dd>$/x)
48
+ <\/dd>$/x
49
+ )
49
50
  end
50
51
  end
51
52
 
@@ -58,7 +59,8 @@ describe FormatHelper do
58
59
  /<dt>label<\/dt>
59
60
  \ <dd\ class=['"]value['"]>
60
61
  value\ &lt;unsafe&gt;
61
- <\/dd>$/x)
62
+ <\/dd>$/x
63
+ )
62
64
  end
63
65
  end
64
66
  end
@@ -70,7 +72,8 @@ describe FormatHelper do
70
72
  it do
71
73
  expect(subject.squish).to match(
72
74
  /<dt>Size<\/dt>
73
- \ <dd\ class=['"]value['"]>3\ chars<\/dd>$/x)
75
+ \ <dd\ class=['"]value['"]>3\ chars<\/dd>$/x
76
+ )
74
77
  end
75
78
  end
76
79
 
@@ -147,7 +150,8 @@ describe FormatHelper do
147
150
 
148
151
  it 'formats empty belongs_to' do
149
152
  expect(format_attr(crud_test_models(:AAAAA), :companion)).to eq(
150
- t('global.associations.no_entry'))
153
+ t('global.associations.no_entry')
154
+ )
151
155
  end
152
156
 
153
157
  it 'formats existing belongs_to' do
@@ -155,6 +159,17 @@ describe FormatHelper do
155
159
  expect(string).to eq('AAAAA')
156
160
  end
157
161
 
162
+ it 'formats empty has_one' do
163
+ expect(format_attr(crud_test_models(:FFFFF), :comrad)).to eq(
164
+ t('global.associations.no_entry')
165
+ )
166
+ end
167
+
168
+ it 'formats existing has_one' do
169
+ string = format_attr(crud_test_models(:AAAAA), :comrad)
170
+ expect(string).to eq('BBBBB')
171
+ end
172
+
158
173
  it 'formats existing has_many' do
159
174
  string = format_attr(crud_test_models(:CCCCC), :others)
160
175
  expect(string).to be_html_safe
@@ -224,7 +239,8 @@ describe FormatHelper do
224
239
  string = format_type(model, :remarks)
225
240
  expect(string).to be_html_safe
226
241
  expect(string).to eq(
227
- "<p>AAAAA BBBBB CCCCC\n<br />AAAAA BBBBB CCCCC\n</p>")
242
+ "<p>AAAAA BBBBB CCCCC\n<br />AAAAA BBBBB CCCCC\n</p>"
243
+ )
228
244
  end
229
245
 
230
246
  it 'escapes texts' do
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  require 'rails_helper'
3
2
 
4
3
  describe I18nHelper do
@@ -12,7 +11,9 @@ describe I18nHelper do
12
11
  I18n.backend.store_translations(
13
12
  I18n.locale,
14
13
  global: {
15
- test_key: 'global' })
14
+ test_key: 'global'
15
+ }
16
+ )
16
17
  end
17
18
  subject { ti(:test_key) }
18
19
 
@@ -24,7 +25,10 @@ describe I18nHelper do
24
25
  I18n.locale,
25
26
  list: {
26
27
  global: {
27
- test_key: 'list global' } })
28
+ test_key: 'list global'
29
+ }
30
+ }
31
+ )
28
32
  end
29
33
  it { is_expected.to eq('list global') }
30
34
 
@@ -34,7 +38,10 @@ describe I18nHelper do
34
38
  I18n.locale,
35
39
  list: {
36
40
  index: {
37
- test_key: 'list index' } })
41
+ test_key: 'list index'
42
+ }
43
+ }
44
+ )
38
45
  end
39
46
  it { is_expected.to eq('list index') }
40
47
 
@@ -44,7 +51,10 @@ describe I18nHelper do
44
51
  I18n.locale,
45
52
  crud: {
46
53
  global: {
47
- test_key: 'crud global' } })
54
+ test_key: 'crud global'
55
+ }
56
+ }
57
+ )
48
58
  end
49
59
  it { is_expected.to eq('crud global') }
50
60
 
@@ -54,7 +64,10 @@ describe I18nHelper do
54
64
  I18n.locale,
55
65
  crud: {
56
66
  index: {
57
- test_key: 'crud index' } })
67
+ test_key: 'crud index'
68
+ }
69
+ }
70
+ )
58
71
  end
59
72
  it { is_expected.to eq('crud index') }
60
73
 
@@ -64,7 +77,10 @@ describe I18nHelper do
64
77
  I18n.locale,
65
78
  crud_test_models: {
66
79
  global: {
67
- test_key: 'test global' } })
80
+ test_key: 'test global'
81
+ }
82
+ }
83
+ )
68
84
  end
69
85
  it { is_expected.to eq('test global') }
70
86
 
@@ -74,7 +90,10 @@ describe I18nHelper do
74
90
  I18n.locale,
75
91
  crud_test_models: {
76
92
  index: {
77
- test_key: 'test index' } })
93
+ test_key: 'test index'
94
+ }
95
+ }
96
+ )
78
97
  end
79
98
  it { is_expected.to eq('test index') }
80
99
  end
@@ -94,7 +113,10 @@ describe I18nHelper do
94
113
  I18n.locale,
95
114
  global: {
96
115
  associations: {
97
- test_key: 'global' } })
116
+ test_key: 'global'
117
+ }
118
+ }
119
+ )
98
120
  end
99
121
  it { is_expected.to eq('global') }
100
122
 
@@ -105,7 +127,11 @@ describe I18nHelper do
105
127
  activerecord: {
106
128
  associations: {
107
129
  crud_test_model: {
108
- test_key: 'model' } } })
130
+ test_key: 'model'
131
+ }
132
+ }
133
+ }
134
+ )
109
135
  end
110
136
 
111
137
  it { is_expected.to eq('model') }
@@ -119,7 +145,13 @@ describe I18nHelper do
119
145
  models: {
120
146
  crud_test_model: {
121
147
  companion: {
122
- test_key: 'companion' } } } } })
148
+ test_key: 'companion'
149
+ }
150
+ }
151
+ }
152
+ }
153
+ }
154
+ )
123
155
  end
124
156
 
125
157
  it { is_expected.to eq('companion') }