dry_crud 2.1.1 → 2.1.2

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 (37) hide show
  1. checksums.yaml +9 -9
  2. data/VERSION +1 -1
  3. data/app/assets/stylesheets/sample.scss +1 -1
  4. data/app/controllers/crud_controller.rb +1 -1
  5. data/app/controllers/dry_crud/generic_model.rb +45 -45
  6. data/app/controllers/dry_crud/nestable.rb +1 -1
  7. data/app/controllers/dry_crud/render_callbacks.rb +2 -0
  8. data/app/controllers/dry_crud/responder.rb +3 -0
  9. data/app/controllers/list_controller.rb +1 -1
  10. data/app/helpers/dry_crud/form/builder.rb +286 -261
  11. data/app/helpers/dry_crud/form/control.rb +156 -153
  12. data/app/helpers/dry_crud/table/actions.rb +69 -67
  13. data/app/helpers/dry_crud/table/builder.rb +96 -95
  14. data/app/helpers/dry_crud/table/col.rb +17 -16
  15. data/app/helpers/dry_crud/table/sorting.rb +48 -46
  16. data/app/helpers/format_helper.rb +2 -2
  17. data/app/helpers/table_helper.rb +2 -2
  18. data/lib/generators/dry_crud/file_generator.rb +2 -2
  19. data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +4 -6
  20. data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb +11 -11
  21. data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +21 -21
  22. data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +21 -17
  23. data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +8 -8
  24. data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +11 -1
  25. data/lib/generators/dry_crud/templates/test/controllers/crud_test_models_controller_test.rb +6 -6
  26. data/lib/generators/dry_crud/templates/test/helpers/custom_assertions_test.rb +1 -0
  27. data/lib/generators/dry_crud/templates/test/helpers/dry_crud/form/builder_test.rb +250 -245
  28. data/lib/generators/dry_crud/templates/test/helpers/dry_crud/table/builder_test.rb +141 -128
  29. data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +54 -54
  30. data/lib/generators/dry_crud/templates/test/helpers/format_helper_test.rb +4 -4
  31. data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +1 -1
  32. data/lib/generators/dry_crud/templates/test/support/crud_controller_test_helper.rb +3 -2
  33. data/lib/generators/dry_crud/templates/test/support/crud_test_helper.rb +8 -8
  34. data/lib/generators/dry_crud/templates/test/support/crud_test_model.rb +0 -2
  35. data/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb +7 -7
  36. data/lib/generators/dry_crud/templates/test/support/custom_assertions.rb +3 -3
  37. metadata +6 -6
@@ -1,133 +1,146 @@
1
1
  # encoding: UTF-8
2
2
  require 'test_helper'
3
3
 
