Commit 2212ee4a by Hugo Maia Vieira

parse must deal with nil param

parent d9227a89
......@@ -5,7 +5,7 @@ module RansackMongo
end
def parse(params)
params.keys.inject({}) do |query, query_param|
(params || {}).keys.inject({}) do |query, query_param|
attr = query_param.to_s
p, attr = detect_and_strip_from_string(attr)
......
......@@ -19,7 +19,7 @@ module RansackMongo
end
end
describe '#parse' do
describe '.parse' do
context 'when not implement matcher' do
it 'raises proper exception' do
params = { 'name_foo' => 'Pablo' }
......@@ -32,7 +32,7 @@ module RansackMongo
end
context 'when MongoAdapter' do
describe '#parse!' do
describe '.parse!' do
it 'raises exception when query evaluates to an empty hash' do
params = { 'name' => 'Pablo' }
expect { described_class.parse!(params) }.to raise_error(MatcherNotFound)
......@@ -45,13 +45,19 @@ module RansackMongo
end
end
describe '#parse' do
describe '.parse' do
it 'returns the query' do
params = { 'name_eq' => 'Pablo', 'fullname_cont' => 'Cantero' }
expect(described_class.parse(params)).to eq('name' => 'Pablo', 'fullname' => /Cantero/i)
end
context 'when nil query' do
it 'return an empty query' do
expect(described_class.parse(nil)).to eq({})
end
end
context 'when or' do
it 'returns the query' do
params = { 'name_or_fullname_eq' => 'Pablo' }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment