source: subversion/sites/rails_port/test/unit/relation_tag_test.rb @ 14668

Last change on this file since 14668 was 14649, checked in by zere, 11 years ago

Extra test for updating relation tags.

File size: 2.0 KB
RevLine 
[11932]1require File.dirname(__FILE__) + '/../test_helper'
2
3class RelationTagTest < Test::Unit::TestCase
[14305]4  api_fixtures
[11932]5 
6  def test_relation_tag_count
[14648]7    assert_equal 7, RelationTag.count
[11932]8  end
9 
[11973]10  def test_length_key_valid
11    key = "k"
12    (0..255).each do |i|
13      tag = RelationTag.new
14      tag.id = 1
15      tag.k = key*i
16      tag.v = "v"
17      assert_valid tag
18    end
19  end
20 
21  def test_length_value_valid
22    val = "v"
23    (0..255).each do |i|
24      tag = RelationTag.new
25      tag.id = 1
26      tag.k = "k"
27      tag.v = val*i
28      assert_valid tag
29    end
30  end
31 
32  def test_length_key_invalid
33    ["k"*256].each do |i|
34      tag = RelationTag.new
35      tag.id = 1
36      tag.k = i
37      tag.v = "v"
38      assert !tag.valid?, "Key #{i} should be too long"
39      assert tag.errors.invalid?(:k)
40    end
41  end
42 
43  def test_length_value_invalid
44    ["v"*256].each do |i|
45      tag = RelationTag.new
46      tag.id = 1
47      tag.k = "k"
48      tag.v = i
49      assert !tag.valid?, "Value #{i} should be too long"
50      assert tag.errors.invalid?(:v)
51    end
52  end
53 
54  def test_empty_tag_invalid
55    tag = RelationTag.new
56    assert !tag.valid?, "Empty relation tag should be invalid"
57    assert tag.errors.invalid?(:id)
58  end
59 
60  def test_uniquness
61    tag = RelationTag.new
62    tag.id = current_relation_tags(:t1).id
63    tag.k = current_relation_tags(:t1).k
64    tag.v = current_relation_tags(:t1).v
65    assert tag.new_record?
66    assert !tag.valid?
67    assert_raise(ActiveRecord::RecordInvalid) {tag.save!}
68    assert tag.new_record?
69  end
[14649]70
71  ##
72  # test that tags can be updated and saved uniquely, i.e: tag.save!
73  # only affects the single tag that the activerecord object
74  # represents. this amounts to testing that the primary key is
75  # unique.
76  def test_update
77    v = "probably unique string here 3142592654"
78    assert_equal 0, RelationTag.count(:conditions => ['v=?', v])
79
80    tag = RelationTag.find(:first)
81    tag.v = v
82    tag.save!
83
84    assert_equal 1, RelationTag.count(:conditions => ['v=?', v])
85  end
[11932]86end
Note: See TracBrowser for help on using the repository browser.