diff options
| author | Luc Donnet | 2017-12-08 07:26:33 +0100 |
|---|---|---|
| committer | Luc Donnet | 2017-12-08 07:26:33 +0100 |
| commit | aa5d50a20bbd07a3b526a20e24474629544a1dbc (patch) | |
| tree | 9e46039a2c81d148d0b01847cb77cd8ef8d455df | |
| parent | 597b8eb21fe64babeb4a3ea03b1367c371237d98 (diff) | |
| parent | 8680f61e8bd0a9cde4b3fa5d438fc86476daae56 (diff) | |
| download | chouette-core-aa5d50a20bbd07a3b526a20e24474629544a1dbc.tar.bz2 | |
Merge branch 'master' into staging
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | app/models/import.rb | 47 | ||||
| -rw-r--r-- | spec/models/import_spec.rb | 22 |
3 files changed, 41 insertions, 32 deletions
@@ -3,7 +3,7 @@ Chouette2 is an open source web project in Ruby/Rails to edit and view transport offer data. It is designed as an [SaaS](http://en.wikipedia.org/wiki/Software_as_a_service) platform and can : * Exchange transport data : [Neptune](http://www.normes-donnees-tc.org/format-dechange/donnees-theoriques/neptune/), [GTFS](https://developers.google.com/transit/gtfs/reference?hl=fr), [NeTEx](http://www.normes-donnees-tc.org/format-dechange/donnees-theoriques/netex/), CSV * Edit transport data -* Be requested via a read-only [Restful API](https://en.wikipedia.org/wiki/Representational_state_transfer) +* Be requested via a read-only [Restful API](https://en.wikipedia.org/wiki/Representational_state_transfer) * [Import, Export and Validate transport data asynchronously](http://github.com/afimb/chouette) * Use a [multi-tenancy database](http://en.wikipedia.org/wiki/Multitenancy) @@ -44,6 +44,7 @@ sudo apt-get install unzip sudo apt-get install proj-bin sudo apt-get install libproj-dev sudo apt-get install make +sudo apt-get install libmagic-dev ``` If Linux distribution doesn't publish an RVM package, @@ -192,4 +193,3 @@ Credits ------- Thanks to Ingolf for his [photo](https://www.flickr.com/photos/ingolfbln/7663851694) under CC BY-SA 2.0 license - diff --git a/app/models/import.rb b/app/models/import.rb index 20e7f2d8a..19e835986 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -14,7 +14,7 @@ class Import < ActiveRecord::Base end extend Enumerize - enumerize :status, in: %i(new pending successful warning failed running aborted canceled), scope: true, default: :new + enumerize :status, in: %w(new pending successful warning failed running aborted canceled), scope: true, default: :new validates :name, presence: true validates :file, presence: true @@ -28,15 +28,19 @@ class Import < ActiveRecord::Base end def children_succeedeed - children.with_status(:successful).count + children.with_status(:successful, :warning).count end - def self.failing_statuses - symbols_with_indifferent_access(%i(failed aborted canceled)) + def self.launched_statuses + %w(new pending) + end + + def self.failed_statuses + %w(failed aborted canceled) end def self.finished_statuses - symbols_with_indifferent_access(%i(successful failed warning aborted canceled)) + %w(successful failed warning aborted canceled) end def notify_parent @@ -52,35 +56,25 @@ class Import < ActiveRecord::Base end def update_status - status_count = children.group(:status).count - children_finished_count = children_failed_count = children_count = 0 - - status_count.each do |status, count| - if self.class.failing_statuses.include?(status) - children_failed_count += count - end - if self.class.finished_statuses.include?(status) - children_finished_count += count - end - children_count += count - end - - attributes = { - current_step: children_finished_count - } - status = - if children_failed_count > 0 + if children.where(status: self.class.failed_statuses).count > 0 'failed' - elsif status_count['successful'] == children_count + elsif children.where(status: "warning").count > 0 + 'warning' + elsif children.where(status: "successful").count == children.count 'successful' end + attributes = { + current_step: children.count, + status: status + } + if self.class.finished_statuses.include?(status) attributes[:ended_at] = Time.now end - update attributes.merge(status: status) + update attributes end def update_referentials @@ -97,7 +91,4 @@ class Import < ActiveRecord::Base self.token_download = SecureRandom.urlsafe_base64 end - def self.symbols_with_indifferent_access(array) - array.flat_map { |symbol| [symbol, symbol.to_s] } - end end diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 4e8aac3f4..3e4128865 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -128,7 +128,7 @@ RSpec.describe Import, type: :model do it "updates :status to successful when all children are successful" do workbench_import = create(:workbench_import) - create_list( + imports = create_list( :netex_import, 2, parent: workbench_import, @@ -140,7 +140,7 @@ RSpec.describe Import, type: :model do expect(workbench_import.status).to eq('successful') end - it "Updates :status to failed when any child has failed" do + it "updates :status to failed when any child has failed" do workbench_import = create(:workbench_import) [ 'failed', @@ -158,6 +158,24 @@ RSpec.describe Import, type: :model do expect(workbench_import.status).to eq('failed') end + it "updates :status to warning when any child has warning or successful" do + workbench_import = create(:workbench_import) + [ + 'warning', + 'successful' + ].each do |status| + create( + :netex_import, + parent: workbench_import, + status: status + ) + end + + workbench_import.update_status + + expect(workbench_import.status).to eq('warning') + end + it "updates :ended_at to now when status is finished" do workbench_import = create(:workbench_import) create( |
