- public_trace_file = create(:trace, :visibility => "public", :user => users(:normal_user))
- public_trace_file.stub :trace_name, "#{GPX_TRACE_DIR}/1.gpx" do
- # Get file to use
- file = Rack::Test::UploadedFile.new(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"
- 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"
- 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 "trackable", trace.visibility
- assert_equal false, trace.inserted
- assert_equal File.new(public_trace_file.trace_name).read, File.new(trace.trace_name).read
- trace.destroy
- assert_equal "trackable", users(:public_user).preferences.where(:k => "gps.trace.visibility").first.v
-
- # Rewind the file
- file.rewind
-
- # Now authenticated, with the legacy public flag
- 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 => 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(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 %w(new trace), trace.tags.order(:tag).collect(&:tag)
- assert_equal "private", trace.visibility
- assert_equal false, trace.inserted
- assert_equal File.new(public_trace_file.trace_name).read, File.new(trace.trace_name).read
- trace.destroy
- assert_equal "private", users(:second_public_user).preferences.where(:k => "gps.trace.visibility").first.v
- end
+ # Get file to use
+ fixture = Rails.root.join("test", "gpx", "fixtures", "a.gpx")
+ file = Rack::Test::UploadedFile.new(fixture, "application/gpx+xml")
+
+ # First with no auth
+ 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"
+ assert_response :success
+ trace = Trace.find(response.body.to_i)
+ assert_equal "a.gpx", trace.name
+ assert_equal "New Trace", trace.description
+ 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(fixture).read, File.new(trace.trace_name).read
+ trace.destroy
+ assert_equal "trackable", users(:public_user).preferences.where(:k => "gps.trace.visibility").first.v
+
+ # Rewind the file
+ file.rewind
+
+ # Now authenticated, with the legacy public flag
+ 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 => 1
+ assert_response :success
+ trace = Trace.find(response.body.to_i)
+ assert_equal "a.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(fixture).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 "a.gpx", trace.name
+ assert_equal "New Trace", trace.description
+ 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(fixture).read, File.new(trace.trace_name).read
+ trace.destroy
+ assert_equal "private", users(:second_public_user).preferences.where(:k => "gps.trace.visibility").first.v