4 class ChangesControllerTest < ActionDispatch::IntegrationTest
6 # test all routes which lead to this controller
9 { :path => "/api/0.6/changes", :method => :get },
10 { :controller => "api/changes", :action => "index" }
14 # MySQL and Postgres require that the C based functions are installed for
15 # this test to work. More information is available from:
16 # http://wiki.openstreetmap.org/wiki/Rails#Installing_the_quadtile_functions
17 # or by looking at the readme in db/README
18 def test_changes_simple
19 # create a selection of nodes
21 create(:node, :timestamp => Time.utc(2007, 1, 1, 0, 0, 0), :lat => n, :lon => n)
23 # deleted nodes should also be counted
24 create(:node, :deleted, :timestamp => Time.utc(2007, 1, 1, 0, 0, 0), :lat => 6, :lon => 6)
25 # nodes in the same tile won't change the total
26 create(:node, :timestamp => Time.utc(2007, 1, 1, 0, 0, 0), :lat => 6, :lon => 6)
27 # nodes with a different timestamp should be ignored
28 create(:node, :timestamp => Time.utc(2008, 1, 1, 0, 0, 0), :lat => 7, :lon => 7)
30 travel_to Time.utc(2010, 4, 3, 10, 55, 0) do
32 assert_response :success
34 hourago = now - 1.hour
35 assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
36 assert_select "changes[starttime='#{hourago.xmlschema}'][endtime='#{now.xmlschema}']", :count => 1 do
37 assert_select "tile", :count => 0
42 travel_to Time.utc(2007, 1, 1, 0, 30, 0) do
44 assert_response :success
45 # print @response.body
46 # As we have loaded the fixtures, we can assume that there are some
47 # changes at the time we have frozen at
49 hourago = now - 1.hour
50 assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
51 assert_select "changes[starttime='#{hourago.xmlschema}'][endtime='#{now.xmlschema}']", :count => 1 do
52 assert_select "tile", :count => 6
58 def test_changes_zoom_invalid
59 zoom_to_test = %w[p -1 0 17 one two]
60 zoom_to_test.each do |zoom|
61 get changes_path(:zoom => zoom)
62 assert_response :bad_request
63 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"
67 def test_changes_zoom_valid
69 get changes_path(:zoom => zoom)
70 assert_response :success
71 # NOTE: there was a test here for the timing, but it was too sensitive to be a good test
72 # and it was annoying.
73 assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
74 assert_select "changes", :count => 1
79 def test_changes_hours_invalid
80 invalid = %w[-21 335 -1 0 25 26 100 one two three ping pong :]
81 invalid.each do |hour|
82 get changes_path(:hours => hour)
83 assert_response :bad_request, "Problem with the hour: #{hour}"
84 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", "Problem with the hour: #{hour}."
88 def test_changes_hours_valid
90 get changes_path(:hours => hour)
91 assert_response :success
95 def test_changes_start_end_invalid
96 get changes_path(:start => "2010-04-03 10:55:00", :end => "2010-04-03 09:55:00")
97 assert_response :bad_request
98 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"
101 def test_changes_start_end_valid
102 get changes_path(:start => "2010-04-03 09:55:00", :end => "2010-04-03 10:55:00")
103 assert_response :success