spec/query_spec.rb in fauna-2.0.0 vs spec/query_spec.rb in fauna-2.1.0

- old
+ new

@@ -8,12 +8,11 @@ end index_y = client.query do create ref('indexes'), name: 'query_by_y', source: @test_class, terms: [{ path: 'data.y' }] end - wait_for_active(index_x[:ref]) - wait_for_active(index_y[:ref]) + wait_for_index(index_x[:ref], index_y[:ref]) @test_by_x = index_x[:ref] @test_by_y = index_y[:ref] end @@ -39,20 +38,42 @@ data end describe Fauna::Query::Expr do - it 'converts to string' do - expr = Fauna::Query::Expr.new( - add: Fauna::Query::Expr.new( - [1, Fauna::Query::Expr.new(divide: Fauna::Query::Expr.new([4, 2]))] + describe '#to_s' do + it 'converts to string' do + expr = Fauna::Query::Expr.new( + add: Fauna::Query::Expr.new( + [1, Fauna::Query::Expr.new(divide: Fauna::Query::Expr.new([4, 2]))] + ) ) - ) - as_string = 'Expr({:add=>Expr([1, Expr({:divide=>Expr([4, 2])})])})' + as_string = 'Expr({:add=>Expr([1, Expr({:divide=>Expr([4, 2])})])})' - expect(expr.to_s).to eq(as_string) + expect(expr.to_s).to eq(as_string) + end end + + describe '#==' do + it 'equals identical expression' do + expr1 = Fauna::Query::Expr.new(add: Fauna::Query::Expr.new([1, 2])) + expr2 = Fauna::Query::Expr.new(add: Fauna::Query::Expr.new([1, 2])) + + expect(expr1).to eq(expr2) + end + + it 'does not equal different expression' do + expr1 = Fauna::Query::Expr.new(add: Fauna::Query::Expr.new([1, 2])) + expr2 = Fauna::Query::Expr.new( + add: Fauna::Query::Expr.new( + [1, Fauna::Query::Expr.new(divide: Fauna::Query::Expr.new([4, 2]))] + ) + ) + + expect(expr1).not_to eq(expr2) + end + end end describe '#expr' do it 'maintains lexical scope' do def test_method @@ -82,14 +103,19 @@ expect(client.query { { '@ref' => 'foo' } }).to eq(:@ref => 'foo') end end describe '#ref' do - it 'creates a ref' do - ref = random_ref - expect(Fauna::Query.ref(ref)).to eq(Fauna::Ref.new(ref)) + it 'returns a ref from a string' do + str = random_ref_string + expect(Fauna::Query.ref(str)).to eq(Fauna::Ref.new(str)) end + + it 'constructs a ref' do + expect(client.query { ref(@test_class, '123') }).to eq(Fauna::Ref.new('classes/query_test/123')) + expect(client.query { ref(@test_class, next_id) }.value).to match(%r{^classes/query_test/\d+$}) + end end describe '#object' do it 'wraps fields in object' do data = { a: random_string, b: random_number } @@ -422,11 +448,11 @@ describe '#distinct' do before do over_z = client.query do create ref('indexes'), name: 'query_over_z', source: @test_class, values: [{ path: 'data.z' }] end - wait_for_active(over_z[:ref]) + wait_for_index(over_z[:ref]) @test_over_z = over_z[:ref] @refs = [] @refs << client.query { create @test_class, data: { z: 0 } }[:ref] @refs << client.query { create @test_class, data: { z: 1 } }[:ref] @@ -468,10 +494,21 @@ # Get associated refs set = Fauna::Query.expr { join(source) { |a| match(@test_by_y, a) } } expect(get_set_data(set)).to eq(@assoc_refs) end end + + context 'with index' do + it 'performs join' do + source = Fauna::Query.match(@test_by_x, @x_value) + expect(get_set_data(source)).to eq(@join_refs) + + # Get associated refs + set = Fauna::Query.expr { join(source, @test_by_y) } + expect(get_set_data(set)).to eq(@assoc_refs) + end + end end describe 'authentication' do before do @password = random_string @@ -545,9 +582,15 @@ end describe '#date' do it 'performs date' do expect(client.query { date('1970-01-01') }).to eq(Date.new(1970, 1, 1)) + end + end + + describe '#next_id' do + it 'gets a new id' do + expect(client.query { next_id }).to be_a(String) end end describe '#equals' do it 'performs equals' do