1 require File.dirname(__FILE__) + '/../test_helper'
3 class TraceTest < ActiveSupport::TestCase
7 @gpx_trace_dir = Object.send("remove_const", "GPX_TRACE_DIR")
8 Object.const_set("GPX_TRACE_DIR", File.dirname(__FILE__) + "/../traces")
12 Object.send("remove_const", "GPX_TRACE_DIR")
13 Object.const_set("GPX_TRACE_DIR", @gpx_trace_dir)
17 assert_equal 5, Trace.count
21 check_query(Trace.visible, [:public_trace_file, :anon_trace_file, :trackable_trace_file, :identifiable_trace_file])
25 check_query(Trace.visible_to(1), [:public_trace_file, :identifiable_trace_file])
26 check_query(Trace.visible_to(2), [:public_trace_file, :anon_trace_file, :trackable_trace_file, :identifiable_trace_file])
27 check_query(Trace.visible_to(3), [:public_trace_file, :identifiable_trace_file])
31 check_query(Trace.public, [:public_trace_file, :identifiable_trace_file, :deleted_trace_file])
35 check_query(Trace.tagged("London"), [:public_trace_file, :anon_trace_file])
36 check_query(Trace.tagged("Birmingham"), [:anon_trace_file, :identifiable_trace_file])
37 check_query(Trace.tagged("Unknown"), [])
42 trace_valid({:user_id => nil}, false)
43 trace_valid({:name => 'a'*255})
44 trace_valid({:name => 'a'*256}, false)
45 trace_valid({:description => nil}, false)
46 trace_valid({:description => 'a'*255})
47 trace_valid({:description => 'a'*256}, false)
48 trace_valid({:visibility => "private"})
49 trace_valid({:visibility => "public"})
50 trace_valid({:visibility => "trackable"})
51 trace_valid({:visibility => "identifiable"})
52 trace_valid({:visibility => "foo"}, false)
57 trace.tagstring = "foo bar baz"
58 assert_equal 3, trace.tags.length
59 assert_equal "foo", trace.tags[0].tag
60 assert_equal "bar", trace.tags[1].tag
61 assert_equal "baz", trace.tags[2].tag
62 assert_equal "foo, bar, baz", trace.tagstring
63 trace.tagstring = "foo, bar baz ,qux"
64 assert_equal 3, trace.tags.length
65 assert_equal "foo", trace.tags[0].tag
66 assert_equal "bar baz", trace.tags[1].tag
67 assert_equal "qux", trace.tags[2].tag
68 assert_equal "foo, bar baz, qux", trace.tagstring
72 assert_equal true, gpx_files(:public_trace_file).public?
73 assert_equal false, gpx_files(:anon_trace_file).public?
74 assert_equal false, gpx_files(:trackable_trace_file).public?
75 assert_equal true, gpx_files(:identifiable_trace_file).public?
76 assert_equal true, gpx_files(:deleted_trace_file).public?
80 assert_equal false, gpx_files(:public_trace_file).trackable?
81 assert_equal false, gpx_files(:anon_trace_file).trackable?
82 assert_equal true, gpx_files(:trackable_trace_file).trackable?
83 assert_equal true, gpx_files(:identifiable_trace_file).trackable?
84 assert_equal false, gpx_files(:deleted_trace_file).trackable?
87 def test_identifiable?
88 assert_equal false, gpx_files(:public_trace_file).identifiable?
89 assert_equal false, gpx_files(:anon_trace_file).identifiable?
90 assert_equal false, gpx_files(:trackable_trace_file).identifiable?
91 assert_equal true, gpx_files(:identifiable_trace_file).identifiable?
92 assert_equal false, gpx_files(:deleted_trace_file).identifiable?
96 assert_equal "application/gpx+xml", gpx_files(:public_trace_file).mime_type
97 assert_equal "application/gpx+xml", gpx_files(:anon_trace_file).mime_type
98 assert_equal "application/x-bzip2", gpx_files(:trackable_trace_file).mime_type
99 assert_equal "application/x-gzip", gpx_files(:identifiable_trace_file).mime_type
102 def test_extension_name
103 assert_equal ".gpx", gpx_files(:public_trace_file).extension_name
104 assert_equal ".gpx", gpx_files(:anon_trace_file).extension_name
105 assert_equal ".gpx.bz2", gpx_files(:trackable_trace_file).extension_name
106 assert_equal ".gpx.gz", gpx_files(:identifiable_trace_file).extension_name
111 def check_query(query, traces)
112 traces = traces.map { |t| gpx_files(t) }.sort
113 assert_equal traces, query.order(:id)
116 def trace_valid(attrs, result = true)
117 entry = Trace.new(gpx_files(:public_trace_file).attributes)
118 entry.assign_attributes(attrs)
119 assert_equal result, entry.valid?, "Expected #{attrs.inspect} to be #{result}"