test/node_model_test.rb in redgraph-0.1.4 vs test/node_model_test.rb in redgraph-0.2.0

- old
+ new

@@ -13,93 +13,49 @@ def teardown @graph.delete end + # test classes + # + class Animal include Redgraph::NodeModel attribute :name self.graph = "pippo" end class Dog < Animal end - def test_graph_accessor - assert_equal("pippo", Animal.graph) - assert_equal("pippo", Animal.new.graph) - end - - def test_class_inheritance - assert_equal("pippo", Dog.graph) - assert_equal("dog", Dog.label) - assert_equal([:id, :name], Dog.attribute_names) - end - class Actor include Redgraph::NodeModel self.graph = GRAPH attribute :name end - def test_count - quick_add_node(label: 'actor', properties: {name: "Al Pacino"}) - quick_add_node(label: 'actor', properties: {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 - - def test_label - assert_equal("actor", Actor.label) - end - - class Artist - include Redgraph::NodeModel - self.label = "person" - end - - def test_custom_label - assert_equal("person", Artist.label) - end - class Film include Redgraph::NodeModel self.graph = GRAPH attribute :name attribute :year end + # tests + # + + def test_graph_accessor + assert_equal("pippo", Animal.graph) + assert_equal("pippo", Animal.new.graph) + end + + def test_class_inheritance + assert_equal("pippo", Dog.graph) + assert_equal("dog", Dog.label) + assert_equal([:id, :name], Dog.attribute_names) + end + def test_attribute_names assert_equal([:id, :name, :year], Film.attribute_names) film = Film.new(name: "Star Wars", year: 1977) assert_equal("Star Wars", film.name) @@ -153,8 +109,18 @@ actor.add_relation(type: "ACTED_IN", node: film, properties: {role: "Han Solo"}, allow_duplicates: true) assert_equal(2, @graph.count_edges) actor.add_relation(type: "ACTED_IN", node: film, properties: {role: "Han Solo"}, allow_duplicates: false) assert_equal(2, @graph.count_edges) + end + + def test_casting_query + Film.new(name: "Star Wars", year: 1977).add_to_graph + Actor.new(name: "Harrison Ford").add_to_graph + + items = Film.query("MATCH (node) RETURN node ORDER BY node.name") + assert_equal(2, items.size) + assert_kind_of(Actor, items[0][0]) + assert_kind_of(Film, items[1][0]) end end