ninoxe 1.1.5 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +9 -12
  3. data/app/models/chouette/access_link.rb +52 -51
  4. data/app/models/chouette/access_point.rb +7 -7
  5. data/app/models/chouette/active_record.rb +28 -28
  6. data/app/models/chouette/company.rb +3 -3
  7. data/app/models/chouette/connection_link.rb +3 -3
  8. data/app/models/chouette/footnote.rb +1 -1
  9. data/app/models/chouette/group_of_line.rb +2 -2
  10. data/app/models/chouette/journey_pattern.rb +7 -3
  11. data/app/models/chouette/line.rb +11 -9
  12. data/app/models/chouette/network.rb +2 -2
  13. data/app/models/chouette/pt_link.rb +1 -1
  14. data/app/models/chouette/route.rb +9 -10
  15. data/app/models/chouette/stop_area.rb +8 -8
  16. data/app/models/chouette/stop_point.rb +3 -3
  17. data/app/models/chouette/time_table.rb +25 -122
  18. data/app/models/chouette/time_table_date.rb +1 -1
  19. data/app/models/chouette/time_table_period.rb +1 -1
  20. data/app/models/chouette/vehicle_journey.rb +82 -77
  21. data/app/models/chouette/vehicle_journey_at_stop.rb +1 -1
  22. data/config/database.yml +16 -8
  23. data/config/database.yml.travis +15 -6
  24. data/db/migrate/20150526075108_add_foreign_key_to_routes.rb +28 -0
  25. data/lib/ninoxe/engine.rb +4 -0
  26. data/lib/ninoxe/version.rb +1 -1
  27. data/lib/ninoxe.rb +3 -0
  28. data/spec/dummy/README.rdoc +15 -248
  29. data/spec/dummy/Rakefile +1 -1
  30. data/spec/dummy/app/{mailers/.gitkeep → assets/images/.keep} +0 -0
  31. data/spec/dummy/app/assets/javascripts/application.js +3 -5
  32. data/spec/dummy/app/assets/stylesheets/application.css +1 -1
  33. data/spec/dummy/app/controllers/application_controller.rb +3 -1
  34. data/spec/dummy/app/{models/.gitkeep → controllers/concerns/.keep} +0 -0
  35. data/spec/dummy/{lib/assets/.gitkeep → app/mailers/.keep} +0 -0
  36. data/spec/dummy/{log/.gitkeep → app/models/.keep} +0 -0
  37. data/spec/dummy/app/models/concerns/.keep +0 -0
  38. data/spec/dummy/app/views/layouts/application.html.erb +2 -2
  39. data/spec/dummy/bin/bundle +3 -0
  40. data/spec/dummy/bin/rails +4 -0
  41. data/spec/dummy/bin/rake +4 -0
  42. data/spec/dummy/config/application.rb +8 -36
  43. data/spec/dummy/config/boot.rb +4 -9
  44. data/spec/dummy/config/database.yml +16 -8
  45. data/spec/dummy/config/environment.rb +2 -4
  46. data/spec/dummy/config/environments/development.rb +11 -19
  47. data/spec/dummy/config/environments/production.rb +41 -28
  48. data/spec/dummy/config/environments/test.rb +13 -14
  49. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  50. data/spec/dummy/config/initializers/inflections.rb +6 -5
  51. data/spec/dummy/config/initializers/secret_token.rb +7 -2
  52. data/spec/dummy/config/initializers/session_store.rb +1 -6
  53. data/spec/dummy/config/initializers/wrap_parameters.rb +6 -6
  54. data/spec/dummy/config/locales/en.yml +20 -2
  55. data/spec/dummy/config/locales/fr.yml +23 -0
  56. data/spec/dummy/config.ru +1 -1
  57. data/spec/dummy/db/schema.rb +147 -143
  58. data/spec/dummy/lib/assets/.keep +0 -0
  59. data/spec/dummy/log/.keep +0 -0
  60. data/spec/dummy/public/404.html +43 -11
  61. data/spec/dummy/public/422.html +43 -11
  62. data/spec/dummy/public/500.html +43 -11
  63. data/spec/dummy/script/rails +1 -1
  64. data/spec/factories/chouette_access_links.rb +13 -0
  65. data/spec/factories/chouette_access_points.rb +12 -0
  66. data/spec/factories/chouette_companies.rb +9 -0
  67. data/spec/factories/chouette_connection_links.rb +13 -0
  68. data/spec/factories/chouette_footnotes.rb +10 -0
  69. data/spec/factories/chouette_group_of_lines.rb +9 -0
  70. data/spec/factories/chouette_journey_pattern.rb +40 -0
  71. data/spec/factories/chouette_lines.rb +44 -0
  72. data/spec/factories/chouette_networks.rb +9 -0
  73. data/spec/factories/chouette_routes.rb +26 -0
  74. data/spec/factories/chouette_stop_areas.rb +12 -0
  75. data/spec/factories/chouette_stop_points.rb +10 -0
  76. data/spec/factories/chouette_time_table.rb +37 -0
  77. data/spec/factories/chouette_vehicle_journey.rb +66 -0
  78. data/spec/factories/chouette_vehicle_journey_at_stop.rb +8 -0
  79. data/spec/models/chouette/access_link_spec.rb +17 -13
  80. data/spec/models/chouette/access_point_spec.rb +106 -103
  81. data/spec/models/chouette/active_record_spec.rb +57 -57
  82. data/spec/models/chouette/area_type_spec.rb +8 -8
  83. data/spec/models/chouette/company_spec.rb +18 -18
  84. data/spec/models/chouette/connection_link_spec.rb +19 -15
  85. data/spec/models/chouette/direction_spec.rb +8 -8
  86. data/spec/models/chouette/exporter_spec.rb +4 -4
  87. data/spec/models/chouette/file_validator_spec.rb +4 -4
  88. data/spec/models/chouette/footnote_spec.rb +1 -1
  89. data/spec/models/chouette/group_of_line_spec.rb +11 -11
  90. data/spec/models/chouette/journey_pattern_spec.rb +16 -14
  91. data/spec/models/chouette/line_spec.rb +36 -32
  92. data/spec/models/chouette/loader_spec.rb +9 -9
  93. data/spec/models/chouette/network_spec.rb +9 -9
  94. data/spec/models/chouette/object_id_spec.rb +31 -28
  95. data/spec/models/chouette/route_spec.rb +51 -47
  96. data/spec/models/chouette/stop_area_spec.rb +191 -188
  97. data/spec/models/chouette/stop_point_spec.rb +13 -10
  98. data/spec/models/chouette/time_table_period_spec.rb +18 -18
  99. data/spec/models/chouette/time_table_spec.rb +303 -255
  100. data/spec/models/chouette/transport_mode_spec.rb +10 -10
  101. data/spec/models/chouette/trident_active_record_spec.rb +17 -17
  102. data/spec/models/chouette/vehicle_journey_at_stop_spec.rb +13 -12
  103. data/spec/models/chouette/vehicle_journey_spec.rb +46 -46
  104. data/spec/presenters/chouette/geometry/line_presenter_spec.rb +2 -2
  105. data/spec/spec_helper.rb +22 -9
  106. metadata +102 -87
  107. data/config/database.yml.ci +0 -14
  108. data/lib/factories/chouette_access_links.rb +0 -11
  109. data/lib/factories/chouette_access_points.rb +0 -8
  110. data/lib/factories/chouette_companies.rb +0 -5
  111. data/lib/factories/chouette_connection_links.rb +0 -11
  112. data/lib/factories/chouette_footnotes.rb +0 -6
  113. data/lib/factories/chouette_group_of_lines.rb +0 -5
  114. data/lib/factories/chouette_journey_pattern.rb +0 -32
  115. data/lib/factories/chouette_lines.rb +0 -31
  116. data/lib/factories/chouette_networks.rb +0 -5
  117. data/lib/factories/chouette_routes.rb +0 -20
  118. data/lib/factories/chouette_stop_areas.rb +0 -8
  119. data/lib/factories/chouette_stop_points.rb +0 -7
  120. data/lib/factories/chouette_time_table.rb +0 -23
  121. data/lib/factories/chouette_vehicle_journey.rb +0 -51
  122. data/lib/factories/chouette_vehicle_journey_at_stop.rb +0 -5
  123. data/spec/dummy/config/initializers/active_record.rb +0 -2
@@ -1,166 +1,169 @@
1
1
  require 'spec_helper'
2
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) }
3
+ describe Chouette::StopArea, :type => :model do
4
+ let!(:quay) { create :stop_area, :area_type => "Quay" }
5
+ let!(:boarding_position) { create :stop_area, :area_type => "BoardingPosition" }
6
+ let!(:commercial_stop_point) { create :stop_area, :area_type => "CommercialStopPoint" }
7
+ let!(:stop_place) { create :stop_area, :area_type => "StopPlace" }
8
+ let!(:itl) { create :stop_area, :area_type => "ITL" }
9
+
10
+ describe '#objectid' do
11
+ subject { super().objectid }
12
+ it { is_expected.to be_kind_of(Chouette::ObjectId) }
13
+ end
11
14
 
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 }
15
+ it { is_expected.to validate_presence_of :name }
16
+ it { is_expected.to validate_presence_of :area_type }
17
+ it { is_expected.to validate_numericality_of :latitude }
18
+ it { is_expected.to validate_numericality_of :longitude }
16
19
 
17
20
 
18
21
  describe ".latitude" do
19
22
  it "should accept -90 value" do
20
- subject = Factory :stop_area, :area_type => "BoardingPosition"
23
+ subject = create :stop_area, :area_type => "BoardingPosition"
21
24
  subject.latitude = -90
22
- subject.valid?.should be_true
25
+ expect(subject.valid?).to be_truthy
23
26
  end
24
27
  it "should reject < -90 value" do
25
- subject = Factory :stop_area, :area_type => "BoardingPosition"
28
+ subject = create :stop_area, :area_type => "BoardingPosition"
26
29
  subject.latitude = -90.0001
27
- subject.valid?.should be_false
30
+ expect(subject.valid?).to be_falsey
28
31
  end
29
32
  it "should accept 90 value" do
30
- subject = Factory :stop_area, :area_type => "BoardingPosition"
33
+ subject = create :stop_area, :area_type => "BoardingPosition"
31
34
  subject.latitude = 90
