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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/app/controllers/crud_controller.rb +5 -7
  4. data/app/controllers/dry_crud/generic_model.rb +4 -8
  5. data/app/controllers/dry_crud/nestable.rb +1 -4
  6. data/app/controllers/dry_crud/rememberable.rb +1 -4
  7. data/app/controllers/dry_crud/render_callbacks.rb +2 -10
  8. data/app/controllers/dry_crud/searchable.rb +3 -10
  9. data/app/controllers/dry_crud/sortable.rb +3 -10
  10. data/app/controllers/list_controller.rb +0 -2
  11. data/app/helpers/actions_helper.rb +8 -10
  12. data/app/helpers/dry_crud/form/builder.rb +23 -26
  13. data/app/helpers/dry_crud/form/control.rb +7 -11
  14. data/app/helpers/dry_crud/table/actions.rb +8 -13
  15. data/app/helpers/dry_crud/table/builder.rb +3 -6
  16. data/app/helpers/dry_crud/table/col.rb +1 -4
  17. data/app/helpers/dry_crud/table/sorting.rb +3 -6
  18. data/app/helpers/form_helper.rb +5 -7
  19. data/app/helpers/format_helper.rb +11 -13
  20. data/app/helpers/i18n_helper.rb +8 -10
  21. data/app/helpers/table_helper.rb +2 -4
  22. data/app/helpers/utility_helper.rb +9 -11
  23. data/app/views/layouts/application.html.erb +1 -1
  24. data/app/views/layouts/application.html.haml +1 -1
  25. data/lib/dry_crud/engine.rb +1 -3
  26. data/lib/dry_crud.rb +1 -1
  27. data/lib/generators/dry_crud/dry_crud_generator.rb +17 -17
  28. data/lib/generators/dry_crud/dry_crud_generator_base.rb +8 -8
  29. data/lib/generators/dry_crud/file_generator.rb +6 -6
  30. data/lib/generators/dry_crud/templates/config/initializers/field_error_proc.rb +1 -1
  31. data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +119 -119
  32. data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb +54 -59
  33. data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/table/builder_spec.rb +23 -25
  34. data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +10 -13
  35. data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +88 -92
  36. data/lib/generators/dry_crud/templates/spec/helpers/i18n_helper_spec.rb +33 -34
  37. data/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb +57 -59
  38. data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +18 -21
  39. data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +62 -62
  40. data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +8 -10
  41. data/lib/generators/dry_crud/templates/test/controllers/crud_test_models_controller_test.rb +63 -65
  42. data/lib/generators/dry_crud/templates/test/helpers/custom_assertions_test.rb +20 -22
  43. data/lib/generators/dry_crud/templates/test/helpers/dry_crud/form/builder_test.rb +74 -74
  44. data/lib/generators/dry_crud/templates/test/helpers/dry_crud/table/builder_test.rb +21 -21
  45. data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +13 -15
  46. data/lib/generators/dry_crud/templates/test/helpers/format_helper_test.rb +68 -70
  47. data/lib/generators/dry_crud/templates/test/helpers/i18n_helper_test.rb +26 -28
  48. data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +25 -27
  49. data/lib/generators/dry_crud/templates/test/helpers/utility_helper_test.rb +15 -17
  50. data/lib/generators/dry_crud/templates/test/support/crud_controller_test_helper.rb +13 -15
  51. data/lib/generators/dry_crud/templates/test/support/crud_test_helper.rb +9 -13
  52. data/lib/generators/dry_crud/templates/test/support/crud_test_model.rb +7 -11
  53. data/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb +13 -15
  54. data/lib/generators/dry_crud/templates/test/support/custom_assertions.rb +2 -4
  55. metadata +5 -5
@@ -1,7 +1,6 @@
1
- require 'rails_helper'
1
+ require "rails_helper"
2
2
 
3
3
  describe TableHelper do
4
-
5
4
  include FormatHelper
6
5
  include UtilityHelper
7
6
  include I18nHelper
@@ -15,171 +14,171 @@ describe TableHelper do
15
14
 
16
15
  after(:all) { reset_db }
17
16
 
18
- describe '#plain_table' do
17
+ describe "#plain_table" do
19
18
  subject { plain_table(%w[foo bar], :size) { |t| t.attrs :upcase } }
20
19
 
21
- it 'contains attrs' do
20
+ it "contains attrs" do
22
21
  is_expected.to match(/<th>Size<\/th>/)
23
22
  end
24
23
 
25
- it 'contains block' do
24
+ it "contains block" do
26
25
  is_expected.to match(/<th>Upcase<\/th>/)
27
26
  end
28
27
  end
29
28
 
30
- describe '#plain_table_or_message' do
31
- context 'with empty data' do
29
+ describe "#plain_table_or_message" do
30
+ context "with empty data" do
32
31
  subject { plain_table_or_message([]) }
33
32
 
34
33
  it { is_expected.to be_html_safe }
35
34
 
36
- it 'handles empty data' do
35
+ it "handles empty data" do
37
36
  is_expected.to match(/div class=.table.>.+<\/div>/)
38
37
  end
39
38
  end
40
39
 
41
- context 'with data' do
40
+ context "with data" do
42
41
  subject do
43
42
  plain_table_or_message(%w[foo bar], :size) { |t| t.attrs :upcase }
44
43
  end
45
44
 
46
45
  it { is_expected.to be_html_safe }
47
46
 
48
- it 'renders table' do
47
+ it "renders table" do
49
48
  is_expected.to match(/^<table.*<\/table>$/)
50
49
  end
51
50
  end
52
51
  end
53
52
 
54
- describe '#list_table' do
53
+ describe "#list_table" do
55
54
  let(:entries) { CrudTestModel.all }
56
55
 
57
- context 'default' do
56
+ context "default" do
58
57
  subject do
59
58
  with_test_routing { list_table }
60
59
  end
61
60
 
62
- it 'has 7 rows' do
61
+ it "has 7 rows" do
63
62
  expect_pattern_count(REGEXP_ROWS, 7)
64
63
  end
65
64
 
66
- it 'has 14 sortable headers' do
65
+ it "has 14 sortable headers" do
67
66
  expect_pattern_count(REGEXP_SORT_HEADERS, 14)
68
67
  end
69
68
  end
70
69
 
71
- context 'with custom attributes' do
70
+ context "with custom attributes" do
72
71
  subject do
73
72
  with_test_routing { list_table(:name, :children, :companion_id) }
74
73
  end
75
74
 
76
- it 'has 7 rows' do
75
+ it "has 7 rows" do
77
76
  expect_pattern_count(REGEXP_ROWS, 7)
78
77
  end
79
78
 
80
- it 'has 3 sortable headers' do
79
+ it "has 3 sortable headers" do
81
80
  expect_pattern_count(REGEXP_SORT_HEADERS, 3)
82
81
  end
83
82
  end
84
83
 
85
- context 'with custom block' do
84
+ context "with custom block" do
86
85
  subject do
87
86
  with_test_routing do
88
87
  list_table do |t|
89
88
  t.attrs :name, :children, :companion_id
90
- t.col('head') { |e| tag.span(e.income.to_s) }
89
+ t.col("head") { |e| tag.span(e.income.to_s) }
91
90
  end
92
91
  end
93
92
  end
94
93
 
95
- it 'has 7 rows' do
94
+ it "has 7 rows" do
96
95
  expect_pattern_count(REGEXP_ROWS, 7)
97
96
  end
98
97
 
99
- it 'has 4 headers' do
98
+ it "has 4 headers" do
100
99
  expect_pattern_count(REGEXP_HEADERS, 4)
101
100
  end
102
101
 
103
- it 'has 0 sortable headers' do
102
+ it "has 0 sortable headers" do
104
103
  expect_pattern_count(REGEXP_SORT_HEADERS, 0)
105
104
  end
106
105
 
107
- it 'has 6 spans' do
106
+ it "has 6 spans" do
108
107
  expect_pattern_count(/<span>.+?<\/span>/, 6)
109
108
  end
110
109
  end
111
110
 
112
- context 'with custom attributes and block' do
111
+ context "with custom attributes and block" do
113
112
  subject do
114
113
  with_test_routing do
115
114
  list_table(:name, :children, :companion_id) do |t|
116
- t.col('head') { |e| tag.span(e.income.to_s) }
115
+ t.col("head") { |e| tag.span(e.income.to_s) }
117
116
  end
118
117
  end
119
118
  end
120
119
 
121
- it 'has 7 rows' do
120
+ it "has 7 rows" do
122
121
  expect_pattern_count(REGEXP_ROWS, 7)
123
122
  end
124
123
 
125
- it 'has 4 headers' do
124
+ it "has 4 headers" do
126
125
  expect_pattern_count(REGEXP_HEADERS, 4)
127
126
  end
128
127
 
129
- it 'has 3 sortable headers' do
128
+ it "has 3 sortable headers" do
130
129
  expect_pattern_count(REGEXP_SORT_HEADERS, 3)
131
130
  end
132
131
 
133
- it 'has 6 spans' do
132
+ it "has 6 spans" do
134
133
  expect_pattern_count(/<span>.+?<\/span>/, 6)
135
134
  end
136
135
  end
137
136
 
138
- context 'with ascending sort params' do
139
- let(:params) { { sort: 'children', sort_dir: 'asc' } }
137
+ context "with ascending sort params" do
138
+ let(:params) { { sort: "children", sort_dir: "asc" } }
140
139
  subject do
