diff options
| -rw-r--r-- | app/models/clean_up.rb | 63 | ||||
| -rw-r--r-- | db/migrate/20161115141458_remove_keep_lines_from_clean_ups.rb | 5 | ||||
| -rw-r--r-- | db/migrate/20161115141525_remove_keep_stops_from_clean_ups.rb | 5 | ||||
| -rw-r--r-- | db/migrate/20161115141541_remove_keep_companies_from_clean_ups.rb | 5 | ||||
| -rw-r--r-- | db/migrate/20161115141559_remove_keep_networks_from_clean_ups.rb | 5 | ||||
| -rw-r--r-- | db/migrate/20161115141625_remove_keep_group_of_lines_from_clean_ups.rb | 5 | ||||
| -rw-r--r-- | db/schema.rb | 9 | ||||
| -rw-r--r-- | spec/models/clean_up_spec.rb | 38 | 
8 files changed, 26 insertions, 109 deletions
| diff --git a/app/models/clean_up.rb b/app/models/clean_up.rb index 986fbdd24..7b4af2fd6 100644 --- a/app/models/clean_up.rb +++ b/app/models/clean_up.rb @@ -36,8 +36,6 @@ class CleanUp < ActiveRecord::Base    end    def clean -    # as foreign keys are presents , delete method can be used for faster performance -    # find and remove time_tables      result = CleanUpResult.new      tms = Chouette::TimeTable.validity_out_from_on?(expected_date)      result.time_table_count = tms.size @@ -45,77 +43,16 @@ class CleanUp < ActiveRecord::Base      result.vehicle_journey_count = self.clean_vehicle_journeys      result.journey_pattern_count = self.clean_journey_patterns -    result.route_count           = self.clean_routes -    result.line_count            = self.clean_lines unless keep_lines - -    unless keep_stops -      result.stop_count += self.clean_physical_stop_areas -      result.stop_count += self.clean_commercial_stop_areas -      result.stop_count += self.clean_stop_place_stop_areas -      result.stop_count += self.clean_itl_stop_areas -    end - -    # If asked remove companies without lines or vehicle journeys -    result.company_count       = self.clean_companies unless keep_companies -    # If asked remove networks without lines -    result.network_count       = self.clean_networks unless keep_networks -    # If asked remove group_of_lines without lines -    result.group_of_line_count = self.clean_group_of_lines unless keep_group_of_lines      result    end -  def clean_physical_stop_areas -    ids = Chouette::StopArea.physical.includes(:stop_points).where(:stop_points => {id: nil}).pluck(:id) -    Chouette::StopArea.physical.where(id: ids).delete_all -  end - -  def clean_commercial_stop_areas -    ids = Chouette::StopArea.commercial.where.not(parent_id: nil).pluck(:parent_id) -    Chouette::StopArea.commercial.where.not(id: ids).delete_all -  end - -  def clean_stop_place_stop_areas -    ids = Chouette::StopArea.stop_place.includes(:stop_points).where(:stop_points => {id: nil}).pluck(:id) -    Chouette::StopArea.stop_place.where(id: ids).delete_all -  end - -  def clean_itl_stop_areas -    ids = Chouette::StopArea.itl.includes(:stop_points).where(:stop_points => {id: nil}).pluck(:id) -    Chouette::StopArea.itl.where(id: ids).delete_all -  end -    def clean_vehicle_journeys      ids = Chouette::VehicleJourney.includes(:time_tables).where(:time_tables => {id: nil}).pluck(:id)      Chouette::VehicleJourney.where(id: ids).delete_all    end -  def clean_lines -    ids = Chouette::Line.includes(:routes).where(:routes => {id: nil}).pluck(:id) -    Chouette::Line.where(id: ids).delete_all -  end - -  def clean_routes -    ids = Chouette::Route.includes(:journey_patterns).where(:journey_patterns => {id: nil}).pluck(:id) -    Chouette::Route.where(id: ids).delete_all -  end -    def clean_journey_patterns      ids = Chouette::JourneyPattern.includes(:vehicle_journeys).where(:vehicle_journeys => {id: nil}).pluck(:id)      Chouette::JourneyPattern.where(id: ids).delete_all    end - -  def clean_companies -    ids = Chouette::Company.includes(:lines).where(:lines => {id: nil}).pluck(:id) -    Chouette::Company.where(id: ids).delete_all -  end - -  def clean_networks -    ids = Chouette::Network.includes(:lines).where(:lines => {id: nil}).pluck(:id) -    Chouette::Network.where(id: ids).delete_all -  end - -  def clean_group_of_lines -    ids = Chouette::GroupOfLine.includes(:lines).where(:lines => {id: nil}).pluck(:id) -    Chouette::GroupOfLine.where(id: ids).delete_all -  end  end diff --git a/db/migrate/20161115141458_remove_keep_lines_from_clean_ups.rb b/db/migrate/20161115141458_remove_keep_lines_from_clean_ups.rb new file mode 100644 index 000000000..08337a72a --- /dev/null +++ b/db/migrate/20161115141458_remove_keep_lines_from_clean_ups.rb @@ -0,0 +1,5 @@ +class RemoveKeepLinesFromCleanUps < ActiveRecord::Migration +  def change +    remove_column :clean_ups, :keep_lines, :boolean +  end +end diff --git a/db/migrate/20161115141525_remove_keep_stops_from_clean_ups.rb b/db/migrate/20161115141525_remove_keep_stops_from_clean_ups.rb new file mode 100644 index 000000000..8a322d43f --- /dev/null +++ b/db/migrate/20161115141525_remove_keep_stops_from_clean_ups.rb @@ -0,0 +1,5 @@ +class RemoveKeepStopsFromCleanUps < ActiveRecord::Migration +  def change +    remove_column :clean_ups, :keep_stops, :boolean +  end +end diff --git a/db/migrate/20161115141541_remove_keep_companies_from_clean_ups.rb b/db/migrate/20161115141541_remove_keep_companies_from_clean_ups.rb new file mode 100644 index 000000000..3a9865071 --- /dev/null +++ b/db/migrate/20161115141541_remove_keep_companies_from_clean_ups.rb @@ -0,0 +1,5 @@ +class RemoveKeepCompaniesFromCleanUps < ActiveRecord::Migration +  def change +    remove_column :clean_ups, :keep_companies, :boolean +  end +end diff --git a/db/migrate/20161115141559_remove_keep_networks_from_clean_ups.rb b/db/migrate/20161115141559_remove_keep_networks_from_clean_ups.rb new file mode 100644 index 000000000..9f88d0edd --- /dev/null +++ b/db/migrate/20161115141559_remove_keep_networks_from_clean_ups.rb @@ -0,0 +1,5 @@ +class RemoveKeepNetworksFromCleanUps < ActiveRecord::Migration +  def change +    remove_column :clean_ups, :keep_networks, :boolean +  end +end diff --git a/db/migrate/20161115141625_remove_keep_group_of_lines_from_clean_ups.rb b/db/migrate/20161115141625_remove_keep_group_of_lines_from_clean_ups.rb new file mode 100644 index 000000000..b188ff194 --- /dev/null +++ b/db/migrate/20161115141625_remove_keep_group_of_lines_from_clean_ups.rb @@ -0,0 +1,5 @@ +class RemoveKeepGroupOfLinesFromCleanUps < ActiveRecord::Migration +  def change +    remove_column :clean_ups, :keep_group_of_lines, :boolean +  end +end diff --git a/db/schema.rb b/db/schema.rb index 0ff2c72a6..8029464f5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@  #  # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161114134518) do +ActiveRecord::Schema.define(version: 20161115141625) do    # These are extensions that must be enabled in order to support this database    enable_extension "plpgsql" @@ -82,11 +82,6 @@ ActiveRecord::Schema.define(version: 20161114134518) do      t.datetime "started_at"      t.datetime "ended_at"      t.integer  "referential_id" -    t.boolean  "keep_lines" -    t.boolean  "keep_stops" -    t.boolean  "keep_companies" -    t.boolean  "keep_networks" -    t.boolean  "keep_group_of_lines"      t.datetime "expected_date"      t.datetime "created_at"      t.datetime "updated_at" @@ -740,8 +735,6 @@ ActiveRecord::Schema.define(version: 20161114134518) do    add_index "workbenches", ["stop_area_referential_id"], :name => "index_workbenches_on_stop_area_referential_id"    Foreigner.load -  add_foreign_key "access_links", "access_points", name: "aclk_acpt_fkey", dependent: :delete -    add_foreign_key "group_of_lines_lines", "group_of_lines", name: "groupofline_group_fkey", dependent: :delete    add_foreign_key "journey_frequencies", "timebands", name: "journey_frequencies_timeband_id_fk", dependent: :nullify diff --git a/spec/models/clean_up_spec.rb b/spec/models/clean_up_spec.rb index e603b09b0..583e28136 100644 --- a/spec/models/clean_up_spec.rb +++ b/spec/models/clean_up_spec.rb @@ -6,50 +6,12 @@ RSpec.describe CleanUp, :type => :model do    it { should validate_presence_of(:expected_date) }    it { should belong_to(:referential) } -  it 'should convert initialize attribute to boolean' do -    params  = { keep_lines: "0", keep_stops: "1" } -    cleaner = CleanUp.new(params) -    expect(cleaner.keep_lines).to eq false -    expect(cleaner.keep_stops).to eq true -  end - -  it 'should delete group of line without lines' do -    create_list(:group_of_line, 2) -    create_list(:line, 2, group_of_lines: [create(:group_of_line)]) -    expect(cleaner.clean_group_of_lines).to eq 2 -  end - -  it 'should delete company without lines' do -    create_list(:company, 2) -    create_list(:line, 2) -    expect(cleaner.clean_companies).to eq 2 -  end - -  it 'should delete physical stop_areas without stop_points' do -    create_list(:stop_area, 2) -    create_list(:stop_point, 2) -    Chouette::StopArea.update_all(area_type: "Quay") -    expect(cleaner.clean_physical_stop_areas).to eq 2 -  end -    it 'should delete vehiclejourneys without timetables' do      create_list(:vehicle_journey, 2)      create_list(:vehicle_journey, 2, time_tables:[create(:time_table)])      expect(cleaner.clean_vehicle_journeys).to eq 2    end -  it 'should delete lines without routes' do -    create_list(:line, 2) -    create_list(:route, 2, line: create(:line)) -    expect(cleaner.clean_lines).to eq 2 -  end - -  it 'should delete routes without journeypatterns' do -    create_list(:route, 2) -    create_list(:journey_pattern, 2, route: create(:route)) -    expect(cleaner.clean_routes).to eq 2 -  end -    it 'should delete journeypatterns without vehicle journeys' do      create_list(:journey_pattern, 2)      create_list(:vehicle_journey, 2, journey_pattern: create(:journey_pattern)) | 
