4 class TraceTest < ActiveSupport::TestCase
8 @gpx_trace_dir = Object.send("remove_const", "GPX_TRACE_DIR")
9 Object.const_set("GPX_TRACE_DIR", File.dirname(__FILE__) + "/../traces")
11 @gpx_image_dir = Object.send("remove_const", "GPX_IMAGE_DIR")
12 Object.const_set("GPX_IMAGE_DIR", File.dirname(__FILE__) + "/../traces")
16 Object.send("remove_const", "GPX_TRACE_DIR")
17 Object.const_set("GPX_TRACE_DIR", @gpx_trace_dir)
19 Object.send("remove_const", "GPX_IMAGE_DIR")
20 Object.const_set("GPX_IMAGE_DIR", @gpx_image_dir)
24 assert_equal 10, Trace.count
28 check_query(Trace.visible, [
29 :public_trace_file, :anon_trace_file, :trackable_trace_file,
30 :identifiable_trace_file, :zipped_trace_file, :tar_trace_file,
31 :tar_gzip_trace_file, :tar_bzip_trace_file, :pending_trace_file
36 check_query(Trace.visible_to(1), [
37 :public_trace_file, :identifiable_trace_file, :pending_trace_file
39 check_query(Trace.visible_to(2), [
40 :public_trace_file, :anon_trace_file, :trackable_trace_file,
41 :identifiable_trace_file, :pending_trace_file
43 check_query(Trace.visible_to(3), [
44 :public_trace_file, :identifiable_trace_file, :pending_trace_file
48 def test_visible_to_all
49 check_query(Trace.visible_to_all, [
50 :public_trace_file, :identifiable_trace_file,
51 :deleted_trace_file, :pending_trace_file
56 check_query(Trace.tagged("London"), [:public_trace_file, :anon_trace_file])
57 check_query(Trace.tagged("Birmingham"), [:anon_trace_file, :identifiable_trace_file])
58 check_query(Trace.tagged("Unknown"), [])
63 trace_valid({ :user_id => nil }, false)
64 trace_valid(:name => "a" * 255)
65 trace_valid({ :name => "a" * 256 }, false)
66 trace_valid({ :description => nil }, false)
67 trace_valid(:description => "a" * 255)
68 trace_valid({ :description => "a" * 256 }, false)
69 trace_valid(:visibility => "private")
70 trace_valid(:visibility => "public")
71 trace_valid(:visibility => "trackable")
72 trace_valid(:visibility => "identifiable")
73 trace_valid({ :visibility => "foo" }, false)
77 trace = Trace.new(gpx_files(:public_trace_file).attributes)
78 trace.tagstring = "foo bar baz"
80 assert_equal 3, trace.tags.length
81 assert_equal "foo", trace.tags[0].tag
82 assert_equal "bar", trace.tags[1].tag
83 assert_equal "baz", trace.tags[2].tag
84 assert_equal "foo, bar, baz", trace.tagstring
85 trace.tagstring = "foo, bar baz ,qux"
87 assert_equal 3, trace.tags.length
88 assert_equal "foo", trace.tags[0].tag
89 assert_equal "bar baz", trace.tags[1].tag
90 assert_equal "qux", trace.tags[2].tag
91 assert_equal "foo, bar baz, qux", trace.tagstring
95 assert_equal true, gpx_files(:public_trace_file).public?
96 assert_equal false, gpx_files(:anon_trace_file).public?
97 assert_equal false, gpx_files(:trackable_trace_file).public?
98 assert_equal true, gpx_files(:identifiable_trace_file).public?
99 assert_equal true, gpx_files(:deleted_trace_file).public?
103 assert_equal false, gpx_files(:public_trace_file).trackable?
104 assert_equal false, gpx_files(:anon_trace_file).trackable?
105 assert_equal true, gpx_files(:trackable_trace_file).trackable?
106 assert_equal true, gpx_files(:identifiable_trace_file).trackable?
107 assert_equal false, gpx_files(:deleted_trace_file).trackable?
110 def test_identifiable?
111 assert_equal false, gpx_files(:public_trace_file).identifiable?
112 assert_equal false, gpx_files(:anon_trace_file).identifiable?
113 assert_equal false, gpx_files(:trackable_trace_file).identifiable?
114 assert_equal true, gpx_files(:identifiable_trace_file).identifiable?
115 assert_equal false, gpx_files(:deleted_trace_file).identifiable?
119 assert_equal "application/gpx+xml", gpx_files(:public_trace_file).mime_type
120 assert_equal "application/gpx+xml", gpx_files(:anon_trace_file).mime_type
121 assert_equal "application/x-bzip2", gpx_files(:trackable_trace_file).mime_type
122 assert_equal "application/x-gzip", gpx_files(:identifiable_trace_file).mime_type
123 assert_equal "application/x-zip", gpx_files(:zipped_trace_file).mime_type
124 assert_equal "application/x-tar", gpx_files(:tar_trace_file).mime_type
125 assert_equal "application/x-gzip", gpx_files(:tar_gzip_trace_file).mime_type
126 assert_equal "application/x-bzip2", gpx_files(:tar_bzip_trace_file).mime_type
129 def test_extension_name
130 assert_equal ".gpx", gpx_files(:public_trace_file).extension_name
131 assert_equal ".gpx", gpx_files(:anon_trace_file).extension_name
132 assert_equal ".gpx.bz2", gpx_files(:trackable_trace_file).extension_name
133 assert_equal ".gpx.gz", gpx_files(:identifiable_trace_file).extension_name
134 assert_equal ".zip", gpx_files(:zipped_trace_file).extension_name
135 assert_equal ".tar", gpx_files(:tar_trace_file).extension_name
136 assert_equal ".tar.gz", gpx_files(:tar_gzip_trace_file).extension_name
137 assert_equal ".tar.bz2", gpx_files(:tar_bzip_trace_file).extension_name
141 assert_equal "848caa72f2f456d1bd6a0fdf228aa1b9", md5sum(gpx_files(:public_trace_file).xml_file)
142 assert_equal "66179ca44f1e93d8df62e2b88cbea732", md5sum(gpx_files(:anon_trace_file).xml_file)
143 assert_equal "848caa72f2f456d1bd6a0fdf228aa1b9", md5sum(gpx_files(:trackable_trace_file).xml_file)
144 assert_equal "abd6675fdf3024a84fc0a1deac147c0d", md5sum(gpx_files(:identifiable_trace_file).xml_file)
145 assert_equal "848caa72f2f456d1bd6a0fdf228aa1b9", md5sum(gpx_files(:zipped_trace_file).xml_file)
146 assert_equal "848caa72f2f456d1bd6a0fdf228aa1b9", md5sum(gpx_files(:tar_trace_file).xml_file)
147 assert_equal "848caa72f2f456d1bd6a0fdf228aa1b9", md5sum(gpx_files(:tar_gzip_trace_file).xml_file)
148 assert_equal "848caa72f2f456d1bd6a0fdf228aa1b9", md5sum(gpx_files(:tar_bzip_trace_file).xml_file)
151 def test_large_picture
152 picture = gpx_files(:public_trace_file).large_picture
155 trace.large_picture = picture
156 assert_equal "7c841749e084ee4a5d13f12cd3bef456", md5sum(File.new(trace.large_picture_name))
157 assert_equal picture, trace.large_picture
162 def test_icon_picture
163 picture = gpx_files(:public_trace_file).icon_picture
166 trace.icon_picture = picture
167 assert_equal "b47baf22ed0e85d77e808694fad0ee27", md5sum(File.new(trace.icon_picture_name))
168 assert_equal picture, trace.icon_picture
175 def check_query(query, traces)
176 traces = traces.map { |t| gpx_files(t).id }.sort
177 assert_equal traces, query.order(:id).ids
180 def trace_valid(attrs, result = true)
181 entry = Trace.new(gpx_files(:public_trace_file).attributes)
182 entry.assign_attributes(attrs)
183 assert_equal result, entry.valid?, "Expected #{attrs.inspect} to be #{result}"
187 io.each_with_object(Digest::MD5.new) { |l, d| d.update(l) }.hexdigest