Sha256: 60087f27d42d48ef9c98a6babbb8133240dfb653e51870697049fd31f23d5a26

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

require "test_helper"

class GraphTest < Minitest::Test
  def setup
    @graph = create_sample_graph("foobar")
  end

  def teardown
    @graph.delete
  end

  def test_list
    list = @graph.list
    assert_includes(list, "foobar")
  end

  def test_delete
    assert_includes(@graph.list, "foobar")

    @graph.delete
    refute_includes(@graph.list, "foobar")
  end

  def test_labels
    @graph = create_sample_graph("foobar")
    assert_equal(["actor"], @graph.labels)

    node = Redgraph::Node.new(label: "film")
    @graph.add_node(node)
    assert_equal(["actor", "film"], @graph.labels)
  end

  def test_properties
    @graph = create_sample_graph("foobar")
    assert_equal(["name"], @graph.properties)

    node = Redgraph::Node.new(label: "actor", properties: {"age": 100})
    @graph.add_node(node)

    assert_equal(["name", "age"], @graph.properties)
  end

  def test_relationship_types
    @graph = create_sample_graph("foobar")

    actor = Redgraph::Node.new(label: "actor", properties: {"name": "Harrison Ford"})
    @graph.add_node(actor)
    film = Redgraph::Node.new(label: "film", properties: {"name": "Star Wars"})
    @graph.add_node(film)
    edge = Redgraph::Edge.new(type: "ACTED_IN", src: actor, dest: film)
    @graph.add_edge(edge)

    assert_equal(["ACTED_IN"], @graph.relationship_types)
  end

  private

  def create_sample_graph(name)
    graph = Redgraph::Graph.new(name, url: $REDIS_URL)
    graph.connection.call(
      "GRAPH.QUERY",
      name,
      "CREATE (:actor {name: 'hello'})"
    )
    graph
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
redgraph-0.1.2 test/graph_test.rb