1 require File.dirname(__FILE__) + '/../test_helper'
3 class NodeTest < Test::Unit::TestCase
4 fixtures :current_nodes, :nodes, :users
5 set_fixture_class :current_nodes => :Node
6 set_fixture_class :nodes => :OldNode
9 node_template = Node.new(:latitude => 12.3456,
10 :longitude => 65.4321,
11 :user_id => users(:normal_user).id,
14 assert node_template.save_with_history
16 node = Node.find(node_template.id)
18 assert_equal node_template.latitude, node.latitude
19 assert_equal node_template.longitude, node.longitude
20 assert_equal node_template.user_id, node.user_id
21 assert_equal node_template.visible, node.visible
22 assert_equal node_template.tags, node.tags
23 assert_equal node_template.timestamp.to_i, node.timestamp.to_i
25 assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 1
26 old_node = OldNode.find(:first, :conditions => [ "id = ?", node_template.id ])
27 assert_not_nil old_node
28 assert_equal node_template.latitude, old_node.latitude
29 assert_equal node_template.longitude, old_node.longitude
30 assert_equal node_template.user_id, old_node.user_id
31 assert_equal node_template.visible, old_node.visible
32 assert_equal node_template.tags, old_node.tags
33 assert_equal node_template.timestamp.to_i, old_node.timestamp.to_i
37 node_template = Node.find(1)
38 assert_not_nil node_template
40 assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 1
41 old_node_template = OldNode.find(:first, :conditions => [ "id = ?", node_template.id ])
42 assert_not_nil old_node_template
44 node_template.latitude = 12.3456
45 node_template.longitude = 65.4321
46 node_template.tags = "updated=yes"
47 assert node_template.save_with_history
49 node = Node.find(node_template.id)
51 assert_equal node_template.latitude, node.latitude
52 assert_equal node_template.longitude, node.longitude
53 assert_equal node_template.user_id, node.user_id
54 assert_equal node_template.visible, node.visible
55 assert_equal node_template.tags, node.tags
56 assert_equal node_template.timestamp.to_i, node.timestamp.to_i
58 assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 2
59 assert_equal OldNode.find(:all, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ]).length, 1
60 old_node = OldNode.find(:first, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ])
61 assert_not_nil old_node
62 assert_equal node_template.latitude, old_node.latitude
63 assert_equal node_template.longitude, old_node.longitude
64 assert_equal node_template.user_id, old_node.user_id
65 assert_equal node_template.visible, old_node.visible
66 assert_equal node_template.tags, old_node.tags
67 assert_equal node_template.timestamp.to_i, old_node.timestamp.to_i
71 node_template = Node.find(1)
72 assert_not_nil node_template
74 assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 1
75 old_node_template = OldNode.find(:first, :conditions => [ "id = ?", node_template.id ])
76 assert_not_nil old_node_template
78 node_template.visible = 0
79 assert node_template.save_with_history
81 node = Node.find(node_template.id)
83 assert_equal node_template.latitude, node.latitude
84 assert_equal node_template.longitude, node.longitude
85 assert_equal node_template.user_id, node.user_id
86 assert_equal node_template.visible, node.visible
87 assert_equal node_template.tags, node.tags
88 assert_equal node_template.timestamp.to_i, node.timestamp.to_i
90 assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 2
91 assert_equal OldNode.find(:all, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ]).length, 1
92 old_node = OldNode.find(:first, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ])
93 assert_not_nil old_node
94 assert_equal node_template.latitude, old_node.latitude
95 assert_equal node_template.longitude, old_node.longitude
96 assert_equal node_template.user_id, old_node.user_id
97 assert_equal node_template.visible, old_node.visible
98 assert_equal node_template.tags, old_node.tags
99 assert_equal node_template.timestamp.to_i, old_node.timestamp.to_i