dry_crud 2.1.2 → 3.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 (37) hide show
  1. checksums.yaml +5 -13
  2. data/README.rdoc +1 -2
  3. data/VERSION +1 -1
  4. data/app/controllers/crud_controller.rb +96 -61
  5. data/app/controllers/dry_crud/generic_model.rb +1 -5
  6. data/app/controllers/dry_crud/rememberable.rb +1 -1
  7. data/app/controllers/dry_crud/render_callbacks.rb +2 -4
  8. data/app/controllers/list_controller.rb +4 -5
  9. data/app/helpers/dry_crud/form/builder.rb +4 -30
  10. data/app/helpers/format_helper.rb +2 -0
  11. data/app/helpers/utility_helper.rb +2 -3
  12. data/app/views/crud/show.json.jbuilder +1 -0
  13. data/app/views/layouts/_flash.html.erb +1 -1
  14. data/app/views/layouts/_flash.html.haml +1 -1
  15. data/app/views/list/index.json.jbuilder +4 -0
  16. data/config/locales/crud.de.yml +1 -1
  17. data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +141 -139
  18. data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/form/builder_spec.rb +47 -48
  19. data/lib/generators/dry_crud/templates/spec/helpers/dry_crud/table/builder_spec.rb +6 -6
  20. data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +66 -66
  21. data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +62 -61
  22. data/lib/generators/dry_crud/templates/spec/helpers/i18n_helper_spec.rb +13 -13
  23. data/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb +42 -38
  24. data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +22 -22
  25. data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +72 -72
  26. data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +54 -45
  27. data/lib/generators/dry_crud/templates/test/controllers/crud_test_models_controller_test.rb +8 -11
  28. data/lib/generators/dry_crud/templates/test/helpers/dry_crud/form/builder_test.rb +1 -6
  29. data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +47 -46
  30. data/lib/generators/dry_crud/templates/test/helpers/format_helper_test.rb +1 -1
  31. data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +9 -3
  32. data/lib/generators/dry_crud/templates/test/support/crud_controller_test_helper.rb +2 -2
  33. data/lib/generators/dry_crud/templates/test/support/crud_test_helper.rb +1 -1
  34. data/lib/generators/dry_crud/templates/test/support/crud_test_model.rb +0 -4
  35. data/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb +5 -10
  36. metadata +15 -18
  37. data/app/controllers/dry_crud/responder.rb +0 -34
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
- require 'spec_helper'
2
+ require 'rails_helper'
3
3
 
4
4
  describe 'DryCrud::Form::Builder' do
5
5
 
@@ -18,24 +18,18 @@ describe 'DryCrud::Form::Builder' do
18
18
  after(:all) { reset_db }
19
19
 
20
20
  let(:entry) { CrudTestModel.first }
21
- if Rails.version < '4.0'
22
- let(:form) do
23
- DryCrud::Form::Builder.new(:entry, entry, self, {}, ->(form) { form })
24
- end
25
- else
26
- let(:form) { DryCrud::Form::Builder.new(:entry, entry, self, {}) }
27
- end
21
+ let(:form) { DryCrud::Form::Builder.new(:entry, entry, self, {}) }
28
22
 
29
23
  describe '#input_field' do
30
24
 
31
25
  it 'dispatches name attr to string field' do
32
- form.should_receive(:string_field)
33
- .with(:name, required: 'required')
34
- .and_return('<input>')
26
+ expect(form).to receive(:string_field)
27
+ .with(:name, required: 'required')
28
+ .and_return('<input>')
35
29
  form.input_field(:name)
36
30
  end
37
31
 
38
- it { form.input_field(:name).should be_html_safe }
32
+ it { expect(form.input_field(:name)).to be_html_safe }
39
33
 
40
34
  { password: :password_field,
41
35
  email: :email_field,
@@ -50,11 +44,11 @@ describe 'DryCrud::Form::Builder' do
50
44
  more_ids: :has_many_field
51
45
  }.each do |attr, method|
52
46
  it 'dispatches #{attr} attr to #{method}' do
53
- form.should_receive(method).with(attr, {})
47
+ expect(form).to receive(method).with(attr, {})
54
48
  form.input_field(attr)
55
49
  end
56
50
 
57
- it { form.input_field(attr).should be_html_safe }
51
+ it { expect(form.input_field(attr)).to be_html_safe }
58
52
  end
59
53
 
60
54
  end
@@ -62,48 +56,48 @@ describe 'DryCrud::Form::Builder' do
62
56
  describe '#labeled_input_fields' do
63
57
  subject { form.labeled_input_fields(:name, :remarks, :children) }
64
58
 
65
- it { should be_html_safe }
66
- it { should include(form.input_field(:name, required: 'required')) }
67
- it { should include(form.input_field(:remarks)) }
68
- it { should include(form.input_field(:children)) }
59
+ it { is_expected.to be_html_safe }
60
+ it { is_expected.to include(form.input_field(:name, required: 'required')) }
61
+ it { is_expected.to include(form.input_field(:remarks)) }
62
+ it { is_expected.to include(form.input_field(:children)) }
69
63
  end
70
64
 
71
65
  describe '#labeled_input_field' do
72
66
  context 'when required' do
73
67
  subject { form.labeled_input_field(:name) }
74
- it { should include('input-group-addon') }
68
+ it { is_expected.to include('input-group-addon') }
75
69
  end
76
70
 
77
71
  context 'when not required' do
78
72
  subject { form.labeled_input_field(:remarks) }
79
- it { should_not include('input-group-addon') }
73
+ it { is_expected.not_to include('input-group-addon') }
80
74
  end
81
75
 
82
76
  context 'with help text' do
83
77
  subject { form.labeled_input_field(:name, help: 'Some Help') }
84
- it { should include(form.help_block('Some Help')) }
78
+ it { is_expected.to include(form.help_block('Some Help')) }
85
79
  end
86
80
  end
87
81
 
88
82
  describe '#belongs_to_field' do
89
83
  it 'has all options by default' do
90
84
  f = form.belongs_to_field(:companion_id)
91
- f.scan('</option>').should have(7).items
85
+ expect_n_options(f, 7)
92
86
  end
93
87
 
94
88
  it 'with has options from :list option' do
95
89
  list = CrudTestModel.all
96
90
  f = form.belongs_to_field(:companion_id,
97
91
  list: [list.first, list.second])
98
- f.scan('</option>').should have(3).items
92
+ expect_n_options(f, 3)
99
93
  end
100
94
 
101
95
  it 'with empty instance list has no select' do
102
96
  assign(:companions, [])
103
97
  @companions = []
104
98
  f = form.belongs_to_field(:companion_id)
105
- f.should match t('global.associations.none_available')
106
- f.scan('</option>').should have(0).items
99
+ expect(f).to match t('global.associations.none_available')
100
+ expect_n_options(f, 0)
107
101
  end
108
102
  end
109
103
 
@@ -112,32 +106,32 @@ describe 'DryCrud::Form::Builder' do
112
106
 
113
107
  it 'has all options by default' do
114
108
  f = form.has_many_field(:other_ids)
115
- f.scan('</option>').should have(6).items
109
+ expect_n_options(f, 6)
116
110
  end
117
111
 
118
112
  it 'uses options from :list option if given' do
119
113
  f = form.has_many_field(:other_ids, list: others)
120
- f.scan('</option>').should have(2).items
114
+ expect_n_options(f, 2)
121
115
  end
122
116
 
123
117
  it 'uses options form instance variable if given' do
124
118
  assign(:others, others)
125
119
  @others = others
126
120
  f = form.has_many_field(:other_ids)
127
- f.scan('</option>').should have(2).items
121
+ expect_n_options(f, 2)
128
122
  end
129
123
 
