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'
1
+ require "rails_helper"
2
2
 
3
3
  describe FormatHelper do
4
-
5
4
  include UtilityHelper
6
5
  include I18nHelper
7
6
  include CrudTestHelper
@@ -15,17 +14,17 @@ describe FormatHelper do
15
14
  after(:all) { reset_db }
16
15
 
17
16
  # define some test format_ methods
18
- def format_size(obj) #:nodoc:
17
+ def format_size(obj) # :nodoc:
19
18
  "#{f(obj.size)} items"
20
19
  end
21
20
 
22
- def format_string_size(obj) #:nodoc:
21
+ def format_string_size(obj) # :nodoc:
23
22
  "#{f(obj.size)} chars"
24
23
  end
25
24
 
26
- describe '#labeled' do
27
- context 'regular' do
28
- subject { labeled('label') { 'value' } }
25
+ describe "#labeled" do
26
+ context "regular" do
27
+ subject { labeled("label") { "value" } }
29
28
 
30
29
  it { is_expected.to be_html_safe }
31
30
  it do
@@ -36,8 +35,8 @@ describe FormatHelper do
36
35
  end
37
36
  end
38
37
 
39
- context 'with empty value' do
40
- subject { labeled('label') { '' } }
38
+ context "with empty value" do
39
+ subject { labeled("label") { "" } }
41
40
 
42
41
  it { is_expected.to be_html_safe }
43
42
  it do
@@ -45,13 +44,13 @@ describe FormatHelper do
45
44
  /<dt>label<\/dt>
46
45
  \ <dd\ class=['"]value['"]>
47
46
  #{UtilityHelper::EMPTY_STRING}
48
- <\/dd>$/x
47
+ <\/dd>$/xo
49
48
  )
50
49
  end
51
50
  end
52
51
 
53
- context 'with unsafe value' do
54
- subject { labeled('label') { 'value <unsafe>' } }
52
+ context "with unsafe value" do
53
+ subject { labeled("label") { "value <unsafe>" } }
55
54
 
56
55
  it { is_expected.to be_html_safe }
57
56
  it do
@@ -65,8 +64,8 @@ describe FormatHelper do
65
64
  end
66
65
  end
67
66
 
68
- describe '#labeled_attr' do
69
- subject { labeled_attr('foo', :size) }
67
+ describe "#labeled_attr" do
68
+ subject { labeled_attr("foo", :size) }
70
69
 
71
70
  it { is_expected.to be_html_safe }
72
71
  it do
@@ -77,110 +76,108 @@ describe FormatHelper do
77
76
  end
78
77
  end
79
78
 
80
- describe '#f' do
81
-
82
- unless ENV['NON_LOCALIZED'] # localization dependent tests
83
- context 'Floats' do
84
- it 'adds two digits' do
85
- expect(f(1.0)).to eq('1.000')
79
+ describe "#f" do
80
+ unless ENV["NON_LOCALIZED"] # localization dependent tests
81
+ context "Floats" do
82
+ it "adds two digits" do
83
+ expect(f(1.0)).to eq("1.000")
86
84
  end
87
85
 
88
- it 'truncates to two digits' do
89
- expect(f(3.14159)).to eq('3.142')
86
+ it "truncates to two digits" do
87
+ expect(f(3.14159)).to eq("3.142")
90
88
  end
91
89
 
92
- it 'adds delimiters' do
93
- expect(f(12_345.6789)).to eq('12,345.679')
90
+ it "adds delimiters" do
91
+ expect(f(12_345.6789)).to eq("12,345.679")
94
92
  end
95
93
  end
96
94
 
97
- context 'Booleans' do
98
- it 'true is_expected.to print yes' do
99
- expect(f(true)).to eq('yes')
95
+ context "Booleans" do
96
+ it "true is_expected.to print yes" do
97
+ expect(f(true)).to eq("yes")
100
98
  end
101
99
 
102
- it 'false is_expected.to print no' do
103
- expect(f(false)).to eq('no')
100
+ it "false is_expected.to print no" do
101
+ expect(f(false)).to eq("no")
104
102
  end
105
103
  end
106
104
 
107
- context 'Dates' do
108
- it 'prints regular date' do
109
- expect(f(Date.new(2013, 6, 9))).to eq('2013-06-09')
105
+ context "Dates" do
106
+ it "prints regular date" do
107
+ expect(f(Date.new(2013, 6, 9))).to eq("2013-06-09")
110
108
  end
111
109
  end
112
110
 
113
- context 'Times' do
114
- it 'prints regular date' do
115
- expect(f(Time.utc(2013, 6, 9, 21, 25))).to eq('2013-06-09 21:25')
111
+ context "Times" do
112
+ it "prints regular date" do
113
+ expect(f(Time.utc(2013, 6, 9, 21, 25))).to eq("2013-06-09 21:25")
116
114
  end
117
115
  end
118
116
  end
119
117
 
120
- context 'nil' do
121
- it 'prints an empty string' do
118
+ context "nil" do
119
+ it "prints an empty string" do
122
120
  expect(f(nil)).to eq(UtilityHelper::EMPTY_STRING)
123
121
  end
124
122
  end
125
123
 
126
- context 'Strings' do
127
- it 'prints regular strings unchanged' do
128
- expect(f('blah blah')).to eq('blah blah')
124
+ context "Strings" do
125
+ it "prints regular strings unchanged" do
126
+ expect(f("blah blah")).to eq("blah blah")
129
127
  end
130
128
 
131
- it 'is not html safe' do
132
- expect(f('<injection>')).not_to be_html_safe
129
+ it "is not html safe" do
130
+ expect(f("<injection>")).not_to be_html_safe
133
131
  end
134
132
  end
135
-
136
133
  end
137
134
 
138
- describe '#format_attr' do
139
- it 'uses #f' do
140
- expect(format_attr('12.342', :to_f)).to eq(f(12.342))
135
+ describe "#format_attr" do
136
+ it "uses #f" do
137
+ expect(format_attr("12.342", :to_f)).to eq(f(12.342))
141
138
  end
142
139
 
143
- it 'uses object attr format method if it exists' do
144
- expect(format_attr('abcd', :size)).to eq('4 chars')
140
+ it "uses object attr format method if it exists" do
141
+ expect(format_attr("abcd", :size)).to eq("4 chars")
145
142
  end
146
143
 
147
- it 'uses general attr format method if it exists' do
148
- expect(format_attr([1, 2], :size)).to eq('2 items')
144
+ it "uses general attr format method if it exists" do
145
+ expect(format_attr([ 1, 2 ], :size)).to eq("2 items")
149
146
  end
150
147
 
151
- it 'formats empty belongs_to' do
148
+ it "formats empty belongs_to" do
152
149
  expect(format_attr(crud_test_models(:AAAAA), :companion)).to eq(
153
- t('global.associations.no_entry')
150
+ t("global.associations.no_entry")
154
151
  )
155
152
  end
156
153
 
157
- it 'formats existing belongs_to' do
154
+ it "formats existing belongs_to" do
158
155
  string = format_attr(crud_test_models(:BBBBB), :companion)
159
- expect(string).to eq('AAAAA')
156
+ expect(string).to eq("AAAAA")
160
157
  end
161
158
 
162
- it 'formats empty has_one' do
159
+ it "formats empty has_one" do
163
160
  expect(format_attr(crud_test_models(:FFFFF), :comrad)).to eq(
164
- t('global.associations.no_entry')
161
+ t("global.associations.no_entry")
165
162
  )
166
163
  end
167
164
 
168
- it 'formats existing has_one' do
165
+ it "formats existing has_one" do
169
166
  string = format_attr(crud_test_models(:AAAAA), :comrad)
170
- expect(string).to eq('BBBBB')
167
+ expect(string).to eq("BBBBB")
171
168
  end
172
169
 
173
- it 'formats existing has_many' do
170
+ it "formats existing has_many" do
174
171
  string = format_attr(crud_test_models(:CCCCC), :others)
175
172
  expect(string).to be_html_safe
176
- expect(string).to eq('<ul><li>AAAAA</li><li>BBBBB</li></ul>')
173
+ expect(string).to eq("<ul><li>AAAAA</li><li>BBBBB</li></ul>")
177
174
  end
178
175
  end
179
176
 
180
- describe '#column_type' do
177
+ describe "#column_type" do
181
178
  let(:model) { crud_test_models(:AAAAA) }
182
179
 
183
- it 'recognizes types' do
180
+ it "recognizes types" do
184
181
  expect(column_type(model, :name)).to eq(:string)
185
182
  expect(column_type(model, :children)).to eq(:integer)
186
183
  expect(column_type(model, :companion_id)).to eq(:integer)
@@ -195,47 +192,47 @@ describe FormatHelper do
195
192
  end
196
193
  end
197
194
 
198
- describe '#format_type' do
195
+ describe "#format_type" do
199
196
  let(:model) { crud_test_models(:AAAAA) }
200
197
 
201
- it 'formats integers' do
198
+ it "formats integers" do
202
199
  model.children = 10_000
203
- expect(format_type(model, :children)).to eq('10,000')
200
+ expect(format_type(model, :children)).to eq("10,000")
204
201
  end
205
202
 
206
- unless ENV['NON_LOCALIZED'] # localization dependent tests
207
- it 'formats floats' do
208
- expect(format_type(model, :rating)).to eq('1.100')
203
+ unless ENV["NON_LOCALIZED"] # localization dependent tests
204
+ it "formats floats" do
205
+ expect(format_type(model, :rating)).to eq("1.100")
209
206
  end
