ninoxe 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/lib/ninoxe/version.rb +1 -1
  3. data/spec/dummy/README.rdoc +261 -0
  4. data/spec/dummy/Rakefile +6 -0
  5. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  6. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  7. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  8. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  9. data/spec/dummy/app/mailers/.gitkeep +0 -0
  10. data/spec/dummy/app/models/.gitkeep +0 -0
  11. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  12. data/spec/dummy/config/application.rb +56 -0
  13. data/spec/dummy/config/boot.rb +10 -0
  14. data/spec/dummy/config/database.yml +9 -0
  15. data/spec/dummy/config/environment.rb +7 -0
  16. data/spec/dummy/config/environments/development.rb +37 -0
  17. data/spec/dummy/config/environments/production.rb +67 -0
  18. data/spec/dummy/config/environments/test.rb +37 -0
  19. data/spec/dummy/config/initializers/active_record.rb +2 -0
  20. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  21. data/spec/dummy/config/initializers/inflections.rb +15 -0
  22. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  23. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  24. data/spec/dummy/config/initializers/session_store.rb +8 -0
  25. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  26. data/spec/dummy/config/locales/en.yml +5 -0
  27. data/spec/dummy/config/routes.rb +4 -0
  28. data/spec/dummy/config.ru +4 -0
  29. data/spec/dummy/db/test.sqlite3 +0 -0
  30. data/spec/dummy/lib/assets/.gitkeep +0 -0
  31. data/spec/dummy/log/.gitkeep +0 -0
  32. data/spec/dummy/public/404.html +26 -0
  33. data/spec/dummy/public/422.html +26 -0
  34. data/spec/dummy/public/500.html +25 -0
  35. data/spec/dummy/public/favicon.ico +0 -0
  36. data/spec/dummy/script/rails +6 -0
  37. data/spec/models/chouette/access_link_spec.rb +78 -0
  38. data/spec/models/chouette/access_point_spec.rb +193 -0
  39. data/spec/models/chouette/active_record_spec.rb +121 -0
  40. data/spec/models/chouette/area_type_spec.rb +53 -0
  41. data/spec/models/chouette/company_spec.rb +51 -0
  42. data/spec/models/chouette/connection_link_spec.rb +56 -0
  43. data/spec/models/chouette/direction_spec.rb +60 -0
  44. data/spec/models/chouette/exporter_spec.rb +28 -0
  45. data/spec/models/chouette/file_validator_spec.rb +28 -0
  46. data/spec/models/chouette/group_of_line_spec.rb +31 -0
  47. data/spec/models/chouette/journey_pattern_spec.rb +62 -0
  48. data/spec/models/chouette/line_spec.rb +106 -0
  49. data/spec/models/chouette/loader_spec.rb +69 -0
  50. data/spec/models/chouette/network_spec.rb +22 -0
  51. data/spec/models/chouette/object_id_spec.rb +146 -0
  52. data/spec/models/chouette/route_spec.rb +159 -0
  53. data/spec/models/chouette/stop_area_spec.rb +354 -0
  54. data/spec/models/chouette/stop_point_spec.rb +39 -0
  55. data/spec/models/chouette/time_table_spec.rb +372 -0
  56. data/spec/models/chouette/transport_mode_spec.rb +64 -0
  57. data/spec/models/chouette/vehicle_journey_at_stop_spec.rb +46 -0
  58. data/spec/models/chouette/vehicle_journey_spec.rb +204 -0
  59. data/spec/presenters/chouette/geometry/general_presenter.rb +1 -0
  60. data/spec/presenters/chouette/geometry/line_presenter_spec.rb +13 -0
  61. data/spec/spec_helper.rb +45 -0
  62. metadata +210 -130
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chouette::Direction do
4
+
5
+ describe ".new" do
6
+ context "when single argument provided is a direction" do
7
+ let(:text) { "dummy"}
8
+ let(:direction){ Chouette::Direction.new( text, 1)}
9
+ it "should be equals to the provided direction" do
10
+ direction.should == Chouette::Direction.new( direction)
11
+ end
12
+ end
13
+ end
14
+
15
+ shared_examples_for "west direction" do
16
+ it "should return true to #west? " do
17
+ direction.should be_west
18
+ end
19
+ context "#to_i" do
20
+ it "should return 6" do
21
+ direction.to_i.should == 6
22
+ end
23
+ end
24
+ end
25
+
26
+ context "when instanciating with existing text only ('west' for example)" do
27
+ let(:direction){ Chouette::Direction.new "west"}
28
+ it_should_behave_like "west direction"
29
+ end
30
+ context "when instanciating with existing numerical code only (6 for example)" do
31
+ let(:direction){ Chouette::Direction.new 6}
32
+ it_should_behave_like "west direction"
33
+ end
34
+
35
+ context "when instanciating with 'dummy' and 1 as argumrent" do
36
+ let(:text) { "dummy"}
37
+ let(:number) { 1}
38
+ let(:direction){ Chouette::Direction.new( text, number)}
39
+
40
+ it "should return true to #dummy? " do
41
+ direction.send( "#{text}?".to_sym).should be_true
42
+ end
43
+
44
+ it "should return false to #other-dummy? " do
45
+ direction.send( "other-#{text}?".to_sym).should be_false
46
+ end
47
+
48
+ context "#to_i" do
49
+ it "should return provided number" do
50
+ direction.to_i.should == number
51
+ end
52
+ end
53
+
54
+ context "#name" do
55
+ it "should return provided text" do
56
+ direction.name.should == text
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chouette::Exporter do
4
+
5
+ subject { Chouette::Exporter.new("test") }
6
+
7
+ describe "#export" do
8
+
9
+ let(:chouette_command) { mock :run! => true }
10
+
11
+ before(:each) do
12
+ subject.stub :chouette_command => chouette_command
13
+ end
14
+
15
+ it "should use specified file in -outputFile option" do
16
+ chouette_command.should_receive(:run!).with(hash_including(:output_file => File.expand_path('file')))
17
+ subject.export "file"
18
+ end
19
+
20
+ it "should use specified format in -format option" do
21
+ chouette_command.should_receive(:run!).with(hash_including(:format => 'DUMMY'))
22
+ subject.export "file", :format => "dummy"
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chouette::FileValidator do
4
+
5
+ subject { Chouette::FileValidator.new("public") }
6
+
7
+ before(:each) do
8
+ subject.stub :execute! => true
9
+ end
10
+
11
+
12
+ describe "#validate" do
13
+
14
+ let(:chouette_command) { mock :run! => true }
15
+
16
+ before(:each) do
17
+ subject.stub :chouette_command => chouette_command
18
+ end
19
+
20
+ it "should use specified file in -inputFile option" do
21
+ chouette_command.should_receive(:run!).with(hash_including(:input_file => File.expand_path('file')))
22
+ subject.validate "file"
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chouette::GroupOfLine do
4
+
5
+ subject { Factory(:group_of_line) }
6
+
7
+ it { should validate_presence_of :name }
8
+
9
+ # it { should validate_presence_of :objectid }
10
+ it { should validate_uniqueness_of :objectid }
11
+
12
+ describe "#stop_areas" do
13
+ let!(:line){Factory(:line, :group_of_lines => [subject])}
14
+ let!(:route){Factory(:route, :line => line)}
15
+ it "should retreive group of line's stop_areas" do
16
+ subject.stop_areas.count.should == route.stop_points.count
17
+ end
18
+ end
19
+
20
+ context "#line_tokens=" do
21
+ let!(:line1){Factory(:line)}
22
+ let!(:line2){Factory(:line)}
23
+
24
+ it "should return associated line ids" do
25
+ subject.update_attributes :line_tokens => [line1.id, line2.id].join(',')
26
+ subject.lines.should include( line1)
27
+ subject.lines.should include( line2)
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chouette::JourneyPattern do
4
+ describe "#stop_point_ids" do
5
+ context "for a journey_pattern using only route's stop on odd position" do
6
+ let!(:journey_pattern){ Factory( :journey_pattern_odd)}
7
+ let!(:vehicle_journey){ Factory( :vehicle_journey_odd, :journey_pattern => journey_pattern)}
8
+
9
+ # workaroud
10
+ #subject { journey_pattern}
11
+ subject { Chouette::JourneyPattern.find(vehicle_journey.journey_pattern_id)}
12
+
13
+ context "when a all route's stop have been removed from journey_pattern" do
14
+ before(:each) do
15
+ subject.stop_point_ids = []
16
+ end
17
+ it "should remove all vehicle_journey_at_stop" do
18
+ vjas_stop_ids = Chouette::VehicleJourney.find(vehicle_journey.id).vehicle_journey_at_stops
19
+ vjas_stop_ids.count.should == 0
20
+ end
21
+ it "should keep departure and arrival shortcut up to date to nil" do
22
+ subject.arrival_stop_point_id.should be_nil
23
+ subject.departure_stop_point_id.should be_nil
24
+ end
25
+ end
26
+ context "when a route's stop has been removed from journey_pattern" do
27
+ let!(:last_stop_id){ subject.stop_point_ids.last}
28
+ before(:each) do
29
+ subject.stop_point_ids = subject.stop_point_ids - [last_stop_id]
30
+ end
31
+ it "should remove vehicle_journey_at_stop for last stop" do
32
+ vjas_stop_ids = Chouette::VehicleJourney.find(vehicle_journey.id).vehicle_journey_at_stops.map(&:stop_point_id)
33
+ vjas_stop_ids.count.should == subject.stop_point_ids.size
34
+ vjas_stop_ids.should_not include( last_stop_id)
35
+ end
36
+ it "should keep departure and arrival shortcut up to date" do
37
+ ordered = subject.stop_points.sort { |a,b| a.position <=> b.position}
38
+
39
+ subject.arrival_stop_point_id.should == ordered.last.id
40
+ subject.departure_stop_point_id.should == ordered.first.id
41
+ end
42
+ end
43
+ context "when a route's stop has been added in journey_pattern" do
44
+ let!(:new_stop){ subject.route.stop_points[1]}
45
+ before(:each) do
46
+ subject.stop_point_ids = subject.stop_point_ids + [new_stop.id]
47
+ end
48
+ it "should add a new vehicle_journey_at_stop for that stop" do
49
+ vjas_stop_ids = Chouette::VehicleJourney.find(vehicle_journey.id).vehicle_journey_at_stops.map(&:stop_point_id)
50
+ vjas_stop_ids.count.should == subject.stop_point_ids.size
51
+ vjas_stop_ids.should include( new_stop.id)
52
+ end
53
+ it "should keep departure and arrival shortcut up to date" do
54
+ ordered = subject.stop_points.sort { |a,b| a.position <=> b.position}
55
+
56
+ subject.arrival_stop_point_id.should == ordered.last.id
57
+ subject.departure_stop_point_id.should == ordered.first.id
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chouette::Line do
4
+
5
+ subject { Factory(:line) }
6
+
7
+ it { should validate_presence_of :network }
8
+ it { should validate_presence_of :company }
9
+
10
+ it { should validate_presence_of :registration_number }
11
+ it { should validate_uniqueness_of :registration_number }
12
+
13
+ it { should validate_presence_of :name }
14
+
15
+ # it { should validate_presence_of :objectid }
16
+ it { should validate_uniqueness_of :objectid }
17
+ its(:objectid) { should be_kind_of(Chouette::ObjectId) }
18
+
19
+ # it { should validate_numericality_of :objectversion }
20
+
21
+ describe ".last_stop_areas_parents" do
22
+
23
+ it "should return stop areas if no parents" do
24
+ line = Factory(:line_with_stop_areas)
25
+ line.stop_areas_last_parents.should == line.stop_areas
26
+ end
27
+
28
+ it "should return stop areas parents if parents" do
29
+ line = Factory(:line_with_stop_areas)
30
+ route = Factory(:route, :line => line)
31
+ parent = Factory(:stop_area)
32
+ stop_areas = [ Factory(:stop_area), Factory(:stop_area), Factory(:stop_area, :parent_id => parent.id) ]
33
+ stop_areas.each do |stop_area|
34
+ Factory(:stop_point, :stop_area => stop_area, :route => route)
35
+ end
36
+
37
+ line.stop_areas_last_parents.should =~ line.stop_areas[0..(line.stop_areas.size - 2)].push(parent)
38
+ end
39
+
40
+ end
41
+
42
+ describe "#stop_areas" do
43
+ let!(:route){Factory(:route, :line => subject)}
44
+ it "should retreive route's stop_areas" do
45
+ subject.stop_areas.count.should == route.stop_points.count
46
+ end
47
+ end
48
+
49
+ describe "#transport_mode" do
50
+
51
+ def self.legacy_transport_mode_names
52
+ %w{Air Train LongDistanceTrain LocalTrain RapidTransit Metro Tramway Coach Bus Ferry Waterborne PrivateVehicle Walk Trolleybus Bicycle Shuttle Taxi VAL Other}
53
+ end
54
+
55
+ legacy_transport_mode_names.each do |transport_mode_name|
56
+ context "when transport_mode_name is #{transport_mode_name}" do
57
+ transport_mode = Chouette::TransportMode.new(transport_mode_name.underscore)
58
+ it "should be #{transport_mode}" do
59
+ subject.transport_mode_name = transport_mode_name
60
+ subject.transport_mode.should == transport_mode
61
+ end
62
+ end
63
+ end
64
+ context "when transport_mode_name is nil" do
65
+ it "should be nil" do
66
+ subject.transport_mode_name = nil
67
+ subject.transport_mode.should be_nil
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ describe "#transport_mode=" do
74
+
75
+ it "should change transport_mode_name with TransportMode#name" do
76
+ subject.transport_mode = "Test"
77
+ subject.transport_mode_name.should == "Test"
78
+ end
79
+
80
+ end
81
+
82
+ describe ".transport_modes" do
83
+
84
+ it "should not include unknown transport_mode" do
85
+ Chouette::Line.transport_modes.should_not include(Chouette::TransportMode.new("unknown"))
86
+ end
87
+
88
+ it "should not include interchange transport_mode" do
89
+ Chouette::Line.transport_modes.should_not include(Chouette::TransportMode.new("interchange"))
90
+ end
91
+
92
+ end
93
+
94
+ context "#group_of_line_tokens=" do
95
+ let!(:group_of_line1){Factory(:group_of_line)}
96
+ let!(:group_of_line2){Factory(:group_of_line)}
97
+
98
+ it "should return associated group_of_line ids" do
99
+ subject.update_attributes :group_of_line_tokens => [group_of_line1.id, group_of_line2.id].join(',')
100
+ subject.group_of_lines.should include( group_of_line1)
101
+ subject.group_of_lines.should include( group_of_line2)
102
+ end
103
+ end
104
+
105
+
106
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chouette::Loader do
4
+
5
+ subject { Chouette::Loader.new("test") }
6
+
7
+ before(:each) do
8
+ subject.stub :execute! => true
9
+ end
10
+
11
+ describe "#load_dump" do
12
+
13
+ end
14
+
15
+ describe "#import" do
16
+
17
+ let(:chouette_command) { mock :run! => true }
18
+
19
+ before(:each) do
20
+ subject.stub :chouette_command => chouette_command
21
+ end
22
+
23
+ it "should use specified file in -inputFile option" do
24
+ chouette_command.should_receive(:run!).with(hash_including(:input_file => File.expand_path('file')))
25
+ subject.import "file"
26
+ end
27
+
28
+ it "should use specified format in -format option" do
29
+ chouette_command.should_receive(:run!).with(hash_including(:format => 'DUMMY'))
30
+ subject.import "file", :format => "dummy"
31
+ end
32
+
33
+ end
34
+
35
+ describe "#create" do
36
+
37
+ it "should quote schema name" do
38
+ subject.should_receive(:execute!).with(/"test"/)
39
+ subject.create
40
+ end
41
+
42
+ end
43
+
44
+ describe "#drop" do
45
+
46
+ it "should quote schema name" do
47
+ subject.should_receive(:execute!).with(/"test"/)
48
+ subject.drop
49
+ end
50
+
51
+ end
52
+
53
+ describe "#backup" do
54
+
55
+ let(:file) { "/dev/null" }
56
+
57
+ it "should call pg_dump" do
58
+ subject.should_receive(:execute!).with(/^pg_dump/)
59
+ subject.backup file
60
+ end
61
+
62
+ it "should dump in specified file" do
63
+ subject.should_receive(:execute!).with(/-f #{file}/)
64
+ subject.backup file
65
+ end
66
+ end
67
+
68
+ end
69
+
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chouette::Network do
4
+
5
+ subject { Factory(:network) }
6
+
7
+ it { should validate_presence_of :registration_number }
8
+ it { should validate_uniqueness_of :registration_number }
9
+
10
+ it { should validate_presence_of :name }
11
+
12
+ # it { should validate_presence_of :objectid }
13
+ it { should validate_uniqueness_of :objectid }
14
+
15
+ describe "#stop_areas" do
16
+ let!(:line){Factory(:line, :network => subject)}
17
+ let!(:route){Factory(:route, :line => line)}
18
+ it "should retreive route's stop_areas" do
19
+ subject.stop_areas.count.should == route.stop_points.count
20
+ end
21
+ end
22
+ end
@@ -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