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

Last change on this file since 3690 was 3690, checked in by tomhughes, 12 years ago

Add some basic tests for nodes.

File size: 4.5 KB
Line 
1require File.dirname(__FILE__) + '/../test_helper'
2
3class NodeTest < Test::Unit::TestCase
4  fixtures :current_nodes, :nodes, :users
5  set_fixture_class :current_nodes => :Node
6  set_fixture_class :nodes => :OldNode
7
8  def test_create
9    node_template = Node.new(:latitude => 12.3456,
10                             :longitude => 65.4321,
11                             :user_id => users(:normal_user).id,
12                             :visible => 1,
13                             :tags => "")
14    assert node_template.save_with_history
15
16    node = Node.find(node_template.id)
17    assert_not_nil node
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
24
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
34  end
35
36  def test_update
37    node_template = Node.find(1)
38    assert_not_nil node_template
39
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
43
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
48
49    node = Node.find(node_template.id)
50    assert_not_nil node
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
57
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
68  end
69
70  def test_delete
71    node_template = Node.find(1)
72    assert_not_nil node_template
73
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
77
78    node_template.visible = 0
79    assert node_template.save_with_history
80
81    node = Node.find(node_template.id)
82    assert_not_nil node
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
89
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
100  end
101end
Note: See TracBrowser for help on using the repository browser.