X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/33ea119c8f520a7e679e38b569c202976907a501..942e62117ff7f12d40618a94ea3f4e86f8cb25af:/test/controllers/traces_controller_test.rb diff --git a/test/controllers/traces_controller_test.rb b/test/controllers/traces_controller_test.rb index 9600ff77e..fbbbe4adc 100644 --- a/test/controllers/traces_controller_test.rb +++ b/test/controllers/traces_controller_test.rb @@ -135,11 +135,11 @@ class TracesControllerTest < ActionController::TestCase ) assert_routing( - { :path => "/trace/create", :method => :get }, - { :controller => "traces", :action => "create" } + { :path => "/traces/new", :method => :get }, + { :controller => "traces", :action => "new" } ) assert_routing( - { :path => "/trace/create", :method => :post }, + { :path => "/traces", :method => :post }, { :controller => "traces", :action => "create" } ) assert_routing( @@ -508,34 +508,34 @@ class TracesControllerTest < ActionController::TestCase assert_response :not_found end - # Test fetching the create page - def test_create_get + # Test fetching the new trace page + def test_new_get # First with no auth - get :create + get :new assert_response :redirect - assert_redirected_to :controller => :user, :action => :login, :referer => trace_create_path + assert_redirected_to :controller => :user, :action => :login, :referer => new_trace_path # Now authenticated as a user with gps.trace.visibility set user = create(:user) create(:user_preference, :user => user, :k => "gps.trace.visibility", :v => "identifiable") - get :create, :session => { :user => user } + get :new, :session => { :user => user } assert_response :success - assert_template :create + assert_template :new assert_select "select#trace_visibility option[value=identifiable][selected]", 1 # Now authenticated as a user with gps.trace.public set second_user = create(:user) create(:user_preference, :user => second_user, :k => "gps.trace.public", :v => "default") - get :create, :session => { :user => second_user } + get :new, :session => { :user => second_user } assert_response :success - assert_template :create + assert_template :new assert_select "select#trace_visibility option[value=public][selected]", 1 # Now authenticated as a user with no preferences third_user = create(:user) - get :create, :session => { :user => third_user } + get :new, :session => { :user => third_user } assert_response :success - assert_template :create + assert_template :new assert_select "select#trace_visibility option[value=private][selected]", 1 end @@ -571,6 +571,21 @@ class TracesControllerTest < ActionController::TestCase assert_equal "trackable", user.preferences.where(:k => "gps.trace.visibility").first.v end + # Test creating a trace with validation errors + def test_create_post_with_validation_errors + # Get file to use + fixture = Rails.root.join("test", "gpx", "fixtures", "a.gpx") + file = Rack::Test::UploadedFile.new(fixture, "application/gpx+xml") + user = create(:user) + + # Now authenticated + create(:user_preference, :user => user, :k => "gps.trace.visibility", :v => "identifiable") + assert_not_equal "trackable", user.preferences.where(:k => "gps.trace.visibility").first.v + post :create, :params => { :trace => { :gpx_file => file, :description => "", :tagstring => "new,trace", :visibility => "trackable" } }, :session => { :user => user } + assert_template :new + assert_match "Description is too short (minimum is 1 character)", response.body + end + # Test fetching the edit page for a trace using GET def test_edit_get public_trace_file = create(:trace, :visibility => "public")