210
207
 
211
- it 'formata decimals' do
212
- expect(format_type(model, :income)).to eq('10,000,000.1111')
208
+ it "formata decimals" do
209
+ expect(format_type(model, :income)).to eq("10,000,000.1111")
213
210
  end
214
211
 
215
- it 'formats dates' do
216
- expect(format_type(model, :birthdate)).to eq('1910-01-01')
212
+ it "formats dates" do
213
+ expect(format_type(model, :birthdate)).to eq("1910-01-01")
217
214
  end
218
215
 
219
- it 'formats times' do
220
- expect(format_type(model, :gets_up_at)).to eq('01:01')
216
+ it "formats times" do
217
+ expect(format_type(model, :gets_up_at)).to eq("01:01")
221
218
  end
222
219
 
223
- it 'formats datetimes' do
224
- expect(format_type(model, :last_seen)).to eq('2010-01-01 11:21')
220
+ it "formats datetimes" do
221
+ expect(format_type(model, :last_seen)).to eq("2010-01-01 11:21")
225
222
  end
226
223
 
227
- it 'formats boolean false' do
224
+ it "formats boolean false" do
228
225
  model.human = false
229
- expect(format_type(model, :human)).to eq('no')
226
+ expect(format_type(model, :human)).to eq("no")
230
227
  end
231
228
 
232
- it 'formats boolean true' do
229
+ it "formats boolean true" do
233
230
  model.human = true
234
- expect(format_type(model, :human)).to eq('yes')
231
+ expect(format_type(model, :human)).to eq("yes")
235
232
  end
236
233
  end
237
234
 
238
- it 'formats texts' do
235
+ it "formats texts" do
239
236
  string = format_type(model, :remarks)
240
237
  expect(string).to be_html_safe
241
238
  expect(string).to eq(
@@ -243,33 +240,32 @@ describe FormatHelper do
243
240
  )
244
241
  end
245
242
 
246
- it 'escapes texts' do
247
- model.remarks = '<unsecure>bla'
243
+ it "escapes texts" do
244
+ model.remarks = "<unsecure>bla"
248
245
  string = format_type(model, :remarks)
249
246
  expect(string).to be_html_safe
250
- expect(string).to eq('<p>&lt;unsecure&gt;bla</p>')
247
+ expect(string).to eq("<p>&lt;unsecure&gt;bla</p>")
251
248
  end
252
249
 
253
- it 'formats empty texts' do
254
- model.remarks = ' '
250
+ it "formats empty texts" do
251
+ model.remarks = " "
255
252
  string = format_type(model, :remarks)
256
253
  expect(string).to be_html_safe
257
254
  expect(string).to eq(UtilityHelper::EMPTY_STRING)
258
255
  end
259
256
  end
260
257
 
261
- describe '#captionize' do
262
- it 'handles symbols' do
263
- expect(captionize(:camel_case)).to eq('Camel Case')
258
+ describe "#captionize" do
259
+ it "handles symbols" do
260
+ expect(captionize(:camel_case)).to eq("Camel Case")
264
261
  end
265
262
 
266
- it 'renders all upper case' do
267
- expect(captionize('all upper case')).to eq('All Upper Case')
263
+ it "renders all upper case" do
264
+ expect(captionize("all upper case")).to eq("All Upper Case")
268
265
  end
269
266
 
270
- it 'renders human attribute name' do
271
- expect(captionize(:gets_up_at, CrudTestModel)).to eq('Gets up at')
267
+ it "renders human attribute name" do
268
+ expect(captionize(:gets_up_at, CrudTestModel)).to eq("Gets up at")
272
269
  end
273
270
  end
274
-
275
271
  end
@@ -1,101 +1,100 @@
1
- require 'rails_helper'
1
+ require "rails_helper"
2
2
 
3
3
  describe I18nHelper do
4
-
5
4
  include CrudTestHelper
6
5
 
7
- describe '#translate_inheritable' do
6
+ describe "#translate_inheritable" do
8
7
  before { @controller = CrudTestModelsController.new }
9
8
 
10
9
  before do
11
10
  I18n.backend.store_translations(
12
11
  I18n.locale,
13
12
  global: {
14
- test_key: 'global'
13
+ test_key: "global"
15
14
  }
16
15
  )
17
16
  end
18
17
  subject { ti(:test_key) }
19
18
 
20
- it { is_expected.to eq('global') }
19
+ it { is_expected.to eq("global") }
21
20
 
22
- context 'with list key' do
21
+ context "with list key" do
23
22
  before do
24
23
  I18n.backend.store_translations(
25
24
  I18n.locale,
26
25
  list: {
27
26
  global: {
28
- test_key: 'list global'
27
+ test_key: "list global"
29
28
  }
30
29
  }
31
30
  )