32
- subject.valid?.should be_true
35
+ expect(subject.valid?).to be_truthy
33
36
  end
34
37
  it "should reject > 90 value" do
35
- subject = Factory :stop_area, :area_type => "BoardingPosition"
38
+ subject = create :stop_area, :area_type => "BoardingPosition"
36
39
  subject.latitude = 90.0001
37
- subject.valid?.should be_false
40
+ expect(subject.valid?).to be_falsey
38
41
  end
39
42
  end
40
43
 
41
44
  describe ".longitude" do
42
45
  it "should accept -180 value" do
43
- subject = Factory :stop_area, :area_type => "BoardingPosition"
46
+ subject = create :stop_area, :area_type => "BoardingPosition"
44
47
  subject.longitude = -180
45
- subject.valid?.should be_true
48
+ expect(subject.valid?).to be_truthy
46
49
  end
47
50
  it "should reject < -180 value" do
48
- subject = Factory :stop_area, :area_type => "BoardingPosition"
51
+ subject = create :stop_area, :area_type => "BoardingPosition"
49
52
  subject.longitude = -180.0001
50
- subject.valid?.should be_false
53
+ expect(subject.valid?).to be_falsey
51
54
  end
52
55
  it "should accept 180 value" do
53
- subject = Factory :stop_area, :area_type => "BoardingPosition"
56
+ subject = create :stop_area, :area_type => "BoardingPosition"
54
57
  subject.longitude = 180
55
- subject.valid?.should be_true
58
+ expect(subject.valid?).to be_truthy
56
59
  end
57
60
  it "should reject > 180 value" do
58
- subject = Factory :stop_area, :area_type => "BoardingPosition"
61
+ subject = create :stop_area, :area_type => "BoardingPosition"
59
62
  subject.longitude = 180.0001
60
- subject.valid?.should be_false
63
+ expect(subject.valid?).to be_falsey
61
64
  end
62
65
  end
63
66
 
64
67
  describe ".long_lat" do
65
68
  it "should accept longitude and latitude both as nil" do
66
- subject = Factory :stop_area, :area_type => "BoardingPosition"
69
+ subject = create :stop_area, :area_type => "BoardingPosition"
67
70
  subject.longitude = nil
68
71
  subject.latitude = nil
69
- subject.valid?.should be_true
72
+ expect(subject.valid?).to be_truthy
70
73
  end
71
74
  it "should accept longitude and latitude both numerical" do
72
- subject = Factory :stop_area, :area_type => "BoardingPosition"
75
+ subject = create :stop_area, :area_type => "BoardingPosition"
73
76
  subject.longitude = 10
74
77
  subject.latitude = 10
75
- subject.valid?.should be_true
78
+ expect(subject.valid?).to be_truthy
76
79
  end
77
80
  it "should reject longitude nil with latitude numerical" do
78
- subject = Factory :stop_area, :area_type => "BoardingPosition"
81
+ subject = create :stop_area, :area_type => "BoardingPosition"
79
82
  subject.longitude = nil
80
83
  subject.latitude = 10
81
- subject.valid?.should be_false
84
+ expect(subject.valid?).to be_falsey
82
85
  end
83
86
  it "should reject longitude numerical with latitude nil" do
84
- subject = Factory :stop_area, :area_type => "BoardingPosition"
87
+ subject = create :stop_area, :area_type => "BoardingPosition"
85
88
  subject.longitude = 10
86
89
  subject.latitude = nil
87
- subject.valid?.should be_false
90
+ expect(subject.valid?).to be_falsey
88
91
  end
89
92
  end
90
93
 
91
94
 
92
95
  describe ".children_in_depth" do
93
96
  it "should return all the deepest children from stop area" do
94
- subject = Factory :stop_area, :area_type => "StopPlace"
95
- commercial_stop_point = Factory :stop_area, :area_type => "CommercialStopPoint", :parent => subject
96
- commercial_stop_point2 = Factory :stop_area, :area_type => "CommercialStopPoint", :parent => commercial_stop_point
97
- quay = Factory :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
98
- subject.children_in_depth.should =~ [commercial_stop_point, commercial_stop_point2, quay]
97
+ subject = create :stop_area, :area_type => "StopPlace"
98
+ commercial_stop_point = create :stop_area, :area_type => "CommercialStopPoint", :parent => subject
99
+ commercial_stop_point2 = create :stop_area, :area_type => "CommercialStopPoint", :parent => commercial_stop_point
100
+ quay = create :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
101
+ expect(subject.children_in_depth).to match_array([commercial_stop_point, commercial_stop_point2, quay])
99
102
  end
100
103
  it "should return only the deepest children from stop area" do
101
- subject = Factory :stop_area, :area_type => "StopPlace"
102
- commercial_stop_point = Factory :stop_area, :area_type => "CommercialStopPoint", :parent => subject
103
- commercial_stop_point2 = Factory :stop_area, :area_type => "CommercialStopPoint", :parent => commercial_stop_point
104
- quay = Factory :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
105
- subject.children_at_base.should =~ [quay]
104
+ subject = create :stop_area, :area_type => "StopPlace"
105
+ commercial_stop_point = create :stop_area, :area_type => "CommercialStopPoint", :parent => subject
106
+ commercial_stop_point2 = create :stop_area, :area_type => "CommercialStopPoint", :parent => commercial_stop_point
107
+ quay = create :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
108
+ expect(subject.children_at_base).to match_array([quay])
106
109
  end
