ninoxe 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. data/app/models/chouette/time_table.rb +74 -22
  2. data/app/models/chouette/vehicle_journey.rb +2 -5
  3. data/db/migrate/20130410063411_add_shortcut_to_time_table.rb +6 -0
  4. data/db/migrate/20130410100706_set_shortcut_to_existing_time_table.rb +10 -0
  5. data/db/migrate/20130410143542_resize_chouette_columns.rb +5 -0
  6. data/lib/factories/chouette_time_table.rb +1 -0
  7. data/lib/ninoxe/version.rb +1 -1
  8. data/spec/dummy/README.rdoc +261 -0
  9. data/spec/dummy/Rakefile +6 -0
  10. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  11. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  12. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  13. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  14. data/spec/dummy/app/mailers/.gitkeep +0 -0
  15. data/spec/dummy/app/models/.gitkeep +0 -0
  16. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  17. data/spec/dummy/config/application.rb +56 -0
  18. data/spec/dummy/config/boot.rb +10 -0
  19. data/{config/database.yml.me → spec/dummy/config/database.yml} +0 -2
  20. data/spec/dummy/config/environment.rb +7 -0
  21. data/spec/dummy/config/environments/development.rb +37 -0
  22. data/spec/dummy/config/environments/production.rb +67 -0
  23. data/spec/dummy/config/environments/test.rb +37 -0
  24. data/spec/dummy/config/initializers/active_record.rb +2 -0
  25. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  26. data/spec/dummy/config/initializers/inflections.rb +15 -0
  27. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  28. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  29. data/spec/dummy/config/initializers/session_store.rb +8 -0
  30. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  31. data/spec/dummy/config/locales/en.yml +5 -0
  32. data/spec/dummy/config/routes.rb +4 -0
  33. data/spec/dummy/config.ru +4 -0
  34. data/spec/dummy/db/test.sqlite3 +0 -0
  35. data/spec/dummy/lib/assets/.gitkeep +0 -0
  36. data/spec/dummy/log/.gitkeep +0 -0
  37. data/spec/dummy/public/404.html +26 -0
  38. data/spec/dummy/public/422.html +26 -0
  39. data/spec/dummy/public/500.html +25 -0
  40. data/spec/dummy/public/favicon.ico +0 -0
  41. data/spec/dummy/script/rails +6 -0
  42. data/spec/models/chouette/access_link_spec.rb +78 -0
  43. data/spec/models/chouette/access_point_spec.rb +222 -0
  44. data/spec/models/chouette/active_record_spec.rb +121 -0
  45. data/spec/models/chouette/area_type_spec.rb +53 -0
  46. data/spec/models/chouette/company_spec.rb +51 -0
  47. data/spec/models/chouette/connection_link_spec.rb +56 -0
  48. data/spec/models/chouette/direction_spec.rb +60 -0
  49. data/spec/models/chouette/exporter_spec.rb +28 -0
  50. data/spec/models/chouette/file_validator_spec.rb +28 -0
  51. data/spec/models/chouette/group_of_line_spec.rb +31 -0
  52. data/spec/models/chouette/journey_pattern_spec.rb +62 -0
  53. data/spec/models/chouette/line_spec.rb +106 -0
  54. data/spec/models/chouette/loader_spec.rb +69 -0
  55. data/spec/models/chouette/network_spec.rb +22 -0
  56. data/spec/models/chouette/object_id_spec.rb +146 -0
  57. data/spec/models/chouette/route_spec.rb +159 -0
  58. data/spec/models/chouette/stop_area_spec.rb +382 -0
  59. data/spec/models/chouette/stop_point_spec.rb +39 -0
  60. data/spec/models/chouette/time_table_spec.rb +350 -0
  61. data/spec/models/chouette/transport_mode_spec.rb +64 -0
  62. data/spec/models/chouette/vehicle_journey_at_stop_spec.rb +46 -0
  63. data/spec/models/chouette/vehicle_journey_spec.rb +204 -0
  64. data/spec/spec_helper.rb +62 -0
  65. metadata +445 -272
  66. data/db/migrate/20130204141720_add_foreign_keys.rb~ +0 -277
  67. data/lib/ninoxe.rb~ +0 -7
