]> git.openstreetmap.org Git - rails.git/blob - test/unit/tracetag_test.rb
0a22919b59f0319f31e3f74c112c2b2a5bbb4055
[rails.git] / test / unit / tracetag_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class TracetagTest < ActiveSupport::TestCase
4   api_fixtures
5   
6   def test_tracetag_count
7     assert_equal 4, Tracetag.count
8   end
9
10   def test_validations
11     tracetag_valid({})
12     tracetag_valid({:tag => nil}, false)
13     tracetag_valid({:tag => ''}, false)
14     tracetag_valid({:tag => 'a'})
15     tracetag_valid({:tag => 'a'*255})
16     tracetag_valid({:tag => 'a'*256}, false)
17     tracetag_valid({:tag => 'a/b'}, false)
18     tracetag_valid({:tag => 'a;b'}, false)
19     tracetag_valid({:tag => 'a.b'}, false)
20     tracetag_valid({:tag => 'a,b'}, false)
21     tracetag_valid({:tag => 'a?b'}, false)
22   end
23
24 private
25
26   def tracetag_valid(attrs, result = true)
27     entry = Tracetag.new(gpx_file_tags(:first_trace_1).attributes, :without_protection => true)
28     entry.assign_attributes(attrs, :without_protection => true)
29     assert_equal result, entry.valid?, "Expected #{attrs.inspect} to be #{result}"
30   end
31 end