Create a node factory, and use it for most node model tests
This commit is contained in:
parent
2d3ca85751
commit
1a3130ec61
2 changed files with 61 additions and 73 deletions
13
test/factories/node.rb
Normal file
13
test/factories/node.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
FactoryGirl.define do
|
||||||
|
factory :node do
|
||||||
|
latitude 1 * GeoRecord::SCALE
|
||||||
|
longitude 1 * GeoRecord::SCALE
|
||||||
|
|
||||||
|
# FIXME: needs changeset factory
|
||||||
|
changeset_id 1
|
||||||
|
|
||||||
|
visible true
|
||||||
|
timestamp Time.now
|
||||||
|
version 1
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,76 +3,49 @@ require "test_helper"
|
||||||
class NodeTest < ActiveSupport::TestCase
|
class NodeTest < ActiveSupport::TestCase
|
||||||
api_fixtures
|
api_fixtures
|
||||||
|
|
||||||
def test_node_count
|
|
||||||
assert_equal 19, Node.count
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_node_too_far_north
|
def test_node_too_far_north
|
||||||
invalid_node_test(:node_too_far_north)
|
node = build(:node, :latitude => 90.01 * OldNode::SCALE)
|
||||||
|
assert_equal false, node.valid?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_node_north_limit
|
def test_node_north_limit
|
||||||
valid_node_test(:node_north_limit)
|
node = build(:node, :latitude => 90 * OldNode::SCALE)
|
||||||
end
|
|
||||||
|
|
||||||
def test_node_too_far_south
|
|
||||||
invalid_node_test(:node_too_far_south)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_node_south_limit
|
|
||||||
valid_node_test(:node_south_limit)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_node_too_far_west
|
|
||||||
invalid_node_test(:node_too_far_west)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_node_west_limit
|
|
||||||
valid_node_test(:node_west_limit)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_node_too_far_east
|
|
||||||
invalid_node_test(:node_too_far_east)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_node_east_limit
|
|
||||||
valid_node_test(:node_east_limit)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_totally_wrong
|
|
||||||
invalid_node_test(:node_totally_wrong)
|
|
||||||
end
|
|
||||||
|
|
||||||
# This helper method will check to make sure that a node is within the world, and
|
|
||||||
# has the the same lat, lon and timestamp than what was put into the db by
|
|
||||||
# the fixture
|
|
||||||
def valid_node_test(nod)
|
|
||||||
node = current_nodes(nod)
|
|
||||||
dbnode = Node.find(node.id)
|
|
||||||
assert_equal dbnode.lat, node.latitude.to_f / Node::SCALE
|
|
||||||
assert_equal dbnode.lon, node.longitude.to_f / Node::SCALE
|
|
||||||
assert_equal dbnode.changeset_id, node.changeset_id
|
|
||||||
assert_equal dbnode.timestamp, node.timestamp
|
|
||||||
assert_equal dbnode.version, node.version
|
|
||||||
assert_equal dbnode.visible, node.visible
|
|
||||||
# assert_equal node.tile, QuadTile.tile_for_point(node.lat, node.lon)
|
|
||||||
assert node.valid?
|
assert node.valid?
|
||||||
end
|
end
|
||||||
|
|
||||||
# This helper method will check to make sure that a node is outwith the world,
|
def test_node_too_far_south
|
||||||
# and has the same lat, lon and timesamp than what was put into the db by the
|
node = build(:node, :latitude => -90.01 * OldNode::SCALE)
|
||||||
# fixture
|
assert_equal false, node.valid?
|
||||||
def invalid_node_test(nod)
|
end
|
||||||
node = current_nodes(nod)
|
|
||||||
dbnode = Node.find(node.id)
|
def test_node_south_limit
|
||||||
assert_equal dbnode.lat, node.latitude.to_f / Node::SCALE
|
node = build(:node, :latitude => -90 * OldNode::SCALE)
|
||||||
assert_equal dbnode.lon, node.longitude.to_f / Node::SCALE
|
assert node.valid?
|
||||||
assert_equal dbnode.changeset_id, node.changeset_id
|
end
|
||||||
assert_equal dbnode.timestamp, node.timestamp
|
|
||||||
assert_equal dbnode.version, node.version
|
def test_node_too_far_west
|
||||||
assert_equal dbnode.visible, node.visible
|
node = build(:node, :longitude => -180.01 * OldNode::SCALE)
|
||||||
# assert_equal node.tile, QuadTile.tile_for_point(node.lat, node.lon)
|
assert_equal false, node.valid?
|
||||||
assert_equal false, dbnode.valid?
|
end
|
||||||
|
|
||||||
|
def test_node_west_limit
|
||||||
|
node = build(:node, :longitude => -180 * OldNode::SCALE)
|
||||||
|
assert node.valid?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_node_too_far_east
|
||||||
|
node = build(:node, :longitude => 180.01 * OldNode::SCALE)
|
||||||
|
assert_equal false, node.valid?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_node_east_limit
|
||||||
|
node = build(:node, :longitude => 180 * OldNode::SCALE)
|
||||||
|
assert node.valid?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_totally_wrong
|
||||||
|
node = build(:node, :latitude => 200 * OldNode::SCALE, :longitude => 200 * OldNode::SCALE)
|
||||||
|
assert_equal false, node.valid?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check that you can create a node and store it
|
# Check that you can create a node and store it
|
||||||
|
@ -106,17 +79,18 @@ class NodeTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_update
|
def test_update
|
||||||
node_template = Node.find(current_nodes(:visible_node).id)
|
node = create(:node)
|
||||||
assert_not_nil node_template
|
create(:old_node, :node_id => node.id, :version => 1)
|
||||||
|
node_template = Node.find(node.id)
|
||||||
|
|
||||||
|
assert_not_nil node_template
|
||||||
assert_equal OldNode.where(:node_id => node_template.id).count, 1
|
assert_equal OldNode.where(:node_id => node_template.id).count, 1
|
||||||
node = Node.find(node_template.id)
|
|
||||||
assert_not_nil node
|
assert_not_nil node
|
||||||
|
|
||||||
node_template.latitude = 12.3456
|
node_template.latitude = 12.3456
|
||||||
node_template.longitude = 65.4321
|
node_template.longitude = 65.4321
|
||||||
# node_template.tags = "updated=yes"
|
# node_template.tags = "updated=yes"
|
||||||
assert node.update_from(node_template, current_nodes(:visible_node).changeset.user)
|
assert node.update_from(node_template, node.changeset.user)
|
||||||
|
|
||||||
node = Node.find(node_template.id)
|
node = Node.find(node_template.id)
|
||||||
assert_not_nil node
|
assert_not_nil node
|
||||||
|
@ -137,14 +111,15 @@ class NodeTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_delete
|
def test_delete
|
||||||
node_template = Node.find(current_nodes(:visible_node).id)
|
node = create(:node)
|
||||||
assert_not_nil node_template
|
create(:old_node, :node_id => node.id, :version => 1)
|
||||||
|
node_template = Node.find(node.id)
|
||||||
|
|
||||||
|
assert_not_nil node_template
|
||||||
assert_equal OldNode.where(:node_id => node_template.id).count, 1
|
assert_equal OldNode.where(:node_id => node_template.id).count, 1
|
||||||
node = Node.find(node_template.id)
|
|
||||||
assert_not_nil node
|
assert_not_nil node
|
||||||
|
|
||||||
assert node.delete_with_history!(node_template, current_nodes(:visible_node).changeset.user)
|
assert node.delete_with_history!(node_template, node.changeset.user)
|
||||||
|
|
||||||
node = Node.find(node_template.id)
|
node = Node.find(node_template.id)
|
||||||
assert_not_nil node
|
assert_not_nil node
|
||||||
|
@ -315,7 +290,7 @@ class NodeTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_node_tags
|
def test_node_tags
|
||||||
node = current_nodes(:node_with_versions)
|
node = create(:node)
|
||||||
taglist = create_list(:node_tag, 2, :node => node)
|
taglist = create_list(:node_tag, 2, :node => node)
|
||||||
tags = Node.find(node.id).node_tags.order(:k)
|
tags = Node.find(node.id).node_tags.order(:k)
|
||||||
assert_equal taglist.count, tags.count
|
assert_equal taglist.count, tags.count
|
||||||
|
@ -326,7 +301,7 @@ class NodeTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tags
|
def test_tags
|
||||||
node = current_nodes(:node_with_versions)
|
node = create(:node)
|
||||||
taglist = create_list(:node_tag, 2, :node => node)
|
taglist = create_list(:node_tag, 2, :node => node)
|
||||||
tags = Node.find(node.id).tags
|
tags = Node.find(node.id).tags
|
||||||
assert_equal taglist.count, tags.count
|
assert_equal taglist.count, tags.count
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue