X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/fd588cd715494092b5f55ac406f7dc69a1104ba9..a0627ec0c651cf33426438e26e4a4a2fe3a34fd5:/test/controllers/trace_controller_test.rb diff --git a/test/controllers/trace_controller_test.rb b/test/controllers/trace_controller_test.rb index f9bcd1337..5a5234cb5 100644 --- a/test/controllers/trace_controller_test.rb +++ b/test/controllers/trace_controller_test.rb @@ -1,7 +1,7 @@ require "test_helper" class TraceControllerTest < ActionController::TestCase - fixtures :users, :user_preferences, :gpx_files + fixtures :users, :gpx_files set_fixture_class :gpx_files => Trace def setup @@ -223,7 +223,7 @@ class TraceControllerTest < ActionController::TestCase check_trace_list users(:public_user).traces.tagged("London") # Should get an error if the user does not exist - get :list, { :display_name => "UnknownUser" } + get :list, :display_name => "UnknownUser" assert_response :not_found assert_template "user/no_such_user" end @@ -455,12 +455,14 @@ class TraceControllerTest < ActionController::TestCase assert_redirected_to :controller => :user, :action => :login, :referer => trace_create_path # Now authenticated as a user with gps.trace.visibility set + create(:user_preference, :user => users(:public_user), :k => "gps.trace.visibility", :v => "identifiable") get :create, {}, { :user => users(:public_user).id } assert_response :success assert_template :create assert_select "select#trace_visibility option[value=identifiable][selected]", 1 # Now authenticated as a user with gps.trace.public set + create(:user_preference, :user => users(:second_public_user), :k => "gps.trace.public", :v => "default") get :create, {}, { :user => users(:second_public_user).id } assert_response :success assert_template :create @@ -479,10 +481,11 @@ class TraceControllerTest < ActionController::TestCase file = Rack::Test::UploadedFile.new(gpx_files(:public_trace_file).trace_name, "application/gpx+xml") # First with no auth - post :create, { :trace => { :gpx_file => file, :description => "New Trace", :tagstring => "new,trace", :visibility => "trackable" } } + post :create, :trace => { :gpx_file => file, :description => "New Trace", :tagstring => "new,trace", :visibility => "trackable" } assert_response :forbidden # Now authenticated + create(:user_preference, :user => users(:public_user), :k => "gps.trace.visibility", :v => "identifiable") assert_not_equal "trackable", users(:public_user).preferences.where(:k => "gps.trace.visibility").first.v post :create, { :trace => { :gpx_file => file, :description => "New Trace", :tagstring => "new,trace", :visibility => "trackable" } }, { :user => users(:public_user).id } assert_response :redirect @@ -491,7 +494,7 @@ class TraceControllerTest < ActionController::TestCase trace = Trace.order(:id => :desc).first assert_equal "1.gpx", trace.name assert_equal "New Trace", trace.description - assert_equal "new, trace", trace.tagstring + assert_equal %w(new trace), trace.tags.order(:tag).collect(&:tag) assert_equal "trackable", trace.visibility assert_equal false, trace.inserted assert_equal File.new(gpx_files(:public_trace_file).trace_name).read, File.new(trace.trace_name).read @@ -639,12 +642,12 @@ class TraceControllerTest < ActionController::TestCase # Now with some other user, which should work since the trace is public basic_authorization(users(:public_user).display_name, "test") - get :api_data, { :display_name => users(:normal_user).display_name, :id => gpx_files(:public_trace_file).id } + get :api_data, :display_name => users(:normal_user).display_name, :id => gpx_files(:public_trace_file).id check_trace_data gpx_files(:public_trace_file) # And finally we should be able to do it with the owner of the trace basic_authorization(users(:normal_user).display_name, "test") - get :api_data, { :display_name => users(:normal_user).display_name, :id => gpx_files(:public_trace_file).id } + get :api_data, :display_name => users(:normal_user).display_name, :id => gpx_files(:public_trace_file).id check_trace_data gpx_files(:public_trace_file) end @@ -674,12 +677,12 @@ class TraceControllerTest < ActionController::TestCase # Now with some other user, which shouldn't work since the trace is anon basic_authorization(users(:normal_user).display_name, "test") - get :api_data, { :display_name => users(:public_user).display_name, :id => gpx_files(:anon_trace_file).id } + get :api_data, :display_name => users(:public_user).display_name, :id => gpx_files(:anon_trace_file).id assert_response :forbidden # And finally we should be able to do it with the owner of the trace basic_authorization(users(:public_user).display_name, "test") - get :api_data, { :display_name => users(:public_user).display_name, :id => gpx_files(:anon_trace_file).id } + get :api_data, :display_name => users(:public_user).display_name, :id => gpx_files(:anon_trace_file).id check_trace_data gpx_files(:anon_trace_file) end @@ -691,12 +694,12 @@ class TraceControllerTest < ActionController::TestCase # Now with a trace that has never existed basic_authorization(users(:public_user).display_name, "test") - get :api_data, { :display_name => users(:public_user).display_name, :id => 0 } + get :api_data, :display_name => users(:public_user).display_name, :id => 0 assert_response :not_found # Now with a trace that has been deleted basic_authorization(users(:public_user).display_name, "test") - get :api_data, { :display_name => users(:public_user).display_name, :id => 5 } + get :api_data, :display_name => users(:public_user).display_name, :id => 5 assert_response :not_found end @@ -706,18 +709,19 @@ class TraceControllerTest < ActionController::TestCase file = Rack::Test::UploadedFile.new(gpx_files(:public_trace_file).trace_name, "application/gpx+xml") # First with no auth - post :api_create, { :file => file, :description => "New Trace", :tags => "new,trace", :visibility => "trackable" } + post :api_create, :file => file, :description => "New Trace", :tags => "new,trace", :visibility => "trackable" assert_response :unauthorized # Now authenticated + create(:user_preference, :user => users(:public_user), :k => "gps.trace.visibility", :v => "identifiable") assert_not_equal "trackable", users(:public_user).preferences.where(:k => "gps.trace.visibility").first.v basic_authorization(users(:public_user).display_name, "test") - post :api_create, { :file => file, :description => "New Trace", :tags => "new,trace", :visibility => "trackable" } + post :api_create, :file => file, :description => "New Trace", :tags => "new,trace", :visibility => "trackable" assert_response :success trace = Trace.find(response.body.to_i) assert_equal "1.gpx", trace.name assert_equal "New Trace", trace.description - assert_equal "new, trace", trace.tagstring + assert_equal %w(new trace), trace.tags.order(:tag).collect(&:tag) assert_equal "trackable", trace.visibility assert_equal false, trace.inserted assert_equal File.new(gpx_files(:public_trace_file).trace_name).read, File.new(trace.trace_name).read @@ -728,19 +732,37 @@ class TraceControllerTest < ActionController::TestCase file.rewind # Now authenticated, with the legacy public flag - assert_not_equal "private", users(:public_user).preferences.where(:k => "gps.trace.visibility").first.v + assert_not_equal "public", users(:public_user).preferences.where(:k => "gps.trace.visibility").first.v basic_authorization(users(:public_user).display_name, "test") - post :api_create, { :file => file, :description => "New Trace", :tags => "new,trace", :public => 0 } + post :api_create, :file => file, :description => "New Trace", :tags => "new,trace", :public => 1 + assert_response :success + trace = Trace.find(response.body.to_i) + assert_equal "1.gpx", trace.name + assert_equal "New Trace", trace.description + assert_equal %w(new trace), trace.tags.order(:tag).collect(&:tag) + assert_equal "public", trace.visibility + assert_equal false, trace.inserted + assert_equal File.new(gpx_files(:public_trace_file).trace_name).read, File.new(trace.trace_name).read + trace.destroy + assert_equal "public", users(:public_user).preferences.where(:k => "gps.trace.visibility").first.v + + # Rewind the file + file.rewind + + # Now authenticated, with the legacy private flag + assert_nil users(:second_public_user).preferences.where(:k => "gps.trace.visibility").first + basic_authorization(users(:second_public_user).display_name, "test") + post :api_create, :file => file, :description => "New Trace", :tags => "new,trace", :public => 0 assert_response :success trace = Trace.find(response.body.to_i) assert_equal "1.gpx", trace.name assert_equal "New Trace", trace.description - assert_equal "new, trace", trace.tagstring + assert_equal %w(new trace), trace.tags.order(:tag).collect(&:tag) assert_equal "private", trace.visibility assert_equal false, trace.inserted assert_equal File.new(gpx_files(:public_trace_file).trace_name).read, File.new(trace.trace_name).read trace.destroy - assert_equal "private", users(:public_user).preferences.where(:k => "gps.trace.visibility").first.v + assert_equal "private", users(:second_public_user).preferences.where(:k => "gps.trace.visibility").first.v end # Check updating a trace through the api