4
- # Test DryCrud::Table::Builder
5
- class DryCrud::Table::BuilderTest < ActionView::TestCase
6
-
7
- # set dummy helper class for ActionView::TestCase
8
- self.helper_class = UtilityHelper
9
-
10
- include FormatHelper
11
-
12
- attr_reader :table, :entries
13
-
14
- def setup
15
- @entries = %w(foo bahr)
16
- @table = DryCrud::Table::Builder.new(entries, self)
17
- end
18
-
19
- def format_size(obj)
20
- "#{obj.size} chars"
21
- end
22
-
23
- test 'html header' do
24
- table.attrs :upcase, :size
25
-
26
- dom = '<tr><th>Upcase</th><th>Size</th></tr>'
27
-
28
- assert_dom_equal dom, table.send(:html_header)
29
- end
30
-
31
- test 'single attr row' do
32
- table.attrs :upcase, :size
33
-
34
- dom = '<tr><td>FOO</td><td>3 chars</td></tr>'
35
-
36
- assert_dom_equal dom, table.send(:html_row, entries.first)
4
+ module DryCrud
5
+ module Table
6
+ # Test DryCrud::Table::Builder
7
+ class BuilderTest < ActionView::TestCase
8
+
9
+ # set dummy helper class for ActionView::TestCase
10
+ self.helper_class = UtilityHelper
11
+
12
+ include FormatHelper
13
+
14
+ attr_reader :table, :entries
15
+
16
+ def setup
17
+ @entries = %w(foo bahr)
18
+ @table = DryCrud::Table::Builder.new(entries, self)
19
+ end
20
+
21
+ def format_size(obj)
22
+ "#{obj.size} chars"
23
+ end
24
+
25
+ test 'html header' do
26
+ table.attrs :upcase, :size
27
+
28
+ dom = '<tr><th>Upcase</th><th>Size</th></tr>'
29
+
30
+ assert_dom_equal dom, table.send(:html_header)
31
+ end
32
+
33
+ test 'single attr row' do
34
+ table.attrs :upcase, :size
35
+
36
+ dom = '<tr><td>FOO</td><td>3 chars</td></tr>'
37
+
38
+ assert_dom_equal dom, table.send(:html_row, entries.first)
39
+ end
40
+
41
+ test 'custom row' do
42
+ table.col('Header', class: 'hula') { |e| "Weights #{e.size} kg" }
43
+
44
+ dom = '<tr><td class="hula">Weights 3 kg</td></tr>'
45
+
46
+ assert_dom_equal dom, table.send(:html_row, entries.first)
47
+ end
48
+
49
+ test 'attr col output' do
50
+ table.attrs :upcase
51
+ col = table.cols.first
52
+
53
+ assert_equal '<th>Upcase</th>', col.html_header
54
+ assert_equal 'FOO', col.content('foo')
55
+ assert_equal '<td>FOO</td>', col.html_cell('foo')
56
+ end
57
+
58
+ test 'attr col content with custom format_size method' do
59
+ table.attrs :size
60
+ col = table.cols.first
61
+
62
+ assert_equal '4 chars', col.content('abcd')
63
+ end
64
+
65
+ test 'two x two table' do
66
+ dom = <<-FIN
67
+ <table>
68
+ <thead>
69
+ <tr><th>Upcase</th><th>Size</th></tr>
70
+ </thead>
71
+ <tbody>
72
+ <tr><td>FOO</td><td>3 chars</td></tr>
73
+ <tr><td>BAHR</td><td>4 chars</td></tr>
74
+ </tbody>
75
+ </table>
76
+ FIN
77
+ dom.gsub!(/[\n\t]/, '').gsub!(/\s{2,}/, '')
78
+
79
+ table.attrs :upcase, :size
80
+
81
+ assert_dom_equal dom, table.to_html
82
+ end
83
+
84
+ test 'table with before and after cells' do
85
+ dom = <<-FIN
86
+ <table>
87
+ <thead>
88
+ <tr>
89
+ <th class='left'>head</th>
90
+ <th>Upcase</th><th>Size</th>
91
+ <th></th>
92
+ </tr>
93
+ </thead>
94
+ <tbody>
95
+ <tr>
96
+ <td class='left'><a href='/'>foo</a></td>
97
+ <td>FOO</td>
98
+ <td>3 chars</td>
99
+ <td>Never foo</td>
100
+ </tr>
101
+ <tr>
102
+ <td class='left'><a href='/'>bahr</a></td>
103
+ <td>BAHR</td>
104
+ <td>4 chars</td>
105
+ <td>Never bahr</td>
106
+ </tr>
107
+ </tbody>
108
+ </table>
109
+ FIN
110
+ dom.gsub!(/[\n\t]/, '').gsub!(/\s{2,}/, '')
111
+
112
+ table.col('head', class: 'left') { |e| link_to e, '/' }
113
+ table.attrs :upcase, :size
114
+ table.col { |e| "Never #{e}" }
115
+
116
+ assert_dom_equal dom, table.to_html
117
+ end
118
+
119
+ test 'empty entries collection renders empty table' do
120
+ dom = <<-FIN
121
+ <table>
122
+ <thead>
123
+ <tr>
124
+ <th class='left'>head</th>
125
+ <th>Upcase</th>
126
+ <th>Size</th>
127
+ <th></th>
128
+ </tr>
129
+ </thead>
130
+ <tbody>
131
+ </tbody>
132
+ </table>
133
+ FIN
134
+ dom.gsub!(/[\n\t]/, '').gsub!(/\s{2,}/, '')
135
+
136
+ table = DryCrud::Table::Builder.new([], self)
137
+ table.col('head', class: 'left') { |e| link_to e, '/' }
138
+ table.attrs :upcase, :size
139
+ table.col { |e| "Never #{e}" }
140
+
141
+ assert_dom_equal dom, table.to_html
142
+ end
143
+
144
+ end
37
145
  end