32
31
  end
33
- it { is_expected.to eq('list global') }
32
+ it { is_expected.to eq("list global") }
34
33
 
35
- context 'and list action key' do
34
+ context "and list action key" do
36
35
  before do
37
36
  I18n.backend.store_translations(
38
37
  I18n.locale,
39
38
  list: {
40
39
  index: {
41
- test_key: 'list index'
40
+ test_key: "list index"
42
41
  }
43
42
  }
44
43
  )
45
44
  end
46
- it { is_expected.to eq('list index') }
45
+ it { is_expected.to eq("list index") }
47
46
 
48
- context 'and crud global key' do
47
+ context "and crud global key" do
49
48
  before do
50
49
  I18n.backend.store_translations(
51
50
  I18n.locale,
52
51
  crud: {
53
52
  global: {
54
- test_key: 'crud global'
53
+ test_key: "crud global"
55
54
  }
56
55
  }
57
56
  )
58
57
  end
59
- it { is_expected.to eq('crud global') }
58
+ it { is_expected.to eq("crud global") }
60
59
 
61
- context 'and crud action key' do
60
+ context "and crud action key" do
62
61
  before do
63
62
  I18n.backend.store_translations(
64
63
  I18n.locale,
65
64
  crud: {
66
65
  index: {
67
- test_key: 'crud index'
66
+ test_key: "crud index"
68
67
  }
69
68
  }
70
69
  )
71
70
  end
72
- it { is_expected.to eq('crud index') }
71
+ it { is_expected.to eq("crud index") }
73
72
 
74
- context 'and controller global key' do
73
+ context "and controller global key" do
75
74
  before do
76
75
  I18n.backend.store_translations(
77
76
  I18n.locale,
78
77
  crud_test_models: {
79
78
  global: {
80
- test_key: 'test global'
79
+ test_key: "test global"
81
80
  }
82
81
  }
83
82
  )
84
83
  end
85
- it { is_expected.to eq('test global') }
84
+ it { is_expected.to eq("test global") }
86
85
 
87
- context 'and controller action key' do
86
+ context "and controller action key" do
88
87
  before do
89
88
  I18n.backend.store_translations(
90
89
  I18n.locale,
91
90
  crud_test_models: {
92
91
  index: {
93
- test_key: 'test index'
92
+ test_key: "test index"
94
93
  }
95
94
  }
96
95
  )
97
96
  end
98
- it { is_expected.to eq('test index') }
97
+ it { is_expected.to eq("test index") }
99
98
  end
100
99
  end
101
100
  end
@@ -104,7 +103,7 @@ describe I18nHelper do
104
103
  end
105
104
  end
106
105
 
107
- describe '#translate_association' do
106
+ describe "#translate_association" do
108
107
  let(:assoc) { CrudTestModel.reflect_on_association(:companion) }
109
108
  subject { ta(:test_key, assoc) }
110
109
 
@@ -113,30 +112,30 @@ describe I18nHelper do
113
112
  I18n.locale,
114
113
  global: {
115
114
  associations: {
116
- test_key: 'global'
115
+ test_key: "global"
117
116
  }
118
117
  }
119
118
  )
120
119
  end
121
- it { is_expected.to eq('global') }
120
+ it { is_expected.to eq("global") }
122
121
 
123
- context 'with model key' do
122
+ context "with model key" do
124
123
  before do
125
124
  I18n.backend.store_translations(
126
125
  I18n.locale,
127
126
  activerecord: {
128
127
  associations: {
129
128
  crud_test_model: {
130
- test_key: 'model'
129
+ test_key: "model"
131
130
  }
132
131
  }
133
132
  }
134
133
  )
135
134
  end
136
135
 
137
- it { is_expected.to eq('model') }
136
+ it { is_expected.to eq("model") }
138
137
 
139
- context 'and assoc key' do
138
+ context "and assoc key" do
140
139
  before do
141
140
  I18n.backend.store_translations(
142
141
  I18n.locale,
@@ -145,7 +144,7 @@ describe I18nHelper do
145
144
  models: {
146
145
  crud_test_model: {
147
146
  companion: {
148
- test_key: 'companion'
147
+ test_key: "companion"
149
148
  }
150
149
  }
151
150
  }
@@ -154,9 +153,9 @@ describe I18nHelper do
154
153
  )
155
154
  end
156
155
 
157
- it { is_expected.to eq('companion') }
158
- it 'uses global without assoc' do
159
- expect(ta(:test_key)).to eq('global')
156
+ it { is_expected.to eq("companion") }
157
+ it "uses global without assoc" do
158
+ expect(ta(:test_key)).to eq("global")
160
159
  end
161
160
  end
162
161
  end