Query generator #3

Merged
bilal.catic merged 5 commits from query-generator into master 2020-01-31 13:58:54 +01:00
Showing only changes of commit 9c2aff53d7 - Show all commits

View File

@@ -35,19 +35,19 @@ class SqlGeneratorTester
it 'tests search without operators' do
@query = TextToSqlQuery.new('123 456', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
expect(@query.where_clause).to eq ['players.device_id LIKE ? OR players.device_id LIKE ?', '%123%', '%456%']
expect(@query.where_clause).to eq ['(players.device_id LIKE ? OR players.device_id LIKE ?)', '%123%', '%456%']
end
it 'tests search with OR operator' do
@query = TextToSqlQuery.new('123 or 456', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
expect(@query.where_clause).to eq ['players.device_id LIKE ? OR players.device_id LIKE ?', '%123%', '%456%']
expect(@query.where_clause).to eq ['(players.device_id LIKE ? OR players.device_id LIKE ?)', '%123%', '%456%']
end
it 'tests search with AND operator' do
@query = TextToSqlQuery.new('123 and 456', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
expect(@query.where_clause).to eq ['players.device_id LIKE ? AND players.device_id LIKE ?', '%123%', '%456%']
expect(@query.where_clause).to eq ['(players.device_id LIKE ? AND players.device_id LIKE ?)', '%123%', '%456%']
end
it 'tests search with NOT operator on default column' do
@@ -65,13 +65,25 @@ class SqlGeneratorTester
it 'tests search with mixed logical operators' do
@query = TextToSqlQuery.new('title:ab and not tag:hf-1', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
expect(@query.where_clause).to eq ['players.title LIKE ? AND NOT players.tag LIKE ?', '%ab%', '%hf-1%']
expect(@query.where_clause).to eq ['(players.title LIKE ? AND NOT players.tag LIKE ?)', '%ab%', '%hf-1%']
end
it 'tests search with mixed logical operators without NOT' do
@query = TextToSqlQuery.new('title:a and title:b or title:c', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
expect(@query.where_clause).to eq ['players.title LIKE ? AND players.title LIKE ? OR players.title LIKE ?', '%a%', '%b%', '%c%']
expect(@query.where_clause).to eq ['((players.title LIKE ? AND players.title LIKE ?) OR players.title LIKE ?)', '%a%', '%b%', '%c%']
end
it 'tests search with brackets in expression' do
@query = TextToSqlQuery.new('title:a and (title:b or title:c)', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
expect(@query.where_clause).to eq ['(players.title LIKE ? AND (players.title LIKE ? OR players.title LIKE ?))', '%a%', '%b%', '%c%']
end
it 'tests search with brackets in expression and with NOT operator' do
@query = TextToSqlQuery.new('title:a and not (title:b or title:c)', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
expect(@query.where_clause).to eq ['(players.title LIKE ? AND NOT (players.title LIKE ? OR players.title LIKE ?))', '%a%', '%b%', '%c%']
end
end
end