130
124
  it 'displays a message for an empty list' do
131
125
  @others = []
132
126
  f = form.has_many_field(:other_ids)
133
- f.should match t('global.associations.none_available')
134
- f.scan('</option>').should have(0).items
127
+ expect(f).to match t('global.associations.none_available')
128
+ expect_n_options(f, 0)
135
129
  end
136
130
  end
137
131
 
138
132
  describe '#string_field' do
139
133
  it 'sets maxlength if attr has a limit' do
140
- form.string_field(:name).should match(/maxlength="50"/)
134
+ expect(form.string_field(:name)).to match(/maxlength="50"/)
141
135
  end
142
136
  end
143
137
 
@@ -145,18 +139,18 @@ describe 'DryCrud::Form::Builder' do
145
139
  context 'only with attr' do
146
140
  subject { form.label(:gugus_dada) }
147
141
 
148
- it { should be_html_safe }
142
+ it { is_expected.to be_html_safe }
149
143
  it 'provides the same interface as rails' do
150
- should match(/label [^>]*for.+Gugus dada/)
144
+ is_expected.to match(/label [^>]*for.+Gugus dada/)
151
145
  end
152
146
  end
153
147
 
154
148
  context 'with attr and text' do
155
149
  subject { form.label(:gugus_dada, 'hoho') }
156
150
 
157
- it { should be_html_safe }
151
+ it { is_expected.to be_html_safe }
158
152
  it 'provides the same interface as rails' do
159
- should match(/label [^>]*for.+hoho/)
153
+ is_expected.to match(/label [^>]*for.+hoho/)
160
154
  end
161
155
  end
162
156
 
@@ -166,9 +160,9 @@ describe 'DryCrud::Form::Builder' do
166
160
  context 'in labeled_ method' do
167
161
  subject { form.labeled_string_field(:name) }
168
162
 
169
- it { should be_html_safe }
163
+ it { is_expected.to be_html_safe }
170
164
  it 'provides the same interface as rails' do
171
- should match(/label [^>]*for.+input/m)
165
+ is_expected.to match(/label [^>]*for.+input/m)
172
166
  end
173
167
  end
174
168
 
@@ -177,8 +171,8 @@ describe 'DryCrud::Form::Builder' do
177
171
  form.labeled('gugus', "<input type='text' name='gugus' />".html_safe)
178
172
  end
179
173
 
180
- it { should be_html_safe }
181
- it { should match(/label [^>]*for.+<input/m) }
174
+ it { is_expected.to be_html_safe }
175
+ it { is_expected.to match(/label [^>]*for.+<input/m) }
182
176
  end
183
177
 
184
178
  context 'with custom content in block' do
@@ -188,8 +182,8 @@ describe 'DryCrud::Form::Builder' do
188
182
  end
189
183
  end
190
184
 
191
- it { should be_html_safe }
192
- it { should match(/label [^>]*for.+<input/m) }
185
+ it { is_expected.to be_html_safe }
186
+ it { is_expected.to match(/label [^>]*for.+<input/m) }
193
187
  end
194
188
 
195
189
  context 'with caption and content in argument' do
@@ -199,8 +193,8 @@ describe 'DryCrud::Form::Builder' do
199
193
  caption: 'Caption')
200
194
  end
201
195
 
202
- it { should be_html_safe }
203
- it { should match(/label [^>]*for.+>Caption<\/label>.*<input/m) }
196
+ it { is_expected.to be_html_safe }
197
+ it { is_expected.to match(/label [^>]*for.+>Caption<\/label>.*<input/m) }
204
198
  end
205
199
 
206
200
  context 'with caption and content in block' do
@@ -210,8 +204,8 @@ describe 'DryCrud::Form::Builder' do
210
204
  end
211
205
  end
212
206
 