107
110
  end
108
111
 
109
112
  describe ".stop_area_type" do
110
113
  it "should have area_type of BoardingPosition when stop_area_type is set to boarding_position" do
111
- subject = Factory :stop_area, :stop_area_type => "boarding_position"
112
- subject.area_type.should == "BoardingPosition"
114
+ subject = create :stop_area, :stop_area_type => "boarding_position"
115
+ expect(subject.area_type).to eq("BoardingPosition")
113
116
  end
114
117
  it "should have area_type of Quay when stop_area_type is set to quay" do
115
- subject = Factory :stop_area, :stop_area_type => "quay"
116
- subject.area_type.should == "Quay"
118
+ subject = create :stop_area, :stop_area_type => "quay"
119
+ expect(subject.area_type).to eq("Quay")
117
120
  end
118
121
  it "should have area_type of CommercialStopPoint when stop_area_type is set to commercial_stop_point" do
119
- subject = Factory :stop_area, :stop_area_type => "commercial_stop_point"
120
- subject.area_type.should == "CommercialStopPoint"
122
+ subject = create :stop_area, :stop_area_type => "commercial_stop_point"
123
+ expect(subject.area_type).to eq("CommercialStopPoint")
121
124
  end
122
125
  it "should have area_type of StopPlace when stop_area_type is set to stop_place" do
123
- subject = Factory :stop_area, :stop_area_type => "stop_place"
124
- subject.area_type.should == "StopPlace"
126
+ subject = create :stop_area, :stop_area_type => "stop_place"
127
+ expect(subject.area_type).to eq("StopPlace")
125
128
  end
126
129
  it "should have area_type of ITL when stop_area_type is set to itl" do
127
- subject = Factory :stop_area, :stop_area_type => "itl"
128
- subject.area_type.should == "ITL"
130
+ subject = create :stop_area, :stop_area_type => "itl"
131
+ expect(subject.area_type).to eq("ITL")
129
132
  end
130
133
  end
131
134
 
132
135
  describe ".parent" do
133
136
  it "should check if parent method exists" do
134
- subject = Factory :stop_area, :parent_id => commercial_stop_point.id
135
- subject.parent.should == commercial_stop_point
137
+ subject = create :stop_area, :parent_id => commercial_stop_point.id
138
+ expect(subject.parent).to eq(commercial_stop_point)
136
139
  end
137
140
  end
138
141
 
139
142
  describe ".possible_children" do
140
143
 
141
144
  it "should find no possible descendant for stop area type quay" do
142
- subject = Factory :stop_area, :area_type => "Quay"
143
- subject.possible_children.should == []
145
+ subject = create :stop_area, :area_type => "Quay"
146
+ expect(subject.possible_children).to eq([])
144
147
  end
145
148
 
146
149
  it "should find no possible descendant for stop area type boarding position" do
147
- subject = Factory :stop_area, :area_type => "BoardingPosition"
148
- subject.possible_children.should == []
150
+ subject = create :stop_area, :area_type => "BoardingPosition"
151
+ expect(subject.possible_children).to eq([])
149
152
  end
150
153
 
151
154
  it "should find descendant of type quay or boarding position for stop area type commercial stop point" do
152
- subject = Factory :stop_area, :area_type => "CommercialStopPoint"
153
- subject.possible_children.should =~ [quay, boarding_position]
155
+ subject = create :stop_area, :area_type => "CommercialStopPoint"
156
+ expect(subject.possible_children).to match_array([quay, boarding_position])
154
157
  end
155
158
 
156
159
  it "should find no children of type stop place or commercial stop point for stop area type stop place" do
157
- subject = Factory :stop_area, :area_type => "StopPlace"
158
- subject.possible_children.should =~ [stop_place, commercial_stop_point]
160
+ subject = create :stop_area, :area_type => "StopPlace"
161
+ expect(subject.possible_children).to match_array([stop_place, commercial_stop_point])
159
162
  end
160
163
 
161
164
  it "should find no children of type ITL for stop area type ITL" do
162
- subject = Factory :stop_area, :area_type => "ITL"
163
- subject.possible_children.should =~ [stop_place, commercial_stop_point, quay, boarding_position]
165
+ subject = create :stop_area, :area_type => "ITL"
166
+ expect(subject.possible_children).to match_array([stop_place, commercial_stop_point, quay, boarding_position])
164
167
  end
165
168
 
166
169
  end
@@ -168,23 +171,23 @@ describe Chouette::StopArea do
168
171
  describe ".possible_parents" do
169
172
 
170
173
  it "should find parent type commercial stop point for stop area type boarding position" do
171
- subject = Factory :stop_area, :area_type => "BoardingPosition"
172
- subject.possible_parents.should == [commercial_stop_point]
174
+ subject = create :stop_area, :area_type => "BoardingPosition"
175
+ expect(subject.possible_parents).to eq([commercial_stop_point])
173
176
  end
