mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-04 04:04:36 +08:00
fixes failing specs
This commit is contained in:
parent
e630d3113f
commit
6e255a4657
4 changed files with 20 additions and 18 deletions
|
@ -68,12 +68,13 @@ module SearchableModel
|
|||
end
|
||||
else
|
||||
unless attrs.empty?
|
||||
id_index = 0 # quick fix to enable searching by repositoy_row id
|
||||
# quick fix to enable searching by repositoy_row id
|
||||
id_index = { present: false }
|
||||
where_str =
|
||||
(attrs.map.with_index do |a, i|
|
||||
if a == 'repository_rows.id'
|
||||
id_index = i
|
||||
"#{a} = :t#{i} OR "
|
||||
id_index = { present: true, val: i }
|
||||
"(#{a}) = :t#{i} OR "
|
||||
else
|
||||
"(trim_html_tags(#{a})) #{like} :t#{i} OR "
|
||||
end
|
||||
|
@ -81,7 +82,7 @@ module SearchableModel
|
|||
).join[0..-5]
|
||||
vals = (
|
||||
attrs.map.with_index do |_, i|
|
||||
if id_index == i
|
||||
if id_index[:present] && id_index[:val] == i
|
||||
["t#{i}".to_sym, sanitize_sql_like(query).to_i]
|
||||
else
|
||||
["t#{i}".to_sym, "%#{sanitize_sql_like(query.to_s)}%"]
|
||||
|
|
|
@ -62,7 +62,7 @@ describe RepositoryRowsController, type: :controller do
|
|||
|
||||
describe 'json object' do
|
||||
it 'returns a valid object' do
|
||||
params = { order: { 0 => { column: '3', dir: 'asc' } },
|
||||
params = { order: { 0 => { column: '4', dir: 'asc' } },
|
||||
drow: '0',
|
||||
search: { value: '' },
|
||||
length: '10',
|
||||
|
@ -77,7 +77,7 @@ describe RepositoryRowsController, type: :controller do
|
|||
|
||||
describe 'pagination' do
|
||||
it 'returns first 10 records' do
|
||||
params = { order: { 0 => { column: '3', dir: 'asc' } },
|
||||
params = { order: { 0 => { column: '4', dir: 'asc' } },
|
||||
drow: '0',
|
||||
search: { value: '' },
|
||||
length: '10',
|
||||
|
@ -86,11 +86,11 @@ describe RepositoryRowsController, type: :controller do
|
|||
get :index, params: params, format: :json
|
||||
response_body = JSON.parse(response.body)
|
||||
expect(response_body['data'].length).to eq 10
|
||||
expect(response_body['data'].first['2']).to eq 'row (0)'
|
||||
expect(response_body['data'].first['3']).to eq 'row (0)'
|
||||
end
|
||||
|
||||
it 'returns next 10 records' do
|
||||
params = { order: { 0 => { column: '3', dir: 'asc' } },
|
||||
params = { order: { 0 => { column: '4', dir: 'asc' } },
|
||||
drow: '0',
|
||||
search: { value: '' },
|
||||
length: '10',
|
||||
|
@ -99,11 +99,11 @@ describe RepositoryRowsController, type: :controller do
|
|||
get :index, params: params, format: :json
|
||||
response_body = JSON.parse(response.body)
|
||||
expect(response_body['data'].length).to eq 10
|
||||
expect(response_body['data'].first['2']).to eq 'row (10)'
|
||||
expect(response_body['data'].first['3']).to eq 'row (10)'
|
||||
end
|
||||
|
||||
it 'returns first 25 records' do
|
||||
params = { order: { 0 => { column: '2', dir: 'desc' } },
|
||||
params = { order: { 0 => { column: '4', dir: 'desc' } },
|
||||
drow: '0',
|
||||
search: { value: '' },
|
||||
length: '25',
|
||||
|
|
|
@ -52,7 +52,7 @@ describe RepositoryDatatableService do
|
|||
|
||||
context 'object' do
|
||||
let(:params) do
|
||||
{ order: { 0 => { column: '2', dir: 'asc' } },
|
||||
{ order: { 0 => { column: '3', dir: 'asc' } },
|
||||
search: { value: 'row' } }
|
||||
end
|
||||
|
||||
|
@ -65,7 +65,7 @@ describe RepositoryDatatableService do
|
|||
contitions = subject.send(:build_conditions, params)
|
||||
expect(contitions[:search_value]).to eq 'row'
|
||||
expect(contitions[:order_by_column]).to eq(
|
||||
{ column: 2, dir: 'asc' }
|
||||
{ column: 3, dir: 'asc' }
|
||||
)
|
||||
end
|
||||
end
|
||||
|
@ -73,7 +73,7 @@ describe RepositoryDatatableService do
|
|||
describe '#sortable_columns' do
|
||||
it 'returns an array of all columns that are sortable' do
|
||||
columns = subject.send(:sortable_columns)
|
||||
expect(columns.length).to eq 5
|
||||
expect(columns.length).to eq 6
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -92,7 +92,7 @@ describe RepositoryDatatableService do
|
|||
|
||||
describe 'ordering' do
|
||||
it 'is ordered by row name asc' do
|
||||
params = { order: { 0 => { column: '2', dir: 'asc' } },
|
||||
params = { order: { 0 => { column: '3', dir: 'asc' } },
|
||||
search: { value: '' } }
|
||||
subject = RepositoryDatatableService.new(repository,
|
||||
params,
|
||||
|
@ -102,7 +102,7 @@ describe RepositoryDatatableService do
|
|||
end
|
||||
|
||||
it 'is ordered by row name desc' do
|
||||
params = { order: { 0 => { column: '2', dir: 'desc' } },
|
||||
params = { order: { 0 => { column: '3', dir: 'desc' } },
|
||||
search: { value: '' } }
|
||||
subject = RepositoryDatatableService.new(repository,
|
||||
params,
|
||||
|
@ -121,7 +121,7 @@ describe RepositoryDatatableService do
|
|||
end
|
||||
|
||||
it 'returns only the searched entity' do
|
||||
params = { order: { 0 => { column: '2', dir: 'desc' } },
|
||||
params = { order: { 0 => { column: '4', dir: 'desc' } },
|
||||
search: { value: 'test' } }
|
||||
subject = RepositoryDatatableService.new(repository,
|
||||
params,
|
||||
|
|
|
@ -8,13 +8,14 @@
|
|||
"data": {
|
||||
"type": "array",
|
||||
"items":{
|
||||
"required": ["DT_RowId", "1", "2", "3", "4", "recordEditUrl", "recordUpdateUrl", "recordInfoUrl"],
|
||||
"required": ["DT_RowId", "1", "2", "3", "4", "5", "recordEditUrl", "recordUpdateUrl", "recordInfoUrl"],
|
||||
"properties": {
|
||||
"DT_RowId": { "type": "integer" },
|
||||
"1": { "type": "string" },
|
||||
"2": { "type": "string" },
|
||||
"2": { "type": "integer" },
|
||||
"3": { "type": "string" },
|
||||
"4": { "type": "string" },
|
||||
"5": { "type": "string" },
|
||||
"recordEditUrl": { "type": "string" },
|
||||
"recordUpdateUrl": { "type": "string" },
|
||||
"recordInfoUrl": { "type": "string" }
|
||||
|
|
Loading…
Add table
Reference in a new issue