Sha256: bed57b2dce270dbc6fb56c7cae6377b5f1f2ca9d3d641ef4a79a7c81a0d5db74

Contents?: true

Size: 946 Bytes

Versions: 6

Compression:

Stored size: 946 Bytes

Contents

require File.expand_path('test/test_helper')
require 'pp'

class CustomNodeTest < ActiveModel::TestCase

  class CustomNode
    include Related::Node::QueryMethods
    attr_accessor :id
    def self.flush
      @database = {}
    end
    def self.create
      n = self.new
      n.id = Related.generate_id
      @database ||= {}
      @database[n.id] = n
      n
    end
    def self.find(*ids)
      ids.pop if ids.size > 1 && ids.last.is_a?(Hash)
      ids.flatten.map do |id|
        @database[id]
      end
    end
    def to_s
      @id
    end
    protected
      def query
        Related::Node::Query.new(self)
      end
  end

  def setup
    Related.redis.flushall
    CustomNode.flush
  end

  def test_property_conversion
    node1 = CustomNode.create
    node2 = CustomNode.create
    Related::Relationship.create(:friend, node1, node2)
    assert_equal [node2], node1.shortest_path_to(node2).outgoing(:friend).nodes.to_a
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
related-0.6.5 test/custom_node_test.rb
related-0.6.4 test/custom_node_test.rb
related-0.6.3 test/custom_node_test.rb
related-0.6.2 test/custom_node_test.rb
related-0.6.1 test/custom_node_test.rb
related-0.6.0 test/custom_node_test.rb