213
- it { should be_html_safe }
214
- it { should match(/label [^>]*for.+>Caption<\/label>.*<input/m) }
207
+ it { is_expected.to be_html_safe }
208
+ it { is_expected.to match(/label [^>]*for.+>Caption<\/label>.*<input/m) }
215
209
  end
216
210
  end
217
211
 
@@ -221,15 +215,20 @@ describe 'DryCrud::Form::Builder' do
221
215
 
222
216
  context '#respond_to?' do
223
217
  it 'returns false for non existing methods' do
224
- form.respond_to?(:blabla).should be_false
218
+ expect(form.respond_to?(:blabla)).to be false
225
219
  end
226
220
 
227
221
  it 'returns true for existing methods' do
228
- form.respond_to?(:text_field).should be_true
222
+ expect(form.respond_to?(:text_field)).to be true
229
223
  end
230
224
 
231
225
  it 'returns true for labeled_ methods' do
232
- form.respond_to?(:labeled_text_field).should be_true
226
+ expect(form.respond_to?(:labeled_text_field)).to be true
233
227
  end
234
228
  end
229
+
230
+ def expect_n_options(f, n)
231
+ expect(f.scan('</option>').size).to eq(n)
232
+ end
233
+
235
234
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
- require 'spec_helper'
2
+ require 'rails_helper'
3
3
 
4
- describe 'DryCrud::TableBuilder' do
4
+ describe 'DryCrud::Table::Builder' do
5
5
 
6
6
  include FormatHelper
7
7
  include UtilityHelper
@@ -37,15 +37,15 @@ describe 'DryCrud::TableBuilder' do
37
37
  context 'output' do
38
38
  before { table.attrs :upcase }
39
39
 
40
- it { col.html_header.should == '<th>Upcase</th>' }
41
- it { col.content('foo').should == 'FOO' }
42
- it { col.html_cell('foo').should == '<td>FOO</td>' }
40
+ it { expect(col.html_header).to eq('<th>Upcase</th>') }
41
+ it { expect(col.content('foo')).to eq('FOO') }
42
+ it { expect(col.html_cell('foo')).to eq('<td>FOO</td>') }
43
43
  end
44
44
 
45
45
  context 'content with custom format_size method' do
46
46
  before { table.attrs :size }
47
47
 
48
- it { col.content('abcd').should == '4 chars' }
48
+ it { expect(col.content('abcd')).to eq('4 chars') }
49
49
  end
50
50
  end
51
51
 
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
- require 'spec_helper'
2
+ require 'rails_helper'
3
3
 
4
4
  describe FormHelper do
5
5
 
@@ -31,27 +31,27 @@ describe FormHelper do
31
31
  let(:entry) { crud_test_models(:AAAAA) }
32
32
 
33
33
  it do
34
- should match(/form .*?action="\/crud_test_models\/#{entry.id}"
35
- .*?class="special\ form-horizontal"
36
- .*?method="post"/x)
34
+ is_expected.to match(/form .*?class="special\ form-horizontal"
35
+ .*?action="\/crud_test_models\/#{entry.id}"
36
+ .*?method="post"/x)
37
37
  end
38
38
 
39
39
  it do
40
- should match(/input .*?name="_method"
41
- .*?type="hidden"
42
- .*?value="(put|patch)"/x)
40
+ is_expected.to match(/input .*?type="hidden"
41
+ .*?name="_method"
42
+ .*?value="(put|patch)"/x)
43
43
  end
44
44
 
45
45
  it do
46
- should match(/input .*?name="crud_test_model\[name\]"
47
- .*?type="text"
48
- .*?value="AAAAA"/x)
46
+ is_expected.to match(/input .*?type="text"
47
+ .*?value="AAAAA"
48
+ .*?name="crud_test_model\[name\]"/x)
49
49
  end
50
50
 
51
51
  it do
52
- should match(/input .*?name="crud_test_model\[birthdate\]"
53
- .*?type="date"
54
- .*?value="1910-01-01"/x)
52
+ is_expected.to match(/input .*?value="1910-01-01"
53
+ .*?type="date"
54
+ .*?name="crud_test_model\[birthdate\]"/x)
55
55
  end
