Skip to content

Commit 56298d9

Browse files
committed
DRY specs
1 parent 11e4890 commit 56298d9

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

spec/ajax-datatables-rails/datatable/column_spec.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
let(:column) { datatable.datatable.columns.first }
1212

13-
before do
14-
datatable.params[:columns] = { '0' => { 'data' => 'username', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => { 'value' => 'searchvalue', 'regex' => 'false' } } }
15-
end
13+
before { datatable.params[:columns]['0'][:search][:value] = 'searchvalue' }
1614

1715
it 'is orderable' do
1816
expect(column.orderable?).to eq(true)
@@ -52,6 +50,7 @@
5250
expect(column.table).to eq User.arel_table
5351
end
5452
end
53+
5554
context 'with other ORM' do
5655
it 'returns the corresponding model' do
5756
expect(User).to receive(:respond_to?).with(:arel_table).and_return(false)
@@ -206,19 +205,15 @@
206205
end
207206

208207
describe 'when empty column' do
209-
before do
210-
datatable.params[:columns] = { '0' => { 'data' => '', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => { 'value' => 'searchvalue', 'regex' => 'false' } } }
211-
end
208+
before { datatable.params[:columns]['0'][:data] = '' }
212209

213210
it 'raises error' do
214211
expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message('Unknown column. Check that `data` field is filled on JS side with the column name')
215212
end
216213
end
217214

218215
describe 'when unknown column' do
219-
before do
220-
datatable.params[:columns] = { '0' => { 'data' => 'foo', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => { 'value' => 'searchvalue', 'regex' => 'false' } } }
221-
end
216+
before { datatable.params[:columns]['0'][:data] = 'foo' }
222217

223218
it 'raises error' do
224219
expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message("Check that column 'foo' exists in view_columns")

0 commit comments

Comments
 (0)