]> git.openstreetmap.org Git - rails.git/blob - test/controllers/swf_controller_test.rb
Refactor putway method tests to use factories
[rails.git] / test / controllers / swf_controller_test.rb
1 require "test_helper"
2
3 class SwfControllerTest < ActionController::TestCase
4   api_fixtures
5
6   ##
7   # test all routes which lead to this controller
8   def test_routes
9     assert_routing(
10       { :path => "/api/0.6/swf/trackpoints", :method => :get },
11       { :controller => "swf", :action => "trackpoints" }
12     )
13   end
14
15   ##
16   # basic test that trackpoints at least returns some sort of flash movie
17   def test_trackpoints
18     user = create(:user)
19     other_user = create(:user)
20     create(:trace, :visibility => "trackable", :latitude => 51.51, :longitude => -0.14, :user => user) do |trace|
21       create(:tracepoint, :trace => trace, :trackid => 1, :latitude => (51.510 * GeoRecord::SCALE).to_i, :longitude => (-0.140 * GeoRecord::SCALE).to_i)
22       create(:tracepoint, :trace => trace, :trackid => 2, :latitude => (51.511 * GeoRecord::SCALE).to_i, :longitude => (-0.141 * GeoRecord::SCALE).to_i)
23     end
24     create(:trace, :visibility => "identifiable", :latitude => 51.512, :longitude => 0.142) do |trace|
25       create(:tracepoint, :trace => trace, :latitude => (51.512 * GeoRecord::SCALE).to_i, :longitude => (0.142 * GeoRecord::SCALE).to_i)
26     end
27
28     get :trackpoints, :xmin => -1, :xmax => 1, :ymin => 51, :ymax => 52, :baselong => 0, :basey => 0, :masterscale => 1
29     assert_response :success
30     assert_equal "application/x-shockwave-flash", response.content_type
31     assert_match /^FWS/, response.body
32     assert_equal 80, response.body.length
33
34     get :trackpoints, :xmin => -1, :xmax => 1, :ymin => 51, :ymax => 52, :baselong => 0, :basey => 0, :masterscale => 1, :token => other_user.tokens.create.token
35     assert_response :success
36     assert_equal "application/x-shockwave-flash", response.content_type
37     assert_match /^FWS/, response.body
38     assert_equal 67, response.body.length
39
40     get :trackpoints, :xmin => -1, :xmax => 1, :ymin => 51, :ymax => 52, :baselong => 0, :basey => 0, :masterscale => 1, :token => user.tokens.create.token
41     assert_response :success
42     assert_equal "application/x-shockwave-flash", response.content_type
43     assert_match /^FWS/, response.body
44     assert_equal 74, response.body.length
45   end
46 end