38
-
39
- test 'custom row' do
40
- table.col('Header', class: 'hula') { |e| "Weights #{e.size} kg" }
41
-
42
- dom = '<tr><td class="hula">Weights 3 kg</td></tr>'
43
-
44
- assert_dom_equal dom, table.send(:html_row, entries.first)
45
- end
46
-
47
- test 'attr col output' do
48
- table.attrs :upcase
49
- col = table.cols.first
50
-
51
- assert_equal '<th>Upcase</th>', col.html_header
52
- assert_equal 'FOO', col.content('foo')
53
- assert_equal '<td>FOO</td>', col.html_cell('foo')
54
- end
55
-
56
- test 'attr col content with custom format_size method' do
57
- table.attrs :size
58
- col = table.cols.first
59
-
60
- assert_equal '4 chars', col.content('abcd')
61
- end
62
-
63
- test 'two x two table' do
64
- dom = <<-FIN
65
- <table>
66
- <thead>
67
- <tr><th>Upcase</th><th>Size</th></tr>
68
- </thead>
69
- <tbody>
70
- <tr><td>FOO</td><td>3 chars</td></tr>
71
- <tr><td>BAHR</td><td>4 chars</td></tr>
72
- </tbody>
73
- </table>
74
- FIN
75
- dom.gsub!(/[\n\t]/, '').gsub!(/\s{2,}/, '')
76
-
77
- table.attrs :upcase, :size
78
-
79
- assert_dom_equal dom, table.to_html
80
- end
81
-
82
- test 'table with before and after cells' do
83
- dom = <<-FIN
84
- <table>
85
- <thead>
86
- <tr><th class='left'>head</th><th>Upcase</th><th>Size</th><th></th></tr>
87
- </thead>
88
- <tbody>
89
- <tr>
90
- <td class='left'><a href='/'>foo</a></td>
91
- <td>FOO</td>
92
- <td>3 chars</td>
93
- <td>Never foo</td>
94
- </tr>
95
- <tr>
96
- <td class='left'><a href='/'>bahr</a></td>
97
- <td>BAHR</td>
98
- <td>4 chars</td>
99
- <td>Never bahr</td>
100
- </tr>
101
- </tbody>
102
- </table>
103
- FIN
104
- dom.gsub!(/[\n\t]/, '').gsub!(/\s{2,}/, '')
105
-
106
- table.col('head', class: 'left') { |e| link_to e, '/' }
107
- table.attrs :upcase, :size
108
- table.col { |e| "Never #{e}" }
109
-
110
- assert_dom_equal dom, table.to_html
111
- end
112
-
113
- test 'empty entries collection renders empty table' do
114
- dom = <<-FIN
115
- <table>
116
- <thead>
117
- <tr><th class='left'>head</th><th>Upcase</th><th>Size</th><th></th></tr>
118
- </thead>
119
- <tbody>
120
- </tbody>
121
- </table>
122
- FIN
123
- dom.gsub!(/[\n\t]/, '').gsub!(/\s{2,}/, '')
124
-
125
- table = DryCrud::Table::Builder.new([], self)
126
- table.col('head', class: 'left') { |e| link_to e, '/' }
127
- table.attrs :upcase, :size
128
- table.col { |e| "Never #{e}" }
129
-
130
- assert_dom_equal dom, table.to_html
131
- end
132
-
133
146
  end
@@ -23,15 +23,15 @@ class FormHelperTest < ActionView::TestCase
23
23
  end
24
24
  end
25
25
 
26
- assert_match /form .*?action="\/crud_test_models\/#{e.id}"
26
+ assert_match(/form .*?action="\/crud_test_models\/#{e.id}"
27
27
  .*?class="special\ form-horizontal"
28
- .*?method="post"/x, f
29
- assert_match /input .*?name="_method"
28
+ .*?method="post"/x, f)
29
+ assert_match(/input .*?name="_method"
30
30
  .*?type="hidden"
31
- .*?value="(patch|put)"/x, f
32
- assert_match /input .*?name="crud_test_model\[name\]"
31
+ .*?value="(patch|put)"/x, f)
32
+ assert_match(/input .*?name="crud_test_model\[name\]"
33
33
  .*?type="text"
34
- .*?value="AAAAA"/x, f
34
+ .*?value="AAAAA"/x, f)
35
35
  end
36
36
 
37
37
  test 'standard form' do
@@ -45,28 +45,28 @@ class FormHelperTest < ActionView::TestCase
45
45
  end
46
46
  end
47
47
 
48
- assert_match /form .*?action="\/crud_test_models\/#{e.id}"
48
+ assert_match(/form .*?action="\/crud_test_models\/#{e.id}"
49
49
  .*?class="special\ form-horizontal"
50
- .*?method="post"/x, f
51
- assert_match /input .*?name="_method"
50
+ .*?method="post"/x, f)
51
+ assert_match(/input .*?name="_method"
52
52
  .*?type="hidden"
53
- .*?value="(patch|put)"/x, f
54
- assert_match /input .*?name="crud_test_model\[name\]"
53
+ .*?value="(patch|put)"/x, f)
54
+ assert_match(/input .*?name="crud_test_model\[name\]"
55
55
  .*?type="text"
56
- .*?value="AAAAA"/x, f
57
- assert_match /input .*?name="crud_test_model\[birthdate\]"
58
- .*?type="date"/x, f
59
- assert_match /input .*?name="crud_test_model\[children\]"
56
+ .*?value="AAAAA"/x, f)
57
+ assert_match(/input .*?name="crud_test_model\[birthdate\]"
58
+ .*?type="date"/x, f)
59
+ assert_match(/input .*?name="crud_test_model\[children\]"
60
60
  .*?type="number"
61
- .*?value=\"9\"/x, f
62
- assert_match /input .*?name="crud_test_model\[human\]"
63
- .*?type="checkbox"/x, f
64
- assert_match /button\ .*?type="submit"\>
61
+ .*?value=\"9\"/x, f)
62
+ assert_match(/input .*?name="crud_test_model\[human\]"
63
+ .*?type="checkbox"/x, f)
64
+ assert_match(/button\ .*?type="submit"\>
65
65
  #{t('global.button.save')}
66
- \<\/button\>/x, f
67
- assert_match /\<a\ .*href="\/somewhere".*\>
66
+ \<\/button\>/x, f)
67
+ assert_match(/\<a\ .*href="\/somewhere".*\>
68
68
  #{t('global.button.cancel')}
69
- \<\/a\>/x, f
69
+ \<\/a\>/x, f)
70
70
  end
71
71
 
72
72
  test 'standard form with errors' do
@@ -82,18 +82,18 @@ class FormHelperTest < ActionView::TestCase
82
82
  end
83
83
  end
84
84
 
85
- assert_match /form .*?action="\/crud_test_models\/#{e.id}"
86
- .*?method="post"/x, f
87
- assert_match /input .*?name="_method"
85
+ assert_match(/form .*?action="\/crud_test_models\/#{e.id}"
86
+ .*?method="post"/x, f)
87
+ assert_match(/input .*?name="_method"
88
88
  .*?type="hidden"
89
- .*?value="(patch|put)"/x, f
90
- assert_match /div[^>]* id='error_explanation'/, f
91
- assert_match /div\ class="form-group\ has-error"\>.*?
89
+ .*?value="(patch|put)"/x, f)
90
+ assert_match(/div[^>]* id='error_explanation'/, f)
91
+ assert_match(/div\ class="form-group\ has-error"\>.*?
92
92
  \<input .*?name="crud_test_model\[name\]"
93
- .*?type="text"/x, f
94
- assert_match /input .*?name="crud_test_model\[birthdate\]"
93
+ .*?type="text"/x, f)
94
+ assert_match(/input .*?name="crud_test_model\[birthdate\]"
95
95
  .*?type="date"
96
- .*?value="1910-01-01"/x, f
96
+ .*?value="1910-01-01"/x, f)
97
97
  end
98
98
 
99
99
  test 'crud form' do
@@ -101,29 +101,29 @@ class FormHelperTest < ActionView::TestCase
101
101
  capture { crud_form }
102
102
  end
103
103
 
104
- assert_match /form .*?action="\/crud_test_models\/#{entry.id}"/, f
105
- assert_match /input .*?name="crud_test_model\[name\]"
106
- .*?type="text"/x, f
107
- assert_match /input .*?name="crud_test_model\[whatever\]"
108
- .*?type="text"/x, f
109
- assert_match /input .*?name="crud_test_model\[children\]"
110
- .*?type="number"/x, f
111
- assert_match /input .*?name="crud_test_model\[rating\]"
112
- .*?type="number"/x, f
113
- assert_match /input .*?name="crud_test_model\[income\]"
114
- .*?type="number"/x, f
115
- assert_match /input .*?name="crud_test_model\[birthdate\]"
116
- .*?type="date"/x, f
117
- assert_match /input .*?name="crud_test_model\[gets_up_at\]"
118
- .*?type="time"/x, f
119
- assert_match /input .*?name="crud_test_model\[last_seen\]"
120
- .*?type="datetime"/x, f
121
- assert_match /input .*?name="crud_test_model\[human\]"
122
- .*?type="checkbox"/x, f
123
- assert_match /select .*?name="crud_test_model\[companion_id\]"/, f
124
- assert_match /textarea .*?name="crud_test_model\[remarks\]"/, f
125
- assert_match /a .*href="\/crud_test_models\/#{entry.id}\?returning=true"
126
- .*>#{t('global.button.cancel')}<\/a>/x, f
104
+ assert_match(/form .*?action="\/crud_test_models\/#{entry.id}"/, f)
105
+ assert_match(/input .*?name="crud_test_model\[name\]"
106
+ .*?type="text"/x, f)
107
+ assert_match(/input .*?name="crud_test_model\[whatever\]"
108
+ .*?type="text"/x, f)
109
+ assert_match(/input .*?name="crud_test_model\[children\]"
110
+ .*?type="number"/x, f)
111
+ assert_match(/input .*?name="crud_test_model\[rating\]"
112
+ .*?type="number"/x, f)
113
+ assert_match(/input .*?name="crud_test_model\[income\]"
114
+ .*?type="number"/x, f)
115
+ assert_match(/input .*?name="crud_test_model\[birthdate\]"
116
+ .*?type="date"/x, f)
117
+ assert_match(/input .*?name="crud_test_model\[gets_up_at\]"
118
+ .*?type="time"/x, f)
119
+ assert_match(/input .*?name="crud_test_model\[last_seen\]"
120
+ .*?type="datetime"/x, f)
121
+ assert_match(/input .*?name="crud_test_model\[human\]"
122
+ .*?type="checkbox"/x, f)
123
+ assert_match(/select .*?name="crud_test_model\[companion_id\]"/, f)
124
+ assert_match(/textarea .*?name="crud_test_model\[remarks\]"/, f)
125
+ assert_match(/a .*href="\/crud_test_models\/#{entry.id}\?returning=true"
126
+ .*>#{t('global.button.cancel')}<\/a>/x, f)
127
127
  end
128
128
 
129
129
  def entry
@@ -24,7 +24,7 @@ class FormatHelperTest < ActionView::TestCase
24
24
  result = labeled('label') { 'value' }
25
25
 
26
26
  assert result.html_safe?
27
- assert_dom_equal '<dt>label</dt> ' +
27
+ assert_dom_equal '<dt>label</dt> ' \
28
28
  "<dd class='value'>value</dd>",
29
29
  result.squish
30
30
  end
@@ -33,7 +33,7 @@ class FormatHelperTest < ActionView::TestCase
33
33
  result = labeled('label', '')
34
34
 
35
35
  assert result.html_safe?
36
- assert_dom_equal '<dt>label</dt> ' +
36
+ assert_dom_equal '<dt>label</dt> ' \
37
37
  "<dd class='value'>#{EMPTY_STRING}</dd>",
38
38
  result.squish
39
39
  end
@@ -42,7 +42,7 @@ class FormatHelperTest < ActionView::TestCase
42
42
  result = labeled('label', 'value <unsafe>')
43
43
 
44
44
  assert result.html_safe?
45
- assert_dom_equal '<dt>label</dt> ' +
45
+ assert_dom_equal '<dt>label</dt> ' \
46
46
  "<dd class='value'>value &lt;unsafe&gt;</dd>",
47
47
  result.squish
48
48
  end
@@ -50,7 +50,7 @@ class FormatHelperTest < ActionView::TestCase
50
50
  test 'labeled attr' do
51
51
  result = labeled_attr('foo', :size)
52
52
  assert result.html_safe?
53
- assert_dom_equal '<dt>Size</dt> ' +
53
+ assert_dom_equal '<dt>Size</dt> ' \
54
54
  "<dd class='value'>3 chars</dd>",
55
55
  result.squish
56
56
  end