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