diff options
| author | Robert | 2017-05-05 06:10:06 +0200 |
|---|---|---|
| committer | Robert | 2017-05-05 16:54:56 +0200 |
| commit | a732c120a9b4747d80bfe773cc70b4d4cc4f7d5b (patch) | |
| tree | 2e0a3dfaedcf8feff438482f3a4a3dae0db260fe | |
| parent | 5227470be41405a27b0cb02fd305401a942998f4 (diff) | |
| download | chouette-core-a732c120a9b4747d80bfe773cc70b4d4cc4f7d5b.tar.bz2 | |
Refs: #3297
- fix of RouteObserver#after_destroy (dead code right now, but see below)
- change specs to use Route#destroy in order to trigger `dependent: :destroy' in stop_points
(#delete does not work as stop_points is used in `has_many :stop_areas, through:', no doc found on this behavior, but #destroy is the advocated method to be used)
| -rw-r--r-- | app/models/route_observer.rb | 2 | ||||
| -rw-r--r-- | spec/models/chouette/route/route_delete_spec.rb | 12 |
2 files changed, 7 insertions, 7 deletions
diff --git a/app/models/route_observer.rb b/app/models/route_observer.rb index 71578c6da..e2217a75e 100644 --- a/app/models/route_observer.rb +++ b/app/models/route_observer.rb @@ -16,6 +16,6 @@ class RouteObserver < ActiveRecord::Observer def after_destroy(route) Rails.logger.debug "after_destroy(#{route.inspect})" - line.routes.where(opposite_route: route).update_all(opposite_route: nil) + route.line.routes.where(opposite_route: route).update_all(opposite_route_id: nil) end end diff --git a/spec/models/chouette/route/route_delete_spec.rb b/spec/models/chouette/route/route_delete_spec.rb index fa8a8a947..ccc14d8bb 100644 --- a/spec/models/chouette/route/route_delete_spec.rb +++ b/spec/models/chouette/route/route_delete_spec.rb @@ -9,23 +9,23 @@ RSpec.describe Chouette::Route, :type => :model do it "deletes the associated journey_patterns" do expected_delta = subject.journey_patterns.count expect( expected_delta ).to be_positive - expect{ subject.delete }.to change{Chouette::JourneyPattern.count}.by -expected_delta + expect{ subject.destroy }.to change{Chouette::JourneyPattern.count}.by -expected_delta end it "deletes the associated stop_points" do expected_delta = subject.stop_points.count expect( expected_delta ).to be_positive - expect{ subject.delete }.to change{Chouette::StopPoint.count}.by -expected_delta + expect{ subject.destroy }.to change{Chouette::StopPoint.count}.by -expected_delta end it "does not delete the associated stop_areas" do count = subject.stop_points.count expect( count ).to be_positive - expect{ subject.delete }.not_to change{Chouette::StopArea.count} + expect{ subject.destroy }.not_to change{Chouette::StopArea.count} end it "deletes the associated vehicle_journeys" do - expect{ vehicle_journey.route.delete }.to change{Chouette::VehicleJourney.count}.by -1 + expect{ vehicle_journey.route.destroy}.to change{Chouette::VehicleJourney.count}.by -1 end it "does not delete the corresponding time_tables" do @@ -33,12 +33,12 @@ RSpec.describe Chouette::Route, :type => :model do tt.vehicle_journeys << vehicle_journey tables = vehicle_journey.route.time_tables expect( tables ).not_to be_empty - expect{ vehicle_journey.route.delete }.not_to change{Chouette::TimeTable.count} + expect{ vehicle_journey.route.destroy }.not_to change{Chouette::TimeTable.count} end it "does not delete the associated line" do expect( subject.line ).not_to be_nil - expect{ subject.delete }.not_to change{Chouette::Line.count} + expect{ subject.destroy }.not_to change{Chouette::Line.count} end end end |
