d6d5561e4cb34274d26b0e0fa4fda870ed2b3751
[erd-marker.git] / spec / erd_handler / erd_spec.rb
1 require 'spec_helper'
2
3 module ErdHandler
4 describe Erd do
5 let(:input) { double('input').as_null_object }
6 let(:output) { double('output').as_null_object }
7 let(:erd) { Erd.new(input, output) }
8
9 describe "#initialize" do
10 it "creates an empty ERD" do
11 erd = Erd.new
12 erd.mark.should be_nil
13 erd.should have(0).vertices
14 erd.should have(0).edges
15 end
16
17 it "reads and creates a single box" do
18 erd = Erd.new(File.new("spec/fixtures/single_box_erd.xml"))
19 erd.mark.should == 6.5
20 erd.should have(1).vertices
21 erd.should have(0).edges
22 end
23 end # #initialize
24
25 describe "#read" do
26 it "reads and creates a single box" do
27 erd = Erd.new
28 erd.read(File.new("spec/fixtures/single_box_erd.xml"))
29 erd.mark.should == 6.5
30 erd.should have(1).vertices
31 erd.should have(0).edges
32 end
33
34 it "reads and creates two boxes with an edge joining them" do
35 erd = Erd.new
36 erd.read(File.new("spec/fixtures/two_boxes_one_link_erd.xml"))
37 erd.mark.should == 4.5
38 erd.should have(2).vertices
39 erd.should have(1).edges
40
41 erd.vertices[0].should have(1).neighbours
42 erd.vertices[1].should have(1).neighbours
43 erd.vertices[0].neighbours.should include(erd.vertices[1])
44 erd.vertices[1].neighbours.should include(erd.vertices[0])
45
46 link = erd.edges[0]
47 b0 = erd.vertices.find {|v| v.id == 0}
48 b1 = erd.vertices.find {|v| v.id == 1}
49 link.connection_at(b0).blob.should be(:closed)
50 link.connection_at(b0).crowsfoot.should be(:yes)
51 link.connection_at(b1).blob.should be(:open)
52 link.connection_at(b1).crowsfoot.should be(:no)
53 end
54
55 it "reads and creates a box with a self-loop" do
56 erd = Erd.new
57 erd.read(File.new("spec/fixtures/single_box_self_loop_erd.xml"))
58 erd.mark.should == 4.5
59 erd.should have(1).vertices
60 erd.should have(1).edges
61
62 erd.vertices[0].should have(1).neighbours
63 erd.vertices[0].neighbours.should include(erd.vertices[0])
64
65 link = erd.edges[0]
66 box = erd.vertices[0]
67 c1 = link.connections.find {|c| c.blob == :closed}
68 c1.crowsfoot.should be(:yes)
69 c2 = link.connections.find {|c| c.blob == :open}
70 c2.crowsfoot.should be(:no)
71 c1.should_not == c2
72 end
73
74 it "reads and creates full diagram" do
75 erd = Erd.new
76 erd.read(File.new("spec/fixtures/complex_erd.xml"))
77 erd.mark.should == 4.0
78 erd.should have(5).vertices
79 erd.should have(6).edges
80
81 b0 = erd.vertices.find {|b| b.id == 0}
82 b0.name.original.should == "Unit"
83 b0.should have(2).neighbours
84
85 b1 = erd.vertices.find {|b| b.id == 1}
86 b1.name.original.should == "Employee"
87 b1.should have(2).neighbours
88
89 b2 = erd.vertices.find {|b| b.id == 2}
90 b2.name.original.should == "Course"
91 b2.should have(3).neighbours
92
93 b3 = erd.vertices.find {|b| b.id == 3}
94 b3.name.original.should == "Presentation"
95 b3.should have(3).neighbours
96
97 b4 = erd.vertices.find {|b| b.id == 4}
98 b4.name.original.should == "Client"
99 b4.should have(1).neighbours
100
101 l0 = erd.edges.find {|e| e.id == 0}
102 l0.name.original.should == "ConsistsOf"
103 l0.connections.find {|c| c.end == b0}.blob.should be :closed
104 l0.connections.find {|c| c.end == b0}.crowsfoot.should be :yes
105 l0.connections.find {|c| c.end == b2}.blob.should be :closed
106 l0.connections.find {|c| c.end == b2}.crowsfoot.should be :no
107
108 l1 = erd.edges.find {|e| e.id == 1}
109 l1.name.original.should == "Prepares"
110 l1.connections.find {|c| c.end == b0}.blob.should be :open
111 l1.connections.find {|c| c.end == b0}.crowsfoot.should be :yes
112 l1.connections.find {|c| c.end == b1}.blob.should be :closed
113 l1.connections.find {|c| c.end == b1}.crowsfoot.should be :no
114
115 l2 = erd.edges.find {|e| e.id == 2}
116 l2.name.original.should == "Presents"
117 l2.connections.find {|c| c.end == b1}.blob.should be :closed
118 l2.connections.find {|c| c.end == b1}.crowsfoot.should be :no
119 l2.connections.find {|c| c.end == b3}.blob.should be :closed
120 l2.connections.find {|c| c.end == b3}.crowsfoot.should be :yes
121
122 l3 = erd.edges.find {|e| e.id == 3}
123 l3.name.original.should == "Presented"
124 l3.connections.find {|c| c.end == b2}.blob.should be :open
125 l3.connections.find {|c| c.end == b2}.crowsfoot.should be :no
126 l3.connections.find {|c| c.end == b3}.blob.should be :closed
127 l3.connections.find {|c| c.end == b3}.crowsfoot.should be :yes
128
129 l4 = erd.edges.find {|e| e.id == 4}
130 l4.name.original.should == "Recieves"
131 l4.connections.find {|c| c.end == b3}.blob.should be :closed
132 l4.connections.find {|c| c.end == b3}.crowsfoot.should be :yes
133 l4.connections.find {|c| c.end == b4}.blob.should be :closed
134 l4.connections.find {|c| c.end == b4}.crowsfoot.should be :no
135
136 l5 = erd.edges.find {|e| e.id == 5}
137 l5.name.original.should == "IsPrerequisiteOf"
138 l5.connections.find {|c| c.crowsfoot == :yes}.blob.should be :open
139 l5.connections.find {|c| c.crowsfoot == :no}.blob.should be :open
140 l5.connections.find {|c| c.crowsfoot == :yes}.end.should be b2
141 l5.connections.find {|c| c.crowsfoot == :no}.end.should be b2
142 end
143 end # #read
144 end
145 end