return
end
- @nodes = Node.bbox(bbox).where(:visible => true).includes(:node_tags).limit(MAX_NUMBER_OF_NODES + 1)
+ nodes = Node.bbox(bbox).where(:visible => true).includes(:node_tags).limit(MAX_NUMBER_OF_NODES + 1)
- node_ids = @nodes.collect(&:id)
+ node_ids = nodes.collect(&:id)
if node_ids.length > MAX_NUMBER_OF_NODES
report_error("You requested too many nodes (limit is #{MAX_NUMBER_OF_NODES}). Either request a smaller area, or use planet.osm")
return
end
- if node_ids.length == 0
- render :text => "<osm version='#{API_VERSION}' generator='#{GENERATOR}'></osm>", :content_type => "text/xml"
- return
- end
doc = OSM::API.new.get_xml_doc
nodes_to_fetch = (list_of_way_nodes.uniq - node_ids) - [0]
if nodes_to_fetch.length > 0
- @nodes += Node.includes(:node_tags).find(nodes_to_fetch)
+ nodes += Node.includes(:node_tags).find(nodes_to_fetch)
end
visible_nodes = {}
changeset_cache = {}
user_display_name_cache = {}
- @nodes.each do |node|
+ nodes.each do |node|
if node.visible?
doc.root << node.to_xml_node(changeset_cache, user_display_name_cache)
visible_nodes[node.id] = node
has_many :old_ways
has_many :old_relations
+ validates :description, :presence => true
+ validates :description_format, :inclusion => { :in => %w(text html markdown) }
+
# this method overrides the AR default to provide the rich
# text object for the description field.
def description
# This should really be more generic
assert_select "tag[k='test'][v='yes']"
end
- # Should also test for the ways and relation
+ assert_select "way", :count => 2
+ assert_select "way[id='1']", :count => 1
+ assert_select "way[id='3']", :count => 1
+ assert_select "relation", :count => 1
+ assert_select "relation[id='1']", :count => 1
end
end
# This should really be more generic
assert_select "tag[k='test'][v='yes']"
end
- # Should also test for the ways and relation
+ assert_select "way", :count => 2
+ assert_select "way[id='1']", :count => 1
+ assert_select "way[id='3']", :count => 1
+ assert_select "relation", :count => 1
+ assert_select "relation[id='1']", :count => 1
+ end
+ end
+
+ def test_map_complete_way
+ node = current_nodes(:used_node_2)
+ bbox = "#{node.lon},#{node.lat},#{node.lon},#{node.lat}"
+ get :map, :bbox => bbox
+ assert_response :success, "The map call should have succeeded"
+ assert_select "osm[version='#{API_VERSION}'][generator='#{GENERATOR}']", :count => 1 do
+ assert_select "bounds[minlon='#{node.lon}'][minlat='#{node.lat}'][maxlon='#{node.lon}'][maxlat='#{node.lat}']", :count => 1
+ assert_select "node", :count => 3
+ assert_select "node[id='4']", :count => 1
+ assert_select "node[id='11']", :count => 1
+ assert_select "node[id='15']", :count => 1
+ assert_select "way", :count => 2
+ assert_select "way[id='5']", :count => 1
+ assert_select "way[id='7']", :count => 1
+ assert_select "relation", :count => 1
+ assert_select "relation[id='8']", :count => 1
+ end
+ end
+
+ def test_map_empty
+ get :map, :bbox => "179.998,89.998,179.999.1,89.999"
+ assert_response :success, "The map call should have succeeded"
+ assert_select "osm[version='#{API_VERSION}'][generator='#{GENERATOR}']", :count => 1 do
+ assert_select "bounds[minlon='179.998'][minlat='89.998'][maxlon='179.999'][maxlat='89.999']", :count => 1
+ assert_select "node", :count => 0
+ assert_select "way", :count => 0
+ assert_select "relation", :count => 0
end
end
now = Time.now.getutc
hourago = now - 1.hour
assert_select "osm[version='#{API_VERSION}'][generator='#{GENERATOR}']", :count => 1 do
- assert_select "changes[starttime='#{hourago.xmlschema}'][endtime='#{now.xmlschema}']", :count => 1
+ assert_select "changes[starttime='#{hourago.xmlschema}'][endtime='#{now.xmlschema}']", :count => 1 do
+ assert_select "tile", :count => 0
+ end
+ end
+ Timecop.return
+
+ Timecop.freeze(Time.parse("2007-01-01 00:30:00"))
+ get :changes
+ assert_response :success
+ # print @response.body
+ # As we have loaded the fixtures, we can assume that there are some
+ # changes at the time we have frozen at
+ now = Time.now.getutc
+ hourago = now - 1.hour
+ assert_select "osm[version='#{API_VERSION}'][generator='#{GENERATOR}']", :count => 1 do
+ assert_select "changes[starttime='#{hourago.xmlschema}'][endtime='#{now.xmlschema}']", :count => 1 do
+ assert_select "tile", :count => 10
+ end
end
Timecop.return
end
end
end
- def test_hours_invalid
+ def test_changes_hours_invalid
invalid = %w(-21 335 -1 0 25 26 100 one two three ping pong :)
invalid.each do |hour|
get :changes, :hours => hour
end
end
- def test_hours_valid
+ def test_changes_hours_valid
1.upto(24) do |hour|
get :changes, :hours => hour
assert_response :success
end
end
+ def test_changes_start_end_invalid
+ get :changes, :start => "2010-04-03 10:55:00", :end => "2010-04-03 09:55:00"
+ assert_response :bad_request
+ assert_equal @response.body, "Requested zoom is invalid, or the supplied start is after the end time, or the start duration is more than 24 hours"
+ end
+
+ def test_changes_start_end_valid
+ get :changes, :start => "2010-04-03 09:55:00", :end => "2010-04-03 10:55:00"
+ assert_response :success
+ end
+
def test_capabilities
get :capabilities
assert_response :success
)
end
- def test_moderators_can_create
+ def test_index
+ get :index
+ assert_response :success
+ assert_template :index
+ assert_select "ul#redaction_list", 1 do
+ assert_select "li", Redaction.count
+ end
+ end
+
+ def test_new
+ get :new
+ assert_response :redirect
+ assert_redirected_to login_path(:referer => new_redaction_path)
+ end
+
+ def test_new_moderator
+ session[:user] = users(:moderator_user).id
+
+ get :new
+ assert_response :success
+ assert_template :new
+ end
+
+ def test_new_non_moderator
+ session[:user] = users(:public_user).id
+
+ get :new
+ assert_response :redirect
+ assert_redirected_to redactions_path
+ end
+
+ def test_create_moderator
session[:user] = users(:moderator_user).id
post :create, :redaction => { :title => "Foo", :description => "Description here." }
assert_redirected_to(redaction_path(Redaction.find_by_title("Foo")))
end
- def test_non_moderators_cant_create
+ def test_create_moderator_invalid
+ session[:user] = users(:moderator_user).id
+
+ post :create, :redaction => { :title => "Foo", :description => "" }
+ assert_response :success
+ assert_template :new
+ end
+
+ def test_create_non_moderator
session[:user] = users(:public_user).id
post :create, :redaction => { :title => "Foo", :description => "Description here." }
assert_response :forbidden
end
- def test_moderators_can_delete_empty
+ def test_destroy_moderator_empty
session[:user] = users(:moderator_user).id
# remove all elements from the redaction
assert_redirected_to(redactions_path)
end
- def test_moderators_cant_delete_nonempty
+ def test_destroy_moderator_non_empty
session[:user] = users(:moderator_user).id
# leave elements in the redaction
assert_match /^Redaction is not empty/, flash[:error]
end
- def test_non_moderators_cant_delete
+ def test_delete_non_moderator
session[:user] = users(:public_user).id
delete :destroy, :id => redactions(:example).id
assert_response :forbidden
end
- def test_moderators_can_edit
+ def test_edit
+ get :edit, :id => redactions(:example).id
+ assert_response :redirect
+ assert_redirected_to login_path(:referer => edit_redaction_path(redactions(:example)))
+ end
+
+ def test_edit_moderator
session[:user] = users(:moderator_user).id
get :edit, :id => redactions(:example).id
assert_response :success
end
- def test_non_moderators_cant_edit
+ def test_edit_non_moderator
session[:user] = users(:public_user).id
get :edit, :id => redactions(:example).id
assert_redirected_to(redactions_path)
end
- def test_moderators_can_update
+ def test_update_moderator
session[:user] = users(:moderator_user).id
redaction = redactions(:example)
assert_redirected_to(redaction_path(redaction))
end
- def test_non_moderators_cant_update
+ def test_update_moderator_invalid
+ session[:user] = users(:moderator_user).id
+
+ redaction = redactions(:example)
+
+ put :update, :id => redaction.id, :redaction => { :title => "Foo", :description => "" }
+ assert_response :success
+ assert_template :edit
+ end
+
+ def test_updated_non_moderator
session[:user] = users(:public_user).id
redaction = redactions(:example)