diff options
| author | Xinhui | 2016-11-14 14:35:43 +0100 |
|---|---|---|
| committer | Xinhui | 2016-11-14 16:04:52 +0100 |
| commit | 5127276d9a9ca17165d36b1feec71792b3338e5c (patch) | |
| tree | 5e2ab040a0c8c48cdf93882518f22982cd4154ee /spec | |
| parent | 23e9efc8e07920b50a3f86c26c19e4e6ea340f13 (diff) | |
| download | chouette-core-5127276d9a9ca17165d36b1feec71792b3338e5c.tar.bz2 | |
Wip refactoring cleanup model
Refs #1933
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/factories/clean_ups.rb | 15 | ||||
| -rw-r--r-- | spec/models/clean_up_spec.rb | 31 | ||||
| -rw-r--r-- | spec/workers/clean_up_worker_spec.rb | 4 |
3 files changed, 43 insertions, 7 deletions
diff --git a/spec/factories/clean_ups.rb b/spec/factories/clean_ups.rb new file mode 100644 index 000000000..41165ac16 --- /dev/null +++ b/spec/factories/clean_ups.rb @@ -0,0 +1,15 @@ +FactoryGirl.define do + factory :clean_up do + status "MyString" +started_at "2016-11-14 14:45:18" +ended_at "2016-11-14 14:45:18" +referential nil +keep_lines false +keep_stops false +keep_companies false +keep_networks false +keep_group_of_lines false +expected_date "2016-11-14 14:45:18" + end + +end diff --git a/spec/models/clean_up_spec.rb b/spec/models/clean_up_spec.rb index d633443ba..e603b09b0 100644 --- a/spec/models/clean_up_spec.rb +++ b/spec/models/clean_up_spec.rb @@ -1,41 +1,58 @@ -require 'spec_helper' +require 'rails_helper' -describe CleanUp, :type => :model do +RSpec.describe CleanUp, :type => :model do let(:cleaner) { CleanUp.new } + 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.physical_stop_areas.count).to eq 2 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.vehicle_journeys.count).to eq 2 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.lines.count).to eq 2 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.routes.count).to eq 2 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)) - expect(cleaner.journey_patterns.count).to eq 2 expect(cleaner.clean_journey_patterns).to eq 2 end end diff --git a/spec/workers/clean_up_worker_spec.rb b/spec/workers/clean_up_worker_spec.rb new file mode 100644 index 000000000..e85768fa3 --- /dev/null +++ b/spec/workers/clean_up_worker_spec.rb @@ -0,0 +1,4 @@ +require 'rails_helper' +RSpec.describe CleanUpWorker, type: :worker do + pending "add some examples to (or delete) #{__FILE__}" +end |