141
140
  with_test_routing { list_table }
142
141
  end
143
142
 
144
- it 'has 13 sortable headers' do
143
+ it "has 13 sortable headers" do
145
144
  expect_pattern_count(REGEXP_SORT_HEADERS, 13)
146
145
  end
147
146
 
148
- it 'has 1 ascending sort headers' do
147
+ it "has 1 ascending sort headers" do
149
148
  expect_pattern_count(
150
149
  /<th><a .*?sort_dir=desc.*?>Children<\/a> &darr;<\/th>/, 1
151
150
  )
152
151
  end
153
152
  end
154
153
 
155
- context 'with descending sort params' do
156
- let(:params) { { sort: 'children', sort_dir: 'desc' } }
154
+ context "with descending sort params" do
155
+ let(:params) { { sort: "children", sort_dir: "desc" } }
157
156
  subject do
158
157
  with_test_routing { list_table }
159
158
  end
160
159
 
161
- it 'has 13 sortable headers' do
160
+ it "has 13 sortable headers" do
162
161
  expect_pattern_count(REGEXP_SORT_HEADERS, 13)
163
162
  end
164
163
 
165
- it 'has 1 descending sort headers' do
164
+ it "has 1 descending sort headers" do
166
165
  expect_pattern_count(
167
166
  /<th><a .*?sort_dir=asc.*?>Children<\/a> &uarr;<\/th>/, 1
168
167
  )
169
168
  end
170
169
  end
171
170
 
172
- context 'with custom column sort params' do
173
- let(:params) { { sort: 'chatty', sort_dir: 'asc' } }
171
+ context "with custom column sort params" do
172
+ let(:params) { { sort: "chatty", sort_dir: "asc" } }
174
173
  subject do
175
174
  with_test_routing { list_table(:name, :children, :chatty) }
176
175
  end
177
176
 
178
- it 'has 2 sortable headers' do
177
+ it "has 2 sortable headers" do
179
178
  expect_pattern_count(REGEXP_SORT_HEADERS, 2)
180
179
  end
181
180
 
182
- it 'has 1 ascending sort headers' do
181
+ it "has 1 ascending sort headers" do
183
182
  expect_pattern_count(
184
183
  /<th><a .*?sort_dir=desc.*?>Chatty<\/a> &darr;<\/th>/, 1
185
184
  )
@@ -187,78 +186,78 @@ describe TableHelper do
187
186
  end
188
187
  end
189
188
 
190
- describe '#crud_table' do
189
+ describe "#crud_table" do
191
190
  let(:entries) { CrudTestModel.all }
192
191
 
193
- context 'default' do
192
+ context "default" do
194
193
  subject do
195
194
  with_test_routing { crud_table }
196
195
  end
197
196
 
198
- it 'has 7 rows' do
197
+ it "has 7 rows" do
199
198
  expect_pattern_count(REGEXP_ROWS, 7)
200
199
  end
201
200
 
202
- it 'has 14 sort headers' do
201
+ it "has 14 sort headers" do
203
202
  expect_pattern_count(REGEXP_SORT_HEADERS, 14)
204
203
  end
205
204
 
206
- it 'has 12 action cells' do
205
+ it "has 12 action cells" do
207
206
  expect_pattern_count(REGEXP_ACTION_CELL, 12)
208
207
  end
209
208
  end
210
209
 
211
- context 'with custom attrs' do
210
+ context "with custom attrs" do
212
211
  subject do
213
212
  with_test_routing { crud_table(:name, :children, :companion_id) }
214
213
  end
215
214
 
216
- it 'has 3 sort headers' do
215
+ it "has 3 sort headers" do
217
216
  expect_pattern_count(REGEXP_SORT_HEADERS, 3)
218
217
  end
219
218
  end
220
219
 
221
- context 'with custom block' do
220
+ context "with custom block" do
222
221
  subject do
223
222
  with_test_routing do
224
223
  crud_table do |t|
225
224
  t.attrs :name, :children, :companion_id
226
- t.col('head') { |e| tag.span(e.income.to_s) }
225
+ t.col("head") { |e| tag.span(e.income.to_s) }
227
226
  end
228
227
  end
229
228
  end
230
229
 
231
- it 'has 4 headers' do
230
+ it "has 4 headers" do
232
231
  expect_pattern_count(REGEXP_HEADERS, 6)
233
232
  end
234
233
 
235
- it 'has 6 custom col spans' do
234
+ it "has 6 custom col spans" do
236
235
  expect_pattern_count(/<span>.+?<\/span>/m, 6)
237
236
  end
238
237
 
239
- it 'has 12 action cells' do
238
+ it "has 12 action cells" do
240
239
  expect_pattern_count(REGEXP_ACTION_CELL, 12)