56
56
  end
57
57
  end
@@ -73,50 +73,50 @@ describe FormHelper do
73
73
  let(:entry) { crud_test_models(:AAAAA) }
74
74
 
75
75
  it do
76
- should match(/form .*?action="\/crud_test_models\/#{entry.id}"
77
- .*?class="special\ form-horizontal"
78
- .*?method="post"/x)
76
+ is_expected.to match(/form .*?class="special\ form-horizontal"
77
+ .*?action="\/crud_test_models\/#{entry.id}"
78
+ .*?method="post"/x)
79
79
  end
80
80
 
81
81
  it do
82
- should match(/input .*?name="_method"
83
- .*?type="hidden"
84
- .*?value="(put|patch)"/x)
82
+ is_expected.to match(/input .*?type="hidden"
83
+ .*?name="_method"
84
+ .*?value="(put|patch)"/x)
85
85
  end
86
86
 
87
87
  it do
88
- should match(/input .*?name="crud_test_model\[name\]"
89
- .*?type="text"
90
- .*?value="AAAAA"/x)
88
+ is_expected.to match(/input .*?type="text"
89
+ .*?value="AAAAA"
90
+ .*?name="crud_test_model\[name\]"/x)
91
91
  end
92
92
 
93
93
  it do
94
- should match(/input .*?name="crud_test_model\[birthdate\]"
95
- .*?type="date"
96
- .*?value="1910-01-01"/x)
94
+ is_expected.to match(/input .*?value="1910-01-01"
95
+ .*?type="date"
96
+ .*?name="crud_test_model\[birthdate\]"/x)
97
97
  end
98
98
 
99
99
  it do
100
- should match(/input .*?name="crud_test_model\[children\]"
101
- .*?type="number"
102
- .*?value=\"9\"/x)
100
+ is_expected.to match(/input .*?type="number"
101
+ .*?value=\"9\"
102
+ .*?name="crud_test_model\[children\]"/x)
103
103
  end
104
104
 
105
105
  it do
106
- should match(/input .*?name="crud_test_model\[human\]"
107
- .*?type="checkbox"/x)
106
+ is_expected.to match(/input .*?type="checkbox"
107
+ .*?name="crud_test_model\[human\]"/x)
108
108
  end
109
109
 
110
110
  it do
111
- should match(/button\ .*?type="submit">
112
- #{t('global.button.save')}
113
- <\/button>/x)
111
+ is_expected.to match(/button\ .*?type="submit".*>
112
+ #{t('global.button.save')}
113
+ <\/button>/x)
114
114
  end
115
115
 
116
116
  it do
117
- should match(/a\ .*href="\/somewhere".*>
118
- #{t('global.button.cancel')}
119
- <\/a>/x)
117
+ is_expected.to match(/a\ .*href="\/somewhere".*>
118
+ #{t('global.button.cancel')}
119
+ <\/a>/x)
120
120
  end
121
121
  end
122
122
 
@@ -129,19 +129,19 @@ describe FormHelper do
129
129
  end
130
130
 
131
131
  it do
132
- should match(/div[^>]* id='error_explanation'/)
132
+ is_expected.to match(/div[^>]* id='error_explanation'/)
133
133
  end
134
134
 
135
135
  it do
136
- should match(/div\ class="form-group\ has-error"\>.*?
137
- \<input .*?name="crud_test_model\[name\]"
138
- .*?type="text"/x)
136
+ is_expected.to match(/div\ class="form-group\ has-error"\>.*?
137
+ \<input .*?type="text"
138
+ .*?name="crud_test_model\[name\]"/x)
139
139
  end
140
140
 
141
141
  it do
142
- should match(/input .*?name="_method"
143
- .*?type="hidden"
144
- .*?value="(put|patch)"/x)
142
+ is_expected.to match(/input .*?type="hidden"
143
+ .*?name="_method"
144
+ .*?value="(put|patch)"/x)
145
145
  end
146
146
  end
147
147
  end
@@ -153,66 +153,66 @@ describe FormHelper do
153
153
  end
154
154
 
155
155
  it do
156
- should match(/form .*?action="\/crud_test_models\/#{entry.id}"/)
156
+ is_expected.to match(/form .*?action="\/crud_test_models\/#{entry.id}"/)
157
157
  end
158
158
 
159
159
  it do
160
- should match(/input .*?name="crud_test_model\[name\]"
161
- .*?type="text"/x)
160
+ is_expected.to match(/input .*?type="text"
161
+ .*?name="crud_test_model\[name\]"/x)
162
162
  end
163
163
 
164
164
  it do
165
- should match(/input .*?name="crud_test_model\[whatever\]"
166
- .*?type="text"/x)
165
+ is_expected.to match(/input .*?type="text"
166
+ .*?name="crud_test_model\[whatever\]"/x)
167
167
  end
168
168
 
169
169
  it do
170
- should match(/input .*?name="crud_test_model\[children\]"
171
- .*?type="number"/x)
170
+ is_expected.to match(/input .*?type="number"
171
+ .*?name="crud_test_model\[children\]"/x)
172
172
  end
173
173
 
174
174
  it do
175
- should match(/input .*?name="crud_test_model\[rating\]"
176
- .*?type="number"/x)
175
+ is_expected.to match(/input .*?type="number"
176
+ .*?name="crud_test_model\[rating\]"/x)
177
177
  end
178
178
 
179
179
  it do
180
- should match(/input .*?name="crud_test_model\[income\]"
181
- .*?type="number"/x)
180
+ is_expected.to match(/input .*?type="number"
181
+ .*?name="crud_test_model\[income\]"/x)
182
182
  end
183
183
 
184
184
  it do
185
- should match(/input .*?name="crud_test_model\[birthdate\]"
186
- .*?type="date"/x)
185
+ is_expected.to match(/input .*?type="date"
186
+ .*?name="crud_test_model\[birthdate\]"/x)
187
187
  end
188
188
 
189
189
  it do
190
- should match(/input .*?name="crud_test_model\[gets_up_at\]"
191
- .*?type="time"/x)
190
+ is_expected.to match(/input .*?type="time"
191
+ .*?name="crud_test_model\[gets_up_at\]"/x)
192
192
  end
193
193
 
194
194
  it do
195
- should match(/input .*?name="crud_test_model\[last_seen\]"
196
- .*?type="datetime"/x)
195
+ is_expected.to match(/input .*?type="datetime"
196
+ .*?name="crud_test_model\[last_seen\]"/x)
197
197
  end
198
198
 
199
199
  it do
200
- should match(/input .*?name="crud_test_model\[human\]"
201
- .*?type="checkbox"/x)
200
+ is_expected.to match(/input .*?type="checkbox"
201
+ .*?name="crud_test_model\[human\]"/x)
202
202
  end
203
203
 
204
204
  it do
205
- should match(/select .*?name="crud_test_model\[companion_id\]"/)
205
+ is_expected.to match(/select .*?name="crud_test_model\[companion_id\]"/)
206
206
  end
207
207
 
208
208
  it do
209
- should match(/textarea .*?name="crud_test_model\[remarks\]"/)
209
+ is_expected.to match(/textarea .*?name="crud_test_model\[remarks\]"/)
210
210
  end
211
211
 
212
212
  it do
213
- should match(/a\ .*href="\/crud_test_models\/#{entry.id}
213
+ is_expected.to match(/a\ .*href="\/crud_test_models\/#{entry.id}
214
214
  \?returning=true".*>
215
- #{t('global.button.cancel')}<\/a>/x)
215
+ #{t('global.button.cancel')}<\/a>/x)
216
216
  end
217
217
  end
218
218