)
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(
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
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")