174
177
 
175
178
  it "should find parent type commercial stop point for stop area type quay" do
176
- subject = Factory :stop_area, :area_type => "Quay"
177
- subject.possible_parents.should == [commercial_stop_point]
179
+ subject = create :stop_area, :area_type => "Quay"
180
+ expect(subject.possible_parents).to eq([commercial_stop_point])
178
181
  end
179
182
 
180
183
  it "should find parent type stop place for stop area type commercial stop point" do
181
- subject = Factory :stop_area, :area_type => "CommercialStopPoint"
182
- subject.possible_parents.should == [stop_place]
184
+ subject = create :stop_area, :area_type => "CommercialStopPoint"
185
+ expect(subject.possible_parents).to eq([stop_place])
183
186
  end
184
187
 
185
188
  it "should find parent type stop place for stop area type stop place" do
186
- subject = Factory :stop_area, :area_type => "StopPlace"
187
- subject.possible_parents.should == [stop_place]
189
+ subject = create :stop_area, :area_type => "StopPlace"
190
+ expect(subject.possible_parents).to eq([stop_place])
188
191
  end
189
192
 
190
193
  end
@@ -192,15 +195,15 @@ describe Chouette::StopArea do
192
195
 
193
196
  describe ".near" do
194
197
 
195
- let(:stop_area) { Factory :stop_area, :latitude => 1, :longitude => 1 }
196
- let(:stop_area2) { Factory :stop_area, :latitude => 1, :longitude => 1 }
198
+ let(:stop_area) { create :stop_area, :latitude => 1, :longitude => 1 }
199
+ let(:stop_area2) { create :stop_area, :latitude => 1, :longitude => 1 }
197
200
 
198
201
  it "should find a StopArea at 300m from given origin" do
199
- Chouette::StopArea.near(stop_area.to_lat_lng.endpoint(0, 0.250, :units => :kms)).should == [stop_area]
202
+ expect(Chouette::StopArea.near(stop_area.to_lat_lng.endpoint(0, 0.250, :units => :kms))).to eq([stop_area])
200
203
  end
201
204
 
202
205
  it "should not find a StopArea at more than 300m from given origin" do
203
- Chouette::StopArea.near(stop_area2.to_lat_lng.endpoint(0, 0.350, :units => :kms)).should be_empty
206
+ expect(Chouette::StopArea.near(stop_area2.to_lat_lng.endpoint(0, 0.350, :units => :kms))).to be_empty
204
207
  end
205
208
 
206
209
  end
@@ -209,12 +212,12 @@ describe Chouette::StopArea do
209
212
 
210
213
  it "should return nil if latitude is nil" do
211
214
  subject.latitude = nil
212
- subject.to_lat_lng.should be_nil
215
+ expect(subject.to_lat_lng).to be_nil
213
216
  end
214
217
 
215
218
  it "should return nil if longitude is nil" do
216
219
  subject.longitude = nil
217
- subject.to_lat_lng.should be_nil
220
+ expect(subject.to_lat_lng).to be_nil
218
221
  end
219
222
 
220
223
  end
@@ -222,8 +225,8 @@ describe Chouette::StopArea do
222
225
  describe "#geometry" do
223
226
 
224
227
  it "should be nil when to_lat_lng is nil" do
225
- subject.stub :to_lat_lng => nil
226
- subject.geometry.should be_nil
228
+ allow(subject).to receive_messages :to_lat_lng => nil
229
+ expect(subject.geometry).to be_nil
227
230
  end
228
231
 
229
232
  end
@@ -231,8 +234,8 @@ describe Chouette::StopArea do
231
234
  describe ".bounds" do
232
235
 
233
236
  it "should return transform coordinates in floats" do
234
- Chouette::StopArea.connection.stub :select_rows => [["113.5292500000000000", "22.1127580000000000", "113.5819330000000000", "22.2157050000000000"]]
235
- GeoRuby::SimpleFeatures::Envelope.should_receive(:from_coordinates).with([[113.5292500000000000, 22.1127580000000000], [113.5819330000000000, 22.2157050000000000]])
237
+ allow(Chouette::StopArea.connection).to receive_messages :select_rows => [["113.5292500000000000", "22.1127580000000000", "113.5819330000000000", "22.2157050000000000"]]
238
+ expect(GeoRuby::SimpleFeatures::Envelope).to receive(:from_coordinates).with([[113.5292500000000000, 22.1127580000000000], [113.5819330000000000, 22.2157050000000000]])
236
239
  Chouette::StopArea.bounds
237
240
  end
238
241
 
@@ -241,70 +244,70 @@ describe Chouette::StopArea do
241
244
  describe "#default_position" do
242
245
 
243
246
  it "should return nil when StopArea.bounds is nil" do
244
- Chouette::StopArea.stub :bounds => nil
245
- subject.default_position.should be_nil
247
+ allow(Chouette::StopArea).to receive_messages :bounds => nil
248
+ expect(subject.default_position).to be_nil
246
249
  end
247
250
 
248
251
  it "should return StopArea.bounds center" do
249
- Chouette::StopArea.stub :bounds => double(:center => "center")
250
- subject.default_position.should == Chouette::StopArea.bounds.center
252
+ allow(Chouette::StopArea).to receive_messages :bounds => double(:center => "center")
253
+ expect(subject.default_position).to eq(Chouette::StopArea.bounds.center)
251
254
  end
252
255
 
253
256
  end
254
257
 
255
258
  describe "#children_at_base" do
256
259
  it "should have 2 children_at_base" do
257
- subject = Factory :stop_area, :area_type => "StopPlace"
258
- commercial_stop_point = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject
259
- quay1 = Factory :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
260
- quay2 = Factory :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
261
- subject.children_at_base.size.should == 2
260
+ subject = create :stop_area, :area_type => "StopPlace"
261
+ commercial_stop_point = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject
262
+ quay1 = create :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
263
+ quay2 = create :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
264
+ expect(subject.children_at_base.size).to eq(2)
262
265
  end
263
266
  end
264
267
 
265
268
 
266
269
  describe "#generic_access_link_matrix" do
267
270
  it "should have no access_links in matrix with no access_point" do
268
- subject = Factory :stop_area, :area_type => "StopPlace"
269
- commercial_stop_point = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject
270
- subject.generic_access_link_matrix.size.should == 0
271
+ subject = create :stop_area, :area_type => "StopPlace"
272
+ commercial_stop_point = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject
273
+ expect(subject.generic_access_link_matrix.size).to eq(0)
271
274
  end
272
275
  it "should have 4 generic_access_links in matrix with 2 access_points" do
273
- subject = Factory :stop_area, :area_type => "StopPlace"
274
- commercial_stop_point = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject
275
- access_point1 = Factory :access_point, :stop_area => subject
276
- access_point2 = Factory :access_point, :stop_area => subject
277
- subject.generic_access_link_matrix.size.should == 4
276
+ subject = create :stop_area, :area_type => "StopPlace"
277
+ commercial_stop_point = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject
278
+ access_point1 = create :access_point, :stop_area => subject
279
+ access_point2 = create :access_point, :stop_area => subject
280
+ expect(subject.generic_access_link_matrix.size).to eq(4)
278
281
  end
279
282
  end
280
283
  describe "#detail_access_link_matrix" do
281
284
  it "should have no access_links in matrix with no access_point" do
282
- subject = Factory :stop_area, :area_type => "StopPlace"
283
- commercial_stop_point = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject
284
- quay1 = Factory :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
285
- quay2 = Factory :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
286
- subject.detail_access_link_matrix.size.should == 0
285
+ subject = create :stop_area, :area_type => "StopPlace"
286
+ commercial_stop_point = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject
287
+ quay1 = create :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
288
+ quay2 = create :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
289
+ expect(subject.detail_access_link_matrix.size).to eq(0)
287
290
  end
288
291
  it "should have 8 detail_access_links in matrix with 2 children_at_base and 2 access_points" do
289
- subject = Factory :stop_area, :area_type => "StopPlace"
290
- commercial_stop_point = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject
291
- quay1 = Factory :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
292
- quay2 = Factory :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
293
- access_point1 = Factory :access_point, :stop_area => subject
294
- access_point2 = Factory :access_point, :stop_area => subject
295
- subject.detail_access_link_matrix.size.should == 8
292
+ subject = create :stop_area, :area_type => "StopPlace"
293
+ commercial_stop_point = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject
294
+ quay1 = create :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
295
+ quay2 = create :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
296
+ access_point1 = create :access_point, :stop_area => subject
297
+ access_point2 = create :access_point, :stop_area => subject
298
+ expect(subject.detail_access_link_matrix.size).to eq(8)
296
299
  end
297
300
  end
298
301
  describe "#parents" do
299
302
  it "should return parent hireachy list" do
300
- stop_place = Factory :stop_area, :area_type => "StopPlace"
301
- commercial_stop_point = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place
302
- subject = Factory :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
303
- subject.parents.size.should == 2
303
+ stop_place = create :stop_area, :area_type => "StopPlace"
304
+ commercial_stop_point = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place
305
+ subject = create :stop_area, :parent => commercial_stop_point, :area_type => "Quay"
306
+ expect(subject.parents.size).to eq(2)
304
307
  end
305
308
  it "should return empty parent hireachy list" do
306
- subject = Factory :stop_area, :area_type => "Quay"
307
- subject.parents.size.should == 0
309
+ subject = create :stop_area, :area_type => "Quay"
310
+ expect(subject.parents.size).to eq(0)
308
311
  end
309
312
  end
310
313
 
@@ -313,126 +316,126 @@ describe Chouette::StopArea do
313
316
  # subject is a CSP with a SP as parent, a quay as child
314
317
  # 2 access_points of SP have access_link, one on subject, one on subject child
315
318
  # when detaching subject from SP, both access_links must be deleted
