source: subversion/sites/rails_port/test/unit/node_test.rb @ 14668

Last change on this file since 14668 was 14586, checked in by tomhughes, 10 years ago

Merge api06 branch to trunk.

File size: 6.7 KB
Line 
1require File.dirname(__FILE__) + '/../test_helper'
2
3class NodeTest < Test::Unit::TestCase
4  api_fixtures
5
6  def test_node_too_far_north
7          invalid_node_test(:node_too_far_north)
8  end
9 
10  def test_node_north_limit
11    valid_node_test(:node_north_limit)
12  end
13 
14  def test_node_too_far_south
15    invalid_node_test(:node_too_far_south)
16  end
17 
18  def test_node_south_limit
19    valid_node_test(:node_south_limit)
20  end
21 
22  def test_node_too_far_west
23    invalid_node_test(:node_too_far_west)
24  end
25 
26  def test_node_west_limit
27    valid_node_test(:node_west_limit)
28  end
29 
30  def test_node_too_far_east
31    invalid_node_test(:node_too_far_east)
32  end
33 
34  def test_node_east_limit
35    valid_node_test(:node_east_limit)
36  end
37 
38  def test_totally_wrong
39    invalid_node_test(:node_totally_wrong)
40  end
41 
42  # This helper method will check to make sure that a node is within the world, and
43  # has the the same lat, lon and timestamp than what was put into the db by
44  # the fixture
45  def valid_node_test(nod)
46    node = current_nodes(nod)
47    dbnode = Node.find(node.id)
48    assert_equal dbnode.lat, node.latitude.to_f/SCALE
49    assert_equal dbnode.lon, node.longitude.to_f/SCALE
50    assert_equal dbnode.changeset_id, node.changeset_id
51    assert_equal dbnode.timestamp, node.timestamp
52    assert_equal dbnode.version, node.version
53    assert_equal dbnode.visible, node.visible
54    #assert_equal node.tile, QuadTile.tile_for_point(node.lat, node.lon)
55    assert_valid node
56  end
57 
58  # This helper method will check to make sure that a node is outwith the world,
59  # and has the same lat, lon and timesamp than what was put into the db by the
60  # fixture
61  def invalid_node_test(nod)
62    node = current_nodes(nod)
63    dbnode = Node.find(node.id)
64    assert_equal dbnode.lat, node.latitude.to_f/SCALE
65    assert_equal dbnode.lon, node.longitude.to_f/SCALE
66    assert_equal dbnode.changeset_id, node.changeset_id
67    assert_equal dbnode.timestamp, node.timestamp
68    assert_equal dbnode.version, node.version
69    assert_equal dbnode.visible, node.visible
70    #assert_equal node.tile, QuadTile.tile_for_point(node.lat, node.lon)
71    assert_equal false, dbnode.valid?
72  end
73 
74  # Check that you can create a node and store it
75  def test_create
76    node_template = Node.new(:latitude => 12.3456,
77                             :longitude => 65.4321,
78                             :changeset_id => changesets(:normal_user_first_change).id,
79                             :visible => 1, 
80                             :version => 1)
81    assert node_template.create_with_history(users(:normal_user))
82
83    node = Node.find(node_template.id)
84    assert_not_nil node
85    assert_equal node_template.latitude, node.latitude
86    assert_equal node_template.longitude, node.longitude
87    assert_equal node_template.changeset_id, node.changeset_id
88    assert_equal node_template.visible, node.visible
89    assert_equal node_template.timestamp.to_i, node.timestamp.to_i
90
91    assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 1
92    old_node = OldNode.find(:first, :conditions => [ "id = ?", node_template.id ])
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.changeset_id, old_node.changeset_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
100  end
101
102  def test_update
103    node_template = Node.find(current_nodes(:visible_node).id)
104    assert_not_nil node_template
105
106    assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 1
107    old_node_template = OldNode.find(:first, :conditions => [ "id = ?", node_template.id ])
108    assert_not_nil old_node_template
109
110    node_template.latitude = 12.3456
111    node_template.longitude = 65.4321
112    #node_template.tags = "updated=yes"
113    assert node_template.update_from(old_node_template, users(:normal_user))
114
115    node = Node.find(node_template.id)
116    assert_not_nil node
117    assert_equal node_template.latitude, node.latitude
118    assert_equal node_template.longitude, node.longitude
119    assert_equal node_template.changeset_id, node.changeset_id
120    assert_equal node_template.visible, node.visible
121    #assert_equal node_template.tags, node.tags
122    assert_equal node_template.timestamp.to_i, node.timestamp.to_i
123
124    assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 2
125    assert_equal OldNode.find(:all, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ]).length, 1
126    old_node = OldNode.find(:first, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ])
127    assert_not_nil old_node
128    assert_equal node_template.latitude, old_node.latitude
129    assert_equal node_template.longitude, old_node.longitude
130    assert_equal node_template.changeset_id, old_node.changeset_id
131    assert_equal node_template.visible, old_node.visible
132    #assert_equal node_template.tags, old_node.tags
133    assert_equal node_template.timestamp.to_i, old_node.timestamp.to_i
134  end
135
136  def test_delete
137    node_template = Node.find(current_nodes(:visible_node))
138    assert_not_nil node_template
139
140    assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 1
141    old_node_template = OldNode.find(:first, :conditions => [ "id = ?", node_template.id ])
142    assert_not_nil old_node_template
143
144    assert node_template.delete_with_history!(old_node_template, users(:normal_user))
145
146    node = Node.find(node_template.id)
147    assert_not_nil node
148    assert_equal node_template.latitude, node.latitude
149    assert_equal node_template.longitude, node.longitude
150    assert_equal node_template.changeset_id, node.changeset_id
151    assert_equal node_template.visible, node.visible
152    #assert_equal node_template.tags, node.tags
153    assert_equal node_template.timestamp.to_i, node.timestamp.to_i
154
155    assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 2
156    assert_equal OldNode.find(:all, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ]).length, 1
157    old_node = OldNode.find(:first, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ])
158    assert_not_nil old_node
159    assert_equal node_template.latitude, old_node.latitude
160    assert_equal node_template.longitude, old_node.longitude
161    assert_equal node_template.changeset_id, old_node.changeset_id
162    assert_equal node_template.visible, old_node.visible
163    #assert_equal node_template.tags, old_node.tags
164    assert_equal node_template.timestamp.to_i, old_node.timestamp.to_i
165  end
166end
Note: See TracBrowser for help on using the repository browser.