241
240
  end
242
241
  end
243
242
 
244
- context 'with custom attributes and block' do
243
+ context "with custom attributes and block" do
245
244
  subject do
246
245
  with_test_routing do
247
246
  crud_table(:name, :children, :companion_id) do |t|
248
- t.col('head') { |e| tag.span(e.income.to_s) }
247
+ t.col("head") { |e| tag.span(e.income.to_s) }
249
248
  end
250
249
  end
251
250
  end
252
251
 
253
- it 'has 3 sort headers' do
252
+ it "has 3 sort headers" do
254
253
  expect_pattern_count(REGEXP_SORT_HEADERS, 3)
255
254
  end
256
255
 
257
- it 'has 6 custom col spans' do
256
+ it "has 6 custom col spans" do
258
257
  expect_pattern_count(/<span>.+?<\/span>/m, 6)
259
258
  end
260
259
 
261
- it 'has 12 action cells' do
260
+ it "has 12 action cells" do
262
261
  expect_pattern_count(REGEXP_ACTION_CELL, 12)
263
262
  end
264
263
  end
@@ -267,5 +266,4 @@ describe TableHelper do
267
266
  def expect_pattern_count(pattern, count)
268
267
  expect(subject.scan(pattern).size).to eq(count)
269
268
  end
270
-
271
269
  end
@@ -1,7 +1,6 @@
1
- require 'rails_helper'
1
+ require "rails_helper"
2
2
 
3
3
  describe UtilityHelper do
4
-
5
4
  include CrudTestHelper
6
5
 
7
6
  before(:all) do
@@ -12,10 +11,10 @@ describe UtilityHelper do
12
11
 
13
12
  after(:all) { reset_db }
14
13
 
15
- describe '#column_type' do
14
+ describe "#column_type" do
16
15
  let(:model) { crud_test_models(:AAAAA) }
17
16
 
18
- it 'recognizes types' do
17
+ it "recognizes types" do
19
18
  expect(column_type(model, :name)).to eq(:string)
20
19
  expect(column_type(model, :children)).to eq(:integer)
21
20
  expect(column_type(model, :companion_id)).to eq(:integer)
@@ -30,39 +29,38 @@ describe UtilityHelper do
30
29
  end
31
30
  end
32
31
 
33
- describe '#content_tag_nested' do
34
-
35
- it 'escapes safe content' do
32
+ describe "#content_tag_nested" do
33
+ it "escapes safe content" do
36
34
  html = content_tag_nested(:div, %w[a b]) { |e| tag.span(e) }
37
35
  expect(html).to be_html_safe
38
- expect(html).to eq('<div><span>a</span><span>b</span></div>')
36
+ expect(html).to eq("<div><span>a</span><span>b</span></div>")
39
37
  end
40
38
 
41
- it 'escapes unsafe content' do
39
+ it "escapes unsafe content" do
42
40
  html = content_tag_nested(:div, %w[a b]) { |e| "<#{e}>" }
43
- expect(html).to eq('<div>&lt;a&gt;&lt;b&gt;</div>')
41
+ expect(html).to eq("<div>&lt;a&gt;&lt;b&gt;</div>")
44
42
  end
45
43
 
46
- it 'simplys join without block' do
44
+ it "simplys join without block" do
47
45
  html = content_tag_nested(:div, %w[a b])
48
- expect(html).to eq('<div>ab</div>')
46
+ expect(html).to eq("<div>ab</div>")
49
47
  end
50
48
  end
51
49
 
52
- describe '#safe_join' do
53
- it 'works as super without block' do
54
- html = safe_join(['<a>', '<b>'.html_safe])
55
- expect(html).to eq('&lt;a&gt;<b>')
50
+ describe "#safe_join" do
51
+ it "works as super without block" do
52
+ html = safe_join([ "<a>", "<b>".html_safe ])
53
+ expect(html).to eq("&lt;a&gt;<b>")
56
54
  end
57
55
 
58
- it 'collects contents for array' do
56
+ it "collects contents for array" do
59
57
  html = safe_join(%w[a b]) { |e| tag.span(e) }
60
- expect(html).to eq('<span>a</span><span>b</span>')
58
+ expect(html).to eq("<span>a</span><span>b</span>")
61
59
  end
62
60
  end
63
61
 
64
- describe '#default_crud_attrs' do
65
- it 'do not contain id and password' do
62
+ describe "#default_crud_attrs" do
63
+ it "do not contain id and password" do
66
64
  expect(default_crud_attrs).to eq(
67
65
  %i[name email whatever children companion_id rating income
68
66
  birthdate gets_up_at last_seen human remarks
@@ -70,5 +68,4 @@ describe UtilityHelper do
70
68
  )
71
69
  end
72
70
  end
73
-
74
71
  end