spec/acceptance/aql_spec.rb in guacamole-0.3.0 vs spec/acceptance/aql_spec.rb in guacamole-0.4.0

- old
+ new

@@ -8,51 +8,43 @@ let(:pegasus_pony) { Fabricate(:pony, type: ['Pegasus']) } let(:earth_pony) { Fabricate(:pony, type: ['Earthpony'], name: 'Candy Mane') } let(:unicorn_pegasus_pony) { Fabricate(:pony, type: ['Pegasus', 'Unicorn']) } - context 'with experimental AQL support enabled' do - before do - Guacamole.configuration.experimental_features = [:aql_support] + before do + [pegasus_pony, earth_pony, unicorn_pegasus_pony] + end - [pegasus_pony, earth_pony, unicorn_pegasus_pony] - end + it 'should retrieve models by simple AQL queries' do + pony_by_name = PoniesCollection.by_aql('FILTER pony.name == @name', name: 'Candy Mane').first + expect(pony_by_name).to eq earth_pony + end - it 'should retrieve models by simple AQL queries' do - pony_by_name = PoniesCollection.by_aql('FILTER pony.name == @name', name: 'Candy Mane').first - expect(pony_by_name).to eq earth_pony - end + it 'should retrieve models by more complex AQL queries' do + ponies_by_type = PoniesCollection.by_aql('FILTER POSITION(pony.type, @pony_type, false) == true', + pony_type: 'Pegasus') + expect(ponies_by_type).to include unicorn_pegasus_pony + expect(ponies_by_type).to include pegasus_pony + end - it 'should retrieve models by more complex AQL queries' do - ponies_by_type = PoniesCollection.by_aql('FILTER POSITION(pony.type, @pony_type, false) == true', - pony_type: 'Pegasus') - expect(ponies_by_type).to include unicorn_pegasus_pony - expect(ponies_by_type).to include pegasus_pony - end - - it 'should allow a custom RETURN statement' do - custom_color = 'fancy white pink with sparkles' - pony_by_name = PoniesCollection.by_aql('FILTER pony.name == @name', - { name: 'Candy Mane' }, - return_as: %Q{RETURN MERGE(pony, {"color": "#{custom_color}"})}).first - expect(pony_by_name.color).to eq custom_color - end - - it 'should allow to disable the mapping' do - pony_hash = PoniesCollection.by_aql('FILTER pony.name == @name', - { name: 'Candy Mane' }, - mapping: false ).first - expect(pony_hash).to be_an(Ashikawa::Core::Document) - end + it 'should allow a custom RETURN statement' do + custom_color = 'fancy white pink with sparkles' + pony_by_name = PoniesCollection.by_aql('FILTER pony.name == @name', + { name: 'Candy Mane' }, + return_as: %{RETURN MERGE(pony, {"color": "#{custom_color}"})}).first + expect(pony_by_name.color).to eq custom_color end - context 'without experimental AQL support enabled' do - before do - Guacamole.configuration.experimental_features = [] - end - - it 'should raise an error accessing the AQL feature' do - expect { PoniesCollection.by_aql("random AQL fragment") }.to raise_error(Guacamole::AQLNotSupportedError) - end + it 'should allow to disable the mapping' do + pony_hash = PoniesCollection.by_aql('FILTER pony.name == @name', + { name: 'Candy Mane' }, + mapping: false).first + expect(pony_hash).to be_an(Ashikawa::Core::Document) end + it 'should allow to provide a custom `FOR x IN y` part' do + pony_by_name = PoniesCollection.by_aql('FILTER p.name == @name', + { name: 'Candy Mane' }, + for_in: 'FOR p IN ponies', return_as: 'RETURN p').first + expect(pony_by_name).to eq earth_pony + end end