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,7 +1,6 @@
1
- require 'rails_helper'
2
-
3
- describe 'DryCrud::Form::Builder' do
1
+ require "rails_helper"
4
2
 
3
+ describe "DryCrud::Form::Builder" do
5
4
  include FormatHelper
6
5
  include FormHelper
7
6
  include UtilityHelper
@@ -19,12 +18,11 @@ describe 'DryCrud::Form::Builder' do
19
18
  let(:entry) { CrudTestModel.first }
20
19
  let(:form) { DryCrud::Form::Builder.new(:entry, entry, self, {}) }
21
20
 
22
- describe '#input_field' do
23
-
24
- it 'dispatches name attr to string field' do
21
+ describe "#input_field" do
22
+ it "dispatches name attr to string field" do
25
23
  expect(form).to receive(:string_field)
26
- .with(:name, required: 'required')
27
- .and_return('<input>')
24
+ .with(:name, required: "required")
25
+ .and_return("<input>")
28
26
  form.input_field(:name)
29
27
  end
30
28
 
@@ -42,140 +40,138 @@ describe 'DryCrud::Form::Builder' do
42
40
  other_ids: :has_many_field,
43
41
  more_ids: :has_many_field }.each do |attr, method|
44
42
  it "dispatches #{attr} attr to #{method}" do
45
- expect(form).to receive(method).with(attr, {})
43
+ expect(form).to receive(method).with(attr)
46
44
  form.input_field(attr)
47
45
  end
48
46
 
49
47
  it { expect(form.input_field(attr)).to be_html_safe }
50
48
  end
51
-
52
49
  end
53
50
 
54
- describe '#labeled_input_fields' do
51
+ describe "#labeled_input_fields" do
55
52
  subject { form.labeled_input_fields(:name, :remarks, :children) }
56
53
 
57
54
  it { is_expected.to be_html_safe }
58
- it { is_expected.to include(form.input_field(:name, required: 'required')) }
55
+ it { is_expected.to include(form.input_field(:name, required: "required")) }
59
56
  it { is_expected.to include(form.input_field(:remarks)) }
60
57
  it { is_expected.to include(form.input_field(:children)) }
61
58
  end
62
59
 
63
- describe '#labeled_input_field' do
64
- context 'when required' do
60
+ describe "#labeled_input_field" do
61
+ context "when required" do
65
62
  subject { form.labeled_input_field(:name) }
66
- it { is_expected.to include('input-group-append') }
63
+ it { is_expected.to include("input-group-text") }
67
64
  end
68
65
 
69
- context 'when not required' do
66
+ context "when not required" do
70
67
  subject { form.labeled_input_field(:remarks) }
71
- it { is_expected.not_to include('input-group-append') }
68
+ it { is_expected.not_to include("input-group-text") }
72
69
  end
73
70
 
74
- context 'with help text' do
75
- subject { form.labeled_input_field(:name, help: 'Some Help') }
76
- it { is_expected.to include(form.help_block('Some Help')) }
71
+ context "with help text" do
72
+ subject { form.labeled_input_field(:name, help: "Some Help") }
73
+ it { is_expected.to include(form.help_block("Some Help")) }
77
74
  end
78
75
  end
79
76
 
80
- describe '#belongs_to_field' do
81
- it 'has all options by default' do
77
+ describe "#belongs_to_field" do
78
+ it "has all options by default" do
82
79
  f = form.belongs_to_field(:companion_id)
83
80
  expect_n_options(f, 7)
84
81
  end
85
82
 
86
- it 'with has options from :list option' do
83
+ it "with has options from :list option" do
87
84
  list = CrudTestModel.all
88
85
  f = form.belongs_to_field(:companion_id,
89
- list: [list.first, list.second])
86
+ list: [ list.first, list.second ])
90
87
  expect_n_options(f, 3)
91
88
  end
92
89
 
93
- it 'with empty instance list has no select' do
90
+ it "with empty instance list has no select" do
94
91
  assign(:companions, [])
95
92
  @companions = []
96
93
  f = form.belongs_to_field(:companion_id)
97
- expect(f).to match t('global.associations.none_available')
94
+ expect(f).to match t("global.associations.none_available")
98
95
  expect_n_options(f, 0)
99
96
  end
100
97
  end
101
98
 
102
- describe '#has_and_belongs_to_many_field' do
99
+ describe "#has_and_belongs_to_many_field" do
103
100
  let(:others) { OtherCrudTestModel.all[0..1] }
104
101
 
105
- it 'has all options by default' do
102
+ it "has all options by default" do
106
103
  f = form.has_many_field(:other_ids)
107
104
  expect_n_options(f, 6)
108
105
  end
109
106
 
110
- it 'uses options from :list option if given' do
107
+ it "uses options from :list option if given" do
111
108
  f = form.has_many_field(:other_ids, list: others)
112
109
  expect_n_options(f, 2)
113
110
  end
114
111
 
115
- it 'uses options form instance variable if given' do
112
+ it "uses options form instance variable if given" do
116
113
  assign(:others, others)
117
114
  @others = others
118
115
  f = form.has_many_field(:other_ids)
119
116
  expect_n_options(f, 2)
120
117
  end
121
118
 
122
- it 'displays a message for an empty list' do
119
+ it "displays a message for an empty list" do
123
120
  @others = []
124
121
  f = form.has_many_field(:other_ids)
125
- expect(f).to match t('global.associations.none_available')
122
+ expect(f).to match t("global.associations.none_available")
126
123
  expect_n_options(f, 0)
127
124
  end
128
125
  end
129
126
 
130
- describe '#string_field' do
131
- it 'sets maxlength if attr has a limit' do
127
+ describe "#string_field" do
128
+ it "sets maxlength if attr has a limit" do
132
129
  expect(form.string_field(:name)).to match(/maxlength="50"/)
133
130
  end
134
131
  end
135
132
 
136
- describe '#label' do
137
- context 'only with attr' do
133
+ describe "#label" do
134
+ context "only with attr" do
138
135
  subject { form.label(:gugus_dada) }
139
136
 
140
137
  it { is_expected.to be_html_safe }
141
- it 'provides the same interface as rails' do
138
+ it "provides the same interface as rails" do
142
139
  is_expected.to match(/label [^>]*for.+Gugus dada/)
143
140
  end
144
141
  end
145
142
 
146
- context 'with attr and text' do
147
- subject { form.label(:gugus_dada, 'hoho') }
143
+ context "with attr and text" do
144
+ subject { form.label(:gugus_dada, "hoho") }
148
145
 
149
146
  it { is_expected.to be_html_safe }
150
- it 'provides the same interface as rails' do
147
+ it "provides the same interface as rails" do
151
148
  is_expected.to match(/label [^>]*for.+hoho/)
152
149
  end
153
150
  end
154
-
155
151
  end
156
152
 
157
- describe '#labeled' do
158
- context 'in labeled_ method' do
153
+ describe "#labeled" do
154
+ context "in labeled_ method" do
159
155
  subject { form.labeled_string_field(:name) }
160
156
 
161
157
  it { is_expected.to be_html_safe }
162
- it 'provides the same interface as rails' do
158
+ it "provides the same interface as rails" do
163
159
  is_expected.to match(/label [^>]*for.+input/m)
164
160
  end
165
161
  end
166
162
 
167
- context 'with custom content in argument' do
163
+ context "with custom content in argument" do
168
164
  subject do
169
- form.labeled('gugus', "<input type='text' name='gugus' />".html_safe)
165
+ form.labeled("gugus", "<input type='text' name='gugus' />".html_safe)
170
166
  end
171
167
 
172
168
  it { is_expected.to be_html_safe }
173
169
  it { is_expected.to match(/label [^>]*for.+<input/m) }
174
170
  end
175
171
 
176
- context 'with custom content in block' do
172
+ context "with custom content in block" do
177
173
  subject do
