1 require File.dirname(__FILE__) + '/../test_helper'
3 class TraceTest < ActiveSupport::TestCase
7 assert_equal 5, Trace.count
11 check_query(Trace.visible, :public_trace_file, :anon_trace_file, :trackable_trace_file, :identifiable_trace_file)
15 check_query(Trace.visible_to(1), :public_trace_file, :identifiable_trace_file)
16 check_query(Trace.visible_to(2), :public_trace_file, :anon_trace_file, :trackable_trace_file, :identifiable_trace_file)
17 check_query(Trace.visible_to(3), :public_trace_file, :identifiable_trace_file)
21 check_query(Trace.public, :public_trace_file, :identifiable_trace_file, :deleted_trace_file)
26 trace_valid({:user_id => nil}, false)
27 trace_valid({:name => 'a'*255})
28 trace_valid({:name => 'a'*256}, false)
29 trace_valid({:description => nil}, false)
30 trace_valid({:description => 'a'*255})
31 trace_valid({:description => 'a'*256}, false)
32 trace_valid({:visibility => "private"})
33 trace_valid({:visibility => "public"})
34 trace_valid({:visibility => "trackable"})
35 trace_valid({:visibility => "identifiable"})
36 trace_valid({:visibility => "foo"}, false)
41 trace.tagstring = "foo bar baz"
42 assert_equal 3, trace.tags.length
43 assert_equal "foo", trace.tags[0].tag
44 assert_equal "bar", trace.tags[1].tag
45 assert_equal "baz", trace.tags[2].tag
46 assert_equal "foo, bar, baz", trace.tagstring
47 trace.tagstring = "foo, bar baz ,qux"
48 assert_equal 3, trace.tags.length
49 assert_equal "foo", trace.tags[0].tag
50 assert_equal "bar baz", trace.tags[1].tag
51 assert_equal "qux", trace.tags[2].tag
52 assert_equal "foo, bar baz, qux", trace.tagstring
56 assert_equal true, gpx_files(:public_trace_file).public?
57 assert_equal false, gpx_files(:anon_trace_file).public?
58 assert_equal false, gpx_files(:trackable_trace_file).public?
59 assert_equal true, gpx_files(:identifiable_trace_file).public?
60 assert_equal true, gpx_files(:deleted_trace_file).public?
64 assert_equal false, gpx_files(:public_trace_file).trackable?
65 assert_equal false, gpx_files(:anon_trace_file).trackable?
66 assert_equal true, gpx_files(:trackable_trace_file).trackable?
67 assert_equal true, gpx_files(:identifiable_trace_file).trackable?
68 assert_equal false, gpx_files(:deleted_trace_file).trackable?
71 def test_identifiable?
72 assert_equal false, gpx_files(:public_trace_file).identifiable?
73 assert_equal false, gpx_files(:anon_trace_file).identifiable?
74 assert_equal false, gpx_files(:trackable_trace_file).identifiable?
75 assert_equal true, gpx_files(:identifiable_trace_file).identifiable?
76 assert_equal false, gpx_files(:deleted_trace_file).identifiable?
81 def check_query(query, *traces)
82 traces = traces.map { |t| gpx_files(t) }.sort
83 assert_equal traces, query.order(:id)
86 def trace_valid(attrs, result = true)
87 entry = Trace.new(gpx_files(:public_trace_file).attributes)
88 entry.assign_attributes(attrs)
89 assert_equal result, entry.valid?, "Expected #{attrs.inspect} to be #{result}"