@@ -0,0 +1,146 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chouette::ObjectId do
4
+
5
+ def objectid(value = "abc:StopArea:abc123")
6
+ Chouette::ObjectId.new value
7
+ end
8
+
9
+ subject { objectid }
10
+
11
+ context "when invalid" do
12
+
13
+ subject { objectid("abc") }
14
+
15
+ it { should_not be_valid }
16
+
17
+ its(:parts) { should be_nil }
18
+ its(:system_id) { should be_nil }
19
+
20
+ end
21
+
22
+ context "when with spaces in last part" do
23
+
24
+ subject { objectid("abc:Line:Aze toto") }
25
+
26
+ it { should_not be_valid }
27
+
28
+
29
+ end
30
+
31
+ context "when with spaces in first part" do
32
+
33
+ subject { objectid("ae abc:Line:Aze") }
34
+
35
+ it { should_not be_valid }
36
+
37
+
38
+ end
39
+
40
+ context "when with spaces in middle part" do
41
+
42
+ subject { objectid("aeabc:Li ne:Aze") }
43
+
44
+ it { should_not be_valid }
45
+
46
+
47
+ end
48
+
49
+ context "when invalid in first part" do
50
+
51
+ subject { objectid("Abc_+19:Line:Abc") }
52
+
53
+ it { should_not be_valid }
54
+ end
55
+
56
+ context "when invalid in middle part" do
57
+
58
+ subject { objectid("Abc_19:Li56ne:Abc") }
59
+
60
+ it { should_not be_valid }
61
+ end
62
+
63
+ context "when invalid in last part" do
64
+
65
+ subject { objectid("Abc_19:Line:Ab+c") }
66
+
67
+ it { should_not be_valid }
68
+ end
69
+ context "when valid" do
70
+
71
+ subject { objectid("Abc_19:Line:Abc_12-") }
72
+
73
+ it { should be_valid }
74
+ end
75
+
76
+ describe "#parts" do
77
+
78
+ it "should be the 3 parts of the ObjectId" do
79
+ objectid("abc:StopArea:abc123").parts.should == %w{abc StopArea abc123}
80
+ end
81
+
82
+ end
83
+
84
+ describe "#system_id" do
85
+
86
+ it "should be the first ObjectId parts" do
87
+ objectid("first:second:third").system_id.should == "first"
88
+ end
89
+
90
+ end
91
+
92
+ describe "#object_type" do
93
+
94
+ it "should be the second ObjectId parts" do
95
+ objectid("first:second:third").object_type.should == "second"
96
+ end
97
+
98
+ end
99
+
100
+ describe "#local_id" do
101
+
102
+ it "should be the third ObjectId parts" do
103
+ objectid("first:second:third").local_id.should == "third"
104
+ end
105
+
106
+ end
107
+
108
+ it "should be valid when parts are found" do
109
+ subject.stub :parts => "dummy"
110
+ subject.should be_valid
111
+ end
112
+
113
+ describe ".create" do
114
+
115
+ let(:given_system_id) { "systemId" }
116
+ let(:given_object_type) { "objectType" }
117
+ let(:given_local_id) { "localId" }
118
+
119
+ subject { Chouette::ObjectId.create(given_system_id, given_object_type, given_local_id) }
120
+
121
+ RSpec::Matchers.define :return_an_objectid_with_given do |attribute|
122
+ match do |actual|
123
+ actual.send(attribute).should == send("given_#{attribute}")
124
+ end
125
+ end
126
+
127
+ it { should return_an_objectid_with_given(:system_id) }
128
+ it { should return_an_objectid_with_given(:object_type) }
129
+ it { should return_an_objectid_with_given(:local_id) }
130
+
131
+ end
132
+
133
+ describe ".new" do
134
+
135
+ it "should return an existing ObjectId" do
136
+ Chouette::ObjectId.new(objectid).should == objectid
137
+ end
138
+
139
+ it "should create an empty ObjectId with nil" do
140
+ Chouette::ObjectId.new(nil).should be_empty
141
+ end
142
+
143
+ end
144
+
145
+
146
+ end
@@ -0,0 +1,159 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chouette::Route do
4
+ subject { Factory(:route) }
5
+
6
+ it { should validate_uniqueness_of :objectid }
7
+ its(:objectid) { should be_kind_of(Chouette::ObjectId) }
8
+
9
+ it { should validate_presence_of :name }
10
+ it { should validate_presence_of :line }
11
+ it { should validate_presence_of :wayback_code }
12
+ it { should validate_presence_of :direction_code }
13
+
14
+ context "reordering methods" do
15
+ let( :bad_stop_point_ids){subject.stop_points.map { |sp| sp.id + 1}}
16
+ let( :ident){subject.stop_points.map(&:id)}
17
+ let( :first_last_swap){ [ident.last] + ident[1..-2] + [ident.first]}
18
+
19
+ describe "#reorder!" do
20
+ context "invalid stop_point_ids" do
21
+ let( :new_stop_point_ids) { bad_stop_point_ids}
22
+ it { subject.reorder!( new_stop_point_ids).should be_false}
23
+ end
24
+
25
+ context "swaped last and first stop_point_ids" do
26
+ let!( :new_stop_point_ids) { first_last_swap}
27
+ let!( :old_stop_point_ids) { subject.stop_points.map(&:id) }
28
+ let!( :old_stop_area_ids) { subject.stop_areas.map(&:id) }
29
+
30
+ it "should keep stop_point_ids order unchanged" do
31
+ subject.reorder!( new_stop_point_ids).should be_true
32
+ subject.stop_points.map(&:id).should eq( old_stop_point_ids)
33
+ end
34
+ it "should have changed stop_area_ids order" do
35
+ subject.reorder!( new_stop_point_ids).should be_true
36
+ subject.reload
37
+ subject.stop_areas.map(&:id).should eq( [old_stop_area_ids.last] + old_stop_area_ids[1..-2] + [old_stop_area_ids.first])
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "#stop_point_permutation?" do
43
+ context "invalid stop_point_ids" do
44
+ let( :new_stop_point_ids) { bad_stop_point_ids}
45
+ it { should_not be_stop_point_permutation( new_stop_point_ids)}
46
+ end
47
+ context "unchanged stop_point_ids" do
48
+ let( :new_stop_point_ids) { ident}
49
+ it { should be_stop_point_permutation( new_stop_point_ids)}
50
+ end
51
+ context "swaped last and first stop_point_ids" do
52
+ let( :new_stop_point_ids) { first_last_swap}
53
+ it { should be_stop_point_permutation( new_stop_point_ids)}
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "#stop_points" do
59
+ context "#find_by_stop_area" do
60
+ context "when arg is first quay id" do
61
+ let(:first_stop_point) { subject.stop_points.first}
62
+ it "should return first quay" do
63
+ subject.stop_points.find_by_stop_area( first_stop_point.stop_area_id).should eq( first_stop_point)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ describe "#stop_areas" do
69
+ let(:line){ Factory(:line)}
70
+ let(:route_1){ Factory(:route, :line => line)}
71
+ let(:route_2){ Factory(:route, :line => line)}
72
+ it "should retreive all stop_area on route" do
73
+ route_1.stop_areas.each do |sa|
74
+ sa.stop_points.map(&:route_id).uniq.should == [route_1.id]
75
+ end
76
+ end
77
+
78
+ context "when route is looping: last and first stop area are the same" do
79
+ it "should retreive same stop_area one last and first position" do
80
+ route_loop = Factory(:route, :line => line)
81
+ first_stop = Chouette::StopPoint.where( :route_id => route_loop.id, :position => 0).first
82
+ last_stop = Factory(:stop_point, :route => route_loop, :position => 5, :stop_area => first_stop.stop_area)
83
+
84
+ route_loop.stop_areas.size.should == 6
85
+ route_loop.stop_areas.select {|s| s.id == first_stop.stop_area.id}.size.should == 2
86
+ end
87
+ end
88
+ end
89
+
90
+ describe "#direction_code" do
91
+ def self.legacy_directions
92
+ %w{A R ClockWise CounterClockWise North NorthWest West SouthWest
93
+ South SouthEast East NorthEast}
94
+ end
95
+ legacy_directions.each do |direction|
96
+ context "when direction is #{direction}" do
97
+ direction_code = Chouette::Direction.new( Chouette::Route.direction_binding[ direction])
98
+ it "should be #{direction_code}" do
99
+ subject.direction = direction
100
+ subject.direction_code.should == direction_code
101
+ end
102
+ end
103
+ end
104
+ context "when direction is nil" do
105
+ it "should be nil" do
106
+ subject.direction = nil
107
+ subject.direction_code.should be_nil
108
+ end
109
+ end
110
+ end
111
+ describe "#direction_code=" do
112
+ context "when unknown direction is provided" do
113
+ it "should change direction to nil" do
114
+ subject.direction_code = "dummy"
115
+ subject.direction.should be_nil
116
+ end
117
+ end
118
+ context "when an existing direction (west) is provided" do
119
+ it "should change direction Direction.west" do
120
+ subject.direction_code = "west"
121
+ subject.direction.should == "West"
122
+ end
123
+ end
124
+ end
125
+ describe "#wayback_code" do
126
+ def self.legacy_waybacks
127
+ %w{A R}
128
+ end
129
+ legacy_waybacks.each do |wayback|
130
+ context "when wayback is #{wayback}" do
131
+ wayback_code = Chouette::Wayback.new( Chouette::Route.wayback_binding[ wayback])
132
+ it "should be #{wayback_code}" do
133
+ subject.wayback = wayback
134
+ subject.wayback_code.should == wayback_code
135
+ end
136
+ end
137
+ end
138
+ context "when wayback is nil" do
139
+ it "should be nil" do
140
+ subject.wayback = nil
141
+ subject.wayback_code.should be_nil
142
+ end
143
+ end
144
+ end
145
+ describe "#wayback_code=" do
146
+ context "when unknown wayback is provided" do
147
+ it "should change wayback to nil" do
148
+ subject.wayback_code = "dummy"
149
+ subject.wayback.should be_nil
150
+ end
151
+ end
152
+ context "when an existing wayback (straight_forward) is provided" do
153
+ it "should change wayback Wayback.straight_forward" do
154
+ subject.wayback_code = "straight_forward"
155
+ subject.wayback.should == "A"
156
+ end
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,382 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chouette::StopArea do
4
+ let!(:quay) { Factory :stop_area, :area_type => "Quay" }
5
+ let!(:boarding_position) { Factory :stop_area, :area_type => "BoardingPosition" }
6
+ let!(:commercial_stop_point) { Factory :stop_area, :area_type => "CommercialStopPoint" }
7
+ let!(:stop_place) { Factory :stop_area, :area_type => "StopPlace" }
8
+ let!(:itl) { Factory :stop_area, :area_type => "ITL" }
9
+
10
+ its(:objectid) { should be_kind_of(Chouette::ObjectId) }
11
+
12
+ it { should validate_presence_of :name }
13
+ it { should validate_presence_of :area_type }
14
+ it { should validate_numericality_of :latitude }
15
+ it { should validate_numericality_of :longitude }
16
+ it { should validate_numericality_of :x }
17
+ it { should validate_numericality_of :y }
18
+
19
+ describe ".x_y" do
20
+ it "should accept x and y both as nil" do
21
+ subject = Factory :stop_area, :area_type => "BoardingPosition"
22
+ subject.x = nil
23
+ subject.y = nil
24
+ subject.valid?.should be_true
25
+ end
26
+ it "should accept x and y both numerical" do
27
+ subject = Factory :stop_area, :area_type => "BoardingPosition"
28
+ subject.x = 10
29
+ subject.y = 10
30
+ subject.valid?.should be_true
31
+ end
32
+ it "should reject x nil with y numerical" do
33
+ subject = Factory :stop_area, :area_type => "BoardingPosition"
34
+ subject.x = nil
35
+ subject.y = 10
36
+ subject.valid?.should be_false
37
+ end
38
+ it "should reject x numerical with y nil" do
39
+ subject = Factory :stop_area, :area_type => "BoardingPosition"
40
+ subject.x = 10
41
+ subject.y = nil
42
+ subject.valid?.should be_false
43
+ end
44
+ end
45
+
46
+ describe ".latitude" do
47
+ it "should accept -90 value" do
48
+ subject = Factory :stop_area, :area_type => "BoardingPosition"
49
+ subject.latitude = -90
50
+ subject.valid?.should be_true
51
+ end
52
+ it "should reject < -90 value" do
53
+ subject = Factory :stop_area, :area_type => "BoardingPosition"
54
+ subject.latitude = -90.0001
55
+ subject.valid?.should be_false
56
+ end
57
+ it "should accept 90 value" do
58
+ subject = Factory :stop_area, :area_type => "BoardingPosition"
59
+ subject.latitude = 90
60
+ subject.valid?.should be_true
61
+ end
62
+ it "should reject > 90 value" do
63
+ subject = Factory :stop_area, :area_type => "BoardingPosition"
64
+ subject.latitude = 90.0001
65
+ subject.valid?.should be_false
66
+ end
67
+ end
68
+
69
+ describe ".longitude" do
70
+ it "should accept -180 value" do
71
+ subject = Factory :stop_area, :area_type => "BoardingPosition"
72
+ subject.longitude = -180
73
+ subject.valid?.should be_true
74
+ end
75
+ it "should reject < -180 value" do
76
+ subject = Factory :stop_area, :area_type => "BoardingPosition"
77
+ subject.longitude = -180.0001
78
+ subject.valid?.should be_false
79
+ end
80
+ it "should accept 180 value" do
81
+ subject = Factory :stop_area, :area_type => "BoardingPosition"
82
+ subject.longitude = 180
83
+ subject.valid?.should be_true
84
+ end
85
+ it "should reject > 180 value" do
86
+ subject = Factory :stop_area, :area_type => "BoardingPosition"
87
+ subject.longitude = 180.0001
88
+ subject.valid?.should be_false
89
+ end
90
+ end
91
+
92
+ describe ".long_lat" do
93
+ it "should accept longitude and latitude both as nil" do
94
+ subject = Factory :stop_area, :area_type => "BoardingPosition"
95
+ subject.longitude = nil
96
+ subject.latitude = nil
97
+ subject.valid?.should be_true
98
+ end
99
+ it "should accept longitude and latitude both numerical" do
100
+ subject = Factory :stop_area, :area_type => "BoardingPosition"
101
+ subject.longitude = 10
102
+ subject.latitude = 10
103
+ subject.valid?.should be_true
104
+ end
105
+ it "should reject longitude nil with latitude numerical" do
106
+ subject = Factory :stop_area, :area_type => "BoardingPosition"
107
+ subject.longitude = nil
108
+ subject.latitude = 10
109
+ subject.valid?.should be_false
110
+ end
111
+ it "should reject longitude numerical with latitude nil" do
112
+ subject = Factory :stop_area, :area_type => "BoardingPosition"
113
+ subject.longitude = 10
114
+ subject.latitude = nil
115
+ subject.valid?.should be_false
116
+ end
117
+ end
118
+
119
+
120
+ describe ".children_in_depth" do
121
+ it "should return all the deepest children from stop area" do
122
+ subject = Factory :stop_area, :area_type => "StopPlace"
123
+ commercial_stop_point = Factory :stop_area, :area_type => "CommercialStopPoint", :parent => subject
124
+ commercial_stop_point2 = Factory :stop_area, :area_type => "CommercialStopPoint", :parent => commercial_stop_point
125
+ quay = Factory :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
126
+ subject.children_in_depth.should =~ [commercial_stop_point, commercial_stop_point2, quay]
127
+ end
128
+ it "should return only the deepest children from stop area" do
129
+ subject = Factory :stop_area, :area_type => "StopPlace"
130
+ commercial_stop_point = Factory :stop_area, :area_type => "CommercialStopPoint", :parent => subject
131
+ commercial_stop_point2 = Factory :stop_area, :area_type => "CommercialStopPoint", :parent => commercial_stop_point
132
+ quay = Factory :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
133
+ subject.children_at_base.should =~ [quay]
134
+ end
135
+ end
136
+
137
+ describe ".stop_area_type" do
138
+ it "should have area_type of BoardingPosition when stop_area_type is set to boarding_position" do
139
+ subject = Factory :stop_area, :stop_area_type => "boarding_position"
140
+ subject.area_type.should == "BoardingPosition"
141
+ end
142
+ it "should have area_type of Quay when stop_area_type is set to quay" do
143
+ subject = Factory :stop_area, :stop_area_type => "quay"
144
+ subject.area_type.should == "Quay"
145
+ end
146
+ it "should have area_type of CommercialStopPoint when stop_area_type is set to commercial_stop_point" do
147
+ subject = Factory :stop_area, :stop_area_type => "commercial_stop_point"
148
+ subject.area_type.should == "CommercialStopPoint"
149
+ end
150
+ it "should have area_type of StopPlace when stop_area_type is set to stop_place" do
151
+ subject = Factory :stop_area, :stop_area_type => "stop_place"
152
+ subject.area_type.should == "StopPlace"
153
+ end
154
+ it "should have area_type of ITL when stop_area_type is set to itl" do
155
+ subject = Factory :stop_area, :stop_area_type => "itl"
156
+ subject.area_type.should == "ITL"
157
+ end
158
+ end
159
+
160
+ describe ".parent" do
161
+ it "should check if parent method exists" do
162
+ subject = Factory :stop_area, :parent_id => commercial_stop_point.id
163
+ subject.parent.should == commercial_stop_point
164
+ end
165
+ end
166
+
167
+ describe ".possible_children" do
168
+
169
+ it "should find no possible descendant for stop area type quay" do
170
+ subject = Factory :stop_area, :area_type => "Quay"
171
+ subject.possible_children.should == []
172
+ end
173
+
174
+ it "should find no possible descendant for stop area type boarding position" do
175
+ subject = Factory :stop_area, :area_type => "BoardingPosition"
176
+ subject.possible_children.should == []
177
+ end
178
+
179
+ it "should find descendant of type quay or boarding position for stop area type commercial stop point" do
180
+ subject = Factory :stop_area, :area_type => "CommercialStopPoint"
181
+ subject.possible_children.should =~ [quay, boarding_position]
182
+ end
183
+
184
+ it "should find no children of type stop place or commercial stop point for stop area type stop place" do
185
+ subject = Factory :stop_area, :area_type => "StopPlace"
186
+ subject.possible_children.should =~ [stop_place, commercial_stop_point]
187
+ end
188
+
189
+ it "should find no children of type ITL for stop area type ITL" do
190
+ subject = Factory :stop_area, :area_type => "ITL"
191
+ subject.possible_children.should =~ [stop_place, commercial_stop_point, quay, boarding_position]
192
+ end
193
+
194
+ end
195
+
196
+ describe ".possible_parents" do
197
+
198
+ it "should find parent type commercial stop point for stop area type boarding position" do
199
+ subject = Factory :stop_area, :area_type => "BoardingPosition"
200
+ subject.possible_parents.should == [commercial_stop_point]
201
+ end
202
+
203
+ it "should find parent type commercial stop point for stop area type quay" do
204
+ subject = Factory :stop_area, :area_type => "Quay"
205
+ subject.possible_parents.should == [commercial_stop_point]
206
+ end
207
+
208
+ it "should find parent type stop place for stop area type commercial stop point" do
209
+ subject = Factory :stop_area, :area_type => "CommercialStopPoint"
210
+ subject.possible_parents.should == [stop_place]
211
+ end
212
+
213
+ it "should find parent type stop place for stop area type stop place" do
214
+ subject = Factory :stop_area, :area_type => "StopPlace"
215
+ subject.possible_parents.should == [stop_place]
216
+ end
217
+
218
+ end
219
+
220
+
221
+ describe ".near" do
222
+
223
+ let(:stop_area) { Factory :stop_area, :latitude => 1, :longitude => 1 }
224
+ let(:stop_area2) { Factory :stop_area, :latitude => 1, :longitude => 1 }
225
+
226
+ it "should find a StopArea at 300m from given origin" do
227
+ Chouette::StopArea.near(stop_area.to_lat_lng.endpoint(0, 0.250, :units => :kms)).should == [stop_area]
228
+ end
229
+
230
+ it "should not find a StopArea at more than 300m from given origin" do
231
+ Chouette::StopArea.near(stop_area2.to_lat_lng.endpoint(0, 0.350, :units => :kms)).should be_empty
232
+ end
233
+
234
+ end
235
+
236
+ describe "#to_lat_lng" do
237
+
238
+ it "should return nil if latitude is nil" do
239
+ subject.latitude = nil
240
+ subject.to_lat_lng.should be_nil
241
+ end
242
+
243
+ it "should return nil if longitude is nil" do
244
+ subject.longitude = nil
245
+ subject.to_lat_lng.should be_nil
246
+ end
247
+
248
+ end
249
+
250
+ describe "#geometry" do
251
+
252
+ it "should be nil when to_lat_lng is nil" do
253
+ subject.stub :to_lat_lng => nil
254
+ subject.geometry.should be_nil
255
+ end
256
+
257
+ end
258
+
259
+ describe ".bounds" do
260
+
261
+ it "should return transform coordinates in floats" do
262
+ Chouette::StopArea.connection.stub :select_rows => [["113.5292500000000000", "22.1127580000000000", "113.5819330000000000", "22.2157050000000000"]]
263
+ GeoRuby::SimpleFeatures::Envelope.should_receive(:from_coordinates).with([[113.5292500000000000, 22.1127580000000000], [113.5819330000000000, 22.2157050000000000]])
264
+ Chouette::StopArea.bounds
265
+ end
266
+
267
+ end
268
+
269
+ describe "#default_position" do
270
+
271
+ it "should return nil when StopArea.bounds is nil" do
272
+ Chouette::StopArea.stub :bounds => nil
273
+ subject.default_position.should be_nil
274
+ end
275
+
276
+ it "should return StopArea.bounds center" do
277
+ Chouette::StopArea.stub :bounds => mock(:center => "center")
278
+ subject.default_position.should == Chouette::StopArea.bounds.center
279
+ end
280
+
281
+ end
282
+
283
+ describe "#children_at_base" do
284
+ it "should have 2 children_at_base" do
285
+ subject = Factory :stop_area, :area_type => "StopPlace"
286
+ commercial_stop_point = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject
287
+ quay1 = Factory :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
288
+ quay2 = Factory :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
289
+ subject.children_at_base.size.should == 2
290
+ end
291
+ end
292
+
293
+
294
+ describe "#generic_access_link_matrix" do
295
+ it "should have no access_links in matrix with no access_point" do
296
+ subject = Factory :stop_area, :area_type => "StopPlace"
297
+ commercial_stop_point = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject
298
+ subject.generic_access_link_matrix.size.should == 0
299
+ end
300
+ it "should have 4 generic_access_links in matrix with 2 access_points" do
301
+ subject = Factory :stop_area, :area_type => "StopPlace"
302
+ commercial_stop_point = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject
303
+ access_point1 = Factory :access_point, :stop_area => subject
304
+ access_point2 = Factory :access_point, :stop_area => subject
305
+ subject.generic_access_link_matrix.size.should == 4
306
+ end
307
+ end
308
+ describe "#detail_access_link_matrix" do
309
+ it "should have no access_links in matrix with no access_point" do
310
+ subject = Factory :stop_area, :area_type => "StopPlace"
311
+ commercial_stop_point = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject
312
+ quay1 = Factory :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
313
+ quay2 = Factory :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
314
+ subject.detail_access_link_matrix.size.should == 0
315
+ end
316
+ it "should have 8 detail_access_links in matrix with 2 children_at_base and 2 access_points" do
317
+ subject = Factory :stop_area, :area_type => "StopPlace"
318
+ commercial_stop_point = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject
319
+ quay1 = Factory :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
320
+ quay2 = Factory :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
321
+ access_point1 = Factory :access_point, :stop_area => subject
322
+ access_point2 = Factory :access_point, :stop_area => subject
323
+ subject.detail_access_link_matrix.size.should == 8
324
+ end
325
+ end
326
+ describe "#parents" do
327
+ it "should return parent hireachy list" do
328
+ stop_place = Factory :stop_area, :area_type => "StopPlace"
329
+ commercial_stop_point = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place
330
+ subject = Factory :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
331
+ subject.parents.size.should == 2
332
+ end
333
+ it "should return empty parent hireachy list" do
334
+ subject = Factory :stop_area, :area_type => "Quay"
335
+ subject.parents.size.should == 0
336
+ end
337
+ end
338
+
339
+ describe "#clean_invalid_access_links" do
340
+ it "should remove invalid access links" do
341
+ # subject is a CSP with a SP as parent, a quay as child
342
+ # 2 access_points of SP have access_link, one on subject, one on subject child
343
+ # when detaching subject from SP, both access_links must be deleted
344
+ stop_place = Factory :stop_area, :area_type => "StopPlace"
345
+ subject = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place
346
+ access_point1 = Factory :access_point, :stop_area => stop_place
347
+ access_point2 = Factory :access_point, :stop_area => stop_place
348
+ quay = Factory :stop_area, :parent => subject, :area_type => "Quay"
349
+ access_link1 = Factory :access_link, :stop_area => subject, :access_point => access_point1
350
+ access_link2 = Factory :access_link, :stop_area => quay, :access_point => access_point2
351
+ subject.save
352
+ subject.access_links.size.should == 1
353
+ quay.access_links.size.should == 1
354
+ subject.parent=nil
355
+ subject.save
356
+ subject.reload
357
+ subject.access_links.size.should == 0
358
+ quay.access_links.size.should == 0
359
+ end
360
+ it "should not remove still valid access links" do
361
+ # subject is a Q of CSP with a SP as parent
362
+ # 2 access_points, one of SP, one of CSP have access_link on subject
363
+ # when changing subject CSP to another CSP of same SP
364
+ # one access_links must be kept
365
+ stop_place = Factory :stop_area, :area_type => "StopPlace"
366
+ commercial_stop_point1 = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place
367
+ commercial_stop_point2 = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place
368
+ access_point1 = Factory :access_point, :stop_area => stop_place
369
+ access_point2 = Factory :access_point, :stop_area => commercial_stop_point1
370
+ subject = Factory :stop_area, :parent => commercial_stop_point1, :area_type => "Quay"
371
+ access_link1 = Factory :access_link, :stop_area => subject, :access_point => access_point1
372
+ access_link2 = Factory :access_link, :stop_area => subject, :access_point => access_point2
373
+ subject.save
374
+ subject.access_links.size.should == 2
375
+ subject.parent=commercial_stop_point2
376
+ subject.save
377
+ subject.reload
378
+ subject.access_links.size.should == 1
379
+ end
380
+ end
381
+
382
+ end