aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/clean_up_spec.rb
diff options
context:
space:
mode:
authorXinhui2017-06-30 14:28:34 +0200
committerXinhui2017-06-30 14:28:34 +0200
commit5dc26b70870f34650b9d9df18e5447a379b67d10 (patch)
tree045dd2aeb105bb0ca906ec3a221350e27c6a1f67 /spec/models/clean_up_spec.rb
parent89d14a4813402d004d407d77fbd32846e367a7ac (diff)
downloadchouette-core-5dc26b70870f34650b9d9df18e5447a379b67d10.tar.bz2
Fix cleanup#destroy_time_tables should only destroy vehicle_journey of deleted time_tables
Refs #3917
Diffstat (limited to 'spec/models/clean_up_spec.rb')
-rw-r--r--spec/models/clean_up_spec.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/spec/models/clean_up_spec.rb b/spec/models/clean_up_spec.rb
index ee88ca773..4dc692ab2 100644
--- a/spec/models/clean_up_spec.rb
+++ b/spec/models/clean_up_spec.rb
@@ -200,9 +200,17 @@ RSpec.describe CleanUp, :type => :model do
end
it 'should destroy time_table vehicle_journey association' do
+ vj = create(:vehicle_journey, time_tables: [time_table, create(:time_table)])
+ cleaner.destroy_time_tables(Chouette::TimeTable.where(id: time_table.id))
+
+ expect(vj.reload.time_tables.map(&:id)).to_not include(time_table.id)
+ end
+
+ it 'should also destroy associated vehicle_journey if it belongs to any other time_table' do
vj = create(:vehicle_journey, time_tables: [time_table])
- cleaner.destroy_time_tables(Chouette::TimeTable.all)
- expect(vj.reload.time_tables).to be_empty
+ expect{cleaner.destroy_time_tables(Chouette::TimeTable.all)}.to change {
+ Chouette::VehicleJourney.count
+ }.by(-1)
end
end