178
- form.labeled('gugus') do
174
+ form.labeled("gugus") do
179
175
  "<input type='text' name='gugus' />".html_safe
180
176
  end
181
177
  end
@@ -184,20 +180,20 @@ describe 'DryCrud::Form::Builder' do
184
180
  it { is_expected.to match(/label [^>]*for.+<input/m) }
185
181
  end
186
182
 
187
- context 'with caption and content in argument' do
183
+ context "with caption and content in argument" do
188
184
  subject do
189
- form.labeled('gugus',
185
+ form.labeled("gugus",
190
186
  "<input type='text' name='gugus' />".html_safe,
191
- caption: 'Caption')
187
+ caption: "Caption")
192
188
  end
193
189
 
194
190
  it { is_expected.to be_html_safe }
195
191
  it { is_expected.to match(/label [^>]*for.+>Caption<\/label>.*<input/m) }
196
192
  end
197
193
 
198
- context 'with caption and content in block' do
194
+ context "with caption and content in block" do
199
195
  subject do
200
- form.labeled('gugus', caption: 'Caption') do
196
+ form.labeled("gugus", caption: "Caption") do
201
197
  "<input type='text' name='gugus' />".html_safe
202
198
  end
203
199
  end
@@ -207,26 +203,25 @@ describe 'DryCrud::Form::Builder' do
207
203
  end
208
204
  end
209
205
 
210
- it 'handles missing methods' do
206
+ it "handles missing methods" do
211
207
  expect { form.blabla }.to raise_error(NoMethodError)
212
208
  end
213
209
 
214
- context '#respond_to?' do
215
- it 'returns false for non existing methods' do
210
+ context "#respond_to?" do
211
+ it "returns false for non existing methods" do
216
212
  expect(form.respond_to?(:blabla)).to be false
217
213
  end
218
214
 
219
- it 'returns true for existing methods' do
215
+ it "returns true for existing methods" do
220
216
  expect(form.respond_to?(:text_field)).to be true
221
217
  end
222
218
 
223
- it 'returns true for labeled_ methods' do
219
+ it "returns true for labeled_ methods" do
224
220
  expect(form.respond_to?(:labeled_text_field)).to be true
225
221
  end
226
222
  end
227
223
 
228
224
  def expect_n_options(form, count)
229
- expect(form.scan('</option>').size).to eq(count)
225
+ expect(form.scan("</option>").size).to eq(count)
230
226
  end
231
-
232
227
  end
@@ -1,54 +1,53 @@
1
- require 'rails_helper'
2
-
3
- describe 'DryCrud::Table::Builder' do
1
+ require "rails_helper"
4
2
 
3
+ describe "DryCrud::Table::Builder" do
5
4
  include FormatHelper
6
5
  include UtilityHelper
7
6
 
8
7
  let(:entries) { %w[foo bahr] }
9
8
  let(:table) { DryCrud::Table::Builder.new(entries, self) }
10
9
 
11
- def format_size(obj) #:nodoc:
10
+ def format_size(obj) # :nodoc:
12
11
  "#{obj.size} chars"
13
12
  end
14
13
 
15
- specify '#html_header' do
14
+ specify "#html_header" do
16
15
  table.attrs :upcase, :size
17
- dom = '<tr><th>Upcase</th><th>Size</th></tr>'
16
+ dom = "<tr><th>Upcase</th><th>Size</th></tr>"
18
17
  assert_dom_equal dom, table.send(:html_header)
19
18
  end
20
19
 
21
- specify 'single attr row' do
20
+ specify "single attr row" do
22
21
  table.attrs :upcase, :size
23
- dom = '<tr><td>FOO</td><td>3 chars</td></tr>'
22
+ dom = "<tr><td>FOO</td><td>3 chars</td></tr>"
24
23
  assert_dom_equal dom, table.send(:html_row, entries.first)
25
24
  end
26
25
 
27
- specify 'custom row' do
28
- table.col('Header', class: 'hula') { |e| "Weights #{e.size} kg" }
26
+ specify "custom row" do
27
+ table.col("Header", class: "hula") { |e| "Weights #{e.size} kg" }
29
28
  dom = '<tr><td class="hula">Weights 3 kg</td></tr>'
30
29
  assert_dom_equal dom, table.send(:html_row, entries.first)
31
30
  end
32
31
 
33
- context 'attr col' do
32
+ context "attr col" do
34
33
  let(:col) { table.cols.first }
35
34
 
36
- context 'output' do
35
+ context "output" do
37
36
  before { table.attrs :upcase }
38
37
 
39
- it { expect(col.html_header).to eq('<th>Upcase</th>') }
40
- it { expect(col.content('foo')).to eq('FOO') }
41
- it { expect(col.html_cell('foo')).to eq('<td>FOO</td>') }
38
+ it { expect(col.html_header).to eq("<th>Upcase</th>") }
39
+ it { expect(col.content("foo")).to eq("FOO") }
40
+ it { expect(col.html_cell("foo")).to eq("<td>FOO</td>") }
42
41
  end
43
42
 
44
- context 'content with custom format_size method' do
43
+ context "content with custom format_size method" do
45
44
  before { table.attrs :size }
46
45
 
47
- it { expect(col.content('abcd')).to eq('4 chars') }
46
+ it { expect(col.content("abcd")).to eq("4 chars") }
48
47
  end
49
48
  end
50
49
 
51
- specify 'two x two table' do
50
+ specify "two x two table" do
52
51
  dom = <<-FIN
53
52
  <table>
54
53
  <thead>
@@ -60,14 +59,14 @@ describe 'DryCrud::Table::Builder' do
60
59
  </tbody>
61
60
  </table>
62
61
  FIN
63
- dom.gsub!(/[\n\t]/, '').gsub!(/\s{2,}/, '')
62
+ dom.gsub!(/[\n\t]/, "").gsub!(/\s{2,}/, "")
64
63
 
65
64
  table.attrs :upcase, :size
66
65
 
67
66
  assert_dom_equal dom, table.to_html
68
67
  end
69
68
 
70
- specify 'table with before and after cells' do
69
+ specify "table with before and after cells" do
71
70
  dom = <<-FIN
72
71
  <table>
73
72
  <thead>
@@ -89,16 +88,16 @@ describe 'DryCrud::Table::Builder' do
89
88
  </tbody>
90
89
  </table>
91
90
  FIN
92
- dom.gsub!(/[\n\t]/, '').gsub!(/\s{2,}/, '')
91
+ dom.gsub!(/[\n\t]/, "").gsub!(/\s{2,}/, "")
93
92
 
94
- table.col('head', class: 'left') { |e| link_to e, '/' }
93
+ table.col("head", class: "left") { |e| link_to e, "/" }
95
94
  table.attrs :upcase, :size
96
95
  table.col { |e| "Never #{e}" }
97
96
 
98
97
  assert_dom_equal dom, table.to_html
99
98
  end
100
99
 
101
- specify 'empty entries collection renders empty table' do
100
+ specify "empty entries collection renders empty table" do
102
101
  dom = <<-FIN
103
102
  <table>
104
103
  <thead>
@@ -108,14 +107,13 @@ describe 'DryCrud::Table::Builder' do
108
107
  </tbody>
109
108
  </table>
110
109
  FIN
111
- dom.gsub!(/[\n\t]/, '').gsub!(/\s{2,}/, '')
110
+ dom.gsub!(/[\n\t]/, "").gsub!(/\s{2,}/, "")
112
111
 
113
112
  table = DryCrud::Table::Builder.new([], self)
114
- table.col('head', class: 'left') { |e| link_to e, '/' }
113
+ table.col("head", class: "left") { |e| link_to e, "/" }
115
114
  table.attrs :upcase, :size
116
115
  table.col { |e| "Never #{e}" }
