1 require File.dirname(__FILE__) + '/../test_helper'
3 class SegmentTest < Test::Unit::TestCase
4 fixtures :current_nodes, :nodes, :current_segments, :segments, :users
5 set_fixture_class :current_segments => :Segment
6 set_fixture_class :segments => :OldSegment
7 set_fixture_class :current_nodes => :Node
8 set_fixture_class :nodes => :OldNode
12 segment_template = Segment.new(:node_a => nodes(:used_node_1).id,
13 :node_b => nodes(:used_node_2).id,
14 :user_id => users(:normal_user).id,
17 assert segment_template.save_with_history
19 segment = Segment.find(segment_template.id)
20 assert_not_nil segment
21 assert_equal segment_template.node_a, segment.node_a
22 assert_equal segment_template.node_b, segment.node_b
23 assert_equal segment_template.user_id, segment.user_id
24 assert_equal segment_template.visible, segment.visible
25 assert_equal segment_template.tags, segment.tags
26 assert_equal segment_template.timestamp.to_i, segment.timestamp.to_i
28 assert_equal OldSegment.find(:all, :conditions => [ "id = ?", segment_template.id ]).length, 1
29 old_segment = OldSegment.find(:first, :conditions => [ "id = ?", segment_template.id ])
30 assert_not_nil old_segment
31 assert_equal segment_template.node_a, old_segment.node_a
32 assert_equal segment_template.node_b, old_segment.node_b
33 assert_equal segment_template.user_id, old_segment.user_id
34 assert_equal segment_template.visible, old_segment.visible
35 assert_equal segment_template.tags, old_segment.tags
36 assert_equal segment_template.timestamp.to_i, old_segment.timestamp.to_i
40 segment_template = Segment.find(1)
41 assert_not_nil segment_template
43 assert_equal OldSegment.find(:all, :conditions => [ "id = ?", segment_template.id ]).length, 1
44 old_segment_template = OldSegment.find(:first, :conditions => [ "id = ?", segment_template.id ])
45 assert_not_nil old_segment_template
47 segment_template.node_a = nodes(:used_node_2).id
48 segment_template.node_b = nodes(:used_node_1).id
49 segment_template.tags = "updated=yes"
50 assert segment_template.save_with_history
52 segment = Segment.find(segment_template.id)
53 assert_not_nil segment
54 assert_equal segment_template.node_a, segment.node_a
55 assert_equal segment_template.node_b, segment.node_b
56 assert_equal segment_template.user_id, segment.user_id
57 assert_equal segment_template.visible, segment.visible
58 assert_equal segment_template.tags, segment.tags
59 assert_equal segment_template.timestamp.to_i, segment.timestamp.to_i
61 assert_equal OldSegment.find(:all, :conditions => [ "id = ?", segment_template.id ]).length, 2
62 assert_equal OldSegment.find(:all, :conditions => [ "id = ? and timestamp = ?", segment_template.id, segment_template.timestamp ]).length, 1
63 old_segment = OldSegment.find(:first, :conditions => [ "id = ? and timestamp = ?", segment_template.id, segment_template.timestamp ])
64 assert_not_nil old_segment
65 assert_equal segment_template.node_a, old_segment.node_a
66 assert_equal segment_template.node_b, old_segment.node_b
67 assert_equal segment_template.user_id, old_segment.user_id
68 assert_equal segment_template.visible, old_segment.visible
69 assert_equal segment_template.tags, old_segment.tags
70 assert_equal segment_template.timestamp.to_i, old_segment.timestamp.to_i
74 segment_template = Segment.find(1)
75 assert_not_nil segment_template
77 assert_equal OldSegment.find(:all, :conditions => [ "id = ?", segment_template.id ]).length, 1
78 old_segment_template = OldSegment.find(:first, :conditions => [ "id = ?", segment_template.id ])
79 assert_not_nil old_segment_template
81 segment_template.visible = 0
82 assert segment_template.save_with_history
84 segment = Segment.find(segment_template.id)
85 assert_not_nil segment
86 assert_equal segment_template.node_a, segment.node_a
87 assert_equal segment_template.node_b, segment.node_b
88 assert_equal segment_template.user_id, segment.user_id
89 assert_equal segment_template.visible, segment.visible
90 assert_equal segment_template.tags, segment.tags
91 assert_equal segment_template.timestamp.to_i, segment.timestamp.to_i
93 assert_equal OldSegment.find(:all, :conditions => [ "id = ?", segment_template.id ]).length, 2
94 assert_equal OldSegment.find(:all, :conditions => [ "id = ? and timestamp = ?", segment_template.id, segment_template.timestamp ]).length, 1
95 old_segment = OldSegment.find(:first, :conditions => [ "id = ? and timestamp = ?", segment_template.id, segment_template.timestamp ])
96 assert_not_nil old_segment
97 assert_equal segment_template.node_a, old_segment.node_a
98 assert_equal segment_template.node_b, old_segment.node_b
99 assert_equal segment_template.user_id, old_segment.user_id
100 assert_equal segment_template.visible, old_segment.visible
101 assert_equal segment_template.tags, old_segment.tags
102 assert_equal segment_template.timestamp.to_i, old_segment.timestamp.to_i