Sha256: 4c8d65b363bcd7c2ce3b1a8b01a349f8676a68b126138e0fb70ed58c5015c43b

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

require "test_helper"

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

  def teardown
    @graph.delete
  end

  def test_add_node
    node = Redgraph::Node.new(label: 'actor', properties: {name: "Al Pacino"})
    result = @graph.add_node(node)
    assert_predicate result, :persisted?
  end

  def test_add_node_with_special_chars
    [
      "apo'str",
      "two''apos",
      "Foø'bÆ®",
      "aa\nbb",
      'aaa "bbb" ccc'
    ].each do |name|

      node = Redgraph::Node.new(label: 'actor', properties: {name: name})
      result = @graph.add_node(node)
      assert_predicate result, :persisted?

      item = @graph.find_node_by_id(node.id)

      assert_equal(name, item.properties["name"])
    end
  end

  def test_add_node_with_nil_value
    node = Redgraph::Node.new(label: 'actor', properties: {name: nil})
    result = @graph.add_node(node)
    assert_predicate result, :persisted?

    item = @graph.find_node_by_id(node.id)

    assert_equal("", item.properties["name"])
  end

  def test_add_edge
    actor = Redgraph::Node.new(label: 'actor', properties: {name: "Al Pacino"})
    @graph.add_node(actor)

    film = Redgraph::Node.new(label: 'film', properties: {name: "Scarface"})
    @graph.add_node(film)

    edge = Redgraph::Edge.new(src: actor, dest: film, type: 'ACTOR_IN', properties: {role: "Tony Montana"})
    result = @graph.add_edge(edge)

    assert_predicate result, :persisted?
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
redgraph-0.1.3 test/graph_manipulation_test.rb
redgraph-0.1.2 test/graph_manipulation_test.rb