Skip to content

Commit

Permalink
The test train rolls ever onwards...
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Mar 1, 2015
1 parent 66efc5f commit fd588cd
Show file tree
Hide file tree
Showing 25 changed files with 362 additions and 24 deletions.
11 changes: 6 additions & 5 deletions app/controllers/trace_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def create
end

if @trace.id
logger.info("id is #{@trace.id}")
flash[:notice] = t "trace.create.trace_uploaded"

if @user.traces.where(:inserted => false).count > 4
Expand Down Expand Up @@ -219,7 +218,7 @@ def georss
def picture
trace = Trace.find(params[:id])

if trace.inserted?
if trace.visible? && trace.inserted?
if trace.public? || (@user && @user == trace.user)
expires_in 7.days, :private => !trace.public?, :public => trace.public?
send_file(trace.large_picture_name, :filename => "#{trace.id}.gif", :type => "image/gif", :disposition => "inline")
Expand All @@ -236,7 +235,7 @@ def picture
def icon
trace = Trace.find(params[:id])

if trace.inserted?
if trace.visible? && trace.inserted?
if trace.public? || (@user && @user == trace.user)
expires_in 7.days, :private => !trace.public?, :public => trace.public?
send_file(trace.icon_picture_name, :filename => "#{trace.id}_icon.gif", :type => "image/gif", :disposition => "inline")
Expand Down Expand Up @@ -295,11 +294,13 @@ def api_delete
end

def api_data
trace = Trace.find(params[:id])
trace = Trace.visible.find(params[:id])

if trace.public? || trace.user == @user
if request.format == Mime::XML || request.format == Mime::GPX
if request.format == Mime::XML
send_file(trace.xml_file, :filename => "#{trace.id}.xml", :type => request.format.to_s, :disposition => "attachment")
elsif request.format == Mime::GPX
send_file(trace.xml_file, :filename => "#{trace.id}.gpx", :type => request.format.to_s, :disposition => "attachment")
else
send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => "attachment")
end
Expand Down
3 changes: 0 additions & 3 deletions app/models/trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,13 @@ def icon_picture=(data)

def large_picture
f = File.new(large_picture_name, "rb")
logger.info "large picture file: '#{f.path}', bytes: #{File.size(f.path)}"
data = f.sysread(File.size(f.path))
logger.info "have read data, bytes: '#{data.length}'"
f.close
data
end

def icon_picture
f = File.new(icon_picture_name, "rb")
logger.info "icon picture file: '#{f.path}'"
data = f.sysread(File.size(f.path))
f.close
data
Expand Down
308 changes: 300 additions & 8 deletions test/controllers/trace_controller_test.rb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/controllers/user_preference_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_read
assert_response :unauthorized, "should be authenticated"

# authenticate as a user with no preferences
basic_authorization("test@example.com", "test")
basic_authorization("moderator@example.com", "test")

# try the read again
get :read
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/gpx_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,16 @@ tar_bzip_trace_file:
visibility: "private"
description: This is a bzipped tarred trace
inserted: true

pending_trace_file:
id: 10
user_id: 2
visible: true
name: Pending Trace.gpx
size: 123
latitude: 51.3
longitude: -0.56
timestamp: "2009-05-06 13:34:34"
visibility: "public"
description: This is a pending trace
inserted: false
10 changes: 10 additions & 0 deletions test/fixtures/user_preferences.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@ two:
user_id: 1
k: "some_key"
v: "some_value"

u2_trace:
user_id: 2
k: "gps.trace.visibility"
v: "identifiable"

u3_trace:
user_id: 4
k: "gps.trace.public"
v: "default"
13 changes: 7 additions & 6 deletions test/models/trace_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,34 @@ def teardown
end

def test_trace_count
assert_equal 9, Trace.count
assert_equal 10, Trace.count
end

def test_visible
check_query(Trace.visible, [
:public_trace_file, :anon_trace_file, :trackable_trace_file,
:identifiable_trace_file, :zipped_trace_file, :tar_trace_file,
:tar_gzip_trace_file, :tar_bzip_trace_file
:tar_gzip_trace_file, :tar_bzip_trace_file, :pending_trace_file
])
end

def test_visible_to
check_query(Trace.visible_to(1), [
:public_trace_file, :identifiable_trace_file
:public_trace_file, :identifiable_trace_file, :pending_trace_file
])
check_query(Trace.visible_to(2), [
:public_trace_file, :anon_trace_file, :trackable_trace_file,
:identifiable_trace_file
:identifiable_trace_file, :pending_trace_file
])
check_query(Trace.visible_to(3), [
:public_trace_file, :identifiable_trace_file
:public_trace_file, :identifiable_trace_file, :pending_trace_file
])
end

def test_visible_to_all
check_query(Trace.visible_to_all, [
:public_trace_file, :identifiable_trace_file, :deleted_trace_file
:public_trace_file, :identifiable_trace_file,
:deleted_trace_file, :pending_trace_file
])
end

Expand Down
2 changes: 1 addition & 1 deletion test/models/user_preference_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class UserPreferenceTest < ActiveSupport::TestCase
# This test needs to be updated for every addition/deletion from
# the fixture file
def test_check_count
assert_equal 2, UserPreference.count
assert_equal 4, UserPreference.count
end

# Checks that you cannot add a new preference, that is a duplicate
Expand Down
Binary file added test/traces/1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions test/traces/10.gpx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<gpx
version="1.0"
creator="GPSBabel - http://www.gpsbabel.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/0"
xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
<time>2009-05-06T13:34:34.000Z</time>
<bounds minlat="51.3" minlon="-0.56" maxlat="51.3" maxlon="-0.56"/>
<trk>
<trkseg>
<trkpt lat="51.3" lon="-0.56">
<time>2009-05-06T13:34:34.000Z</time>
<course>112.430000</course>
<speed>0.072022</speed>
<fix>3d</fix>
<sat>4</sat>
<hdop>2.400000</hdop>
<vdop>2.600000</vdop>
<pdop>3.600000</pdop>
</trkpt>
</trkseg>
</trk>
</gpx>
Binary file added test/traces/1_icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/traces/2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/traces/2_icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/traces/3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/traces/3_icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/traces/4.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/traces/4_icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/traces/6.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/traces/6_icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/traces/7.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/traces/7_icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/traces/8.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/traces/8_icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/traces/9.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/traces/9_icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fd588cd

Please sign in to comment.