Sha256: ff6ca503abeb21a5e26a952d840ec7810ae92e88b29ea9a038d6183721c016aa

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

require "test_helper"

class NodeModelClassMethodsTest < Minitest::Test
  include TestHelpers

  GRAPH = Redgraph::Graph.new("movies", url: $REDIS_URL)

  def setup
    @graph = GRAPH
  end

  def teardown
    @graph.delete
  end

  # test classes
  #

  class Actor
    include Redgraph::NodeModel
    self.graph = GRAPH
    attribute :name
  end

  # tests
  #

  def test_count
    quick_add_node(label: 'actor', properties: {_type: Actor.name, name: "Al Pacino"})
    quick_add_node(label: 'actor', properties: {_type: Actor.name, name: "John Travolta"})
    assert_equal(2, Actor.count)
    assert_equal(1, Actor.count(properties: {name: "Al Pacino"}))
  end

  def test_all
    al = Actor.new(name: "Al Pacino").add_to_graph
    john = Actor.new(name: "John Travolta").add_to_graph

    items = Actor.all
    assert_equal(2, items.size)
    assert_includes(items, al)
    assert_includes(items, john)

    items = Actor.all(properties: {name: "Al Pacino"})
    assert_equal(1, items.size)
    assert_includes(items, al)
  end

  def test_find
    al = quick_add_node(label: 'actor', properties: {name: "Al Pacino"})
    item = Actor.find(al.id)

    assert_equal(Actor, item.class)
    assert_predicate(item, :persisted?)
    assert_equal(al.id, item.id)
    assert_equal("Al Pacino", item.name)
  end

  def test_find_bad_id
    quick_add_node(label: 'actor', properties: {name: "Al Pacino"})
    item = Actor.find("-1")
    assert_nil(item)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
redgraph-0.2.0 test/node_model_class_methods_test.rb