316
- stop_place = Factory :stop_area, :area_type => "StopPlace"
317
- subject = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place
318
- access_point1 = Factory :access_point, :stop_area => stop_place
319
- access_point2 = Factory :access_point, :stop_area => stop_place
320
- quay = Factory :stop_area, :parent => subject, :area_type => "Quay"
321
- access_link1 = Factory :access_link, :stop_area => subject, :access_point => access_point1
322
- access_link2 = Factory :access_link, :stop_area => quay, :access_point => access_point2
319
+ stop_place = create :stop_area, :area_type => "StopPlace"
320
+ subject = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place
321
+ access_point1 = create :access_point, :stop_area => stop_place
322
+ access_point2 = create :access_point, :stop_area => stop_place
323
+ quay = create :stop_area, :parent => subject, :area_type => "Quay"
324
+ access_link1 = create :access_link, :stop_area => subject, :access_point => access_point1
325
+ access_link2 = create :access_link, :stop_area => quay, :access_point => access_point2
323
326
  subject.save
324
- subject.access_links.size.should == 1
325
- quay.access_links.size.should == 1
327
+ expect(subject.access_links.size).to eq(1)
328
+ expect(quay.access_links.size).to eq(1)
326
329
  subject.parent=nil
327
330
  subject.save
328
331
  subject.reload
329
- subject.access_links.size.should == 0
330
- quay.access_links.size.should == 0
332
+ expect(subject.access_links.size).to eq(0)
333
+ expect(quay.access_links.size).to eq(0)
331
334
  end
332
335
  it "should not remove still valid access links" do
333
336
  # subject is a Q of CSP with a SP as parent
334
337
  # 2 access_points, one of SP, one of CSP have access_link on subject
335
338
  # when changing subject CSP to another CSP of same SP
336
339
  # one access_links must be kept
337
- stop_place = Factory :stop_area, :area_type => "StopPlace"
338
- commercial_stop_point1 = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place
339
- commercial_stop_point2 = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place
340
- access_point1 = Factory :access_point, :stop_area => stop_place
341
- access_point2 = Factory :access_point, :stop_area => commercial_stop_point1
342
- subject = Factory :stop_area, :parent => commercial_stop_point1, :area_type => "Quay"
343
- access_link1 = Factory :access_link, :stop_area => subject, :access_point => access_point1
344
- access_link2 = Factory :access_link, :stop_area => subject, :access_point => access_point2
340
+ stop_place = create :stop_area, :area_type => "StopPlace"
341
+ commercial_stop_point1 = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place
342
+ commercial_stop_point2 = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place
343
+ access_point1 = create :access_point, :stop_area => stop_place
344
+ access_point2 = create :access_point, :stop_area => commercial_stop_point1
345
+ subject = create :stop_area, :parent => commercial_stop_point1, :area_type => "Quay"
346
+ access_link1 = create :access_link, :stop_area => subject, :access_point => access_point1
347
+ access_link2 = create :access_link, :stop_area => subject, :access_point => access_point2
345
348
  subject.save
346
- subject.access_links.size.should == 2
349
+ expect(subject.access_links.size).to eq(2)
347
350
  subject.parent=commercial_stop_point2
348
351
  subject.save
349
352
  subject.reload
350
- subject.access_links.size.should == 1
353
+ expect(subject.access_links.size).to eq(1)
351
354
  end
352
355
  end
353
356
 
354
357
  describe "#coordinates" do
355
358
  it "should convert coordinates into latitude/longitude" do
356
- subject = Factory :stop_area, :area_type => "BoardingPosition", :coordinates => "45.123,120.456"
357
- subject.longitude.should be_within(0.001).of(120.456)
358
- subject.latitude.should be_within(0.001).of(45.123)
359
+ subject = create :stop_area, :area_type => "BoardingPosition", :coordinates => "45.123,120.456"
360
+ expect(subject.longitude).to be_within(0.001).of(120.456)
361
+ expect(subject.latitude).to be_within(0.001).of(45.123)
359
362
  end
360
363
  it "should set empty coordinates into nil latitude/longitude" do
361
- subject = Factory :stop_area, :area_type => "BoardingPosition", :coordinates => "45.123,120.456"
362
- subject.longitude.should be_within(0.001).of(120.456)
363
- subject.latitude.should be_within(0.001).of(45.123)
364
+ subject = create :stop_area, :area_type => "BoardingPosition", :coordinates => "45.123,120.456"
365
+ expect(subject.longitude).to be_within(0.001).of(120.456)
366
+ expect(subject.latitude).to be_within(0.001).of(45.123)
364
367
  subject.coordinates = ""
365
368
  subject.save
366
- subject.longitude.should be_nil
367
- subject.latitude.should be_nil
369
+ expect(subject.longitude).to be_nil
370
+ expect(subject.latitude).to be_nil
368
371
  end
369
372
  it "should convert latitude/longitude into coordinates" do
370
- subject = Factory :stop_area, :area_type => "BoardingPosition", :longitude => 120.456, :latitude => 45.123
371
- subject.coordinates.should == "45.123,120.456"
373
+ subject = create :stop_area, :area_type => "BoardingPosition", :longitude => 120.456, :latitude => 45.123
374
+ expect(subject.coordinates).to eq("45.123,120.456")
372
375
  end
373
376
  it "should convert nil latitude/longitude into empty coordinates" do
374
- subject = Factory :stop_area, :area_type => "BoardingPosition", :longitude => nil, :latitude => nil
375
- subject.coordinates.should == ""
377
+ subject = create :stop_area, :area_type => "BoardingPosition", :longitude => nil, :latitude => nil
378
+ expect(subject.coordinates).to eq("")
376
379
  end
