ninoxe 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
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,121 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chouette::ActiveRecord do
4
+
5
+ it { Chouette::ActiveRecord.ancestors.should include(ActiveRecord::Base) }
6
+
7
+ describe "table_name" do
8
+
9
+ it "should return line for Chouette::Line" do
10
+ Chouette::Line.table_name.should == "lines"
11
+ end
12
+
13
+ it "should return ptnetwork for Chouette::Network" do
14
+ Chouette::Network.table_name.should == "networks"
15
+ end
16
+
17
+ it "should return timetable_date for Chouette::TimeTableDate" do
18
+ Chouette::TimeTableDate.table_name.should == "time_table_dates"
19
+ end
20
+
21
+ it "should return timetable_period for Chouette::TimeTablePeriod" do
22
+ Chouette::TimeTablePeriod.table_name.should == "time_table_periods"
23
+ end
24
+
25
+ end
26
+
27
+ describe "method_missing" do
28
+
29
+ it "should support method with additionnal underscores" do
30
+ stop_area = Chouette::StopArea.new
31
+ stop_area.area_type.should == stop_area.area_type
32
+ end
33
+
34
+ end
35
+
36
+
37
+ describe "respond_to?" do
38
+
39
+ it "should respond to method with additionnal underscores" do
40
+ stop_area = Chouette::StopArea.new
41
+ stop_area.respond_to?(:area_type).should be_true
42
+ end
43
+
44
+ end
45
+
46
+ describe "create_reflection" do
47
+
48
+ let(:macro) { :has_many }
49
+ let(:name) { :lines }
50
+ let(:options) { {} }
51
+ let(:active_record) { Chouette::Network }
52
+
53
+ let(:modified_options) { {:modified => true} }
54
+
55
+ it "should invoke create_reflection_without_chouette_naming with modified options" do
56
+ Chouette::ActiveRecord::Reflection.stub :new => mock(:options_with_default => modified_options)
57
+ Chouette::ActiveRecord.should_receive(:create_reflection_without_chouette_naming).with macro, name, modified_options, active_record
58
+
59
+ Chouette::ActiveRecord.create_reflection macro, name, options, active_record
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+
66
+ describe Chouette::ActiveRecord::Reflection do
67
+
68
+ let(:macro) { :has_many }
69
+ let(:name) { :lines }
70
+ let(:options) { {} }
71
+ let(:active_record) { Chouette::Network }
72
+
73
+ subject { Chouette::ActiveRecord::Reflection.new macro, name, options, active_record }
74
+
75
+ describe "collection?" do
76
+
77
+ it "should be true when macro is has_many" do
78
+ subject.stub :macro => :has_many
79
+ subject.should be_collection
80
+ end
81
+
82
+ it "should be false when macro is belongs_to" do
83
+ subject.stub :macro => :belong_to
84
+ subject.should_not be_collection
85
+ end
86
+
87
+ end
88
+
89
+ describe "class_name" do
90
+
91
+ it "should be Chouette::Line when name is line" do
92
+ subject.stub :name => "line"
93
+ subject.class_name.should == "Chouette::Line"
94
+ end
95
+
96
+ it "should be Chouette::Routes when name is routes and reflection is a collection" do
97
+ subject.stub :name => "routes", :collection? => true
98
+ subject.class_name.should == "Chouette::Route"
99
+ end
100
+
101
+ end
102
+
103
+
104
+ describe "options" do
105
+
106
+ it "should define class_name if not" do
107
+ subject.stub :options => {}, :class_name => "class_name"
108
+ subject.options_with_default[:class_name].should == "class_name"
109
+ end
110
+
111
+ it "should not define class_name if presents" do
112
+ subject.stub :options => {:class_name => "dummy"}
113
+ subject.options_with_default[:class_name].should == "dummy"
114
+ end
115
+
116
+ end
117
+
118
+
119
+ end
120
+
121
+
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chouette::AreaType do
4
+
5
+ def mode(text_code = "test", numerical_code = nil)
6
+ numerical_code ||= 1 if text_code == "test"
7
+ Chouette::AreaType.new(text_code, numerical_code)
8
+ end
9
+
10
+ describe "#to_i" do
11
+
12
+ it "should return numerical code" do
13
+ mode("test", 1).to_i.should == 1
14
+ end
15
+
16
+ end
17
+
18
+ it "should return true to #test? when text code is 'test'" do
19
+ mode("test").should be_test
20
+ end
21
+
22
+ it "should be equal when text codes are identical" do
23
+ mode("test",1).should == mode("test", 2)
24
+ end
25
+
26
+ describe ".new" do
27
+
28
+ it "should find numerical code from text code" do
29
+ mode("boarding_position").to_i.should == 0
30
+ end
31
+
32
+ it "should find text code from numerical code" do
33
+ mode(0).should == "boarding_position"
34
+ end
35
+
36
+ it "should accept another mode" do
37
+ Chouette::AreaType.new(mode("test")).should == mode("test")
38
+ end
39
+
40
+ end
41
+
42
+
43
+ describe ".all" do
44
+
45
+ Chouette::AreaType.definitions.each do |text_code, numerical_code|
46
+ it "should include a AreaType #{text_code}" do
47
+ Chouette::AreaType.all.should include(Chouette::AreaType.new(text_code))
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chouette::Company do
4
+
5
+ subject { Factory(:company) }
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 "#nullables empty" do
16
+ it "should set null empty nullable attributes" do
17
+ subject.organizational_unit = ''
18
+ subject.operating_department_name = ''
19
+ subject.code = ''
20
+ subject.phone = ''
21
+ subject.fax = ''
22
+ subject.email = ''
23
+ subject.nil_if_blank
24
+ subject.organizational_unit.should be_nil
25
+ subject.operating_department_name.should be_nil
26
+ subject.code.should be_nil
27
+ subject.phone.should be_nil
28
+ subject.fax.should be_nil
29
+ subject.email.should be_nil
30
+ end
31
+ end
32
+
33
+ describe "#nullables non empty" do
34
+ it "should not set null non epmty nullable attributes" do
35
+ subject.organizational_unit = 'a'
36
+ subject.operating_department_name = 'b'
37
+ subject.code = 'c'
38
+ subject.phone = 'd'
39
+ subject.fax = 'z'
40
+ subject.email = 'r'
41
+ subject.nil_if_blank
42
+ subject.organizational_unit.should_not be_nil
43
+ subject.operating_department_name.should_not be_nil
44
+ subject.code.should_not be_nil
45
+ subject.phone.should_not be_nil
46
+ subject.fax.should_not be_nil
47
+ subject.email.should_not be_nil
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chouette::ConnectionLink 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
+ subject { Factory(:connection_link) }
10
+
11
+ it { should validate_uniqueness_of :objectid }
12
+ its(:objectid) { should be_kind_of(Chouette::ObjectId) }
13
+
14
+ it { should validate_presence_of :name }
15
+
16
+ describe "#connection_link_type" do
17
+
18
+ def self.legacy_link_types
19
+ %w{Underground Mixed Overground}
20
+ end
21
+
22
+ legacy_link_types.each do |link_type|
23
+ context "when link_type is #{link_type}" do
24
+ connection_link_type = Chouette::ConnectionLinkType.new(link_type.underscore)
25
+ it "should be #{connection_link_type}" do
26
+ subject.link_type = link_type
27
+ subject.connection_link_type.should == connection_link_type
28
+ end
29
+ end
30
+ end
31
+ context "when link_type is nil" do
32
+ it "should be nil" do
33
+ subject.link_type = nil
34
+ subject.connection_link_type.should be_nil
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ describe "#connection_link_type=" do
41
+
42
+ it "should change link_type with ConnectionLinkType#name" do
43
+ subject.connection_link_type = "Test"
44
+ subject.link_type.should == "Test"
45
+ end
46
+
47
+ end
48
+
49
+ describe ".possible_areas" do
50
+
51
+ it "should not find areas type ITL" do
52
+ subject.possible_areas.should_not == [itl]
53
+ end
54
+ end
55
+
56
+ end
@@ -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