117
116
 
118
117
  assert_dom_equal dom, table.to_html
119
118
  end
120
-
121
119
  end
@@ -1,7 +1,6 @@
1
- require 'rails_helper'
1
+ require "rails_helper"
2
2
 
3
3
  describe FormHelper do
4
-
5
4
  include UtilityHelper
6
5
  include FormatHelper
7
6
  include I18nHelper
@@ -15,18 +14,18 @@ describe FormHelper do
15
14
 
16
15
  after(:all) { reset_db }
17
16
 
18
- describe '#plain_form' do
17
+ describe "#plain_form" do
19
18
  subject do
20
19
  with_test_routing do
21
20
  capture do
22
- plain_form(entry, html: { class: 'special' }) do |f|
21
+ plain_form(entry, html: { class: "special" }) do |f|
23
22
  f.labeled_input_fields :name, :birthdate
24
23
  end
25
24
  end
26
25
  end
27
26
  end
28
27
 
29
- context 'for existing entry' do
28
+ context "for existing entry" do
30
29
  let(:entry) { crud_test_models(:AAAAA) }
31
30
 
32
31
  it do
@@ -55,20 +54,19 @@ describe FormHelper do
55
54
  end
56
55
  end
57
56
 
58
- describe '#standard_form' do
59
-
57
+ describe "#standard_form" do
60
58
  subject do
61
59
  with_test_routing do
62
60
  capture do
63
61
  standard_form(entry,
64
62
  :name, :children, :birthdate, :human,
65
- cancel_url: '/somewhere',
66
- html: { class: 'special' })
63
+ cancel_url: "/somewhere",
64
+ html: { class: "special" })
67
65
  end
68
66
  end
69
67
  end
70
68
 
71
- context 'for existing entry' do
69
+ context "for existing entry" do
72
70
  let(:entry) { crud_test_models(:AAAAA) }
73
71
 
74
72
  it do
@@ -97,7 +95,7 @@ describe FormHelper do
97
95
 
98
96
  it do
99
97
  is_expected.to match(/input .*?type="number"
100
- .*?value=\"9\"
98
+ .*?value="9"
101
99
  .*?name="crud_test_model\[children\]"/x)
102
100
  end
103
101
 
@@ -119,7 +117,7 @@ describe FormHelper do
119
117
  end
120
118
  end
121
119
 
122
- context 'for invalid entry' do
120
+ context "for invalid entry" do
123
121
  let(:entry) do
124
122
  e = crud_test_models(:AAAAA)
125
123
  e.name = nil
@@ -132,9 +130,10 @@ describe FormHelper do
132
130
  end
133
131
 
134
132
  it do
135
- is_expected.to match(/div\ class="form-group\ has-error"\>.*?
136
- \<input .*?type="text"
137
- .*?name="crud_test_model\[name\]"/x)
133
+ is_expected.to match(/div\ class="row\ mb-3">.*?
134
+ <input .*?class="is-invalid\ form-control"
135
+ .*?type="text"
136
+ .*?name="crud_test_model\[name\]"/x)
138
137
  end
139
138
 
140
139
  it do
@@ -145,7 +144,7 @@ describe FormHelper do
145
144
  end
146
145
  end
147
146
 
148
- describe '#crud_form' do
147
+ describe "#crud_form" do
149
148
  let(:entry) { CrudTestModel.first }
150
149
  subject do
151
150
  with_test_routing { crud_form }
@@ -191,7 +190,7 @@ describe FormHelper do
191
190
  end
192
191
 
193
192
  it do
194
- is_expected.to match(/input .*?type="datetime\-local"
193
+ is_expected.to match(/input .*?type="datetime-local"
195
194
  .*?name="crud_test_model\[last_seen\]"/x)
196
195
  end
197
196
 
@@ -214,5 +213,4 @@ describe FormHelper do
214
213
  #{t('global.button.cancel')}<\/a>/x)
215
214
  end
216
215
  end
217
-
218
216
  end