34 行
1.7 KiB
Ruby
34 行
1.7 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe QueryState do
|
|
it 'decodes typed axis values and keeps absence distinct from an empty set' do
|
|
{ 'boolean' => ['false', false], 'number' => ['7', 7],
|
|
'string' => ['a b & c', 'a b & c'], 'null' => ['', nil] }.each do |type, (raw, expected)|
|
|
params = { 'conditions' => '', 'conditions.0.field' => 'user',
|
|
'conditions.0.operator' => 'axis_eq',
|
|
'conditions.0.value_type' => type, 'conditions.0.value' => raw }
|
|
expect(described_class.records(params, 'conditions').sole['value']).to eq(expected)
|
|
end
|
|
expect(described_class.records({}, 'conditions')).to eq([])
|
|
expect(described_class.records({ 'conditions' => '' }, 'conditions')).to eq([])
|
|
expect(described_class.records({ 'conditions' => '', 'conditions.0.values' => '1' },
|
|
'conditions')).to eq([{ 'values' => true }])
|
|
end
|
|
|
|
it 'rejects gaps, unknown keys, JSON, wrong types and oversized lists' do
|
|
[
|
|
{ 'conditions' => '[]' }, { 'conditions' => '', 'conditions.1.field' => 'user' },
|
|
{ 'conditions' => '', 'conditions.0.sql' => 'TRUE' },
|
|
{ 'conditions' => '', 'conditions.0.blank' => 'true' },
|
|
{ 'conditions' => '', 'conditions.0.value' => ['x'] },
|
|
{ 'drill' => '', 'drill.0.field' => 'user', 'drill.0.value_type' => 'object' },
|
|
{ 'conditions' => 'x' * 131_073 }].each do |params|
|
|
expect { described_class.validate!(params, ['conditions', 'drill']) }
|
|
.to raise_error(ArgumentError)
|
|
end
|
|
['user user', 'user title', ' user', (1..201).to_a.join(' ')].each do |value|
|
|
expect { described_class.list(value) }.to raise_error(ArgumentError)
|
|
end
|
|
end
|
|
end
|