spec/query_spec.rb in fauna-2.3.0 vs spec/query_spec.rb in fauna-2.4.0
- old
+ new
@@ -121,10 +121,17 @@
data = { a: random_string, b: random_number }
expect(Fauna::Query.object(data).raw).to eq(object: data)
end
end
+ describe '#query' do
+ it 'wraps fields in query' do
+ data = Fauna::Query::Expr.new(lambda: random_string, expr: Fauna::Query::Expr.new(add: Fauna::Query::Expr.wrap([1, 1])))
+ expect(Fauna::Query.query(data).raw).to eq(query: data)
+ end
+ end
+
describe '#at' do
it 'performs at for given expression' do
instance = create_instance
ref = instance[:ref]
ts = instance[:ts]
@@ -213,10 +220,42 @@
expect(to_json(expr)).to eq(to_json(query))
expect(client.query { map([[1], [2], [3]], expr) }).to eq([2, 4, 6])
end
end
+ describe '#call' do
+ it 'performs called function' do
+ test_func = client.query do
+ func_body = lambda do |x|
+ [add(x, 1), add(x, 2), add(x, 3)]
+ end
+
+ create ref('functions'), name: 'call_func_test', body: query(func_body)
+ end
+
+ x = random_number
+
+ expect(client.query { call(test_func[:ref], x) }).to eq([x + 1, x + 2, x + 3])
+ end
+
+ it 'handles multiple arguments' do
+ test_func = client.query do
+ func_body = lambda do |x, y, z|
+ [multiply(x, 2), multiply(y, 3), multiply(z, 4)]
+ end
+
+ create ref('functions'), name: 'call_multiarg_test', body: query(func_body)
+ end
+
+ x = random_number
+ y = random_number
+ z = random_number
+
+ expect(client.query { call(test_func[:ref], x, y, z) }).to eq([x * 2, y * 3, z * 4])
+ end
+ end
+
describe '#map' do
it 'performs map from expression' do
input = (1..3).collect { random_number }
output = input.collect { |x| 2 * x }
@@ -456,10 +495,20 @@
# Assert it was created
expect(admin_client.query { exists(ref) }).to be(true)
end
end
+ describe '#create_function' do
+ it 'creates a function' do
+ # Create a function
+ ref = client.query { create_function(name: random_string, body: query(lambda { |a| add(a, 1) })) }[:ref]
+
+ # Assert it was created
+ expect(client.query { exists(ref) }).to be(true)
+ end
+ end
+
describe 'sets' do
before do
@x_value = random_number
@y_value = random_number
@@ -654,11 +703,11 @@
# Get the database ref
expect(admin_client.query { database(name) }).to eq(ref)
end
end
- describe '#class' do
+ describe '#class_' do
it 'gets an existing class' do
# Create a class
name = random_string
ref = client.query { create_class(name: name) }[:ref]
@@ -674,9 +723,20 @@
name = random_string
ref = client.query { create_index(name: name, source: class_ref) }[:ref]
# Get the index ref
expect(client.query { index(name) }).to eq(ref)
+ end
+ end
+
+ describe '#function' do
+ it 'gets an existing function' do
+ # Create a function
+ name = random_string
+ ref = client.query { create_function(name: name, body: query(lambda { |a| add(a, 1) })) }[:ref]
+
+ # Get the function ref
+ expect(client.query { function(name) }).to eq(ref)
end
end
describe '#equals' do
it 'performs equals' do