Sha256: 252e686e9932b022cdacd9cedd9005153307d304db07f9b3a12eb4de29b9970a

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

require "test_helper"

class GraphQueriesTest < Minitest::Test
  def setup
    @graph = Redgraph::Graph.new("movies", url: $REDIS_URL)

    @al = quick_add_node(label: 'actor', properties: {name: "Al Pacino", born: 1940})
    @john = quick_add_node(label: 'actor', properties: {name: "John Travolta", born: 1954})
  end

  def teardown
    @graph.delete
  end

  def test_query_string_attribute
    result = @graph.query("MATCH (n) RETURN n.name ORDER BY n.name")
    assert_equal([["Al Pacino"], ["John Travolta"]], result)
  end

  def test_query_string_and_number_attributes
    result = @graph.query("MATCH (n) RETURN n.name, n.born ORDER BY n.born")
    assert_equal([["Al Pacino", 1940], ["John Travolta", 1954]], result)
  end

  def test_query_nodes
    result = @graph.query("MATCH (n) RETURN n ORDER BY n.born")
    assert_equal([[@al], [@john]], result)
  end

  def test_query_edge
    edge = quick_add_edge(type: 'FRIEND_OF', src: @al, dest: @john, properties: {since: 1980})
    result = @graph.query("MATCH (src)-[edge]->(dest) RETURN edge")
    assert_equal([[edge]], result)
  end

  def test_query_node_and_edge
    edge = quick_add_edge(type: 'FRIEND_OF', src: @al, dest: @john, properties: {since: 1980})
    result = @graph.query("MATCH (src)-[edge:FRIEND_OF]->(dest) RETURN src, edge")
    assert_equal([[@al, edge]], result)
  end

  private

  def quick_add_node(label:, properties:)
    @graph.add_node(Redgraph::Node.new(label: label, properties: properties))
  end

  def quick_add_edge(type:, src:, dest:, properties:)
    @graph.add_edge(Redgraph::Edge.new(type: type, src: src, dest: dest, properties: properties))
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
redgraph-0.1.3 test/graph_queries_test.rb