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