377
380
  it "should accept valid coordinates" do
378
- subject = Factory :stop_area, :area_type => "BoardingPosition", :coordinates => "45.123,120.456"
379
- subject.valid?.should be_true
381
+ subject = create :stop_area, :area_type => "BoardingPosition", :coordinates => "45.123,120.456"
382
+ expect(subject.valid?).to be_truthy
380
383
  subject.coordinates = "45.123, 120.456"
381
- subject.valid?.should be_true
382
- subject.longitude.should be_within(0.001).of(120.456)
383
- subject.latitude.should be_within(0.001).of(45.123)
384
+ expect(subject.valid?).to be_truthy
385
+ expect(subject.longitude).to be_within(0.001).of(120.456)
386
+ expect(subject.latitude).to be_within(0.001).of(45.123)
384
387
  subject.coordinates = "45.123, -120.456"
385
- subject.valid?.should be_true
388
+ expect(subject.valid?).to be_truthy
386
389
  subject.coordinates = "45.123 ,120.456"
387
- subject.valid?.should be_true
390
+ expect(subject.valid?).to be_truthy
388
391
  subject.coordinates = "45.123 , 120.456"
389
- subject.valid?.should be_true
392
+ expect(subject.valid?).to be_truthy
390
393
  subject.coordinates = " 45.123,120.456"
391
- subject.valid?.should be_true
394
+ expect(subject.valid?).to be_truthy
392
395
  subject.coordinates = "45.123,120.456 "
393
- subject.valid?.should be_true
396
+ expect(subject.valid?).to be_truthy
394
397
  end
395
398
  it "should accept valid coordinates on limits" do
396
- subject = Factory :stop_area, :area_type => "BoardingPosition", :coordinates => "90,180"
397
- subject.valid?.should be_true
399
+ subject = create :stop_area, :area_type => "BoardingPosition", :coordinates => "90,180"
400
+ expect(subject.valid?).to be_truthy
398
401
  subject.coordinates = "-90,-180"
399
- subject.valid?.should be_true
402
+ expect(subject.valid?).to be_truthy
400
403
  subject.coordinates = "-90.,180."
401
- subject.valid?.should be_true
404
+ expect(subject.valid?).to be_truthy
402
405
  subject.coordinates = "-90.0,180.00"
403
- subject.valid?.should be_true
406
+ expect(subject.valid?).to be_truthy
404
407
  end
405
408
  it "should reject invalid coordinates" do
406
- subject = Factory :stop_area, :area_type => "BoardingPosition"
409
+ subject = create :stop_area, :area_type => "BoardingPosition"
407
410
  subject.coordinates = ",12"
408
- subject.valid?.should be_false
411
+ expect(subject.valid?).to be_falsey
409
412
  subject.coordinates = "-90"
410
- subject.valid?.should be_false
413
+ expect(subject.valid?).to be_falsey
411
414
  subject.coordinates = "-90.1,180."
412
- subject.valid?.should be_false
415
+ expect(subject.valid?).to be_falsey
413
416
  subject.coordinates = "-90.0,180.1"
414
- subject.valid?.should be_false
417
+ expect(subject.valid?).to be_falsey
415
418
  subject.coordinates = "-91.0,18.1"
416
- subject.valid?.should be_false
419
+ expect(subject.valid?).to be_falsey
417
420
  end
418
421
  end
419
422
 
420
423
  describe "#duplicate" do
421
424
  it "should be a copy of" do
422
- stop_place = Factory :stop_area, :area_type => "StopPlace"
423
- subject = Factory :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place, :coordinates => "45.123,120.456"
424
- access_point1 = Factory :access_point, :stop_area => subject
425
- access_point2 = Factory :access_point, :stop_area => subject
426
- quay1 = Factory :stop_area, :parent => subject, :area_type => "Quay"
425
+ stop_place = create :stop_area, :area_type => "StopPlace"
426
+ subject = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place, :coordinates => "45.123,120.456"
427
+ access_point1 = create :access_point, :stop_area => subject
428
+ access_point2 = create :access_point, :stop_area => subject
429
+ quay1 = create :stop_area, :parent => subject, :area_type => "Quay"
427
430
  target=subject.duplicate
428
- target.id.should be_nil
429
- target.name.should == "Copy of "+subject.name
430
- target.objectid.should == subject.objectid+"_1"
431
- target.area_type.should == subject.area_type
432
- target.parent.should be_nil
433
- target.children.size.should == 0
434
- target.access_points.size.should == 0
435
- target.coordinates.should == "45.123,120.456"
431
+ expect(target.id).to be_nil
432
+ expect(target.name).to eq("Copy of "+subject.name)
433
+ expect(target.objectid).to eq(subject.objectid+"_1")
434
+ expect(target.area_type).to eq(subject.area_type)
435
+ expect(target.parent).to be_nil
436
+ expect(target.children.size).to eq(0)
437
+ expect(target.access_points.size).to eq(0)
438
+ expect(target.coordinates).to eq("45.123,120.456")
436
439
  end
437
440
  end
438
441